Package org.snmp4j.agent.agentx
Class AgentX
java.lang.Object
org.snmp4j.agent.agentx.AgentX
- All Implemented Interfaces:
EventListener,AgentXCommandListener
The
AgentX class implements the AgentX protocol that sends
and receives AgentX PDUs over one or more transport mappings.- Version:
- 3.0.0
- Author:
- Frank Fock
-
Constructor Summary
ConstructorsConstructorDescriptionAgentX(AgentXMessageDispatcher dispatcher) Create anAgentXprotocol engine based on the givenAgentXMessageDispatcher. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCommandResponder(AgentXCommandListener listener) Adds aAgentXCommandListenerto this AgentX session.voidaddTransportMapping(org.snmp4j.TransportMapping<?> transport) Add aTransportMappingfor sending/receiving AgentX messages.Map<AgentXSession<?>, Integer> closeAllSessions(byte reason) ThrowsUnsupportedOperationExceptionbecause AgentX sessions are not managed on protocol level.protected voidfireProcessPdu(AgentXCommandEvent<?> event) Fires aCommandResponderEventevent to inform listeners about a received PDU.Get the AgentX message dispatcher.<A extends org.snmp4j.smi.Address>
voidprocessCommand(AgentXCommandEvent<A> event) Process an AgentX message.voidremoveCommandResponder(AgentXCommandListener listener) Removes aAgentXCommandListenerfrom this AgentX session.voidremoveTransportMapping(org.snmp4j.TransportMapping<?> transport) Remove aTransportMappingfor sending/receiving AgentX messages.<A extends org.snmp4j.smi.Address>
AgentXResponseEvent<A> send(AgentXPDU pdu, AgentXTarget<A> target, org.snmp4j.TransportMapping<? super A> transport) Sends aAgentXPDUto the given target and returns the response synchronously.<A extends org.snmp4j.smi.Address>
voidsend(AgentXPDU pdu, AgentXTarget<A> target, org.snmp4j.TransportMapping<? super A> transport, Object userHandle, AgentXResponseListener listener) Sends aAgentXPDUto the given target and returns the response asynchronously.protected <A extends org.snmp4j.smi.Address>
org.snmp4j.mp.PduHandlesendMessage(AgentXPDU pdu, AgentXTarget<A> target, org.snmp4j.TransportMapping<? super A> transport, org.snmp4j.mp.PduHandleCallback<AgentXPDU> pduHandleCallback) Actually sends a PDU to a target and returns a handle for the sent PDU.
-
Constructor Details
-
AgentX
Create anAgentXprotocol engine based on the givenAgentXMessageDispatcher.- Parameters:
dispatcher- aAgentXMessageDispatcherfor dispatching AgentX messages.
-
-
Method Details
-
addTransportMapping
public void addTransportMapping(org.snmp4j.TransportMapping<?> transport) Add aTransportMappingfor sending/receiving AgentX messages.- Parameters:
transport- aTransportMapping.
-
removeTransportMapping
public void removeTransportMapping(org.snmp4j.TransportMapping<?> transport) Remove aTransportMappingfor sending/receiving AgentX messages.- Parameters:
transport- theTransportMappingto be removed.
-
removeCommandResponder
Removes aAgentXCommandListenerfrom this AgentX session.- Parameters:
listener- a previously addedAgentXCommandListenerinstance.
-
addCommandResponder
Adds aAgentXCommandListenerto this AgentX session. The command responder will then be informed about incoming SNMP PDUs of any kind that are not related to any outstanding requests of this SNMP session.- Parameters:
listener- theAgentXCommandListenerinstance to be added.
-
send
public <A extends org.snmp4j.smi.Address> AgentXResponseEvent<A> send(AgentXPDU pdu, AgentXTarget<A> target, org.snmp4j.TransportMapping<? super A> transport) throws IOException Sends aAgentXPDUto the given target and returns the response synchronously.- Type Parameters:
A- address type associated with the providedTransportMapping.- Parameters:
pdu- aAgentXPDUinstance.target- the AgentXTarget instance representing the target AgentX entity where to send thepdu.transport- specifies theTransportMappingto be used when sending the PDU. Iftransportisnull, the associated message dispatcher will try to determine the transport mapping by thetarget's address.- Returns:
- the received response encapsulated in a
AgentXResponseEventinstance. To obtain the received responseAgentXPDUcallAgentXResponseEvent.getResponse(). If the request timed out, that method will returnnull. - Throws:
IOException- if the message could not be sent.
-
send
public <A extends org.snmp4j.smi.Address> void send(AgentXPDU pdu, AgentXTarget<A> target, org.snmp4j.TransportMapping<? super A> transport, Object userHandle, AgentXResponseListener listener) throws IOException Sends aAgentXPDUto the given target and returns the response asynchronously.- Type Parameters:
A- address type associated with the providedTransportMapping.- Parameters:
pdu- aAgentXPDUinstance.target- the AgentXTarget instance representing the target AgentX entity where to send thepdu.transport- specifies theTransportMappingto be used when sending the PDU. Iftransportisnull, the associated message dispatcher will try to determine the transport mapping by thetarget's address.userHandle- an arbitrary user handle which is transparently returned to the response listener.listener- the listener that should be informed about the reponse or timeout.- Throws:
IOException- if the message could not be sent.
-
sendMessage
protected <A extends org.snmp4j.smi.Address> org.snmp4j.mp.PduHandle sendMessage(AgentXPDU pdu, AgentXTarget<A> target, org.snmp4j.TransportMapping<? super A> transport, org.snmp4j.mp.PduHandleCallback<AgentXPDU> pduHandleCallback) throws IOException Actually sends a PDU to a target and returns a handle for the sent PDU.- Type Parameters:
A- address type associated with the providedTransportMapping.- Parameters:
pdu- thePDUinstance to be sent.target- aAgentXTargetinstance denoting the target AgentX entity.transport- the (optional) transport mapping to be used to send the request. Iftransportisnulla suitable transport mapping is determined from thetargetaddress.pduHandleCallback- an optional callback instance that is informed (if notnull) about the newly assigned PduHandle just before the message is sent out.- Returns:
- PduHandle that uniquely identifies the sent PDU for further reference.
- Throws:
IOException- if the transport fails to send the PDU or the if the message cannot be BER encoded.
-
processCommand
Description copied from interface:AgentXCommandListenerProcess an AgentX message.- Specified by:
processCommandin interfaceAgentXCommandListener- Type Parameters:
A-Addresstype of peer that trigger this command.- Parameters:
event- the AgentX message and necessary context information.
-
closeAllSessions
ThrowsUnsupportedOperationExceptionbecause AgentX sessions are not managed on protocol level. UseAgentXCommandListenerimplementations on agent/application level instead.- 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:
- nothing, instead
UnsupportedOperationExceptionis thrown. - Since:
- 3.0.0
-
fireProcessPdu
Fires aCommandResponderEventevent to inform listeners about a received PDU. If a listener has marked the event as processed further listeners will not be informed about the event.- Parameters:
event- aCommandResponderEvent.
-
getMessageDispatcher
Get the AgentX message dispatcher.- Returns:
- the associated
AgentXMessageDispatcher.
-