com.adventnet.snmp.snmp2.agent
Class SnmpTrapReceiverService

java.lang.Object
  |
  +--com.adventnet.snmp.snmp2.agent.Cache
        |
        +--com.adventnet.snmp.snmp2.agent.BaseSnmpStore
              |
              +--com.adventnet.snmp.snmp2.agent.SnmpStore
                    |
                    +--com.adventnet.snmp.snmp2.agent.SnmpTrapReceiverService

public class SnmpTrapReceiverService
extends SnmpStore
implements SnmpClient, java.io.Serializable

This class listens for the Traps at the specified port by opening a new Receiver Snmp Session.

This can be instantiated in the Master Agent's so that the Traps sent by the SubAgents can be listened and forwarded to the MasterAgent's Managers.

API users can use this class to listen for Traps at a Specific Port and forward them to the Managers in the SnmpTrapService, which should be set for this class using the addTrapRequestListener method.

See Also:
Serialized Form

Field Summary
(package private)  boolean callbackThread
          Used to facilitate CallBacks
(package private)  SnmpSession receiverSession
           
(package private)  AgentTableModel tModelComplete
           
protected  TrapRequestListener trapListener
           
 
Fields inherited from class com.adventnet.snmp.snmp2.agent.BaseSnmpStore
debugLevel, localAddress, oldAddress, oldPort, protocol, session, snmpLog
 
Fields inherited from class com.adventnet.snmp.snmp2.agent.Cache
cache, debug
 
Constructor Summary
SnmpTrapReceiverService(int port)
          Constructor with the port argument.
 
Method Summary
 void addTrapRequestListener(TrapRequestListener trapListener)
          Method to add a SnmpTrapService with this TrapReceiverService to forward the received Traps.
 boolean authenticate(SnmpPDU pdu, java.lang.String community)
          This method is called before the callback and related processing methods are called has a simple checks based on the community of the pdu which has been received.
 boolean callback(SnmpSession session, SnmpPDU pdu, int reqid)
          The callback of SnmpClient interface for incoming Snmp Trap PDUs which is implemented by this Service.
 void debugPrint(java.lang.String s)
          To print errors in Error Output stream for debug.
 int getPort()
          The port on which the Trap Receiver Service is running
 long getUpTime()
          gets the up time of the agent
(package private)  void initTrapReceiverSession()
           
 boolean isAgentAddressFlag()
          Gets the subagent's agent address flag which says to send the subagent's agent address to the manager.
 boolean isCallbackThread()
          getter for Callback Thread
 boolean isStarted()
          Getter of the receiver status.
 boolean restartTrapReceiverService()
          Restarts the receiver Thread for receiving requests
 void setAgentAddressFlag(boolean flag)
          Sets the subagent's agent address flag which says to send the subagent's agent address to the manager.
 void setAgentTableModel(AgentTableModel tModelComplete)
          Method to set the TrapFiltering Table's Model.
 void setCallbackThread(boolean callbackThread)
          setter for Callback Thread.
 void setPort(int port)
          The port on which the TrapReceiverService is going to run.
 void setPort(int port, boolean restart)
          The port on which the TrapReceiverService is going to run.
 void stopTrapReceiverService()
          Stops the receiver Thread and closes the socket used by this TrapReceiverService.
 
Methods inherited from class com.adventnet.snmp.snmp2.agent.SnmpStore
getProxySession, getTrapReceiverSession, initSnmpStore
 
Methods inherited from class com.adventnet.snmp.snmp2.agent.BaseSnmpStore
closeAll, createProtocolOptions, finalize, getSnmpAPI, getSnmpSession, getSnmpSession, initSession, initSnmpStore, isAlive, isDebug, killSnmpAgent, setDebug
 
Methods inherited from class com.adventnet.snmp.snmp2.agent.Cache
getFromCache, getMibOperations, putInCache, setMibOperations
 
Methods inherited from class java.lang.Object
, clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

receiverSession

SnmpSession receiverSession

callbackThread

boolean callbackThread
Used to facilitate CallBacks

trapListener

protected TrapRequestListener trapListener

tModelComplete

AgentTableModel tModelComplete
Constructor Detail

SnmpTrapReceiverService

public SnmpTrapReceiverService(int port)
Constructor with the port argument.
Parameters:
port - the port which has to be listened for Traps.
Method Detail

getUpTime

public long getUpTime()
gets the up time of the agent
Returns:
The uptime of the agent.

setCallbackThread

public void setCallbackThread(boolean callbackThread)
setter for Callback Thread.

