org.snmp4j.agent
Class CommandProcessor

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

public class CommandProcessor
extends java.lang.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:
1.0
Author:
Frank Fock

Field Summary
protected  CoexistenceInfoProvider coexistenceProvider
           
protected  java.util.Vector<MOServer> moServers
           
protected  NotificationOriginator notificationOriginator
           
protected  java.util.List<org.snmp4j.smi.OctetString> ownContextEngineIDs
           
protected  java.util.Vector<RequestHandler> pduHandler
           
protected  ProxyMap proxyForwarder
           
protected  RequestFactory<org.snmp4j.CommandResponderEvent> requestFactory
           
protected  TemporaryList<Request> requestList
           
protected  org.snmp4j.util.WorkerPool threadPool
           
protected  VACM vacm
           
 
Constructor Summary
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.
 
Method Summary
 void addCounterListener(org.snmp4j.event.CounterListener l)
           
 void addMOServer(MOServer server)
           
 void addPduHandler(RequestHandler handler)
           
 ProxyForwarder addProxyForwarder(ProxyForwarder proxyForwarder, org.snmp4j.smi.OctetString contextEngineID, int proxyType)
           
protected  void dispatchCommand(org.snmp4j.CommandResponderEvent command, CoexistenceInfo cinfo)
           
protected  void finalizeRequest(org.snmp4j.CommandResponderEvent command, Request req, MOServer server)
           
protected  void fireIncrementCounter(org.snmp4j.event.CounterEvent event)
           
 CoexistenceInfoProvider getCoexistenceProvider()
           
 org.snmp4j.smi.OctetString getContextEngineID()
           
protected  RequestHandler getHandler(int pduType)
           
 int getInternalRequestTimeout()
          Gets the internal request timeout millis.
 NotificationOriginator getNotificationOriginator()
           
 ProxyMap getProxyForwarder()
           
 TemporaryList<Request> getRequestList()
           
 MOServer getServer(org.snmp4j.smi.OctetString context)
           
 VACM getVacm()
           
protected  org.snmp4j.smi.OctetString getViewName(org.snmp4j.CommandResponderEvent req, CoexistenceInfo cinfo, int viewType)
           
 java.lang.Object notify(org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID notificationID, org.snmp4j.smi.TimeTicks sysUpTime, org.snmp4j.smi.VariableBinding[] vbs)
          Sends notifications (traps) to all appropriate notification targets.
 java.lang.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.
protected  void processNextSubRequest(Request request, MOServer server, org.snmp4j.smi.OctetString context, SubRequest sreq)
           
 void processPdu(org.snmp4j.CommandResponderEvent event)
           
protected  void processRequest(org.snmp4j.CommandResponderEvent command, CoexistenceInfo cinfo, RequestHandler handler)
           
protected  void processRequest(MOServer server, RequestHandler handler, Request req)
          Processs (or re-process) a request and try to complete the request (thus to complete any incomplete subrequests).
protected  void release(MOServer server, Request req)
           
 void removeCounterListener(org.snmp4j.event.CounterListener l)
           
 void removeMOServer(MOServer server)
           
 void removePduHandler(RequestHandler handler)
           
 ProxyForwarder removeProxyForwarder(org.snmp4j.smi.OctetString contextEngineID, int proxyType)
           
protected  void reprocessRequest(MOServer server, SnmpRequest req)
           
protected  void sendResponse(org.snmp4j.CommandResponderEvent requestEvent, org.snmp4j.PDU response)
           
protected  void setAuthorizationError(Request req, int vacmStatus)
           
 void setCoexistenceProvider(CoexistenceInfoProvider coexistenceProvider)
           
 void setContextEngineID(org.snmp4j.smi.OctetString contextEngineID)
           
 void setInternalRequestTimeout(int timeoutMillis)
          Sets the internal request timeout.
 void setNotificationOriginator(NotificationOriginator notificationOriginator)
           
 void setThreadPool(org.snmp4j.util.WorkerPool threadPool)
          Deprecated. Use setWorkerPool(org.snmp4j.util.WorkerPool) instead
 void setVacm(VACM vacm)
           
 void setWorkerPool(org.snmp4j.util.WorkerPool threadPool)
          Sets the internal thread pool for task execution.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

