1 20 21 package org.snmp4j; 22 23 import org.snmp4j.smi.Address; 24 import org.snmp4j.mp.SnmpConstants; 25 26 38 public abstract class AbstractTarget implements Target { 39 40 private Address address; 41 private int version = SnmpConstants.version3; 42 private int retries = 0; 43 private long timeout = 1000; 44 private int maxSizeRequestPDU = 65535; 45 46 49 protected AbstractTarget() { 50 } 51 52 57 protected AbstractTarget(Address address) { 58 this.address = address; 59 } 60 61 66 public Address getAddress() { 67 return address; 68 } 69 70 75 public void setAddress(Address address) { 76 this.address = address; 77 } 78 79 88 public void setVersion(int version) { 89 this.version = version; 90 } 91 92 100 public int getVersion() { 101 return version; 102 } 103 104 110 public void setRetries(int retries) { 111 if (retries < 0) { 112 throw new IllegalArgumentException ("Number of retries < 0"); 113 } 114 this.retries = retries; 115 } 116 117 122 public int getRetries() { 123 return retries; 124 } 125 126 132 public void setTimeout(long timeout) { 133 this.timeout = timeout; 134 } 135 136 141 public long getTimeout() { 142 return timeout; 143 } 144 145 152 public int getMaxSizeRequestPDU() { 153 return maxSizeRequestPDU; 154 } 155 156 162 public void setMaxSizeRequestPDU(int maxSizeRequestPDU) { 163 if (maxSizeRequestPDU < SnmpConstants.MIN_PDU_LENGTH) { 164 throw new IllegalArgumentException ("The minimum PDU length is: "+ 165 SnmpConstants.MIN_PDU_LENGTH); 166 } 167 this.maxSizeRequestPDU = maxSizeRequestPDU; 168 } 169 170 protected String toStringAbstractTarget() { 171 return "address="+getAddress()+", version="+version+ 172 ", timeout="+timeout+", retries="+retries; 173 } 174 175 public String toString() { 176 return getClass().getName()+"["+toStringAbstractTarget()+"]"; 177 } 178 179 public Object clone() { 180 try { 181 return super.clone(); 182 } 183 catch (CloneNotSupportedException ex) { 184 return null; 185 } 186 } 187 } 188 189 | Popular Tags |