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
ConstructorDescriptionAgentX
(AgentXMessageDispatcher dispatcher) Create anAgentX
protocol engine based on the givenAgentXMessageDispatcher
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCommandResponder
(AgentXCommandListener listener) Adds aAgentXCommandListener
to this AgentX session.void
addTransportMapping
(org.snmp4j.TransportMapping<?> transport) Add aTransportMapping
for sending/receiving AgentX messages.Map
<AgentXSession<?>, Integer> closeAllSessions
(byte reason) ThrowsUnsupportedOperationException
because AgentX sessions are not managed on protocol level.protected void
fireProcessPdu
(AgentXCommandEvent<?> event) Fires aCommandResponderEvent
event 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.void
removeCommandResponder
(AgentXCommandListener listener) Removes aAgentXCommandListener
from this AgentX session.void
removeTransportMapping
(org.snmp4j.TransportMapping<?> transport) Remove aTransportMapping
for 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 aAgentXPDU
to 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 aAgentXPDU
to 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 anAgentX
protocol engine based on the givenAgentXMessageDispatcher
.- Parameters:
dispatcher
- aAgentXMessageDispatcher
for dispatching AgentX messages.
-
-
Method Details
-
addTransportMapping
public void addTransportMapping(org.snmp4j.TransportMapping<?> transport) Add aTransportMapping
for sending/receiving AgentX messages.- Parameters:
transport
- aTransportMapping
.
-
removeTransportMapping
public void removeTransportMapping(org.snmp4j.TransportMapping<?> transport) Remove aTransportMapping
for sending/receiving AgentX messages.- Parameters:
transport
- theTransportMapping
to be removed.
-
removeCommandResponder
Removes aAgentXCommandListener
from this AgentX session.- Parameters:
listener
- a previously addedAgentXCommandListener
instance.
-
addCommandResponder
Adds aAgentXCommandListener
to 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
- theAgentXCommandListener
instance 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 aAgentXPDU
to the given target and returns the response synchronously.- Type Parameters:
A
- address type associated with the providedTransportMapping
.- Parameters:
pdu
- aAgentXPDU
instance.target
- the AgentXTarget instance representing the target AgentX entity where to send thepdu
.transport
- specifies theTransportMapping
to be used when sending the PDU. Iftransport
isnull
, the associated message dispatcher will try to determine the transport mapping by thetarget
's address.- Returns:
- the received response encapsulated in a
AgentXResponseEvent
instance. To obtain the received responseAgentXPDU
callAgentXResponseEvent.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 aAgentXPDU
to the given target and returns the response asynchronously.- Type Parameters:
A
- address type associated with the providedTransportMapping
.- Parameters:
pdu
- aAgentXPDU
instance.target
- the AgentXTarget instance representing the target AgentX entity where to send thepdu
.transport
- specifies theTransportMapping
to be used when sending the PDU. Iftransport
isnull
, 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
- thePDU
instance to be sent.target
- aAgentXTarget
instance denoting the target AgentX entity.transport
- the (optional) transport mapping to be used to send the request. Iftransport
isnull
a suitable transport mapping is determined from thetarget
address.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:AgentXCommandListener
Process an AgentX message.- Specified by:
processCommand
in interfaceAgentXCommandListener
- Type Parameters:
A
-Address
type of peer that trigger this command.- Parameters:
event
- the AgentX message and necessary context information.
-
closeAllSessions
ThrowsUnsupportedOperationException
because AgentX sessions are not managed on protocol level. UseAgentXCommandListener
implementations on agent/application level instead.- Specified by:
closeAllSessions
in 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
UnsupportedOperationException
is thrown. - Since:
- 3.0.0
-
fireProcessPdu
Fires aCommandResponderEvent
event 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
.
-