org.snmp4j.agent.agentx.subagent
Class AgentXSubagent

java.lang.Object
  extended by org.snmp4j.agent.agentx.subagent.AgentXSubagent
All Implemented Interfaces:
java.util.EventListener, AgentXCommandListener, org.snmp4j.agent.NotificationOriginator

public class AgentXSubagent
extends java.lang.Object
implements AgentXCommandListener, org.snmp4j.agent.NotificationOriginator

The AgentXSubagent class implements the AgentX communication for an AgentX subagent implementation.

Version:
1.1
Author:
Frank Fock

Field Summary
protected  int nextTransactionID
           
protected  java.util.Map<org.snmp4j.smi.Address,AgentXPeer> peers
           
protected  org.snmp4j.agent.RequestHandler requestHandlerCleanupSet
           
protected  org.snmp4j.agent.RequestHandler requestHandlerCommitSet
           
protected  org.snmp4j.agent.RequestHandler requestHandlerGet
           
protected  org.snmp4j.agent.RequestHandler requestHandlerGetBulk
           
protected  org.snmp4j.agent.RequestHandler requestHandlerGetNext
           
protected  org.snmp4j.agent.RequestHandler requestHandlerTestSet
           
protected  org.snmp4j.agent.RequestHandler requestHandlerUndoSet
           
protected  java.util.Map<org.snmp4j.agent.agentx.subagent.AgentXSubagent.RequestID,AgentXRequest> requestList
           
protected  java.util.Map<java.lang.Integer,AgentXSession> sessions
           
 
Constructor Summary
AgentXSubagent(AgentX agentX, org.snmp4j.smi.OID subagentID, org.snmp4j.smi.OctetString subagentDescr)
           
 
Method Summary
 int addAgentCaps(AgentXSession session, org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID id, org.snmp4j.smi.OctetString descr)
           
protected  org.snmp4j.TransportMapping addMaster(org.snmp4j.smi.Address localAddress)
           
 void addMOServer(org.snmp4j.agent.MOServer server)
           
 void addPingListener(PingListener l)
           
 int close(AgentXSession session, byte reason)
           
protected  int closeSession(int sessionID, byte reason)
           
 int connect(org.snmp4j.smi.Address masterAddress, org.snmp4j.smi.Address localAddress, AgentXSession session)
           
 void disconnect(org.snmp4j.smi.Address masterAddress)
           
 void dispatchCommand(AgentXCommandEvent cmd)
           
protected  void firePinged(PingEvent event)
           
 AgentXSession firstSession()
          Returns the first session that have been opened by this subagent and is still open.
 java.util.Collection<org.snmp4j.smi.OctetString> getContexts()
           
 byte getDefaultPriority()
           
protected  int getNextTransactionID()
           
protected  byte getPriority(org.snmp4j.agent.ManagedObject mo, AgentXRegion region)
          Gets the priority with which the supplied managed object and region should be registered at the master agent.
 org.snmp4j.agent.MOServer getServer(org.snmp4j.smi.OctetString context)
           
 org.snmp4j.util.WorkerPool getWorkerPool()
           
 AgentXResponseEvent notify(AgentXSession session, org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID notificationID, org.snmp4j.smi.TimeTicks sysUpTime, org.snmp4j.smi.VariableBinding[] vbs)
           
 java.lang.Object notify(org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID notificationID, org.snmp4j.smi.TimeTicks sysUpTime, org.snmp4j.smi.VariableBinding[] vbs)
           
 java.lang.Object notify(org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID notificationID, org.snmp4j.smi.VariableBinding[] vbs)
          Sends notifications (traps) to all appropriate notification targets through the master agent.
protected  int openSession(org.snmp4j.TransportMapping transport, org.snmp4j.smi.Address masterAddress, AgentXSession session)
           
 void processCommand(AgentXCommandEvent event)
           
protected  void processNextSubRequest(org.snmp4j.agent.request.Request request, org.snmp4j.agent.MOServer server, org.snmp4j.smi.OctetString context, org.snmp4j.agent.request.SubRequest sreq)
           
protected  void processResponse(AgentXCommandEvent cmd)
           
protected  int registerRegion(AgentXSession session, org.snmp4j.smi.OctetString context, AgentXRegion region, byte priority, org.snmp4j.smi.TimeTicks sysUpTime)
           
 void registerRegions(AgentXSession session, org.snmp4j.smi.OctetString context, org.snmp4j.smi.TimeTicks sysUpTime, RegistrationCallback registrationCallback)
          Registers the subagent regions at the master agent.
 void registerSharedTableRows(AgentXSession session, org.snmp4j.smi.OctetString context, AgentXSharedMOTable mo, RegistrationCallback registrationCallback)
          Registers the indexes and (row) regions of a shared table.
