MySnmpCrawler API

snmp.comm
Class SnmpAdaptor

java.lang.Object
  |
  +--com.sun.jdmk.comm.CommunicatorServer
        |
        +--snmp.comm.SnmpAdaptor
All Implemented Interfaces:
com.sun.jdmk.comm.CommunicatorServerMBean, javax.management.MBeanRegistration, javax.management.NotificationBroadcaster, java.lang.Runnable

public class SnmpAdaptor
extends com.sun.jdmk.comm.CommunicatorServer

The SnmpAdaptor is a SNMP agent that listens for SNMP requests. It is the subclass of the CommunicatorServer to inherit the behavior from JMX API. The SnmpAdaptor is also a MBean that can be managed through the JMX MBean server.

When the SnmpAdaptor receives a request, it creates a new session and schedules a thread from the thread pool to handle the request. Then the SnmpAdaptor continues accepting the incoming requests.

Version:
$Revision: 0.1 $ $Date: 2004/03/09 06:03:57 $
Author:
Scott Cheng
See Also:
CommunicatorServer

Field Summary
private  int BUFFER_SIZE
           
private  java.lang.String community
           
private  java.lang.String host
           
private  java.lang.String MBEAN_NAME
           
private  java.net.DatagramPacket packet
           
private  EDU.oswego.cs.dl.util.concurrent.PooledExecutor pool
           
private  int port
           
private  java.lang.String PROTOCOL_NAME
           
private  java.net.DatagramSocket socket
           
private  int THREAD_POOL_SIZE
           
 
Fields inherited from class com.sun.jdmk.comm.CommunicatorServer
HTML_TYPE, HTTP_TYPE, HTTPS_TYPE, OFFLINE, ONLINE, RMI_TYPE, SNMP_TYPE, STARTING, STOPPING
 
Constructor Summary
SnmpAdaptor(java.lang.String host, int port, java.lang.String community)
          Constructs the SnmpAdaptor object using the passed host name, port number, and community string.
 
Method Summary
 void doBind()
          Binds the datagram socket to a particular port.
protected  void doError(java.lang.Exception e)
          Invoked when the exception occurs.
protected  void doProcess()
          Processes the received packet when the request comes in.
protected  void doReceive()
          Receives the packet from the bind socket.
protected  void doUnbind()
          Invoked whenever the adaptor goes OFFLINE to unbind the socket.
protected  void finalize()
          Invoked to close the socket and set the socket to NULL.
 java.lang.String getMBeanName()
          Gets the MBean name of the SnmpAdaptor.
 java.lang.String getProtocol()
          Gets the protocol name of the adaptor.
private  void setupThreadPool()
          Setups thread pool to handle the incoming requests.
 void start()
          Invoked to start the SNMP adaptor.
 void stop()
          Invoked when the SNMP adaptor goes from "ONLINE" to "OFFLINE".
 
Methods inherited from class com.sun.jdmk.comm.CommunicatorServer
addNotificationListener, getHost, getMBeanServer, getNotificationInfo, getPort, getState, getStateString, isActive, postDeregister, postRegister, preDeregister, preRegister, removeNotificationListener, run, setMBeanServer, setPort, waitState
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROTOCOL_NAME

private java.lang.String PROTOCOL_NAME

MBEAN_NAME

private final java.lang.String MBEAN_NAME
See Also:
Constant Field Values

BUFFER_SIZE

private int BUFFER_SIZE

THREAD_POOL_SIZE

private int THREAD_POOL_SIZE

socket

private java.net.DatagramSocket socket

packet

private java.net.DatagramPacket packet

host

private java.lang.String host

port

private int port

community

private java.lang.String community

pool

private EDU.oswego.cs.dl.util.concurrent.PooledExecutor pool
Constructor Detail

SnmpAdaptor

public SnmpAdaptor(java.lang.String host,
                   int port,
                   java.lang.String community)
            throws java.lang.Exception
Constructs the SnmpAdaptor object using the passed host name, port number, and community string.

