public class MessageDispatcherImpl extends Object implements MessageDispatcher
MessageDispatcherImpl decodes and dispatches incoming
messages using MessageProcessingModel instances and encodes
and sends outgoing messages using an appropriate TransportMapping
instances.
The method processMessage(org.snmp4j.TransportMapping, org.snmp4j.smi.Address, java.nio.ByteBuffer, org.snmp4j.TransportStateReference) will be called from a
TransportMapping whereas the method sendPdu(org.snmp4j.Target, org.snmp4j.PDU, boolean) will be
called by the application.
Snmp,
TransportMapping,
MessageProcessingModel,
MPv1,
MPv2c,
MPv3| Constructor and Description |
|---|
MessageDispatcherImpl()
Default constructor creates a message dispatcher without any associated
message processing models.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAuthenticationFailureListener(AuthenticationFailureListener l)
Adds a listener for authentication failure events caused by unauthenticated
incoming messages.
|
void |
addCommandResponder(CommandResponder l)
Adds a
CommandResponder instance to the message dispatcher. |
void |
addCounterListener(CounterListener counterListener)
Adds a
CounterListener. |
void |
addMessageProcessingModel(MessageProcessingModel model)
Adds a message processing model to this message dispatcher.
|
void |
addTransportMapping(TransportMapping transport)
Adds a transport mapping.
|
protected void |
checkOutgoingMsg(Address transportAddress,
int messageProcessingModel,
PDU pdu)
Checks outgoing messages for consistency between PDU and target used.
|
protected void |
configureAuthoritativeEngineID(Target target,
MessageProcessingModel mp) |
protected PduHandle |
createPduHandle() |
protected void |
dispatchMessage(TransportMapping sourceTransport,
MessageProcessingModel mp,
Address incomingAddress,
BERInputStream wholeMessage,
TransportStateReference tmStateReference)
Actually decodes and dispatches an incoming SNMP message using the supplied
message processing model.
|
protected void |
fireAuthenticationFailure(AuthenticationFailureEvent event)
Fires an
AuthenticationFailureEvent to all registered
listeners. |
protected void |
fireIncrementCounter(CounterEvent event)
Fires a counter incrementation event.
|
protected void |
fireProcessPdu(CommandResponderEvent e)
Fires a
CommandResponderEvent. |
MessageProcessingModel |
getMessageProcessingModel(int messageProcessingModel)
Gets the
MessageProcessingModel for the supplied message
processing model ID. |
int |
getNextRequestID()
Gets the next unique request ID.
|
TransportMapping |
getTransport(Address destAddress)
Returns a transport mapping that can handle the supplied address.
|
Collection<TransportMapping> |
getTransportMappings()
Gets a collection of all registered transport mappings.
|
boolean |
isCheckOutgoingMsg()
Returns whether consistency checks for outgoing messages are activated.
|
void |
processMessage(TransportMapping sourceTransport,
Address incomingAddress,
BERInputStream wholeMessage,
TransportStateReference tmStateReference) |
void |
processMessage(TransportMapping sourceTransport,
Address incomingAddress,
ByteBuffer wholeMessage,
TransportStateReference tmStateReference)
Process an incoming SNMP message.
|
void |
releaseStateReference(int messageProcessingModel,
PduHandle pduHandle)
Release any state references associated with the supplied
PduHandle in the specified message processing model. |
void |
removeAuthenticationFailureListener(AuthenticationFailureListener l)
Removes an
AuthenticationFailureListener. |
void |
removeCommandResponder(CommandResponder l)
Removes a previously added
CommandResponder instance from
the message dispatcher. |
void |
removeCounterListener(CounterListener counterListener)
Removes a
CounterListener. |
void |
removeMessageProcessingModel(MessageProcessingModel model)
Removes a message processing model from this message dispatcher.
|
TransportMapping |
removeTransportMapping(TransportMapping transport)
Removes a transport mapping.
|
int |
returnResponsePdu(int messageProcessingModel,
int securityModel,
byte[] securityName,
int securityLevel,
PDU pdu,
int maxSizeResponseScopedPDU,
StateReference stateReference,
StatusInformation statusInformation)
Returns a response PDU to the sender of the corresponding request PDU.
|
protected void |
sendMessage(TransportMapping transport,
Address destAddress,
byte[] message,
TransportStateReference tmStateReference)
Sends a message using the
TransportMapping that has been
assigned for the supplied address type. |
PduHandle |
sendPdu(Target target,
PDU pdu,
boolean expectResponse)
Sends a PDU to the supplied transport address.
|
PduHandle |
sendPdu(TransportMapping transportMapping,
Target target,
PDU pdu,
boolean expectResponse)
Sends a PDU to the supplied transport address.
|
PduHandle |
sendPdu(TransportMapping transport,
Target target,
PDU pdu,
boolean expectResponse,
PduHandleCallback<PDU> pduHandleCallback)
Sends a PDU to the supplied transport address and returns the
PduHandle that uniquely identifies the request as response
after the request has been sent and optional, if a
PduHandleCallback is given, it returns also the
PduHandle just before the request is sent through the
the callback interface. |
void |
setCheckOutgoingMsg(boolean checkOutgoingMsg)
Enables or disables the consistency checks for outgoing messages.
|
public MessageDispatcherImpl()
public void addMessageProcessingModel(MessageProcessingModel model)
removeMessageProcessingModel(org.snmp4j.mp.MessageProcessingModel)
before to replace a message processing model.addMessageProcessingModel in interface MessageDispatchermodel - a MessageProcessingModel instance.public void removeMessageProcessingModel(MessageProcessingModel model)
removeMessageProcessingModel in interface MessageDispatchermodel - a previously added MessageProcessingModel instance.public void addTransportMapping(TransportMapping transport)
addTransportMapping in interface MessageDispatchertransport - a TransportMapping instance. If there is already another transport
mapping registered that supports the same address class, then
transport will be registered but not used for messages
without specific transport mapping.public TransportMapping removeTransportMapping(TransportMapping transport)
removeTransportMapping in interface MessageDispatchertransport - a previously added TransportMapping instance.nullotherwise.public Collection<TransportMapping> getTransportMappings()
getTransportMappings in interface MessageDispatcherpublic int getNextRequestID()
MessageDispatchergetNextRequestID in interface MessageDispatcherprotected PduHandle createPduHandle()
protected void sendMessage(TransportMapping transport, Address destAddress, byte[] message, TransportStateReference tmStateReference) throws IOException
TransportMapping that has been
assigned for the supplied address type.transport - the transport mapping to be used to send the message.destAddress - the transport address where to send the message. The
destAddress must be compatible with the supplied
transport.message - the SNMP message to send.IOException - if an I/O error occurred while sending the message or if there is
no transport mapping defined for the supplied address type.public TransportMapping getTransport(Address destAddress)
getTransport in interface MessageDispatcherdestAddress - an Address instance.TransportMapping instance that can be used to sent
a SNMP message to destAddress or null if
such a transport mapping does not exists.protected void dispatchMessage(TransportMapping sourceTransport, MessageProcessingModel mp, Address incomingAddress, BERInputStream wholeMessage, TransportStateReference tmStateReference) throws IOException
sourceTransport - a TransportMapping that matches the incomingAddress type.mp - a MessageProcessingModel to process the message.incomingAddress - the Address from the entity that sent this message.wholeMessage - the BERInputStream containing the SNMP message.tmStateReference - the transport model state reference as defined by RFC 5590.IOException - if the message cannot be decoded.public void processMessage(TransportMapping sourceTransport, Address incomingAddress, ByteBuffer wholeMessage, TransportStateReference tmStateReference)
MessageDispatcherprocessMessage in interface MessageDispatcherprocessMessage in interface TransportListenersourceTransport - a TransportMapping instance denoting the transport that
received the message and that will be used to send any responses to
this message. The sourceTransport has to support the
incomingAddress's implementation class.incomingAddress - the Address from which the message has been received.wholeMessage - an ByteBuffer containing the received SNMP message.tmStateReference - the transport model state reference as defined by RFC 5590.public void processMessage(TransportMapping sourceTransport, Address incomingAddress, BERInputStream wholeMessage, TransportStateReference tmStateReference)
public PduHandle sendPdu(Target target, PDU pdu, boolean expectResponse) throws MessageException
MessageDispatcherMessageDispatcher.sendPdu(TransportMapping transportMapping, Target target,
PDU pdu, boolean expectResponse)
with transportMapping set to null.sendPdu in interface MessageDispatchertarget - the target which identifies, transport address, message processing model,
security model, security name and level.pdu - the SNMP Protocol Data UnitexpectResponse - true if a response is expected and a state reference should
be saved (if needed for the supplied message processing model).PduHandle that uniquely identifies this request.MessageExceptionpublic PduHandle sendPdu(TransportMapping transport, Target target, PDU pdu, boolean expectResponse, PduHandleCallback<PDU> pduHandleCallback) throws MessageException
MessageDispatcherPduHandle that uniquely identifies the request as response
after the request has been sent and optional, if a
PduHandleCallback is given, it returns also the
PduHandle just before the request is sent through the
the callback interface.sendPdu in interface MessageDispatchertransport - the TransportMapping to be used to send the PDU. If
transportMapping is null the message
dispatcher will determine the appropriate transport mapping for the
given transport address.target - the target which identifies, transport address, message processing model,
security model, security name and level.pdu - the SNMP Protocol Data UnitexpectResponse - true if a response is expected and a state reference should
be saved (if needed for the supplied message processing model).pduHandleCallback - an optional callback instance that is informed (if not
null) about the newly assigned PduHandle just before the
message is sent out.PduHandle that uniquely identifies this request.MessageExceptionprotected void configureAuthoritativeEngineID(Target target, MessageProcessingModel mp)
protected void checkOutgoingMsg(Address transportAddress, int messageProcessingModel, PDU pdu) throws MessageException
transportAddress - the target address.messageProcessingModel - the message processing model to be used.pdu - the PDU to be sent.MessageException - if unrecoverable inconsistencies have been detected.public int returnResponsePdu(int messageProcessingModel,
int securityModel,
byte[] securityName,
int securityLevel,
PDU pdu,
int maxSizeResponseScopedPDU,
StateReference stateReference,
StatusInformation statusInformation)
throws MessageException
MessageDispatcherreturnResponsePdu in interface MessageDispatchermessageProcessingModel - intsecurityModel - intsecurityName - byte[]securityLevel - intpdu - PDUmaxSizeResponseScopedPDU - intstateReference - StateReferencestatusInformation - StatusInformationSnmpConstants.SNMP_MP_OK if
the operation was successful.MessageException - if message processing fails with a fatal error.public void releaseStateReference(int messageProcessingModel,
PduHandle pduHandle)
MessageDispatcherPduHandle in the specified message processing model.releaseStateReference in interface MessageDispatchermessageProcessingModel - a message processing model ID.pduHandle - the PduHandle that identifies a confirmed class message.MessageProcessingModelpublic void removeCommandResponder(CommandResponder l)
MessageDispatcherCommandResponder instance from
the message dispatcher.removeCommandResponder in interface MessageDispatcherl - a CommandResponder instance.public void addCommandResponder(CommandResponder l)
MessageDispatcherCommandResponder instance to the message dispatcher.
Successfully processed SNMP messages will be presented to all command
responder (in the order in which they have been added) until a responder
uses the CommandResponderEvent.setProcessed(boolean processed)
to set the processed status of the event to true.addCommandResponder in interface MessageDispatcherl - a CommandResponder instance.protected void fireProcessPdu(CommandResponderEvent e)
CommandResponderEvent. Listeners are called
in order of their registration until a listener has processed the
PDU successfully.e - a CommandResponderEvent event.public MessageProcessingModel getMessageProcessingModel(int messageProcessingModel)
MessageProcessingModel for the supplied message
processing model ID.getMessageProcessingModel in interface MessageDispatchermessageProcessingModel - a message processing model ID
(see MessageProcessingModel.getID()).nullpublic void removeCounterListener(CounterListener counterListener)
CounterListener.counterListener - a previously added CounterListener.public void addCounterListener(CounterListener counterListener)
CounterListener.counterListener - a CounterListener that will be informed when a counter
needs to incremented.protected void fireIncrementCounter(CounterEvent event)
event - the CounterEvent containing the OID of the counter
that needs to be incremented.public void setCheckOutgoingMsg(boolean checkOutgoingMsg)
In general, if an automatically conversion is not possible, an error is thrown when such a message is to be sent.
The default is consistency checks enabled.
checkOutgoingMsg - if true outgoing messages are checked for consistency.
Currently, only the PDU type will be checked against the used SNMP
version. If false, no checks will be performed.public boolean isCheckOutgoingMsg()
true outgoing messages are checked for consistency.
If false, no checks are performed.public void addAuthenticationFailureListener(AuthenticationFailureListener l)
l - the AuthenticationFailureListener to add.public void removeAuthenticationFailureListener(AuthenticationFailureListener l)
AuthenticationFailureListener.l - the AuthenticationFailureListener to remove.protected void fireAuthenticationFailure(AuthenticationFailureEvent event)
AuthenticationFailureEvent to all registered
listeners.event - the event to fire.public PduHandle sendPdu(TransportMapping transportMapping, Target target, PDU pdu, boolean expectResponse) throws MessageException
MessageDispatchersendPdu in interface MessageDispatchertransportMapping - the TransportMapping to be used to send the PDU. If
transportMapping is null the message
dispatcher will determine the appropriate transport mapping for the
given transport address.target - the target which identifies, transport address, message processing model,
security model, security name and level.pdu - the SNMP Protocol Data UnitexpectResponse - true if a response is expected and a state reference should
be saved (if needed for the supplied message processing model).PduHandle that uniquely identifies this request.MessageExceptionCopyright © 2016 SNMP4J.org. All Rights Reserved.