Class CommandProcessor

java.lang.Object
org.snmp4j.agent.CommandProcessor
All Implemented Interfaces:
EventListener, NotificationOriginator, org.snmp4j.CommandResponder

public class CommandProcessor extends Object implements org.snmp4j.CommandResponder, NotificationOriginator
The CommandProcessor is the central glue code that puts together the various sub-systems of a SNMP agent.
Version:
3.1
Author:
Frank Fock
  • Field Details

    • threadPool

      protected org.snmp4j.util.WorkerPool threadPool
    • vacm

      protected VACM vacm
    • moServers

      protected List<MOServer> moServers
    • ownContextEngineIDs

      protected List<org.snmp4j.smi.OctetString> ownContextEngineIDs
    • pduHandler

      protected final List<RequestHandler<SnmpRequest>> pduHandler
    • requestList

      protected TemporaryList<SnmpRequest> requestList
    • requestFactory

      protected RequestFactory<org.snmp4j.CommandResponderEvent<?>,org.snmp4j.PDU,SnmpRequest> requestFactory
    • notificationOriginator

      protected NotificationOriginator notificationOriginator
    • proxyForwarder

      protected ProxyMap proxyForwarder
    • coexistenceProvider

      protected CoexistenceInfoProvider coexistenceProvider
    • lockNonNextRequestsSortedByVbOid

      protected boolean lockNonNextRequestsSortedByVbOid
      Lock the ManagedObjects when processing a SET or GET request in ascending lexicographic order of their VariableBinding OID if true.
  • Constructor Details

    • CommandProcessor

      public CommandProcessor(org.snmp4j.smi.OctetString contextEngineID)
      Creates a CommandProcessor and registers all PDU types with the supplied contextEngineID as well as with MPv3.LOCAL_ENGINE_ID as required by RFC 5343.
      Parameters:
      contextEngineID - the custom engine ID to use (should equal the engineID of the agent, i.e. USM).
  • Method Details

    • setInternalRequestTimeout

      public void setInternalRequestTimeout(int timeoutMillis)
      Sets the internal request timeout. Any request must return within this amount of milliseconds. Default is five minutes.
      Parameters:
      timeoutMillis - the maximum number of milliseconds a request can be processed.
      Since:
      1.3
    • getInternalRequestTimeout

      public int getInternalRequestTimeout()
      Gets the internal request timeout millis.
      Returns:
      the maximum number of milliseconds a request can be processed.
      Since:
      1.3
    • processPdu

      public <A extends org.snmp4j.smi.Address> void processPdu(org.snmp4j.CommandResponderEvent<A> event)
      Specified by:
      processPdu in interface org.snmp4j.CommandResponder
    • setThreadPool

      @Deprecated public void setThreadPool(org.snmp4j.util.WorkerPool threadPool)
      Sets the internal thread pool for task execution.
      Parameters:
      threadPool - a pool of workers/threads which can execute tasks.
    • setWorkerPool

      public void setWorkerPool(org.snmp4j.util.WorkerPool threadPool)
      Sets the internal thread pool for task execution.
      Parameters:
      threadPool - a pool of workers/threads which can execute tasks.
      Since:
      1.9
    • getVacm

      public VACM getVacm()
    • setVacm

      public void setVacm(VACM vacm)
    • getContextEngineID

      public org.snmp4j.smi.OctetString getContextEngineID()
    • setContextEngineID

      public void setContextEngineID(org.snmp4j.smi.OctetString contextEngineID)
    • notify

      public Object notify(org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID notificationID, org.snmp4j.smi.VariableBinding[] vbs)
      Sends notification/inform messages to all registered targets. This method uses the internal ThreadPool to send the message(s) via the NotificationOriginator (see getNotificationOriginator()) to the targets specified by the SnmpTargetMIB and SnmpNotificationMIB instances supplied to the notification originator.
      Specified by:
      notify in interface 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 array of ResponseEvent instances or NotificationTask instance if the notification has been sent asynchronously. Since the NotificationOriginator determines on behalf of the SNMP-NOTIFICATION-MIB contents whether a notification is sent as trap/notification or as inform request, the returned array will contain an element for each addressed target, but only a response PDU for inform targets. null will be returned when sending the notification failed because there is no NotificationOriginator set.

      NOTE: If this command processor is using a ThreadPool then the returned object will be NotificationTask instance. If all response have been received Object.notify() will be called on the returned NotificationTask object by the sending thread.

    • notify

      public Object notify(org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID notificationID, org.snmp4j.smi.TimeTicks sysUpTime, org.snmp4j.smi.VariableBinding[] vbs)
      Description copied from interface: NotificationOriginator
      Sends notifications (traps) to all appropriate notification targets. The targets to notify are determined through the SNMP-TARGET-MIB and the SNMP-NOTIFICATION-MIB.
      Specified by:
      notify in interface 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.
      sysUpTime - the value of the sysUpTime for the context context. This value will be included in the generated notification as sysUpTime.0.
      vbs - an array of VariableBinding instances representing the payload of the notification.
      Returns:
      an array of ResponseEvent instances. Since the NotificationOriginator determines on behalf of the SNMP-NOTIFICATON-MIB contents whether a notification is sent as trap/notification or as inform request, the returned array contains an element for each addressed target, but only a response PDU for inform targets.
    • setNotificationOriginator

      public void setNotificationOriginator(NotificationOriginator notificationOriginator)
    • setCoexistenceProvider

      public void setCoexistenceProvider(CoexistenceInfoProvider coexistenceProvider)
    • addProxyForwarder

      public ProxyForwarder addProxyForwarder(ProxyForwarder proxyForwarder, org.snmp4j.smi.OctetString contextEngineID, int proxyType)
    • removeProxyForwarder

      public ProxyForwarder removeProxyForwarder(org.snmp4j.smi.OctetString contextEngineID, int proxyType)
    • getHandler

      protected RequestHandler<SnmpRequest> getHandler(int pduType)
    • dispatchCommand

      protected <A extends org.snmp4j.smi.Address> void dispatchCommand(org.snmp4j.CommandResponderEvent<A> command, CoexistenceInfo cinfo)
    • processRequest

      protected <A extends org.snmp4j.smi.Address> void processRequest(org.snmp4j.CommandResponderEvent<A> command, CoexistenceInfo cinfo, RequestHandler<SnmpRequest> handler)
    • reprocessRequest

      protected void reprocessRequest(MOServer server, SnmpRequest req)
    • processRequest

      protected <R extends Request<Source, Response, ? extends SubRequest<?>>, Source, Response> void processRequest(MOServer server, RequestHandler<R> handler, R req)
      Processes (or re-process) a request and try to complete the request (thus to complete any incomplete subrequests).
      Type Parameters:
      R - the Request type to process.
      Source - the source object that created the request for processing.
      Response - the response PDU type created by the request processing.
      Parameters:
      server - the MOServer instance to use for accessing instrumentation.
      handler - the RequestHandler to use to process the request.
      req - the Request.
    • finalizeRequest

      protected <A extends org.snmp4j.smi.Address> void finalizeRequest(org.snmp4j.CommandResponderEvent<A> command, SnmpRequest req, MOServer server)
    • release

      protected void release(MOServer server, SnmpRequest req)
    • sendResponse

      protected <A extends org.snmp4j.smi.Address> void sendResponse(org.snmp4j.CommandResponderEvent<A> requestEvent, org.snmp4j.PDU response)
    • setAuthorizationError

      protected void setAuthorizationError(Request<?,?,?> req, int vacmStatus)
    • addPduHandler

      public void addPduHandler(RequestHandler<SnmpRequest> handler)
    • removePduHandler

      public void removePduHandler(RequestHandler<SnmpRequest> handler)
    • addMOServer

      public boolean addMOServer(MOServer server)
      Adds a MOServer to this command processor and returns true on success.
      Parameters:
      server - the MOServer to add to this command processor with the least priority.
      Returns:
      true if the MOServer has been added, false if the MOServer is already present in this command processor.
    • removeMOServer

      public boolean removeMOServer(MOServer server)
      Removes a MOServer from this command processor and returns true on success.
      Parameters:
      server - the MOServer to remove from this command processor.
      Returns:
      true if the server has been removed, false if the server was not subject to command processing.
    • getServer

      public MOServer getServer(org.snmp4j.smi.OctetString context)
      Gets a MOServer responsible for the specified context.
      Parameters:
      context - a SNMPv3 context or null for the default context.
      Returns:
      a MOServer that returns true on MOServer.isContextSupported(OctetString) for the supplied SNMPv3 context or null if such a MOServer instance does not exists.
    • getRequestList

      public TemporaryList<SnmpRequest> getRequestList()
    • getNotificationOriginator

      public NotificationOriginator getNotificationOriginator()
    • getProxyForwarder

      public ProxyMap getProxyForwarder()
    • getCoexistenceProvider

      public CoexistenceInfoProvider getCoexistenceProvider()
    • isLockNonNextRequestsSortedByVbOid

      public boolean isLockNonNextRequestsSortedByVbOid()
      Get the status of the lock optimization for GEt and SET requests to avoid deadlocks by locking ManagedObjects in ascending lexicographic order of their VariableBinding OID.
      Returns:
      true if activated and false otherwise (default).
      Since:
      3.7.0
    • setLockNonNextRequestsSortedByVbOid

      public void setLockNonNextRequestsSortedByVbOid(boolean lockNonNextRequestsSortedByVbOid)
      Lock the ManagedObjects when processing a SET or GET request in ascending lexicographic order of their VariableBinding OID if true.
      Parameters:
      lockNonNextRequestsSortedByVbOid - if true then lock managed objects for GET and SET requests in ascending lexicographic order of the OIDs of their VariableBindings. Default is false.
      Since:
      3.7.0
    • isContextNotSupported

      protected boolean isContextNotSupported(org.snmp4j.smi.OctetString context)
      Check if the supplied context is known and available or not. If the context is not known, the SnmpTargetMIB.snmpUnknownContexts counter is being incremented.
      Parameters:
      context - the context name to check.
      Returns:
      true if the context is not supported and false otherwise. By default, this method checks only if the context is not known. Thus, availability is always assumed if a context is known. To change this behavior this method has to be overwritten in a subclass.
    • getViewName

      protected org.snmp4j.smi.OctetString getViewName(org.snmp4j.CommandResponderEvent<?> req, CoexistenceInfo cinfo, int viewType)
    • processNextSubRequest

      protected void processNextSubRequest(SnmpRequest request, MOServer server, org.snmp4j.smi.OctetString context, SubRequest<?> sreq) throws NoSuchElementException
      Throws:
      NoSuchElementException
    • unlockManagedObjectIfLockedByLookup

      protected void unlockManagedObjectIfLockedByLookup(MOServer server, ManagedObject<?> mo, LockRequest lockRequest)
      Unlock the provided ManagedObject if the also provided LockRequest indicates that the managed object was locked by a preceding MOServer.lookup(MOQuery, LockRequest) operation.
      Parameters:
      server - a MOServer that put the lock.
      mo - the possibly locked managed object.
      lockRequest - the lock request with the status of the (potentially acquired) lock.
      Since:
      2.4.0
    • addCounterListener

      public void addCounterListener(org.snmp4j.event.CounterListener l)
    • removeCounterListener

      public void removeCounterListener(org.snmp4j.event.CounterListener l)
    • fireIncrementCounter

      protected void fireIncrementCounter(org.snmp4j.event.CounterEvent event)