Package org.snmp4j
Interface MessageDispatcher
- All Superinterfaces:
 TransportListener
- All Known Implementing Classes:
 MessageDispatcherImpl,MultiThreadedMessageDispatcher
The 
MessageDispatcher interface defines common services of
 instances that process incoming SNMP messages and dispatch them to
 interested CommandResponder instances. It also provides a service
 to send out outgoing SNMP messages.
 A MessageDispatcher needs at least one TransportMapping
 and at least one MessageProcessingModel in order to be able to
 process any messages.- Version:
 - 2.0
 - Author:
 - Frank Fock
 
- 
Method Summary
Modifier and TypeMethodDescriptionvoidaddCommandResponder(CommandResponder listener) Adds aCommandResponderinstance to the message dispatcher.voidAdds aMessageProcessingModelto the dispatcher.voidaddTransportMapping(TransportMapping<? extends Address> transport) Adds aTransportMappingto the dispatcher.getMessageProcessingModel(int messageProcessingModel) Gets theMessageProcessingModelfor the supplied message processing model ID.intGets the next unique request ID.getTransport(Address destAddress) Returns a transport mapping that can handle the supplied address.Gets theCollectionof transport mappings in this message dispatcher.voidprocessMessage(TransportMapping sourceTransport, Address incomingAddress, ByteBuffer wholeMessage, TransportStateReference tmStateReference) Process an incoming SNMP message.voidreleaseStateReference(int messageProcessingModel, PduHandle pduHandle) Release any state references associated with the suppliedPduHandlein the specified message processing model.voidremoveCommandResponder(CommandResponder listener) Removes a previously addedCommandResponderinstance from the message dispatcher.voidRemoves a previously addedMessageProcessingModelfrom the dispatcher.removeTransportMapping(TransportMapping<? extends Address> transport) Removes a previously addedTransportMappingfrom the dispatcher.intreturnResponsePdu(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.Sends a PDU to the supplied transport address.sendPdu(TransportMapping transportMapping, Target target, PDU pdu, boolean expectResponse) Sends a PDU to the supplied transport address.sendPdu(TransportMapping transportMapping, Target target, PDU pdu, boolean expectResponse, PduHandleCallback<PDU> callback) Sends a PDU to the supplied transport address and returns thePduHandlethat uniquely identifies the request as response after the request has been sent and optional, if aPduHandleCallbackis given, it returns also thePduHandlejust before the request is sent through the the callback interface. 
- 
Method Details
- 
getNextRequestID
int getNextRequestID()Gets the next unique request ID. The returned ID is unique across the last 2^31-1 IDs generated by this message dispatcher.- Returns:
 - an integer value in the range 1..2^31-1. The returned ID can be used to map responses to requests send through this message dispatcher.
 - Since:
 - 1.1
 
 - 
addMessageProcessingModel
Adds aMessageProcessingModelto the dispatcher. In order to support a specific SNMP protocol version, the message dispatcher needs a message processing model to process messages before they can be dispatched.- Parameters:
 model- aMessageProcessingModelinstance.
 - 
removeMessageProcessingModel
Removes a previously addedMessageProcessingModelfrom the dispatcher.- Parameters:
 model- aMessageProcessingModelinstance.
 - 
getMessageProcessingModel
Gets theMessageProcessingModelfor the supplied message processing model ID.- Parameters:
 messageProcessingModel- a message processing model ID (seeMessageProcessingModel.getID()).- Returns:
 - a MessageProcessingModel instance if the ID is known, otherwise
    
null 
 - 
addTransportMapping
Adds aTransportMappingto the dispatcher. The transport mapping is used to send and receive messages to/from the network.- Parameters:
 transport- aTransportMappinginstance.
 - 
removeTransportMapping
Removes a previously addedTransportMappingfrom the dispatcher.- Parameters:
 transport- aTransportMappinginstance.- Returns:
 - the 
TransportMappinginstance supplied if it could be successfully removed,nullotherwise. 
 - 
getTransportMappings
Collection<TransportMapping> getTransportMappings()Gets theCollectionof transport mappings in this message dispatcher.- Returns:
 - a Collection with the registered transport mappings.
 
 - 
getTransport
Returns a transport mapping that can handle the supplied address.- Parameters:
 destAddress- an Address instance.- Returns:
 - a 
TransportMappinginstance that can be used to sent a SNMP message todestAddressornullif such a transport mapping does not exists. - Since:
 - 1.6
 
 - 
addCommandResponder
Adds aCommandResponderinstance 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 theCommandResponderEvent.setProcessed(boolean processed)to set the processed status of the event totrue.- Parameters:
 listener- aCommandResponderinstance.
 - 
removeCommandResponder
Removes a previously addedCommandResponderinstance from the message dispatcher.- Parameters:
 listener- aCommandResponderinstance.
 - 
sendPdu
PduHandle sendPdu(TransportMapping transportMapping, Target target, PDU pdu, boolean expectResponse) throws MessageException Sends a PDU to the supplied transport address.- Parameters:
 transportMapping- theTransportMappingto be used to send the PDU. IftransportMappingisnullthe 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-trueif a response is expected and a state reference should be saved (if needed for the supplied message processing model).- Returns:
 - an 
PduHandlethat uniquely identifies this request. - Throws:
 MessageException- if sending of the PDU failed.
 - 
sendPdu
PduHandle sendPdu(TransportMapping transportMapping, Target target, PDU pdu, boolean expectResponse, PduHandleCallback<PDU> callback) throws MessageException Sends a PDU to the supplied transport address and returns thePduHandlethat uniquely identifies the request as response after the request has been sent and optional, if aPduHandleCallbackis given, it returns also thePduHandlejust before the request is sent through the the callback interface.- Parameters:
 transportMapping- theTransportMappingto be used to send the PDU. IftransportMappingisnullthe 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-trueif a response is expected and a state reference should be saved (if needed for the supplied message processing model).callback- an optional callback instance that is informed (if notnull) about the newly assigned PduHandle just before the message is sent out.- Returns:
 - an 
PduHandlethat uniquely identifies this request. - Throws:
 MessageException- if sending of the PDU failed.
 - 
sendPdu
Sends a PDU to the supplied transport address. This method behaves like a call tosendPdu(TransportMapping transportMapping, Target target, PDU pdu, boolean expectResponse)withtransportMappingset tonull.- Parameters:
 target- the target which identifies, transport address, message processing model, security model, security name and level.pdu- the SNMP Protocol Data UnitexpectResponse-trueif a response is expected and a state reference should be saved (if needed for the supplied message processing model).- Returns:
 - an 
PduHandlethat uniquely identifies this request. - Throws:
 MessageException- if sending of the PDU failed.
 - 
returnResponsePdu
int returnResponsePdu(int messageProcessingModel, int securityModel, byte[] securityName, int securityLevel, PDU pdu, int maxSizeResponseScopedPDU, StateReference stateReference, StatusInformation statusInformation) throws MessageException Returns a response PDU to the sender of the corresponding request PDU.- Parameters:
 messageProcessingModel- intsecurityModel- intsecurityName- byte[]securityLevel- intpdu- PDUmaxSizeResponseScopedPDU- intstateReference- StateReferencestatusInformation- StatusInformation- Returns:
 - an MP error status or 
SnmpConstants.SNMP_MP_OKif the operation was successful. - Throws:
 MessageException- if message processing fails with a fatal error.
 - 
processMessage
void processMessage(TransportMapping sourceTransport, Address incomingAddress, ByteBuffer wholeMessage, TransportStateReference tmStateReference) Process an incoming SNMP message. The message is processed and dispatched according to the message's content, the message processing models, and the command responder available to the dispatcher.- Specified by:
 processMessagein interfaceTransportListener- Parameters:
 sourceTransport- aTransportMappinginstance denoting the transport that received the message and that will be used to send any responses to this message. ThesourceTransporthas to support theincomingAddress's implementation class.incomingAddress- theAddressfrom which the message has been received.wholeMessage- anByteBuffercontaining the received SNMP message.tmStateReference- the transport model state reference as defined by RFC 5590.
 - 
releaseStateReference
Release any state references associated with the suppliedPduHandlein the specified message processing model.- Parameters:
 messageProcessingModel- a message processing model ID.pduHandle- thePduHandlethat identifies a confirmed class message.- See Also:
 
 
 -