Package org.snmp4j.agent.agentx.master
Class AgentXCommandProcessor
java.lang.Object
org.snmp4j.agent.CommandProcessor
org.snmp4j.agent.agentx.master.AgentXCommandProcessor
- All Implemented Interfaces:
EventListener,AgentXCommandListener,AgentXResponseListener,org.snmp4j.agent.NotificationOriginator,org.snmp4j.CommandResponder,org.snmp4j.transport.TransportStateListener
public class AgentXCommandProcessor
extends org.snmp4j.agent.CommandProcessor
implements AgentXCommandListener, org.snmp4j.transport.TransportStateListener, AgentXResponseListener
The
AgentXCommandProcessor implements the CommandProcessor
interface for AgentX command processing of an AgentX master agent.
It holds the AgentX sessions and region registrations internally.
The context engine ID of the master agent, the AgentXQueue,
the AgentX protocol adapter, and the MOServers have
to be provided for instance creation.- Author:
- Frank Fock
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classComparator forAgentXCommandProcessor.AgentXRegEntryComparatorto compare objects by context and region. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AgentXIndexRegistryIndex registry of the AgentX master agent.static final intThe default maximum reprocessing count.Fields inherited from class org.snmp4j.agent.CommandProcessor
coexistenceProvider, lockNonNextRequestsSortedByVbOid, moServers, notificationOriginator, ownContextEngineIDs, pduHandler, proxyForwarder, requestFactory, requestList, threadPool, vacm -
Constructor Summary
ConstructorsConstructorDescriptionAgentXCommandProcessor(org.snmp4j.smi.OctetString contextEngineID, AgentXQueue queue, AgentX agentX, org.snmp4j.agent.MOServer[] server) Creates anAgentXCommandProcessorusing aAgentXentity and an array ofMOServerinstances representing the master agentsManagedObjects. -
Method Summary
Modifier and TypeMethodDescriptionprotected intacceptSession(AgentXMasterSession<?> session) Accept a new session and fire the correspondingAgentXMasterEvent.SESSION_ADDEDevent.addAgentCaps(AgentXAddAgentCapsPDU pdu, AgentXMasterSession<?> session) Process anAgentXAddAgentCapsPDU.voidAdds aAgentXMasterListener.protected voidaddPeer(AgentXPeer<?> peer) Adds an AgentXPeer and fires the correspondingAgentXMasterEvent.protected voidaddRegion(AgentXRegEntry<?> registration, AgentXRegion region) Adds a region to the registry.protected voidaddRegistration(AgentXRegEntry<?> registration) Adds a registration to this master server.protected voidaddSession(AgentXMasterSession<?> session) Add a new session and fire the correspondingAgentXMasterEvent.SESSION_ADDEDevent.Map<AgentXSession<?>, Integer> closeAllSessions(byte reason) Close all sessions associated with thisAgentXCommandListenerand return the AgentX status of the close operation together with theAgentXSessionobject.protected AgentXPeer<?> closePeer(org.snmp4j.smi.Address peerAddress, byte reason) Close a peer, i.e.closeSession(AgentXClosePDU pdu, AgentXMasterSession<?> session) Process anAgentXClosePDU, close the session and remove all registrations.<A extends org.snmp4j.smi.Address>
intcloseSession(AgentXMasterSession<A> session, byte reason) Close the specifiedAgentXSession.voidconnectionStateChanged(org.snmp4j.transport.TransportStateEvent change) Process a connection state change, i.e.protected AgentXResponsePDUcreateResponse(AgentXPDU request, AgentXSession<?> session) Create a response for an AgentX request.protected <A extends org.snmp4j.smi.Address>
voidfinalizeRequest(org.snmp4j.CommandResponderEvent<A> command, org.snmp4j.agent.request.SnmpRequest req, org.snmp4j.agent.MOServer server) Finish a request a free all related resources.protected voidFire aAgentXMasterEventprotected org.snmp4j.agent.mo.snmp.AgentCapabilityListgetAgentCaps(org.snmp4j.smi.OctetString contextName) Gets the Agent-Capabilities for a context.byteGets the AgentX version.protected org.snmp4j.smi.TimeTicksgetContextSysUpTime(org.snmp4j.smi.OctetString context) Gets the sysUpTime for the specified context.byteGets the default timeout for this AgentX entity.intGets the maximum number of consecutive timeouts allowed per session.intGets the upper limit for parse errors for an AgentX peer.intGets the request maximum reprocessing value.protected intGets the next session ID.protected <A extends org.snmp4j.smi.Address>
AgentXPeer<A> getPeer(A address) Gets a peer based on its address.org.snmp4j.agent.MOServerDeprecated.protected AgentXMasterSession<?> getSession(int sessionID) Gets the session for a given session ID.protected AgentXMasterSession<?> getSession(AgentXPDU pdu) Gets the session for anAgentXPDU.indexAllocate(AgentXIndexAllocatePDU pdu, AgentXMasterSession<?> session) Allocate an index.indexDeallocate(AgentXIndexDeallocatePDU pdu, AgentXMasterSession<?> session) Deallocate an index.booleanIndicates whether subagents can register contexts that are not yet supported by this master agent.protected booleanisDuplicate(AgentXRegEntry<?> registration) Checks whether a new registration is a duplicate.protected AgentXResponsePDUnotify(AgentXNotifyPDU pdu, AgentXMasterSession<?> session) Process a notification PDU for anAgentXSession.voidonResponse(AgentXResponseEvent<?> event) Process anAgentXResponseEvent.<A extends org.snmp4j.smi.Address>
AgentXResponsePDUopenSession(AgentXOpenPDU pdu, AgentXCommandEvent<A> event) Opens a new AgentX session.protected AgentXResponsePDUping(AgentXPingPDU pdu, AgentXMasterSession<?> session) Respond to a Ping request.protected voidprocessAgentXBulkResponse(AgentXPending<?> pending, AgentXResponsePDU pdu) Process an AgentX-GETBULK-Response.protected voidprocessAgentXGetNextResponse(AgentXPending<?> pending, AgentXResponsePDU pdu) Process a pending GETNEXT response.protected voidprocessAgentXGetResponse(AgentXPending<?> pending, AgentXResponsePDU pdu) Process a pending GET response.protected voidprocessAgentXSetResponse(AgentXPending<?> pending, AgentXResponsePDU pdu) Process a pending SET response.<A extends org.snmp4j.smi.Address>
voidprocessCommand(AgentXCommandEvent<A> event) Process anAgentXCommandEvent.protected static voidprocesssErrorResponse(AgentXPending<?> pending, AgentXResponsePDU pdu) Process an error response.protected <A extends org.snmp4j.smi.Address>
AgentXResponsePDUregister(AgentXRegisterPDU pdu, AgentXCommandEvent<A> command, AgentXMasterSession<A> session) Process aAgentXRegisterPDU.removeAgentCaps(AgentXRemoveAgentCapsPDU pdu, AgentXMasterSession<?> session) Process anAgentXRemoveAgentCapsPDU.voidRemove aAgentXMasterListener.protected voidremoveAllRegistrations(AgentXMasterSession<?> session) Remove all registrations for a session.protected AgentXPeer<?> removePeer(org.snmp4j.smi.Address peerAddress) Removes a peer and all its sessions.protected booleanremoveRegistration(AgentXRegEntry<?> registration, Iterator<AgentXRegEntry<?>> regIterator) Remove a registrationprotected AgentXMasterSession<?> removeSession(int sessionID) Remove a session.protected <A extends org.snmp4j.smi.Address>
voidsendResponse(AgentXPDU response, AgentXSession<A> session) Sends a response to a session.voidsetAcceptNewContexts(boolean acceptNewContexts) Enables or disables accepting new contexts from subagents.voidsetDefaultTimeout(byte defaultTimeout) Sets the default timeout.voidsetMaxConsecutiveTimeouts(int maxConsecutiveTimeouts) Sets the maximum number of timeouts allowed per session.voidsetMaxParseErrors(int maxParseErrors) Sets the maximum number of parse errors allowed per peer.voidsetMaxReprocessing(int maxReprocessing) Sets the maximum reprocessing.protected <A extends org.snmp4j.smi.Address>
AgentXResponsePDUunregister(AgentXUnregisterPDU pdu, AgentXCommandEvent<A> event, AgentXMasterSession<A> session) Process aAgentXUnregisterPDU.Methods inherited from class org.snmp4j.agent.CommandProcessor
addCounterListener, addMOServer, addPduHandler, addProxyForwarder, dispatchCommand, fireIncrementCounter, getCoexistenceProvider, getContextEngineID, getHandler, getInternalRequestTimeout, getNotificationOriginator, getProxyForwarder, getRequestList, getServer, getVacm, getViewName, isContextNotSupported, isLockNonNextRequestsSortedByVbOid, notify, notify, processNextSubRequest, processPdu, processRequest, processRequest, release, removeCounterListener, removeMOServer, removePduHandler, removeProxyForwarder, reprocessRequest, sendResponse, setAuthorizationError, setCoexistenceProvider, setContextEngineID, setInternalRequestTimeout, setLockNonNextRequestsSortedByVbOid, setNotificationOriginator, setThreadPool, setVacm, setWorkerPool, unlockManagedObjectIfLockedByLookup
-
Field Details
-
MAX_REPROCESSING_DEFAULT
public static final int MAX_REPROCESSING_DEFAULTThe default maximum reprocessing count. This value should be high enough to allow enough GETBULK repetitions but low enough to avoid sub-agent overload, if reprocessing fails.- See Also:
-
indexRegistry
Index registry of the AgentX master agent.
-
-
Constructor Details
-
AgentXCommandProcessor
public AgentXCommandProcessor(org.snmp4j.smi.OctetString contextEngineID, AgentXQueue queue, AgentX agentX, org.snmp4j.agent.MOServer[] server) Creates anAgentXCommandProcessorusing aAgentXentity and an array ofMOServerinstances representing the master agentsManagedObjects.- Parameters:
contextEngineID- the context engine ID of associated with this AgentX command processor (by default the master agent's local engine ID).queue- theAgentXQueueto store pending requests.agentX- theAgentXserver.server- the managed objects of the master agent.
-
-
Method Details
-
setMaxReprocessing
public void setMaxReprocessing(int maxReprocessing) Sets the maximum reprocessing. Default isMAX_REPROCESSING_DEFAULT- Parameters:
maxReprocessing- the maximum reprocessing of AgentX requests.
-
getMaxReprocessing
public int getMaxReprocessing()Gets the request maximum reprocessing value.- Returns:
- the maximum reprocessing count of AgentX requests.
-
setMaxParseErrors
public void setMaxParseErrors(int maxParseErrors) Sets the maximum number of parse errors allowed per peer. If this number is exceeded then the peer will be closed with reasonAgentXProtocol.REASON_PARSE_ERROR.- Parameters:
maxParseErrors- a positive value (including zero) sets the upper limit of parse errors tolerated per peer. If the number of parse errors exceeds this limit, all sessions with that peer will be closed. A negative value deactivates any limit.- Since:
- 1.0.1
-
getMaxParseErrors
public int getMaxParseErrors()Gets the upper limit for parse errors for an AgentX peer.- Returns:
- a positive value (including zero) indicates the upper limit of parse errors tolerated per peer. A negative value indicates that there is no limit.
- Since:
- 1.0.1
-
finalizeRequest
protected <A extends org.snmp4j.smi.Address> void finalizeRequest(org.snmp4j.CommandResponderEvent<A> command, org.snmp4j.agent.request.SnmpRequest req, org.snmp4j.agent.MOServer server) Finish a request a free all related resources.- Overrides:
finalizeRequestin classorg.snmp4j.agent.CommandProcessor- Parameters:
command- the request processed.req- the associatedSnmpRequest.server- theMOServerto reprocess the request, if necessary.
-
getNextSessionID
protected int getNextSessionID()Gets the next session ID.- Returns:
- a new session ID.
-
getServer
Deprecated.UseCommandProcessor.getServer(OctetString context)instead.Gets the default server (for thenullcontext).- Returns:
- the default server instance.
-
getDefaultTimeout
public byte getDefaultTimeout()Gets the default timeout for this AgentX entity.- Returns:
- the timout in seconds.
-
getMaxConsecutiveTimeouts
public int getMaxConsecutiveTimeouts()Gets the maximum number of consecutive timeouts allowed per session.- Returns:
- the maximum number of consecutive timeouts allowed per session
-
isAcceptNewContexts
public boolean isAcceptNewContexts()Indicates whether subagents can register contexts that are not yet supported by this master agent.- Returns:
trueif subagents can register objects for new contexts.
-
setDefaultTimeout
public void setDefaultTimeout(byte defaultTimeout) Sets the default timeout.- Parameters:
defaultTimeout- the default timeout in seconds.
-
setMaxConsecutiveTimeouts
public void setMaxConsecutiveTimeouts(int maxConsecutiveTimeouts) Sets the maximum number of timeouts allowed per session. If the number is exceeded then the session will be closed with reasonAgentXProtocol.REASON_TIMEOUTS.- Parameters:
maxConsecutiveTimeouts- the maximum number of timeouts (should be greater than zero).
-
setAcceptNewContexts
public void setAcceptNewContexts(boolean acceptNewContexts) Enables or disables accepting new contexts from subagents.- Parameters:
acceptNewContexts-trueif subagents are allowed to register objects for new contexts,falseotherwise. Default isfalse.
-
processCommand
Process anAgentXCommandEvent.- Specified by:
processCommandin interfaceAgentXCommandListener- Type Parameters:
A-Addresstype of peer that trigger this command.- Parameters:
event- the AgentX message and necessary context information.
-
indexDeallocate
public AgentXResponsePDU indexDeallocate(AgentXIndexDeallocatePDU pdu, AgentXMasterSession<?> session) Deallocate an index.- Parameters:
pdu- the deallocation PDU.session- the session deallocating.- Returns:
- the
AgentXResponsePDU.
-
indexAllocate
Allocate an index.- Parameters:
pdu- the allocation PDU.session- the session allocating.- Returns:
- the
AgentXResponsePDU.
-
processAgentXBulkResponse
Process an AgentX-GETBULK-Response.- Parameters:
pending- the pending GETBULK requestpdu- the response PDU.
-
processsErrorResponse
protected static void processsErrorResponse(AgentXPending<?> pending, AgentXResponsePDU pdu) throws NoSuchElementException Process an error response.- Parameters:
pending- the pending GETBULK requestpdu- the response PDU.- Throws:
NoSuchElementException- if there are less sub-request in the pending request that reported by the error statusof the response PDU.
-
ping
Respond to a Ping request.- Parameters:
pdu- the ping request.session- the session that received the request.- Returns:
- the ping response PDU.
-
notify
Process a notification PDU for anAgentXSession.- Parameters:
pdu- the notification PDU.session- the source session.- Returns:
- the notification PDU response.
-
getContextSysUpTime
protected org.snmp4j.smi.TimeTicks getContextSysUpTime(org.snmp4j.smi.OctetString context) Gets the sysUpTime for the specified context.- Parameters:
context- a SNMPv3 context (or an emptyOctetStringfor the default context).- Returns:
TimeTicksvalue representing the context's sysUpTime.0.
-
addAgentCaps
Process anAgentXAddAgentCapsPDU.- Parameters:
pdu- the addAgentCaps-PDU.session- the source session.- Returns:
- the
AgentXResponsePDU
-
getAgentCaps
protected org.snmp4j.agent.mo.snmp.AgentCapabilityList getAgentCaps(org.snmp4j.smi.OctetString contextName) Gets the Agent-Capabilities for a context.- Parameters:
contextName- a context name.- Returns:
- the
AgentCapabilityListassociated with the context ornullif that does not exist.
-
removeAgentCaps
public AgentXResponsePDU removeAgentCaps(AgentXRemoveAgentCapsPDU pdu, AgentXMasterSession<?> session) Process anAgentXRemoveAgentCapsPDU.- Parameters:
pdu- the removeAgentCaps-PDU.session- the source session.- Returns:
- the
AgentXResponsePDU
-
closeSession
Process anAgentXClosePDU, close the session and remove all registrations.- Parameters:
pdu- the close-PDU.session- the source session.- Returns:
- the
AgentXResponsePDU
-
closeAllSessions
Close all sessions associated with thisAgentXCommandListenerand return the AgentX status of the close operation together with theAgentXSessionobject.- Specified by:
closeAllSessionsin interfaceAgentXCommandListener- Parameters:
reason- the AgentX reason (AgentXProtocol.REASON_SHUTDOWN,AgentXProtocol.REASON_TIMEOUTS,AgentXProtocol.REASON_BY_MANAGER,AgentXProtocol.REASON_PROTOCOL_ERROR,AgentXProtocol.REASON_PARSE_ERROR,AgentXProtocol.REASON_OTHER) for closing the session.- Returns:
- a map of the AgentXSession session objects hold by this agent and the corresponding AgentX error code. An
error code of
AgentXProtocol.AGENTX_SUCCESSindicates that this session was successfully closed. - Since:
- 3.0.0
-
closeSession
public <A extends org.snmp4j.smi.Address> int closeSession(AgentXMasterSession<A> session, byte reason) Close the specifiedAgentXSession.- Type Parameters:
A- the address type.- Parameters:
session- theAgentXSessionto close.reason- the AgentX reason (AgentXProtocol.REASON_SHUTDOWN,AgentXProtocol.REASON_TIMEOUTS,AgentXProtocol.REASON_BY_MANAGER,AgentXProtocol.REASON_PROTOCOL_ERROR,AgentXProtocol.REASON_PARSE_ERROR,AgentXProtocol.REASON_OTHER) for closing the session.- Returns:
- the AgentX error/status code.
AgentXProtocol.AGENTX_SUCCESSis returned on success.
-
removeAllRegistrations
Remove all registrations for a session.- Parameters:
session- aAgentXSessionto clean its registrations.
-
getSession
Gets the session for a given session ID.- Parameters:
sessionID- a session ID.- Returns:
- the associated session or
nullif the session could not be found.
-
getSession
Gets the session for anAgentXPDU.- Parameters:
pdu- a PDU.- Returns:
- the session for the specified PDU.
-
register
protected <A extends org.snmp4j.smi.Address> AgentXResponsePDU register(AgentXRegisterPDU pdu, AgentXCommandEvent<A> command, AgentXMasterSession<A> session) Process aAgentXRegisterPDU.- Type Parameters:
A- the address type.- Parameters:
pdu- the PDU.command- the AgentX command.session- the master agent session.- Returns:
- the response PDU.
-
unregister
protected <A extends org.snmp4j.smi.Address> AgentXResponsePDU unregister(AgentXUnregisterPDU pdu, AgentXCommandEvent<A> event, AgentXMasterSession<A> session) Process aAgentXUnregisterPDU.- Type Parameters:
A- the address type.- Parameters:
pdu- the PDU.event- the AgentX command.session- the master agent session.- Returns:
- the response PDU.
-
isDuplicate
Checks whether a new registration is a duplicate.- Parameters:
registration- a MIB region registration.- Returns:
trueif another region with same or lower priority value intersects/overlaps with this region.
-
addRegistration
protected void addRegistration(AgentXRegEntry<?> registration) throws org.snmp4j.agent.DuplicateRegistrationException Adds a registration to this master server.- Parameters:
registration- a MIB region registration.- Throws:
org.snmp4j.agent.DuplicateRegistrationException- if there is already another registration with lower priority value that overlaps/intersects with this region.
-
addRegion
protected void addRegion(AgentXRegEntry<?> registration, AgentXRegion region) throws org.snmp4j.agent.DuplicateRegistrationException Adds a region to the registry.- Parameters:
registration- a new registration.region- the new region to add to an existing registration.- Throws:
org.snmp4j.agent.DuplicateRegistrationException- if there is already MIB region with lower or same priority value registered that intersects/overlaps with this region.
-
removeRegistration
protected boolean removeRegistration(AgentXRegEntry<?> registration, Iterator<AgentXRegEntry<?>> regIterator) Remove a registration- Parameters:
registration- the registration to be removed.regIterator- an iterator on all region requests to be removed.- Returns:
trueif a region was removed,falseotherwise.
-
openSession
public <A extends org.snmp4j.smi.Address> AgentXResponsePDU openSession(AgentXOpenPDU pdu, AgentXCommandEvent<A> event) Opens a new AgentX session.- Type Parameters:
A- the address type.- Parameters:
pdu- theAgentXOpenPDU.event- the AgentX command.- Returns:
- the
AgentXResponsePDU.
-
addPeer
Adds an AgentXPeer and fires the correspondingAgentXMasterEvent.- Parameters:
peer- a peer to add.
-
getPeer
Gets a peer based on its address.- Type Parameters:
A- the address type.- Parameters:
address- an AgentX peer address.- Returns:
- the
AgentXPeerif found ornullif not.
-
acceptSession
Accept a new session and fire the correspondingAgentXMasterEvent.SESSION_ADDEDevent.- Parameters:
session- a session.- Returns:
- the veto reason, if the session has not been added or
AgentXProtocol.AGENTX_SUCCESSotherwise.
-
addSession
Add a new session and fire the correspondingAgentXMasterEvent.SESSION_ADDEDevent.- Parameters:
session- a new session.
-
removeSession
Remove a session.- Parameters:
sessionID- the session ID.- Returns:
- the removed
AgentXMasterSessionornullif the session no longer exists.
-
createResponse
Create a response for an AgentX request.- Parameters:
request- an AgentX PDU.session- a session.- Returns:
- the generated
AgentXResponsePDU.
-
sendResponse
protected <A extends org.snmp4j.smi.Address> void sendResponse(AgentXPDU response, AgentXSession<A> session) Sends a response to a session.- Type Parameters:
A- the address type.- Parameters:
response- the response to be sent.session- the session.
-
connectionStateChanged
public void connectionStateChanged(org.snmp4j.transport.TransportStateEvent change) Process a connection state change, i.e. remove the peer if the connect closed.- Specified by:
connectionStateChangedin interfaceorg.snmp4j.transport.TransportStateListener- Parameters:
change- theTransportStateEvent.
-
removePeer
Removes a peer and all its sessions.- Parameters:
peerAddress- the peer's address.- Returns:
- the removed
AgentXPeer.
-
closePeer
Close a peer, i.e. sending a close PDU to that peer.- Parameters:
peerAddress- the peer to inform about the connection closing.reason- the reason for closing the session(s), seeAgentXProtocol.REASON_OTHERfor example.- Returns:
- the closed peer.
-
getAgentXVersion
public byte getAgentXVersion()Gets the AgentX version.- Returns:
AgentXProtocol.VERSION_1_0
-
addAgentXMasterListener
Adds aAgentXMasterListener.- Parameters:
l- a listener AgentX master agent events.
-
removeAgentXMasterListener
Remove aAgentXMasterListener.- Parameters:
l- a listener AgentX master agent events.
-
fireMasterChanged
Fire aAgentXMasterEvent- Parameters:
event- the event to fire.
-
onResponse
Process anAgentXResponseEvent.- Specified by:
onResponsein interfaceAgentXResponseListener- Parameters:
event- an response event including request and response PDU.
-
processAgentXGetResponse
Process a pending GET response.- Parameters:
pending- theAgentXPendingPDU.pdu- theAgentXResponsePDUreturned.
-
processAgentXGetNextResponse
Process a pending GETNEXT response.- Parameters:
pending- theAgentXPendingPDU.pdu- theAgentXResponsePDUreturned.
-
processAgentXSetResponse
Process a pending SET response.- Parameters:
pending- theAgentXPendingPDU.pdu- theAgentXResponsePDUreturned.
-
CommandProcessor.getServer(OctetString context)instead.