When the callbackThread is set to false, the callback method is called in the context of the SnmpSession receiver thread. When callbackThread is set to true, the callback method is invoked in the context of a separate callback thread. API users can set the value of callbackThread based on whether they want callback's to be invoked from a seperate thread or from the SnmpSession receiver thread itself.

Parameters:
callbackThread - the value to set enable or false the Callback Thread.
See Also:
isCallbackThread(), SnmpCallback

isCallbackThread

public boolean isCallbackThread()
getter for Callback Thread
Returns:
true if Callback thread is set otherwise false.
See Also:
()

debugPrint

public void debugPrint(java.lang.String s)
To print errors in Error Output stream for debug.
Specified by:
debugPrint in interface SnmpClient
Parameters:
s - the debug message

callback

public boolean callback(SnmpSession session,
                        SnmpPDU pdu,
                        int reqid)
The callback of SnmpClient interface for incoming Snmp Trap PDUs which is implemented by this Service.

When a pdu reached at the session for which this SnmpTrapReceiverService is registered as SnmpClient, then the client(here SnmpAgent) callback is called.

Specified by:
callback in interface SnmpClient
Parameters:
session - the session on which agent is communicating.
pdu - the Snmp PDU.
reqid - the value of reqid.
Returns:
boolean false if a Non Snmp Trap PDU is received.

setAgentAddressFlag

public void setAgentAddressFlag(boolean flag)
Sets the subagent's agent address flag which says to send the subagent's agent address to the manager. Mainly used when the Subagent's trap is forwarded to the SNMP Manager from the Master Agent to show the actual address from where the trap is received.
Parameters:
flag - true if the subagent's agent address has to be passed to the manager, false otherwise.

isAgentAddressFlag

public boolean isAgentAddressFlag()
Gets the subagent's agent address flag which says to send the subagent's agent address to the manager. Mainly used when the Subagent's trap is forwarded to the SNMP Manager from the Master Agent to show the actual address from where the trap is received.
Returns:
true if the subagent's agent address has to be passed to the manager, false otherwise.

authenticate

public boolean authenticate(SnmpPDU pdu,
                            java.lang.String community)
This method is called before the callback and related processing methods are called has a simple checks based on the community of the pdu which has been received.
Specified by:
authenticate in interface SnmpClient
Parameters:
pdu - the Snmp PDU.
community - the value of the community.
Returns:
false if the PDU doesnt satisfy authentication mechanism
See Also:
SnmpClient

isStarted

public boolean isStarted()
Getter of the receiver status.
Returns:
true if Receiver Session is started otherwise false.
See Also:
restartSnmpTrapReceiverService(), stopSnmpTrapReceiverService(), setStarted(boolean flag)

restartTrapReceiverService

public boolean restartTrapReceiverService()
                                   throws AgentRuntimeException
Restarts the receiver Thread for receiving requests
Returns:
false if unsuccessful
See Also:
BaseSnmpStore.isAlive(), restartSnmpAgent()

stopTrapReceiverService

public void stopTrapReceiverService()
Stops the receiver Thread and closes the socket used by this TrapReceiverService.

This thread doesn't kill all the threads and sessions.

See Also:
SnmpStore

setPort

public void setPort(int port)
             throws AgentRuntimeException
The port on which the TrapReceiverService is going to run.

This restarts the SnmpTrapReceiverService at the specified port.

Parameters:
port - the udp port number to whcih the SnmpSession is start.
See Also:
getPort()

setPort

public void setPort(int port,
                    boolean restart)
             throws AgentRuntimeException
The port on which the TrapReceiverService is going to run.

This restarts the SnmpTrapReceiverService at the specified port.

Parameters:
port - the udp port number to whcih the SnmpSession is start.
restart - specifies whether the TrapReceiverService needs to be restarted after setting the port.
See Also:
getPort(), setPort(int port)

getPort

public int getPort()
The port on which the Trap Receiver Service is running
Returns:
the port number
See Also:
setPort(int port), setPort(int port, boolean restart)

addTrapRequestListener

public void addTrapRequestListener(TrapRequestListener trapListener)
Method to add a SnmpTrapService with this TrapReceiverService to forward the received Traps.
Parameters:
trapListener - The SnmpTrapService instance.

initTrapReceiverSession

void initTrapReceiverSession()
                       throws SnmpException

setAgentTableModel

public void setAgentTableModel(AgentTableModel tModelComplete)
Method to set the TrapFiltering Table's Model. This adds Filtering of the Traps received by this Session.
Parameters:
tModelComplete - The AgentTableModel Instance of TrapFiltering Table.
See Also:
TrapFilteringTable