Parameters:
host - The host name of the SNMP agent
port - The port number of the SNMP agent
community - The community string used in the SNMP agent
Throws:
java.lang.Exception - thrown if any error occurs during the object instantiation.
Method Detail

doError

protected void doError(java.lang.Exception e)
                throws com.sun.jdmk.comm.CommunicationException
Invoked when the exception occurs.

Specified by:
doError in class com.sun.jdmk.comm.CommunicatorServer
Throws:
com.sun.jdmk.comm.CommunicationException - thrown when any exception occurs.

doBind

public void doBind()
            throws com.sun.jdmk.comm.CommunicationException,
                   java.lang.InterruptedException
Binds the datagram socket to a particular port.

Specified by:
doBind in class com.sun.jdmk.comm.CommunicatorServer
Throws:
com.sun.jdmk.comm.CommunicationException - thrown when any SocketException occurs.
java.lang.InterruptedException - thrown when the thread is interrupted.

doReceive

protected void doReceive()
                  throws com.sun.jdmk.comm.CommunicationException,
                         java.lang.InterruptedException
Receives the packet from the bind socket. This method blocks until the packet is available.

Specified by:
doReceive in class com.sun.jdmk.comm.CommunicatorServer
Throws:
com.sun.jdmk.comm.CommunicationException - thrown when any SocketException occurs.
java.lang.InterruptedException - thrown when the thread is interrupted.

doProcess

protected void doProcess()
                  throws com.sun.jdmk.comm.CommunicationException,
                         java.lang.InterruptedException
Processes the received packet when the request comes in. This method creates a new session for the request and schedules a thread to process it.

Specified by:
doProcess in class com.sun.jdmk.comm.CommunicatorServer
Throws:
com.sun.jdmk.comm.CommunicationException - thrown when any SocketException occurs.
java.lang.InterruptedException - thrown when the thread is interrupted.

doUnbind

protected void doUnbind()
                 throws com.sun.jdmk.comm.CommunicationException,
                        java.lang.InterruptedException
Invoked whenever the adaptor goes OFFLINE to unbind the socket.

Specified by:
doUnbind in class com.sun.jdmk.comm.CommunicatorServer
Throws:
com.sun.jdmk.comm.CommunicationException - thrown when any SocketException occurs.
java.lang.InterruptedException - thrown when the thread is interrupted.

getProtocol

public java.lang.String getProtocol()
Gets the protocol name of the adaptor.

Specified by:
getProtocol in interface com.sun.jdmk.comm.CommunicatorServerMBean
Specified by:
getProtocol in class com.sun.jdmk.comm.CommunicatorServer
Returns:
PROTOCOL_NAME

finalize

protected void finalize()
Invoked to close the socket and set the socket to NULL.

Overrides:
finalize in class java.lang.Object
Throws:
com.sun.jdmk.comm.CommunicationException - thrown when any SocketException occurs.
java.lang.InterruptedException - thrown when the thread is interrupted.

start

public void start()
Invoked to start the SNMP adaptor. Before the adaptor goes ONLINE, it setups the thread pool to handle the incoming request.

Specified by:
start in interface com.sun.jdmk.comm.CommunicatorServerMBean
Overrides:
start in class com.sun.jdmk.comm.CommunicatorServer

stop

public void stop()
Invoked when the SNMP adaptor goes from "ONLINE" to "OFFLINE". When the adaptor is ready to stop, it shuts down the thread pool and unbinds the communication socket.

Specified by:
stop in interface com.sun.jdmk.comm.CommunicatorServerMBean
Overrides:
stop in class com.sun.jdmk.comm.CommunicatorServer

getMBeanName

public java.lang.String getMBeanName()
Gets the MBean name of the SnmpAdaptor.

Returns:
MBEAN_NAME The MBean name of the SnmpAdaptor.

setupThreadPool

private void setupThreadPool()
Setups thread pool to handle the incoming requests.


MySnmpCrawler API