Module org.snmp4j
Package org.snmp4j.transport
Class TcpTransportMapping<S extends AbstractSocketEntry<TcpAddress>>
java.lang.Object
org.snmp4j.transport.AbstractTransportMapping<TcpAddress>
org.snmp4j.transport.AbstractConnectionOrientedTransportMapping<TcpAddress,S>
org.snmp4j.transport.TcpTransportMapping<S>
- Type Parameters:
S
- defines the type ofAbstractSocketEntry
used by this transport mapping.
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ConnectionOrientedTransportMapping<TcpAddress>
,TransportMapping<TcpAddress>
- Direct Known Subclasses:
DefaultTcpTransportMapping
,TLSTM
public abstract class TcpTransportMapping<S extends AbstractSocketEntry<TcpAddress>>
extends AbstractConnectionOrientedTransportMapping<TcpAddress,S>
implements ConnectionOrientedTransportMapping<TcpAddress>
The
TcpTransportMapping
is the abstract base class for
TCP transport mappings.- Version:
- 3.7.0
- 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.AbstractConnectionOrientedTransportMapping
serverEnabled, sockets
Fields inherited from class org.snmp4j.transport.AbstractTransportMapping
asyncMsgProcessingSupported, connectionTimeout, listenWorkerTask, maxInboundMessageSize, socketCleaner, suspendedAddresses, transportListener, transportStateListeners
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionDeprecated.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 the primaryAddress
class that is supported by this transport mapping.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, long, int)
.abstract void
listen()
Listen for incoming messages.abstract void
sendMessage
(TcpAddress address, byte[] message, TransportStateReference tmStateReference, long timeoutMillis, int maxRetries) Sends a message to the supplied address using this transport.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, long, int)
is called but there is no listening socket.Methods inherited from class org.snmp4j.transport.AbstractConnectionOrientedTransportMapping
cancelNonServerSelectionKey, close, close, closeSockets, getConnectionTimeout, getMaxBusyLoops, getSockets, isServerEnabled, setConnectionTimeout, setMaxBusyLoops, setServerEnabled, setSocketOptions, timeoutSocket, wakeupServerSelector
Methods inherited from class org.snmp4j.transport.AbstractTransportMapping
addTransportListener, addTransportStateListener, fireConnectionStateChanged, fireProcessMessage, getListenWorkerTask, getMaxInboundMessageSize, getPriority, getSocketCleaner, getSuspendedAddresses, getThreadName, handleDroppedMessageToSend, isAsyncMsgProcessingSupported, isListening, removeAllTransportListeners, removeTransportListener, removeTransportStateListener, resumeAddress, setAsyncMsgProcessingSupported, setPriority, setThreadName, suspendAddress
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
addTransportStateListener, close, getConnectionTimeout, getSocketCleaner, isServerEnabled, removeTransportStateListener, resumeAddress, setConnectionTimeout, setServerEnabled, suspendAddress
Methods inherited from interface org.snmp4j.TransportMapping
addTransportListener, close, getMaxInboundMessageSize, getMaxOutboundMessageSize, getSupportedAddressClasses, getSupportedTransportType, isAddressSupported, isAddressSupported, isListening, removeTransportListener
-
Field Details
-
tcpAddress
-
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 the primaryAddress
class that is supported by this transport mapping.- Specified by:
getSupportedAddressClass
in interfaceTransportMapping<S extends AbstractSocketEntry<TcpAddress>>
- Specified by:
getSupportedAddressClass
in classAbstractTransportMapping<TcpAddress>
- Returns:
- a subclass of
Address
.
-
getAddress
Deprecated.UsegetListenAddress()
instead.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<S extends AbstractSocketEntry<TcpAddress>>
- Specified by:
getListenAddress
in classAbstractTransportMapping<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, long timeoutMillis, int maxRetries) throws IOException Description copied from class:AbstractTransportMapping
Sends a message to the supplied address using this transport. If the target address has been suspended, then instead actually sending the message on the wire, the methodAbstractTransportMapping.handleDroppedMessageToSend(Address, byte[], TransportStateReference, long, int)
will be called. To stop suspending of a target address, callAbstractTransportMapping.resumeAddress(Address)
for that address.- Specified by:
sendMessage
in interfaceTransportMapping<S extends AbstractSocketEntry<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.timeoutMillis
- maximum number of milliseconds the connection creation might take (if connection based).maxRetries
- maximum retries during connection creation.- Throws:
IOException
- if any underlying IO operation fails.
-
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, long, int)
.- Returns:
true
ifsendMessage(TcpAddress, byte[], TransportStateReference, long, int)
will ensure that a server socket is there for receiving responses,false
otherwise.- Since:
- 3.4.4
-
setOpenSocketOnSending
public void setOpenSocketOnSending(boolean openSocketOnSending) Activate or deactivate autolisten()
whensendMessage(TcpAddress, byte[], TransportStateReference, long, int)
is called but there is no listening socket.- Parameters:
openSocketOnSending
-true
ifsendMessage(TcpAddress, byte[], TransportStateReference, long, int)
should ensure that server socket is available for communication,false
iflisten()
must be called explicitly.- Since:
- 3.4.4
-
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, long, int)
is called for the first time.- Specified by:
listen
in interfaceTransportMapping<S extends AbstractSocketEntry<TcpAddress>>
- Specified by:
listen
in classAbstractTransportMapping<TcpAddress>
- Throws:
IOException
- if an IO operation exception occurs while starting the listener.
-
getMessageLengthDecoder
Returns theMessageLengthDecoder
used by this transport mapping.- Specified by:
getMessageLengthDecoder
in interfaceConnectionOrientedTransportMapping<S extends AbstractSocketEntry<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<S extends AbstractSocketEntry<TcpAddress>>
- Parameters:
messageLengthDecoder
- a MessageLengthDecoder instance.- Since:
- 1.7
-
getListenAddress()
instead.