|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.snmp4j.MessageDispatcherImpl
public class MessageDispatcherImpl
The 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) will be called from a
TransportMapping whereas the method sendPdu(org.snmp4j.smi.Address, int, int, byte[], int, org.snmp4j.PDU, boolean) will be
called by the application.
Snmp,
TransportMapping,
MessageProcessingModel,
MPv1,
MPv2c,
MPv3| Constructor Summary | |
|---|---|
MessageDispatcherImpl()
Default constructor creates a message dispatcher without any associated message processing models. |
|
| Method Summary | |
|---|---|
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 PduHandle |
createPduHandle()
|
protected void |
dispatchMessage(TransportMapping sourceTransport,
MessageProcessingModel mp,
Address incomingAddress,
BERInputStream wholeMessage)
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. |
java.util.Collection |
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)
Process an incoming SNMP message. |
void |
processMessage(TransportMapping sourceTransport,
Address incomingAddress,
java.nio.ByteBuffer wholeMessage)
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)
Sends a message using the TransportMapping that has been
assigned for the supplied address type. |
PduHandle |
sendPdu(Address transportAddress,
int messageProcessingModel,
int securityModel,
byte[] securityName,
int securityLevel,
PDU pdu,
boolean expectResponse)
Sends a PDU to the supplied transport address. |
PduHandle |
sendPdu(TransportMapping transportMapping,
Address transportAddress,
int messageProcessingModel,
int securityModel,
byte[] securityName,
int securityLevel,
PDU pdu,
boolean expectResponse)
Sends a PDU to the supplied transport address. |
PduHandle |
sendPdu(TransportMapping transport,
Address transportAddress,
int messageProcessingModel,
int securityModel,
byte[] securityName,
int securityLevel,
PDU pdu,
boolean expectResponse,
PduHandleCallback 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 otional, 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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MessageDispatcherImpl()
| Method Detail |
|---|
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 java.util.Collection getTransportMappings()
getTransportMappings in interface MessageDispatcherpublic int getNextRequestID()
MessageDispatcher
getNextRequestID in interface MessageDispatcherprotected PduHandle createPduHandle()
protected void sendMessage(TransportMapping transport,
Address destAddress,
byte[] message)
throws java.io.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.
java.io.IOException - if an I/O error occured 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)
throws java.io.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.
java.io.IOException - if the message cannot be decoded.
public void processMessage(TransportMapping sourceTransport,
Address incomingAddress,
java.nio.ByteBuffer wholeMessage)
MessageDispatcher
processMessage 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.
public void processMessage(TransportMapping sourceTransport,
Address incomingAddress,
BERInputStream wholeMessage)
MessageDispatcher
processMessage in interface MessageDispatchersourceTransport - 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 BERInputStream containing the received SNMP message.
The supplied input stream must support marks, otherwise an
IllegalArgumentException is thrown.
public PduHandle sendPdu(Address transportAddress,
int messageProcessingModel,
int securityModel,
byte[] securityName,
int securityLevel,
PDU pdu,
boolean expectResponse)
throws MessageException
MessageDispatcherMessageDispatcher.sendPdu(TransportMapping transportMapping,
Address transportAddress, int messageProcessingModel,
int securityModel, byte[] securityName, int securityLevel, PDU pdu,
boolean expectResponse) with transportMapping set to
null.
sendPdu in interface MessageDispatchertransportAddress - the target transport address.messageProcessingModel - typically the SNMP version.securityModel - Security Model to use.securityName - on behalf of this principal.securityLevel - Level of Security requested.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.
MessageException
public PduHandle sendPdu(TransportMapping transport,
Address transportAddress,
int messageProcessingModel,
int securityModel,
byte[] securityName,
int securityLevel,
PDU pdu,
boolean expectResponse,
PduHandleCallback pduHandleCallback)
throws MessageException
MessageDispatcherPduHandle that uniquely identifies the request as response
after the request has been sent and otional, 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.transportAddress - the target transport address.messageProcessingModel - typically the SNMP version.securityModel - Security Model to use.securityName - on behalf of this principal.securityLevel - Level of Security requested.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.
MessageException
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
MessageDispatcher
returnResponsePdu in interface MessageDispatchermessageProcessingModel - intsecurityModel - intsecurityName - byte[]securityLevel - intpdu - PDUmaxSizeResponseScopedPDU - intstateReference - StateReferencestatusInformation - StatusInformation
MessageException
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,
Address transportAddress,
int messageProcessingModel,
int securityModel,
byte[] securityName,
int securityLevel,
PDU pdu,
boolean expectResponse)
throws MessageException
MessageDispatcher
sendPdu 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.transportAddress - the target transport address.messageProcessingModel - typically the SNMP version.securityModel - Security Model to use.securityName - on behalf of this principal.securityLevel - Level of Security requested.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.
MessageException
|
Copyright 2003-2009 Frank Fock and Jochen Katz (SNMP4J.org) | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||