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 Summary
FieldsModifier and TypeFieldDescriptionprotected CoexistenceInfoProviderprotected booleanLock theManagedObjects when processing a SET or GET request in ascending lexicographic order of theirVariableBindingOID iftrue.protected NotificationOriginatorprotected List<org.snmp4j.smi.OctetString> protected final List<RequestHandler<SnmpRequest>> protected ProxyMapprotected RequestFactory<org.snmp4j.CommandResponderEvent<?>, org.snmp4j.PDU, SnmpRequest> protected TemporaryList<SnmpRequest> protected org.snmp4j.util.WorkerPoolprotected VACM -
Constructor Summary
ConstructorsConstructorDescriptionCommandProcessor(org.snmp4j.smi.OctetString contextEngineID) Creates aCommandProcessorand registers all PDU types with the supplied contextEngineID as well as withMPv3.LOCAL_ENGINE_IDas required by RFC 5343. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCounterListener(org.snmp4j.event.CounterListener l) booleanaddMOServer(MOServer server) Adds aMOServerto this command processor and returnstrueon success.voidaddPduHandler(RequestHandler<SnmpRequest> handler) addProxyForwarder(ProxyForwarder proxyForwarder, org.snmp4j.smi.OctetString contextEngineID, int proxyType) protected <A extends org.snmp4j.smi.Address>
voiddispatchCommand(org.snmp4j.CommandResponderEvent<A> command, CoexistenceInfo cinfo) protected <A extends org.snmp4j.smi.Address>
voidfinalizeRequest(org.snmp4j.CommandResponderEvent<A> command, SnmpRequest req, MOServer server) protected voidfireIncrementCounter(org.snmp4j.event.CounterEvent event) org.snmp4j.smi.OctetStringprotected RequestHandler<SnmpRequest> getHandler(int pduType) intGets the internal request timeout millis.getServer(org.snmp4j.smi.OctetString context) Gets aMOServerresponsible for the specified context.getVacm()protected org.snmp4j.smi.OctetStringgetViewName(org.snmp4j.CommandResponderEvent<?> req, CoexistenceInfo cinfo, int viewType) protected <A extends org.snmp4j.smi.Address>
booleanisContextNotSupported(org.snmp4j.smi.OctetString context, org.snmp4j.CommandResponderEvent<A> command) Check if the supplied context is known and available or not.booleanGet the status of the lock optimization for GEt and SET requests to avoid deadlocks by lockingManagedObjects in ascending lexicographic order of theirVariableBindingOID.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.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 voidprocessNextSubRequest(SnmpRequest request, MOServer server, org.snmp4j.smi.OctetString context, SubRequest<?> sreq) <A extends org.snmp4j.smi.Address>
voidprocessPdu(org.snmp4j.CommandResponderEvent<A> event) protected <R extends Request<Source,Response, ? extends SubRequest<?>>, Source, Response>
voidprocessRequest(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).protected <A extends org.snmp4j.smi.Address>
voidprocessRequest(org.snmp4j.CommandResponderEvent<A> command, CoexistenceInfo cinfo, RequestHandler<SnmpRequest> handler) protected voidrelease(MOServer server, SnmpRequest req) voidremoveCounterListener(org.snmp4j.event.CounterListener l) booleanremoveMOServer(MOServer server) Removes aMOServerfrom this command processor and returnstrueon success.voidremovePduHandler(RequestHandler<SnmpRequest> handler) removeProxyForwarder(org.snmp4j.smi.OctetString contextEngineID, int proxyType) protected voidreprocessRequest(MOServer server, SnmpRequest req) protected <A extends org.snmp4j.smi.Address>
voidsendResponse(org.snmp4j.CommandResponderEvent<A> requestEvent, org.snmp4j.PDU response) protected voidsetAuthorizationError(Request<?, ?, ?> req, int vacmStatus) voidsetCoexistenceProvider(CoexistenceInfoProvider coexistenceProvider) voidsetContextEngineID(org.snmp4j.smi.OctetString contextEngineID) voidsetInternalRequestTimeout(int timeoutMillis) Sets the internal request timeout.voidsetLockNonNextRequestsSortedByVbOid(boolean lockNonNextRequestsSortedByVbOid) Lock theManagedObjects when processing a SET or GET request in ascending lexicographic order of theirVariableBindingOID iftrue.voidsetNotificationOriginator(NotificationOriginator notificationOriginator) voidsetThreadPool(org.snmp4j.util.WorkerPool threadPool) Deprecated.voidvoidsetWorkerPool(org.snmp4j.util.WorkerPool threadPool) Sets the internal thread pool for task execution.protected voidunlockManagedObjectIfLockedByLookup(MOServer server, ManagedObject<?> mo, LockRequest lockRequest) Unlock the providedManagedObjectif the also providedLockRequestindicates that the managed object was locked by a precedingMOServer.lookup(MOQuery, LockRequest)operation.
-
Field Details
-
threadPool
protected org.snmp4j.util.WorkerPool threadPool -
vacm
-
moServers
-
ownContextEngineIDs
-
pduHandler
-
requestList
-
requestFactory
protected RequestFactory<org.snmp4j.CommandResponderEvent<?>,org.snmp4j.PDU, requestFactorySnmpRequest> -
notificationOriginator
-
proxyForwarder
-
coexistenceProvider
-
lockNonNextRequestsSortedByVbOid
protected boolean lockNonNextRequestsSortedByVbOidLock theManagedObjects when processing a SET or GET request in ascending lexicographic order of theirVariableBindingOID iftrue.
-
-
Constructor Details
-
CommandProcessor
public CommandProcessor(org.snmp4j.smi.OctetString contextEngineID) Creates aCommandProcessorand registers all PDU types with the supplied contextEngineID as well as withMPv3.LOCAL_ENGINE_IDas 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:
processPduin interfaceorg.snmp4j.CommandResponder
-
setThreadPool
Deprecated.UsesetWorkerPool(org.snmp4j.util.WorkerPool)insteadSets 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
-
setVacm
-
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 internalThreadPoolto send the message(s) via theNotificationOriginator(seegetNotificationOriginator()) to the targets specified by the SnmpTargetMIB and SnmpNotificationMIB instances supplied to the notification originator.- Specified by:
notifyin interfaceNotificationOriginator- 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 ofVariableBindinginstances representing the payload of the notification.- Returns:
- an array of ResponseEvent instances or NotificationTask instance if
the notification has been sent asynchronously. Since the
NotificationOriginatordetermines 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.nullwill be returned when sending the notification failed because there is noNotificationOriginatorset.NOTE: If this command processor is using a ThreadPool then the returned object will be
NotificationTaskinstance. If all response have been receivedObject.notify()will be called on the returnedNotificationTaskobject 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:NotificationOriginatorSends 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:
notifyin interfaceNotificationOriginator- 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 contextcontext. This value will be included in the generated notification assysUpTime.0.vbs- an array ofVariableBindinginstances representing the payload of the notification.- Returns:
- an array of ResponseEvent instances. Since the
NotificationOriginatordetermines 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
-
setCoexistenceProvider
-
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
-
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
-
processRequest
protected <R extends Request<Source,Response, void processRequest? extends SubRequest<?>>, Source, Response> (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- theRequesttype to process.Source- the source object that created the request for processing.Response- the response PDU type created by the request processing.- Parameters:
server- theMOServerinstance to use for accessing instrumentation.handler- theRequestHandlerto use to process the request.req- theRequest.
-
finalizeRequest
protected <A extends org.snmp4j.smi.Address> void finalizeRequest(org.snmp4j.CommandResponderEvent<A> command, SnmpRequest req, MOServer server) -
release
-
sendResponse
protected <A extends org.snmp4j.smi.Address> void sendResponse(org.snmp4j.CommandResponderEvent<A> requestEvent, org.snmp4j.PDU response) -
setAuthorizationError
-
addPduHandler
-
removePduHandler
-
addMOServer
Adds aMOServerto this command processor and returnstrueon success. -
removeMOServer
Removes aMOServerfrom this command processor and returnstrueon success.- Parameters:
server- theMOServerto remove from this command processor.- Returns:
trueif the server has been removed,falseif the server was not subject to command processing.
-
getServer
Gets aMOServerresponsible for the specified context.- Parameters:
context- a SNMPv3 context ornullfor the default context.- Returns:
- a
MOServerthat returnstrueonMOServer.isContextSupported(OctetString)for the supplied SNMPv3 context ornullif such aMOServerinstance does not exists.
-
getRequestList
-
getNotificationOriginator
-
getProxyForwarder
-
getCoexistenceProvider
-
isLockNonNextRequestsSortedByVbOid
public boolean isLockNonNextRequestsSortedByVbOid()Get the status of the lock optimization for GEt and SET requests to avoid deadlocks by lockingManagedObjects in ascending lexicographic order of theirVariableBindingOID.- Returns:
trueif activated andfalseotherwise (default).- Since:
- 3.7.0
-
setLockNonNextRequestsSortedByVbOid
public void setLockNonNextRequestsSortedByVbOid(boolean lockNonNextRequestsSortedByVbOid) Lock theManagedObjects when processing a SET or GET request in ascending lexicographic order of theirVariableBindingOID iftrue.- Parameters:
lockNonNextRequestsSortedByVbOid- iftruethen lock managed objects for GET and SET requests in ascending lexicographic order of the OIDs of theirVariableBindings. Default isfalse.- Since:
- 3.7.0
-
isContextNotSupported
protected <A extends org.snmp4j.smi.Address> boolean isContextNotSupported(org.snmp4j.smi.OctetString context, org.snmp4j.CommandResponderEvent<A> command) Check if the supplied context is known and available or not. If the context is not known, theSnmpTargetMIB.snmpUnknownContextscounter is being incremented and a REPORT PDU is sent back to the command originator.- Parameters:
context- the context name to check.command- theCommandResponderEventfor which the context support is being checked. If it fails, a REPORT PDU is sent back to the command originator instead of a response PDU. If command isnull, no REPORT will be sent.- Returns:
- a
trueif the context is not supported andfalseotherwise. 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. - Since:
- 3.8.1
-
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 providedManagedObjectif the also providedLockRequestindicates that the managed object was locked by a precedingMOServer.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)
-
setWorkerPool(org.snmp4j.util.WorkerPool)instead