threadPool

protected org.snmp4j.util.WorkerPool threadPool

vacm

protected VACM vacm

moServers

protected java.util.Vector<MOServer> moServers

ownContextEngineIDs

protected java.util.List<org.snmp4j.smi.OctetString> ownContextEngineIDs

pduHandler

protected final java.util.Vector<RequestHandler> pduHandler

requestList

protected TemporaryList<Request> requestList

requestFactory

protected RequestFactory<org.snmp4j.CommandResponderEvent> requestFactory

notificationOriginator

protected NotificationOriginator notificationOriginator

proxyForwarder

protected ProxyMap proxyForwarder

coexistenceProvider

protected CoexistenceInfoProvider coexistenceProvider
Constructor Detail

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 Detail

setInternalRequestTimeout

public void setInternalRequestTimeout(int timeoutMillis)
Sets the internal request timeout. Any request must return within this amount of milli-seconds. Default is five minutes.

Parameters:
timeoutMillis - the maximum number of milli-seconds a request can be processed.
Since:
1.3

getInternalRequestTimeout

public int getInternalRequestTimeout()
Gets the internal request timeout millis.

Returns:
the maximum number of milli-seconds a request can be processed.
Since:
1.3

processPdu

public void processPdu(org.snmp4j.CommandResponderEvent event)
Specified by:
processPdu in interface org.snmp4j.CommandResponder

setThreadPool

public void setThreadPool(org.snmp4j.util.WorkerPool threadPool)
Deprecated. Use setWorkerPool(org.snmp4j.util.WorkerPool) instead

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 java.lang.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 send asynchronously. Since the NotificationOriginator determines on behalf of the SNMP-NOTIFICTON-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 java.lang.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-NOTIFICTON-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 getHandler(int pduType)

dispatchCommand

protected void dispatchCommand(org.snmp4j.CommandResponderEvent command,
                               CoexistenceInfo cinfo)

processRequest

protected void processRequest(org.snmp4j.CommandResponderEvent command,
                              CoexistenceInfo cinfo,
                              RequestHandler handler)

reprocessRequest

protected void reprocessRequest(MOServer server,
                                SnmpRequest req)

processRequest

protected void processRequest(MOServer server,
                              RequestHandler handler,
                              Request req)
Processs (or re-process) a request and try to complete the request (thus to complete any incomplete subrequests).

Parameters:
server - the MOServer instance to use for accessing instrumentation.
handler - the RequestHandler to use to process the request.
req - the Request.

finalizeRequest

protected void finalizeRequest(org.snmp4j.CommandResponderEvent command,
                               Request req,
                               MOServer server)

release

protected void release(MOServer server,
                       Request req)

sendResponse

protected void sendResponse(org.snmp4j.CommandResponderEvent requestEvent,
                            org.snmp4j.PDU response)

setAuthorizationError

protected void setAuthorizationError(Request req,
                                     int vacmStatus)

addPduHandler

public void addPduHandler(RequestHandler handler)

removePduHandler

public void removePduHandler(RequestHandler handler)

addMOServer

public void addMOServer(MOServer server)

removeMOServer

public void removeMOServer(MOServer server)

getServer

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

getRequestList

public TemporaryList<Request> getRequestList()

getNotificationOriginator

public NotificationOriginator getNotificationOriginator()

getProxyForwarder

public ProxyMap getProxyForwarder()

getCoexistenceProvider

public CoexistenceInfoProvider getCoexistenceProvider()

getViewName

protected org.snmp4j.smi.OctetString getViewName(org.snmp4j.CommandResponderEvent req,
                                                 CoexistenceInfo cinfo,
                                                 int viewType)

processNextSubRequest

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

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)

Copyright 2005-2010 Frank Fock (SNMP4J.org)

Copyright © 2011 SNMP4J.org. All Rights Reserved.