All Packages Class Hierarchy This Package Previous Next Index
Class com.sun.jaw.snmp.manager.SnmpSocket
java.lang.Object
|
+----com.sun.jaw.snmp.manager.SnmpSocket
- public final class SnmpSocket
- extends Object
- implements Runnable
This class creates a SNMP Datagram Socket. This class has methods helpful
to send SNMP packets to an arbitrary port of a specified device.
It also runs a thread that is devoted to receiving messages on the socket.
It marks a socket as a default socket. All operations are directed to the
this default socket.
A user can create a new socket and use it exclusively for certain
operations.
A socket imposes an upper limit on size of response packet. Any
packet which exceeds this limit is truncated. By default, this
limit is {@link SnmpConst#defaultSnmpResponsePktSize}. It can be
changed using {@link #setResponsePktSize}.
-
SnmpSocket(DatagramHandlerIf)
- Creates a new
SnmpSocket object.
-
close()
- Closes the socket and its associated resources.
-
createNewDefaultSnmpSocket()
- Creates a new
SnmpSocket object.
-
deregister(Object)
- Removes the specified object to its list indicating that
the object is using the socket.
-
finalize()
- Closes the socket and its associated resources.
-
getAllRegisteredUsers()
- Gets a list of objects (mostly
SnmpSession objects), which
have registered to use this socket.
-
getDefaultSnmpSocket()
- Gets the default socket object.
-
getInPkts()
- Gets the number of packets received.
-
getOutPkts()
- Gets the number of packets sent.
-
getPktsErrors()
- Gets the number of errors that occured.
-
getResponsePktSize()
- Get the maximum size allowed for response packet.
-
getUserCount()
- Gets the number of objects using this socket.
-
isValid()
- Checks if the socket is initialised correctly and if it is still active.
-
performResetPktStatistics()
- Reset all the counters.
-
register(Object)
- Adds the specified object to its list indicating that
the object is using the socket.
-
run()
- Dispatcher method for this socket thread.
-
sendPacket(byte[], int, InetAddress, int)
- Sends a datagram packet to a specified device at specified port.
-
sendPacket(DatagramPacket)
- Sends a datagram packet to a specified device at specified port.
-
setDefaultSnmpSocket()
- Defines the current socket as being the default one.
-
setResponsePktSize(int)
- Set the maximum size allowed for response packet.
-
toString()
- Returns the detailed statistics of the socket and activity stats.
SnmpSocket
public SnmpSocket(DatagramHandlerIf rspHdlr) throws SocketException
- Creates a new
SnmpSocket object.
- Parameters:
- rspHdlr - A Datagram handler.
- Throws: SocketException
- A socket could not be created.
createNewDefaultSnmpSocket
public static final synchronized SnmpSocket createNewDefaultSnmpSocket() throws SocketException
- Creates a new
SnmpSocket object.
- Returns:
- The new
SnmpSocket.
- Throws: SocketException
- A socket could not be created.
getDefaultSnmpSocket
public static final SnmpSocket getDefaultSnmpSocket()
- Gets the default socket object.
- Returns:
- The default socket object.
setDefaultSnmpSocket
public final synchronized void setDefaultSnmpSocket() throws SocketException
- Defines the current socket as being the default one.
- Throws: SocketException
- A socket could not be created.
getPktsErrors
public final synchronized int getPktsErrors()
- Gets the number of errors that occured.
- Returns:
- The number of errors that occured.
getInPkts
public final synchronized int getInPkts()
- Gets the number of packets received.
- Returns:
- The number of packets received.
getOutPkts
public final synchronized int getOutPkts()
- Gets the number of packets sent.
- Returns:
- The number of packets sent.
performResetPktStatistics
public final synchronized void performResetPktStatistics()
- Reset all the counters.
getAllRegisteredUsers
public final synchronized Enumeration getAllRegisteredUsers()
- Gets a list of objects (mostly
SnmpSession objects), which
have registered to use this socket.
- Returns:
- Enumeration which gives a list of all users using this socket.
getUserCount
public final synchronized int getUserCount()
- Gets the number of objects using this socket.
- Returns:
- The count of objects using this socket.
toString
public synchronized String toString()
- Returns the detailed statistics of the socket and activity stats.
- Returns:
- The detailed statistics of the socket and activity stats.
- Overrides:
- toString in class Object
register
public final synchronized void register(Object obj)
- Adds the specified object to its list indicating that
the object is using the socket. This method is similar to reference counting.
- Parameters:
- obj - The object to add.
deregister
public final synchronized void deregister(Object obj)
- Removes the specified object to its list indicating that
the object is using the socket.
- Parameters:
- obj - The object to be removed.
getResponsePktSize
public final int getResponsePktSize()
- Get the maximum size allowed for response packet.
Any packet which exceeds this limit will be truncated.
The default value is {@link SnmpConst#defaultSnmpResponsePktSize}.
setResponsePktSize
public final synchronized void setResponsePktSize(int size)
- Set the maximum size allowed for response packet.
sendPacket
public synchronized void sendPacket(byte buff[],
int length,
InetAddress addr,
int port) throws IOException
- Sends a datagram packet to a specified device at specified port.
It also updates packet statistics.
- Parameters:
- buff - The packet data.
- length - The packet length.
- addr - The destination address.
- port - The destination port number.
- Throws: IOException
- Signals that an I/O exception of some sort has occurred.
sendPacket
public synchronized void sendPacket(DatagramPacket dgrmpkt) throws IOException
- Sends a datagram packet to a specified device at specified port.
It also updates packet statistics.
- Parameters:
- dgrmpkt - The datagram packet.
- Throws: IOException
- Signals that an I/O exception of some sort has occurred.
close
public synchronized void close()
- Closes the socket and its associated resources.
Note: the default socket can not be closed directly through a
call to close.
isValid
public synchronized boolean isValid()
- Checks if the socket is initialised correctly and if it is still active.
- Returns:
- True if the socket is initialised correctly and if it is still active;
false otherwise.
run
public void run()
- Dispatcher method for this socket thread. This is the dispatcher method
which goes in an endless-loop and waits for receiving datagram packets on the socket.
finalize
public synchronized void finalize()
- Closes the socket and its associated resources.
- Overrides:
- finalize in class Object
All Packages Class Hierarchy This Package Previous Next Index