public class MultiThreadedMessageDispatcher extends Object implements MessageDispatcher
MultiThreadedMessageDispatcher
class is a decorator
for any MessageDispatcher
instances that processes incoming
message with a supplied ThreadPool
. The processing is thus
parallelized on up to the size of the supplied thread pool threads.
In contrast to a MessageDispatcherImpl
a
MultiThreadedMessageDispatcher
copies the incoming
ByteBuffer
for processMessage(TransportMapping
sourceTransport, Address incomingAddress, ByteBuffer wholeMessage,
TransportStateReference tmStateReference)
to allow
concurrent processing of the buffer.
Constructor and Description |
---|
MultiThreadedMessageDispatcher(WorkerPool workerPool,
MessageDispatcher decoratedDispatcher)
Creates a multi-threaded message dispatcher using the provided
ThreadPool to concurrently process incoming messages
that are forwarded to the supplied decorated
MessageDispatcher . |
Modifier and Type | Method and Description |
---|---|
void |
addCommandResponder(CommandResponder listener)
Adds a
CommandResponder instance to the message dispatcher. |
void |
addMessageProcessingModel(MessageProcessingModel model)
Adds a
MessageProcessingModel to the dispatcher. |
void |
addTransportMapping(TransportMapping transport)
Adds a
TransportMapping to the dispatcher. |
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 the
Collection of transport mappings in this message
dispatcher. |
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 |
removeCommandResponder(CommandResponder listener)
Removes a previously added
CommandResponder instance from
the message dispatcher. |
void |
removeMessageProcessingModel(MessageProcessingModel model)
Removes a previously added
MessageProcessingModel from
the dispatcher. |
TransportMapping |
removeTransportMapping(TransportMapping transport)
Removes a previously added
TransportMapping from
the dispatcher. |
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.
|
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 transportMapping,
Target target,
PDU pdu,
boolean expectResponse,
PduHandleCallback callback)
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. |
public MultiThreadedMessageDispatcher(WorkerPool workerPool, MessageDispatcher decoratedDispatcher)
ThreadPool
to concurrently process incoming messages
that are forwarded to the supplied decorated
MessageDispatcher
.workerPool
- a WorkerPool
instance (that can be shared). The worker
pool has to be stopped externally.decoratedDispatcher
- the decorated MessageDispatcher
that must be
multi-threading safe.public int getNextRequestID()
MessageDispatcher
getNextRequestID
in interface MessageDispatcher
public void addMessageProcessingModel(MessageProcessingModel model)
MessageDispatcher
MessageProcessingModel
to 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.addMessageProcessingModel
in interface MessageDispatcher
model
- a MessageProcessingModel
instance.public void removeMessageProcessingModel(MessageProcessingModel model)
MessageDispatcher
MessageProcessingModel
from
the dispatcher.removeMessageProcessingModel
in interface MessageDispatcher
model
- a MessageProcessingModel
instance.public MessageProcessingModel getMessageProcessingModel(int messageProcessingModel)
MessageDispatcher
MessageProcessingModel
for the supplied message
processing model ID.getMessageProcessingModel
in interface MessageDispatcher
messageProcessingModel
- a message processing model ID
(see MessageProcessingModel.getID()
).null
public void addTransportMapping(TransportMapping transport)
MessageDispatcher
TransportMapping
to the dispatcher. The transport mapping
is used to send and receive messages to/from the network.addTransportMapping
in interface MessageDispatcher
transport
- a TransportMapping
instance.public TransportMapping removeTransportMapping(TransportMapping transport)
MessageDispatcher
TransportMapping
from
the dispatcher.removeTransportMapping
in interface MessageDispatcher
transport
- a TransportMapping
instance.TransportMapping
instance supplied if it
could be successfully removed, null
otherwise.public Collection<TransportMapping> getTransportMappings()
MessageDispatcher
Collection
of transport mappings in this message
dispatcher.getTransportMappings
in interface MessageDispatcher
public void addCommandResponder(CommandResponder listener)
MessageDispatcher
CommandResponder
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 MessageDispatcher
listener
- a CommandResponder
instance.public void removeCommandResponder(CommandResponder listener)
MessageDispatcher
CommandResponder
instance from
the message dispatcher.removeCommandResponder
in interface MessageDispatcher
listener
- a CommandResponder
instance.public PduHandle sendPdu(Target target, PDU pdu, boolean expectResponse) throws MessageException
MessageDispatcher
MessageDispatcher.sendPdu(TransportMapping transportMapping, Target target,
PDU pdu, boolean expectResponse)
with transportMapping
set to null
.sendPdu
in interface MessageDispatcher
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.MessageException
public PduHandle sendPdu(TransportMapping transportMapping, Target target, PDU pdu, boolean expectResponse) throws MessageException
MessageDispatcher
sendPdu
in interface MessageDispatcher
transportMapping
- 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.MessageException
public PduHandle sendPdu(TransportMapping transportMapping, Target target, PDU pdu, boolean expectResponse, PduHandleCallback callback) throws MessageException
MessageDispatcher
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.sendPdu
in interface MessageDispatcher
transportMapping
- 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).callback
- 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
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 MessageDispatcher
messageProcessingModel
- 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)
MessageDispatcher
PduHandle
in the specified message processing model.releaseStateReference
in interface MessageDispatcher
messageProcessingModel
- a message processing model ID.pduHandle
- the PduHandle
that identifies a confirmed class message.MessageProcessingModel
public TransportMapping getTransport(Address destAddress)
MessageDispatcher
getTransport
in interface MessageDispatcher
destAddress
- 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.public void processMessage(TransportMapping sourceTransport, Address incomingAddress, ByteBuffer wholeMessage, TransportStateReference tmStateReference)
MessageDispatcher
processMessage
in interface MessageDispatcher
processMessage
in interface TransportListener
sourceTransport
- 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.Copyright © 2014 SNMP4J.org. All rights reserved.