com.sun.jaw.snmp.manager
Class SnmpPeer

java.lang.Object
  |
  +--com.sun.jaw.snmp.manager.SnmpPeer

public class SnmpPeer
extends java.lang.Object
implements java.io.Serializable

This class holds information about a SNMP agent. Such information is used to communicate with the agent. These are the IP address, port number, SNMP parameters, and peer channel parameters (such as the maximum request packet size, maximum number of varbinds in a packet, retries, and timeouts). Changing these would affect all active requests.

The class contains the following properties:

JavaBean compliant getters and setters allow to modify the properties listed above.

See Also:
SnmpSession, SnmpRequest, SnmpParameters, SnmpConst, Serialized Form

Field Summary
protected  int maxRetries
          Number of times to retry before giving up.
protected  int maxSnmpPacketSize
          Maximum packet size of Request PDU.
protected  int maxVarbindLimit
          Maximum number of OIDs which can be encoded in a single request packet.
protected  SnmpPduFactoryIf pduFactory
          The PDU factory.
protected  int portNum
          Port number of the destination host.
protected  int timeout
          The amount of time to wait for a response from the peer.
 
Constructor Summary
SnmpPeer(java.net.InetAddress netaddr)
          Creates an SNMP peer object for a device.
SnmpPeer(java.lang.String host)
          Creates an SNMP peer object for a device.
SnmpPeer(java.lang.String host, int port)
          Creates an SNMP peer object for a device with the specified port.
 
Method Summary
 boolean allowSnmpSets()
          Determines if a SNMP set operation is allowed using this peer object.
 boolean equals(java.lang.Object obj)
          Compares the two peer objects to determine if they are the same.
 void finalize()
          Sets all the references to the SnmpPeer object to null.
 long getAvgRtt()
          Gets the average round trip time for a packet with the peer.
 java.net.InetAddress getDestAddr()
          Gets the InetAddress object for this peer.
 java.net.InetAddress[] getDestAddrList()
          Gets the list of alternate InetAddress configured for this peer.
 int getDestPort()
          Gets the destination port number of the peer to which SNMP requests are to be sent.
 java.lang.String getDevName()
          Gets the name specified in the constructor while creating this object.
 int getMaxRetries()
          Gets the number of times to retry before giving up.
 long getMaxRtt()
          Gets the maximum round trip time for a packet with the peer.
 int getMaxSnmpPktSize()
          Gets the maximum request packet size that is currently used.
 long getMinRtt()
          Gets the minimum round trip time for a packet with the peer.
 SnmpPduFactoryIf getPduFactory()
          Gets the PDU factory.
 SnmpParameters getSnmpParam()
          Gets the SnmpParameter object associated with the peer.
 int getTimeout()
          Gets the timeout to wait for a response from the peer.
 int getVarbindLimit()
          Gets the maximum number of varbinds that can be sent to a peer.
 java.lang.String ipAddressInUse()
          Returns the dot-formatted IP address string (for example 171.69.220.224).
 void setDestPort(int newPort)
          Changes the port address of the destination for the request.
 void setMaxRetries(int newMaxRetries)
          Changes the maximun number of times to retry before giving up.
 void setMaxSnmpPktSize(int newsize)
          Configures the maximum packet size that can be used when generating an SNMP request.
 void setPduFactory(SnmpPduFactoryIf factory)
          Sets the PDU factory.
 void setSnmpParam(SnmpParameters param)
          Sets the SnmpParameter object associated with the peer.
 void setTimeout(int newTimeout)
          Changes the timeout to wait for a response from the peer.
 void setVarbindLimit(int limit)
          Configures the maximum number of varbinds that can be sent to a peer.
 java.lang.String toString()
          Returns the string representation for this SnmpPeer.
 void useAddressList(java.net.InetAddress[] adrList)
          Specifies the list of address to be used.
 void useIPAddress(java.lang.String ipaddr)
          Sets a specific IP address where the peer will communicate.
 void useNextAddress()
          Causes all subsequent requests to go to the new address that is obtained from the specified list of alternate addresses.
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

portNum

protected int portNum
Port number of the destination host. The default port is 161.

maxVarbindLimit

protected int maxVarbindLimit
Maximum number of OIDs which can be encoded in a single request packet. This is set by the user. A request which contains more than this limit will be automatically split into multiple request. Typically used when multiplexing requests. The default value is SnmpConst.MAX_VARBIND_LIMIT.

maxSnmpPacketSize

protected int maxSnmpPacketSize
Maximum packet size of Request PDU. This could be set by the user. If the request crosses this limit while encoding, the request is automatically split into multiple small request. Each of these requests will again be within this limit. The default value is SnmpConst.defaultSnmpRequestPktSize.

maxRetries

protected int maxRetries
Number of times to retry before giving up. The default number is 3.

timeout

protected int timeout
The amount of time to wait for a response from the peer. The default amount of time is 3000 millisec.

pduFactory

protected SnmpPduFactoryIf pduFactory
The PDU factory. The default factory is an instance of SnmpPduFactory.
Constructor Detail

SnmpPeer

public SnmpPeer(java.lang.String host)
         throws java.net.UnknownHostException
Creates an SNMP peer object for a device. The default port is 161.
Parameters:
host - The peer name.
Throws:
java.net.UnknownHostException - If the host name cannot be resolved.

SnmpPeer

public SnmpPeer(java.net.InetAddress netaddr)
Creates an SNMP peer object for a device. The default port is 161.
Parameters:
netaddr - The peer InetAddress.