protected  void release(org.snmp4j.agent.MOServer server, org.snmp4j.agent.request.Request<AgentXCommandEvent,AgentXResponsePDU> req)
           
 int removeAgentCaps(AgentXSession session, org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID id)
           
protected  void removeMaster(org.snmp4j.TransportMapping transport)
           
 void removeMOServer(org.snmp4j.agent.MOServer server)
           
 void removePingListener(PingListener l)
           
protected  void sendResponse(AgentXCommandEvent cmd, AgentXRequest request)
           
 void setDefaultPriority(byte priority)
           
 void setPingDelay(int seconds)
          Sets the ping delay in seconds.
 void setThreadPool(org.snmp4j.util.ThreadPool threadPool)
           
protected  int unregisterRegion(AgentXSession session, org.snmp4j.smi.OctetString context, AgentXRegion region, byte timeout)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

requestList

protected java.util.Map<org.snmp4j.agent.agentx.subagent.AgentXSubagent.RequestID,AgentXRequest> requestList

peers

protected java.util.Map<org.snmp4j.smi.Address,AgentXPeer> peers

sessions

protected java.util.Map<java.lang.Integer,AgentXSession> sessions

requestHandlerGet

protected org.snmp4j.agent.RequestHandler requestHandlerGet

requestHandlerGetNext

protected org.snmp4j.agent.RequestHandler requestHandlerGetNext

requestHandlerGetBulk

protected org.snmp4j.agent.RequestHandler requestHandlerGetBulk

requestHandlerTestSet

protected org.snmp4j.agent.RequestHandler requestHandlerTestSet

requestHandlerCommitSet

protected org.snmp4j.agent.RequestHandler requestHandlerCommitSet

requestHandlerUndoSet

protected org.snmp4j.agent.RequestHandler requestHandlerUndoSet

requestHandlerCleanupSet

protected org.snmp4j.agent.RequestHandler requestHandlerCleanupSet

nextTransactionID

protected int nextTransactionID
Constructor Detail

AgentXSubagent

public AgentXSubagent(AgentX agentX,
                      org.snmp4j.smi.OID subagentID,
                      org.snmp4j.smi.OctetString subagentDescr)
Method Detail

setPingDelay

public void setPingDelay(int seconds)
Sets the ping delay in seconds. If greater than zero, for each session a ping PDU is sent to the master to validate the session regularly with the specified delay. To monitor the ping requests, it is necessary to add a PingListener with addPingListener(org.snmp4j.agent.agentx.event.PingListener).

Parameters:
seconds - the delay. If zero or a negative value is supplied, no pings are sent

processCommand

public void processCommand(AgentXCommandEvent event)
Specified by:
processCommand in interface AgentXCommandListener

getNextTransactionID

protected int getNextTransactionID()

closeSession

protected int closeSession(int sessionID,
                           byte reason)
                    throws java.io.IOException
Throws:
java.io.IOException

openSession

protected int openSession(org.snmp4j.TransportMapping transport,
                          org.snmp4j.smi.Address masterAddress,
                          AgentXSession session)
                   throws java.io.IOException
Throws:
java.io.IOException

disconnect

public void disconnect(org.snmp4j.smi.Address masterAddress)
                throws java.io.IOException
Throws:
java.io.IOException

connect

public int connect(org.snmp4j.smi.Address masterAddress,
                   org.snmp4j.smi.Address localAddress,
                   AgentXSession session)
            throws java.io.IOException
Throws:
java.io.IOException

close

public int close(AgentXSession session,
                 byte reason)
          throws java.io.IOException
Throws:
java.io.IOException

setDefaultPriority

public void setDefaultPriority(byte priority)

getDefaultPriority

public byte getDefaultPriority()

getPriority

protected byte getPriority(org.snmp4j.agent.ManagedObject mo,
                           AgentXRegion region)
Gets the priority with which the supplied managed object and region should be registered at the master agent. Overwrite this method to use individual priorities depending on the registered region/managed object. The default implementation returns getDefaultPriority().

Parameters:
mo - ManagedObject a managed object instance that manages region.
region - the region to be registered.
Returns:
the priority between 0 and 255 (lower value results in higher priority).

registerRegions

public void registerRegions(AgentXSession session,
                            org.snmp4j.smi.OctetString context,
                            org.snmp4j.smi.TimeTicks sysUpTime,
                            RegistrationCallback registrationCallback)
Registers the subagent regions at the master agent.

Parameters:
session - the session on whose behalf regions are registered.
context - the context to use for registration.
sysUpTime - if not null, the master agent's notion of the sysUpTime for the registered context is returned. The input value is always ignored!
registrationCallback - a possibly null reference to a RegistrationCallback instance to handle registration events.

registerSharedTableRows

public void registerSharedTableRows(AgentXSession session,
                                    org.snmp4j.smi.OctetString context,
                                    AgentXSharedMOTable mo,
                                    RegistrationCallback registrationCallback)
