Package org.snmp4j.transport
Class TcpTransportMapping
- All Implemented Interfaces:
ConnectionOrientedTransportMapping<TcpAddress>
,TransportMapping<TcpAddress>
- Direct Known Subclasses:
DefaultTcpTransportMapping
,TLSTM
public abstract class TcpTransportMapping
extends AbstractTransportMapping<TcpAddress>
implements ConnectionOrientedTransportMapping<TcpAddress>
The
TcpTransportMapping
is the abstract base class for
TCP transport mappings.- Version:
- 2.8.6
- Author:
- Frank Fock
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
Enable or disable automatic (re)opening the communication socket when sending a messageprotected TcpAddress
Fields inherited from class org.snmp4j.transport.AbstractTransportMapping
asyncMsgProcessingSupported, maxInboundMessageSize, maxOutboundMessageSize, transportListener
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a transport state listener that is to be informed about connection state changes.protected void
abstract void
close()
Closes the transport an releases all bound resources synchronously.protected void
Returns the transport address that is used by this transport mapping for sending and receiving messages.Returns the address that represents the actual incoming address this transport mapping uses to listen for incoming packets.abstract MessageLengthDecoder
Returns theMessageLengthDecoder
used by this transport mapping.Gets theAddress
class that is supported by this transport mapping.protected void
handleDroppedMessageToSend
(TcpAddress address, byte[] message, TransportStateReference transportStateReference) Handle a message that could not be send to the specified address, because there is no server socket for receiving responses.boolean
Iftrue
and methodlisten()
has not been called yet or the connection has been closed or reset, thenlisten()
will be called to open the communication socket when a message is being sent usingsendMessage(TcpAddress, byte[], TransportStateReference)
.abstract void
listen()
Listen for incoming messages.void
Removes the supplied transport state listener.boolean
resumeAddress
(TcpAddress addressToResumeSending) Resume sending of messages to the specified address.abstract void
sendMessage
(TcpAddress address, byte[] message, TransportStateReference tmStateReference) Sends a message to the supplied address using this transport.abstract void
setConnectionTimeout
(long connectionTimeout) Sets the connection timeout.abstract void
setMessageLengthDecoder
(MessageLengthDecoder messageLengthDecoder) Sets theMessageLengthDecoder
that decodes the total message length from the header of a message.void
setOpenSocketOnSending
(boolean openSocketOnSending) Activate or deactivate autolisten()
whensendMessage(TcpAddress, byte[], TransportStateReference)
is called but there is no listening socket.void
suspendAddress
(TcpAddress addressToSuspendSending) Suspend sending of messages to the specified address, regardless if a connection is already established or not.Methods inherited from class org.snmp4j.transport.AbstractTransportMapping
addTransportListener, fireProcessMessage, getMaxInboundMessageSize, getMaxOutboundMessageSize, isAsyncMsgProcessingSupported, removeAllTransportListeners, removeTransportListener, setAsyncMsgProcessingSupported
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.snmp4j.transport.ConnectionOrientedTransportMapping
close
Methods inherited from interface org.snmp4j.TransportMapping
addTransportListener, getMaxInboundMessageSize, getMaxOutboundMessageSize, isListening, removeTransportListener
-
Field Details
-
tcpAddress
-
suspendedAddresses
-
openSocketOnSending
protected boolean openSocketOnSendingEnable or disable automatic (re)opening the communication socket when sending a message
-
-
Constructor Details
-
TcpTransportMapping
-
-
Method Details
-
getSupportedAddressClass
Description copied from interface:TransportMapping
Gets theAddress
class that is supported by this transport mapping.- Specified by:
getSupportedAddressClass
in interfaceTransportMapping<TcpAddress>
- Specified by:
getSupportedAddressClass
in classAbstractTransportMapping<TcpAddress>
- Returns:
- a subclass of
Address
.
-
getAddress
Returns the transport address that is used by this transport mapping for sending and receiving messages.- Returns:
- the
Address
used by this transport mapping. The returned instance must not be modified!
-
getListenAddress
Description copied from interface:TransportMapping
Returns the address that represents the actual incoming address this transport mapping uses to listen for incoming packets.- Specified by:
getListenAddress
in interfaceTransportMapping<TcpAddress>
- Returns:
- the address for incoming packets or
null
this transport mapping is not configured to listen for incoming packets.
-
sendMessage
public abstract void sendMessage(TcpAddress 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<TcpAddress>
- Specified by:
sendMessage
in classAbstractTransportMapping<TcpAddress>
- 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.
-
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<TcpAddress>
- Specified by:
listen
in classAbstractTransportMapping<TcpAddress>
- Throws:
IOException
- if an IO operation exception occurs while starting the listener.
-
close
Description copied from interface:TransportMapping
Closes the transport an releases all bound resources synchronously.- Specified by:
close
in interfaceTransportMapping<TcpAddress>
- Specified by:
close
in classAbstractTransportMapping<TcpAddress>
- Throws:
IOException
- if any IO operation for the close fails.
-
getMessageLengthDecoder
Returns theMessageLengthDecoder
used by this transport mapping.- Specified by:
getMessageLengthDecoder
in interfaceConnectionOrientedTransportMapping<TcpAddress>
- Returns:
- a MessageLengthDecoder instance.
- Since:
- 1.7
-
setMessageLengthDecoder
Sets theMessageLengthDecoder
that decodes the total message length from the header of a message.- Specified by:
setMessageLengthDecoder
in interfaceConnectionOrientedTransportMapping<TcpAddress>
- Parameters:
messageLengthDecoder
- a MessageLengthDecoder instance.- Since:
- 1.7
-
setConnectionTimeout
public abstract void setConnectionTimeout(long connectionTimeout) Sets the connection timeout. This timeout specifies the time a connection may be idle before it is closed.- Specified by:
setConnectionTimeout
in interfaceConnectionOrientedTransportMapping<TcpAddress>
- Parameters:
connectionTimeout
- the idle timeout in milliseconds. A zero or negative value will disable any timeout and connections opened by this transport mapping will stay opened until they are explicitly closed.- Since:
- 1.7
-
addTransportStateListener
Description copied from interface:ConnectionOrientedTransportMapping
Adds a transport state listener that is to be informed about connection state changes.- Specified by:
addTransportStateListener
in interfaceConnectionOrientedTransportMapping<TcpAddress>
- Parameters:
l
- a TransportStateListener.
-
removeTransportStateListener
Description copied from interface:ConnectionOrientedTransportMapping
Removes the supplied transport state listener.- Specified by:
removeTransportStateListener
in interfaceConnectionOrientedTransportMapping<TcpAddress>
- Parameters:
l
- a TransportStateListener.
-
fireConnectionStateChanged
-
isOpenSocketOnSending
public boolean isOpenSocketOnSending()Iftrue
and methodlisten()
has not been called yet or the connection has been closed or reset, thenlisten()
will be called to open the communication socket when a message is being sent usingsendMessage(TcpAddress, byte[], TransportStateReference)
.- Returns:
true
ifsendMessage(TcpAddress, byte[], TransportStateReference)
will ensure that a server socket is there for receiving responses,false
otherwise.- Since:
- 2.8.6
-
setOpenSocketOnSending
public void setOpenSocketOnSending(boolean openSocketOnSending) Activate or deactivate autolisten()
whensendMessage(TcpAddress, byte[], TransportStateReference)
is called but there is no listening socket.- Parameters:
openSocketOnSending
-true
ifsendMessage(TcpAddress, byte[], TransportStateReference)
should ensure that server socket is available for communication,false
iflisten()
must be called explicitly.- Since:
- 2.8.6
-
suspendAddress
Suspend sending of messages to the specified address, regardless if a connection is already established or not. To be able to send messages again to the specified address usingsendMessage(TcpAddress, byte[], TransportStateReference)
, callresumeAddress(org.snmp4j.smi.TcpAddress)
.- Specified by:
suspendAddress
in interfaceConnectionOrientedTransportMapping<TcpAddress>
- Parameters:
addressToSuspendSending
- an arbitrary remote address for which any messages send bysendMessage(TcpAddress, byte[], TransportStateReference)
should be dropped before sending and reopening a connection to that address.- Since:
- 2.8.6
-
resumeAddress
Resume sending of messages to the specified address.- Specified by:
resumeAddress
in interfaceConnectionOrientedTransportMapping<TcpAddress>
- Parameters:
addressToResumeSending
- an arbitrary remote address for which any messages send bysendMessage(TcpAddress, byte[], TransportStateReference)
should be dropped before sending and reopening a connection to that address.- Returns:
true
if the specified address was previously suspended and is now resumed to allow sending messages,false
otherwise.- Since:
- 2.8.6
-
handleDroppedMessageToSend
protected void handleDroppedMessageToSend(TcpAddress address, byte[] message, TransportStateReference transportStateReference) Handle a message that could not be send to the specified address, because there is no server socket for receiving responses.- Parameters:
address
- anAddress
instance denoting the target address.message
- the whole message as an array of bytes.transportStateReference
- the (optional) transport model state reference as defined by RFC 5590 section 6.1.- Since:
- 2.8.6
-
cancelNonServerSelectionKey
-