1 20 21 package org.snmp4j.util; 22 23 import java.util.EventObject ; 24 import org.snmp4j.PDU; 25 import org.snmp4j.smi.VariableBinding; 26 import java.util.Arrays ; 27 28 36 public abstract class RetrievalEvent extends EventObject { 37 38 41 public static final int STATUS_OK = 0; 42 45 public static final int STATUS_TIMEOUT = -1; 46 49 public static final int STATUS_WRONG_ORDER = -2; 50 54 public static final int STATUS_REPORT = -3; 55 59 public static final int STATUS_EXCEPTION = -4; 60 61 protected VariableBinding[] vbs; 62 protected int status = STATUS_OK; 63 protected Object userObject; 64 protected Exception exception; 65 protected PDU reportPDU; 66 67 protected RetrievalEvent(Object source, Object userObject) { 68 super(source); 69 this.userObject = userObject; 70 } 71 72 81 public RetrievalEvent(Object source, Object userObject, int status) { 82 this(source, userObject); 83 this.status = status; 84 } 85 86 95 public RetrievalEvent(Object source, Object userObject, Exception exception) { 96 this(source, userObject); 97 this.exception = exception; 98 this.status = STATUS_EXCEPTION; 99 } 100 101 110 public RetrievalEvent(Object source, Object userObject, PDU report) { 111 this(source, userObject); 112 this.reportPDU = report; 113 this.status = STATUS_REPORT; 114 } 115 116 126 public RetrievalEvent(Object source, Object userObject, 127 VariableBinding[] variableBindings) { 128 this(source, userObject); 129 this.vbs = variableBindings; 130 } 131 132 139 public int getStatus() { 140 return status; 141 } 142 143 148 public boolean isError() { 149 return (status != STATUS_OK); 150 } 151 152 159 public Object getUserObject() { 160 return userObject; 161 } 162 163 170 public Exception getException() { 171 return exception; 172 } 173 174 181 public PDU getReportPDU() { 182 return reportPDU; 183 } 184 185 190 public String getErrorMessage() { 191 switch (status) { 192 case STATUS_EXCEPTION: { 193 return exception.getMessage(); 194 } 195 case STATUS_REPORT: { 196 return "Report: "+reportPDU.get(0); 197 } 198 case STATUS_TIMEOUT: { 199 return "Request timed out."; 200 } 201 case STATUS_WRONG_ORDER: { 202 return "Agent did not return variable bindings in lexicographic order."; 203 } 204 default: { 205 return ""; 206 } 207 } 208 } 209 210 public String toString() { 211 return getClass().getName()+"[vbs="+Arrays.asList(vbs)+ 212 ",status="+status+",exception="+ 213 exception+",report="+reportPDU+"]"; 214 } 215 216 } 217 | Popular Tags |