SnmpPeer

public SnmpPeer(java.lang.String host,
                int port)
         throws java.net.UnknownHostException
Creates an SNMP peer object for a device with the specified port.
Parameters:
host - The peer name.
port - The port number.
Throws:
java.net.UnknownHostException - If the host name cannot be resolved.
Method Detail

useIPAddress

public final void useIPAddress(java.lang.String ipaddr)
                        throws java.net.UnknownHostException
Sets a specific IP address where the peer will communicate. Typically used to set an alternate IP address or a specific address which is known to respond to requests. It will not resolve the IP address if specified in dot format such as 171.69.220.225.
Parameters:
ipaddr - Dot formatted IP address. It can also be a name.
Throws:
java.net.UnknownHostException - If the host name cannot be resolved.

ipAddressInUse

public final java.lang.String ipAddressInUse()
Returns the dot-formatted IP address string (for example 171.69.220.224). Useful when you like to know which IP address is used when the address was resolved using a DNS name.
Returns:
The dot-formatted IP address being use.

useAddressList

public final void useAddressList(java.net.InetAddress[] adrList)
Specifies the list of address to be used. When a host is not responding the user can switch to the next address by calling useNextAddress.
Parameters:
adrList - The list of InetAddresses.

useNextAddress

public final void useNextAddress()
Causes all subsequent requests to go to the new address that is obtained from the specified list of alternate addresses. If it reaches the end of list, it begins again with the first address.

allowSnmpSets

public boolean allowSnmpSets()
Determines if a SNMP set operation is allowed using this peer object. For now it just makes sure parameter is configured for a write operation.
Returns:
True if SNMP set is allowed and parameter is configured; false otherwise.

equals

public boolean equals(java.lang.Object obj)
Compares the two peer objects to determine if they are the same. This is used to determine whether requests can be multiplexed.
Parameters:
obj - The object to compare this with.
Returns:
True if they are referring to same peer and using same address; false otherwise.
Overrides:
equals in class java.lang.Object

getDestAddrList

public final java.net.InetAddress[] getDestAddrList()
Gets the list of alternate InetAddress configured for this peer.
Returns:
The InetAddress of the peer.
See Also:
InetAddress

getDestAddr

public final java.net.InetAddress getDestAddr()
Gets the InetAddress object for this peer.
Returns:
The InetAddress of the peer.
See Also:
InetAddress

getDestPort

public final int getDestPort()
Gets the destination port number of the peer to which SNMP requests are to be sent.
Returns:
The destination port number.

setDestPort

public final void setDestPort(int newPort)
Changes the port address of the destination for the request.
Parameters:
newPort - The destination port.

getTimeout

public final int getTimeout()
Gets the timeout to wait for a response from the peer.
Returns:
The value of timeout property.

setTimeout

public final void setTimeout(int newTimeout)
Changes the timeout to wait for a response from the peer.
Parameters:
newTimeout - The timeout (in milliseconds).

getMaxRetries

public final int getMaxRetries()
Gets the number of times to retry before giving up.
Returns:
The maximun number of retries.

setMaxRetries

public final void setMaxRetries(int newMaxRetries)
Changes the maximun number of times to retry before giving up.
Parameters:
newMaxRetries - The maximun number of retries.

getDevName

public final java.lang.String getDevName()
Gets the name specified in the constructor while creating this object.
Returns:
The name of the host as specified while creating this object.

toString

public java.lang.String toString()
Returns the string representation for this SnmpPeer.
Returns:
The string representation.
Overrides:
toString in class java.lang.Object

getVarbindLimit

public final int getVarbindLimit()
Gets the maximum number of varbinds that can be sent to a peer.
Returns:
The maximum varbind that can be encoded into a request packet.

setVarbindLimit

public final void setVarbindLimit(int limit)
Configures the maximum number of varbinds that can be sent to a peer.
Parameters:
limit - The desired limit.

getSnmpParam

public final SnmpParameters getSnmpParam()
Gets the SnmpParameter object associated with the peer.
Returns:
The associated parameter.

setSnmpParam

public final void setSnmpParam(SnmpParameters param)
Sets the SnmpParameter object associated with the peer.
Parameters:
param - The desired parameter.

setMaxSnmpPktSize

public final void setMaxSnmpPktSize(int newsize)
Configures the maximum packet size that can be used when generating an SNMP request.
Parameters:
newsize - The desired packet size.

getMaxSnmpPktSize

public final int getMaxSnmpPktSize()
Gets the maximum request packet size that is currently used.
Returns:
The maximum request packet size.

setPduFactory

public final void setPduFactory(SnmpPduFactoryIf factory)
Sets the PDU factory.
Parameters:
factory - The new factory. If null is passed, the default factory will be set.

getPduFactory

public final SnmpPduFactoryIf getPduFactory()
Gets the PDU factory.
Returns:
The PDU factory.

finalize

public void finalize()
Sets all the references to the SnmpPeer object to null.
Overrides:
finalize in class java.lang.Object

getMinRtt

public long getMinRtt()
Gets the minimum round trip time for a packet with the peer.
Returns:
The minimum round trip time for a packet with the peer.

getMaxRtt

public long getMaxRtt()
Gets the maximum round trip time for a packet with the peer.
Returns:
The maximum round trip time for a packet with the peer.

getAvgRtt

public long getAvgRtt()
Gets the average round trip time for a packet with the peer.
Returns:
The average round trip time for a packet with the peer.