Package org.snmp4j.transport
Class AbstractTransportMapping<A extends Address>
java.lang.Object
org.snmp4j.transport.AbstractTransportMapping<A>
- All Implemented Interfaces:
TransportMapping<A>
- Direct Known Subclasses:
DefaultSshTransportMapping
,DummyTransport
,DummyTransport.DummyTransportResponder
,TcpTransportMapping
,UdpTransportMapping
public abstract class AbstractTransportMapping<A extends Address>
extends Object
implements TransportMapping<A>
The
AbstractTransportMapping
provides an abstract
implementation for the message dispatcher list and the maximum inbound
message size.- Version:
- 2.0
- Author:
- Frank Fock
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
protected int
protected int
protected List<TransportListener>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a transport listener to the transport.abstract void
close()
Closes the transport an releases all bound resources synchronously.protected void
fireProcessMessage
(Address address, ByteBuffer buf, TransportStateReference tmStateReference) int
Gets the maximum length of an incoming message that can be successfully processed by this transport mapping implementation.int
Gets the maximum length of an outgoing message that can be successfully processed by this transport mapping implementation.Gets theAddress
class that is supported by this transport mapping.boolean
Returnstrue
if asynchronous (multithreaded) message processing may be implemented.abstract void
listen()
Listen for incoming messages.void
void
Removes a transport listener.abstract void
sendMessage
(A address, byte[] message, TransportStateReference tmStateReference) Sends a message to the supplied address using this transport.void
setAsyncMsgProcessingSupported
(boolean asyncMsgProcessingSupported) Specifies whether this transport mapping has to support asynchronous messages processing or not.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.snmp4j.TransportMapping
getListenAddress, isListening
-
Field Details
-
transportListener
-
maxInboundMessageSize
protected int maxInboundMessageSize -
asyncMsgProcessingSupported
protected boolean asyncMsgProcessingSupported -
maxOutboundMessageSize
protected int maxOutboundMessageSize
-
-
Constructor Details
-
AbstractTransportMapping
public AbstractTransportMapping()
-
-
Method Details
-
getSupportedAddressClass
Description copied from interface:TransportMapping
Gets theAddress
class that is supported by this transport mapping.- Specified by:
getSupportedAddressClass
in interfaceTransportMapping<A extends Address>
- Returns:
- a subclass of
Address
.
-
sendMessage
public abstract void sendMessage(A address, byte[] message, TransportStateReference tmStateReference) throws IOException Description copied from interface:TransportMapping
Sends a message to the supplied address using this transport.- Specified by:
sendMessage
in interfaceTransportMapping<A extends Address>
- Parameters:
address
- anAddress
instance denoting the target address.message
- the whole message as an array of bytes.tmStateReference
- the (optional) transport model state reference as defined by RFC 5590 section 6.1.- Throws:
IOException
- if any underlying IO operation fails.
-
addTransportListener
Description copied from interface:TransportMapping
Adds a transport listener to the transport. Normally, at least one transport listener needs to be added to process incoming messages.- Specified by:
addTransportListener
in interfaceTransportMapping<A extends Address>
- Parameters:
l
- aTransportListener
instance.
-
removeTransportListener
Description copied from interface:TransportMapping
Removes a transport listener. Incoming messages will no longer be propagated to the suppliedTransportListener
.- Specified by:
removeTransportListener
in interfaceTransportMapping<A extends Address>
- Parameters:
l
- aTransportListener
instance.
-
removeAllTransportListeners
public void removeAllTransportListeners() -
fireProcessMessage
protected void fireProcessMessage(Address address, ByteBuffer buf, TransportStateReference tmStateReference) -
close
Description copied from interface:TransportMapping
Closes the transport an releases all bound resources synchronously.- Specified by:
close
in interfaceTransportMapping<A extends Address>
- Throws:
IOException
- if any IO operation for the close fails.
-
listen
Description copied from interface:TransportMapping
Listen for incoming messages. For connection oriented transports, this method needs to be called beforeTransportMapping.sendMessage(A, byte[], org.snmp4j.TransportStateReference)
is called for the first time.- Specified by:
listen
in interfaceTransportMapping<A extends Address>
- Throws:
IOException
- if an IO operation exception occurs while starting the listener.
-
getMaxInboundMessageSize
public int getMaxInboundMessageSize()Description copied from interface:TransportMapping
Gets the maximum length of an incoming message that can be successfully processed by this transport mapping implementation.- Specified by:
getMaxInboundMessageSize
in interfaceTransportMapping<A extends Address>
- Returns:
- an integer > 484.
-
getMaxOutboundMessageSize
public int getMaxOutboundMessageSize()Description copied from interface:TransportMapping
Gets the maximum length of an outgoing message that can be successfully processed by this transport mapping implementation.- Specified by:
getMaxOutboundMessageSize
in interfaceTransportMapping<A extends Address>
- Returns:
- an integer > 484.
-
isAsyncMsgProcessingSupported
public boolean isAsyncMsgProcessingSupported()Returnstrue
if asynchronous (multithreaded) message processing may be implemented. The default istrue
.- Returns:
- if
false
is returned theMessageDispatcher.processMessage(org.snmp4j.TransportMapping, org.snmp4j.smi.Address, java.nio.ByteBuffer, org.snmp4j.TransportStateReference)
method must not return before the message has been entirely processed.
-
setAsyncMsgProcessingSupported
public void setAsyncMsgProcessingSupported(boolean asyncMsgProcessingSupported) Specifies whether this transport mapping has to support asynchronous messages processing or not.- Parameters:
asyncMsgProcessingSupported
- iffalse
theMessageDispatcher.processMessage(org.snmp4j.TransportMapping, org.snmp4j.smi.Address, java.nio.ByteBuffer, org.snmp4j.TransportStateReference)
method must not return before the message has been entirely processed, because the incoming message buffer is not copied before the message is being processed. Iftrue
the message buffer is copied for each call, so that the message processing can be implemented asynchronously.
-