java.io.Closeable
, java.lang.AutoCloseable
, ConnectionOrientedTransportMapping<TcpAddress>
, TransportMapping<TcpAddress>
DefaultTcpTransportMapping
, TLSTM
public abstract class TcpTransportMapping extends AbstractTransportMapping<TcpAddress> implements ConnectionOrientedTransportMapping<TcpAddress>
TcpTransportMapping
is the abstract base class for
TCP transport mappings.Modifier and Type | Field | Description |
---|---|---|
protected long |
connectionTimeout |
|
protected WorkerTask |
server |
|
protected CommonTimer |
socketCleaner |
|
protected java.util.Map<Address,ServerSocketEntry> |
sockets |
|
protected TcpAddress |
tcpAddress |
asyncMsgProcessingSupported, maxInboundMessageSize, transportListener
Constructor | Description |
---|---|
TcpTransportMapping(TcpAddress tcpAddress) |
Modifier and Type | Method | Description |
---|---|---|
void |
addTransportStateListener(TransportStateListener l) |
Adds a transport state listener that is to be informed about connection
state changes.
|
abstract void |
close() |
Closes the transport an releases all bound resources synchronously.
|
boolean |
close(TcpAddress remoteAddress) |
Closes a connection to the supplied remote address, if it is open.
|
protected void |
closeSockets(java.util.Map<Address,ServerSocketEntry> sockets) |
|
protected void |
fireConnectionStateChanged(TransportStateEvent change) |
|
TcpAddress |
getAddress() |
Returns the transport address that is used by this transport mapping for
sending and receiving messages.
|
long |
getConnectionTimeout() |
Gets the connection timeout.
|
TcpAddress |
getListenAddress() |
Returns the address that represents the actual incoming address this transport
mapping uses to listen for incoming packets.
|
abstract MessageLengthDecoder |
getMessageLengthDecoder() |
Returns the
MessageLengthDecoder used by this transport
mapping. |
WorkerTask |
getServer() |
|
java.lang.Class<? extends Address> |
getSupportedAddressClass() |
Gets the
Address class that is supported by this transport mapping. |
abstract void |
listen() |
Listen for incoming messages.
|
void |
removeTransportStateListener(TransportStateListener l) |
Removes the supplied transport state listener.
|
abstract void |
sendMessage(TcpAddress address,
byte[] message,
TransportStateReference tmStateReference,
long timeoutMillis,
int maxRetries) |
Sends a message to the supplied address using this transport.
|
void |
setConnectionTimeout(long connectionTimeout) |
Sets the connection timeout.
|
abstract void |
setMessageLengthDecoder(MessageLengthDecoder messageLengthDecoder) |
Sets the
MessageLengthDecoder that decodes the total
message length from the header of a message. |
protected void |
setSocketOptions(java.net.ServerSocket serverSocket) |
Sets optional server socket options.
|
protected void |
timeoutSocket(ServerSocketEntry entry) |
addTransportListener, fireProcessMessage, getMaxInboundMessageSize, isAsyncMsgProcessingSupported, removeTransportListener, setAsyncMsgProcessingSupported
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addTransportListener, getMaxInboundMessageSize, isListening, removeTransportListener
protected TcpAddress tcpAddress
protected java.util.Map<Address,ServerSocketEntry> sockets
protected long connectionTimeout
protected CommonTimer socketCleaner
protected WorkerTask server
public TcpTransportMapping(TcpAddress tcpAddress)
public java.lang.Class<? extends Address> getSupportedAddressClass()
TransportMapping
Address
class that is supported by this transport mapping.getSupportedAddressClass
in interface TransportMapping<TcpAddress>
getSupportedAddressClass
in class AbstractTransportMapping<TcpAddress>
Address
.public TcpAddress getAddress()
Address
used by this transport mapping. The returned
instance must not be modified!protected void timeoutSocket(ServerSocketEntry entry)
public TcpAddress getListenAddress()
TransportMapping
getListenAddress
in interface TransportMapping<TcpAddress>
null
this transport
mapping is not configured to listen for incoming packets.protected void closeSockets(java.util.Map<Address,ServerSocketEntry> sockets)
public boolean close(TcpAddress remoteAddress) throws java.io.IOException
close
in interface ConnectionOrientedTransportMapping<TcpAddress>
remoteAddress
- the address of the peer socket.true
if the connection has been closed and
false
if there was nothing to close.java.io.IOException
- if the remote address cannot be closed due to an IO exception.public abstract void sendMessage(TcpAddress address, byte[] message, TransportStateReference tmStateReference, long timeoutMillis, int maxRetries) throws java.io.IOException
TransportMapping
sendMessage
in interface TransportMapping<TcpAddress>
sendMessage
in class AbstractTransportMapping<TcpAddress>
address
- an Address
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 milli seconds the connection creation might take (if connection based).maxRetries
- maximum retries during connection creation.java.io.IOException
- if any underlying IO operation fails.public abstract void listen() throws java.io.IOException
TransportMapping
TransportMapping.sendMessage(A, byte[], org.snmp4j.TransportStateReference, long, int)
is called for the
first time.listen
in interface TransportMapping<TcpAddress>
listen
in class AbstractTransportMapping<TcpAddress>
java.io.IOException
- if an IO operation exception occurs while starting the listener.public abstract void close() throws java.io.IOException
TransportMapping
close
in interface java.lang.AutoCloseable
close
in interface java.io.Closeable
close
in interface TransportMapping<TcpAddress>
close
in class AbstractTransportMapping<TcpAddress>
java.io.IOException
- if any IO operation for the close fails.public abstract MessageLengthDecoder getMessageLengthDecoder()
MessageLengthDecoder
used by this transport
mapping.getMessageLengthDecoder
in interface ConnectionOrientedTransportMapping<TcpAddress>
public abstract void setMessageLengthDecoder(MessageLengthDecoder messageLengthDecoder)
MessageLengthDecoder
that decodes the total
message length from the header of a message.setMessageLengthDecoder
in interface ConnectionOrientedTransportMapping<TcpAddress>
messageLengthDecoder
- a MessageLengthDecoder instance.public long getConnectionTimeout()
public void setConnectionTimeout(long connectionTimeout)
setConnectionTimeout
in interface ConnectionOrientedTransportMapping<TcpAddress>
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.public void addTransportStateListener(TransportStateListener l)
ConnectionOrientedTransportMapping
addTransportStateListener
in interface ConnectionOrientedTransportMapping<TcpAddress>
l
- a TransportStateListener.public void removeTransportStateListener(TransportStateListener l)
ConnectionOrientedTransportMapping
removeTransportStateListener
in interface ConnectionOrientedTransportMapping<TcpAddress>
l
- a TransportStateListener.protected void fireConnectionStateChanged(TransportStateEvent change)
protected void setSocketOptions(java.net.ServerSocket serverSocket)
serverSocket
- the ServerSocketEntry
to apply additional non-default options.public WorkerTask getServer()
Copyright © 2018 SNMP4J.org. All rights reserved.