Registers the indexes and (row) regions of a shared table. This method is called on behalf of registerRegions(org.snmp4j.agent.agentx.AgentXSession, org.snmp4j.smi.OctetString, org.snmp4j.smi.TimeTicks, RegistrationCallback).

Parameters:
session - the session on whose behalf regions are registered.
context - the context to use for registration.
mo - the AgentXSharedMOTable instance to register.
registrationCallback - if not null the callback is informed when registration of a row succeeded or failed.

registerRegion

protected int registerRegion(AgentXSession session,
                             org.snmp4j.smi.OctetString context,
                             AgentXRegion region,
                             byte priority,
                             org.snmp4j.smi.TimeTicks sysUpTime)
                      throws java.io.IOException
Throws:
java.io.IOException

unregisterRegion

protected int unregisterRegion(AgentXSession session,
                               org.snmp4j.smi.OctetString context,
                               AgentXRegion region,
                               byte timeout)
                        throws java.io.IOException
Throws:
java.io.IOException

addMaster

protected org.snmp4j.TransportMapping addMaster(org.snmp4j.smi.Address localAddress)
                                         throws java.io.IOException
Throws:
java.io.IOException

removeMaster

protected void removeMaster(org.snmp4j.TransportMapping transport)

addMOServer

public void addMOServer(org.snmp4j.agent.MOServer server)

removeMOServer

public void removeMOServer(org.snmp4j.agent.MOServer server)

getServer

public org.snmp4j.agent.MOServer getServer(org.snmp4j.smi.OctetString context)

getContexts

public java.util.Collection<org.snmp4j.smi.OctetString> getContexts()

getWorkerPool

public org.snmp4j.util.WorkerPool getWorkerPool()

setThreadPool

public void setThreadPool(org.snmp4j.util.ThreadPool threadPool)

dispatchCommand

public void dispatchCommand(AgentXCommandEvent cmd)

sendResponse

protected void sendResponse(AgentXCommandEvent cmd,
                            AgentXRequest request)

release

protected void release(org.snmp4j.agent.MOServer server,
                       org.snmp4j.agent.request.Request<AgentXCommandEvent,AgentXResponsePDU> req)

processResponse

protected void processResponse(AgentXCommandEvent cmd)

processNextSubRequest

protected void processNextSubRequest(org.snmp4j.agent.request.Request request,
                                     org.snmp4j.agent.MOServer server,
                                     org.snmp4j.smi.OctetString context,
                                     org.snmp4j.agent.request.SubRequest sreq)
                              throws java.util.NoSuchElementException
Throws:
java.util.NoSuchElementException

notify

public java.lang.Object notify(org.snmp4j.smi.OctetString context,
                               org.snmp4j.smi.OID notificationID,
                               org.snmp4j.smi.VariableBinding[] vbs)
Sends notifications (traps) to all appropriate notification targets through the master agent.

Specified by:
notify in interface org.snmp4j.agent.NotificationOriginator
Parameters:
context - the context name of the context on whose behalf this notification has been generated.
notificationID - the object ID that uniquely identifies this notification. For SNMPv1 traps, the notification ID has to be build using the rules provided by RFC 2576.
vbs - an array of VariableBinding instances representing the payload of the notification.
Returns:
an AgentXResponseEvent instance or null if the notification request timed out.

notify

public java.lang.Object notify(org.snmp4j.smi.OctetString context,
                               org.snmp4j.smi.OID notificationID,
                               org.snmp4j.smi.TimeTicks sysUpTime,
                               org.snmp4j.smi.VariableBinding[] vbs)
Specified by:
notify in interface org.snmp4j.agent.NotificationOriginator

firstSession

public final AgentXSession firstSession()
Returns the first session that have been opened by this subagent and is still open. If no open session exists, null is returned.

Returns:
an AgentXSession.

notify

public AgentXResponseEvent notify(AgentXSession session,
                                  org.snmp4j.smi.OctetString context,
                                  org.snmp4j.smi.OID notificationID,
                                  org.snmp4j.smi.TimeTicks sysUpTime,
                                  org.snmp4j.smi.VariableBinding[] vbs)
                           throws java.io.IOException
Throws:
java.io.IOException

addAgentCaps

public int addAgentCaps(AgentXSession session,
                        org.snmp4j.smi.OctetString context,
                        org.snmp4j.smi.OID id,
                        org.snmp4j.smi.OctetString descr)

removeAgentCaps

public int removeAgentCaps(AgentXSession session,
                           org.snmp4j.smi.OctetString context,
                           org.snmp4j.smi.OID id)

addPingListener

public void addPingListener(PingListener l)

removePingListener

public void removePingListener(PingListener l)

firePinged

protected void firePinged(PingEvent event)

Copyright 2005-2011 Frank Fock (SNMP4J.org)

Copyright © 2011 SNMP4J.org. All Rights Reserved.