Module org.snmp4j
Package org.snmp4j.transport
Class TcpTransportMapping<S extends AbstractSocketEntry>
- java.lang.Object
-
- org.snmp4j.transport.AbstractTransportMapping<TcpAddress>
-
- org.snmp4j.transport.TcpTransportMapping<S>
-
- Type Parameters:
S- defines the type ofAbstractSocketEntryused by this transport mapping.
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,ConnectionOrientedTransportMapping<TcpAddress>,TransportMapping<TcpAddress>
- Direct Known Subclasses:
DefaultTcpTransportMapping,TLSTM
public abstract class TcpTransportMapping<S extends AbstractSocketEntry> extends AbstractTransportMapping<TcpAddress> implements ConnectionOrientedTransportMapping<TcpAddress>
TheTcpTransportMappingis the abstract base class for TCP transport mappings.- Version:
- 3.0
- Author:
- Frank Fock
-
-
Field Summary
Fields Modifier and Type Field Description protected longconnectionTimeoutprotected WorkerTaskserverprotected CommonTimersocketCleanerprotected java.util.Map<Address,S>socketsprotected TcpAddresstcpAddress-
Fields inherited from class org.snmp4j.transport.AbstractTransportMapping
asyncMsgProcessingSupported, maxInboundMessageSize, transportListener
-
-
Constructor Summary
Constructors Constructor Description TcpTransportMapping(TcpAddress tcpAddress)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddTransportStateListener(TransportStateListener l)Adds a transport state listener that is to be informed about connection state changes.abstract voidclose()Closes the transport an releases all bound resources synchronously.booleanclose(TcpAddress remoteAddress)Closes a connection to the supplied remote address, if it is open.protected voidcloseSockets(java.util.Map<Address,S> sockets)protected voidfireConnectionStateChanged(TransportStateEvent change)TcpAddressgetAddress()Returns the transport address that is used by this transport mapping for sending and receiving messages.longgetConnectionTimeout()Gets the connection timeout.TcpAddressgetListenAddress()Returns the address that represents the actual incoming address this transport mapping uses to listen for incoming packets.abstract MessageLengthDecodergetMessageLengthDecoder()Returns theMessageLengthDecoderused by this transport mapping.WorkerTaskgetServer()java.lang.Class<? extends Address>getSupportedAddressClass()Gets the primaryAddressclass that is supported by this transport mapping.abstract voidlisten()Listen for incoming messages.voidremoveTransportStateListener(TransportStateListener l)Removes the supplied transport state listener.abstract voidsendMessage(TcpAddress address, byte[] message, TransportStateReference tmStateReference, long timeoutMillis, int maxRetries)Sends a message to the supplied address using this transport.voidsetConnectionTimeout(long connectionTimeout)Sets the connection timeout.abstract voidsetMessageLengthDecoder(MessageLengthDecoder messageLengthDecoder)Sets theMessageLengthDecoderthat decodes the total message length from the header of a message.protected voidsetSocketOptions(java.net.ServerSocket serverSocket)Sets optional server socket options.protected voidtimeoutSocket(AbstractServerSocket<TcpAddress> entry)-
Methods inherited from class org.snmp4j.transport.AbstractTransportMapping
addTransportListener, fireProcessMessage, getMaxInboundMessageSize, isAsyncMsgProcessingSupported, removeTransportListener, setAsyncMsgProcessingSupported
-
Methods inherited from interface org.snmp4j.transport.ConnectionOrientedTransportMapping
getSocketCleaner
-
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
addTransportListener, getMaxInboundMessageSize, getSupportedAddressClasses, getSupportedTransportType, isAddressSupported, isAddressSupported, isListening, removeTransportListener
-
-
-
-
Field Detail
-
tcpAddress
protected TcpAddress tcpAddress
-
sockets
protected java.util.Map<Address,S extends AbstractSocketEntry> sockets
-
connectionTimeout
protected long connectionTimeout
-
socketCleaner
protected CommonTimer socketCleaner
-
server
protected WorkerTask server
-
-
Constructor Detail
-
TcpTransportMapping
public TcpTransportMapping(TcpAddress tcpAddress)
-
-
Method Detail
-
getSupportedAddressClass
public java.lang.Class<? extends Address> getSupportedAddressClass()
Description copied from interface:TransportMappingGets the primaryAddressclass that is supported by this transport mapping.- Specified by:
getSupportedAddressClassin interfaceTransportMapping<S extends AbstractSocketEntry>- Specified by:
getSupportedAddressClassin classAbstractTransportMapping<TcpAddress>- Returns:
- a subclass of
Address.
-
getAddress
public TcpAddress getAddress()
Returns the transport address that is used by this transport mapping for sending and receiving messages.- Returns:
- the
Addressused by this transport mapping. The returned instance must not be modified!
-
timeoutSocket
protected void timeoutSocket(AbstractServerSocket<TcpAddress> entry)
-
getListenAddress
public TcpAddress getListenAddress()
Description copied from interface:TransportMappingReturns the address that represents the actual incoming address this transport mapping uses to listen for incoming packets.- Specified by:
getListenAddressin interfaceTransportMapping<S extends AbstractSocketEntry>- Returns:
- the address for incoming packets or
nullthis transport mapping is not configured to listen for incoming packets.
-
close
public boolean close(TcpAddress remoteAddress) throws java.io.IOException
Closes a connection to the supplied remote address, if it is open. This method is particularly useful when not using a timeout for remote connections.- Specified by:
closein interfaceConnectionOrientedTransportMapping<S extends AbstractSocketEntry>- Parameters:
remoteAddress- the address of the peer socket.- Returns:
trueif the connection has been closed andfalseif there was nothing to close.- Throws:
java.io.IOException- if the remote address cannot be closed due to an IO exception.- Since:
- 1.7.1
-
sendMessage
public abstract void sendMessage(TcpAddress address, byte[] message, TransportStateReference tmStateReference, long timeoutMillis, int maxRetries) throws java.io.IOException
Description copied from interface:TransportMappingSends a message to the supplied address using this transport.- Specified by:
sendMessagein interfaceTransportMapping<S extends AbstractSocketEntry>- Specified by:
sendMessagein classAbstractTransportMapping<TcpAddress>- Parameters:
address- anAddressinstance 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.- Throws:
java.io.IOException- if any underlying IO operation fails.
-
listen
public abstract void listen() throws java.io.IOExceptionDescription copied from interface:TransportMappingListen 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:
listenin interfaceTransportMapping<S extends AbstractSocketEntry>- Specified by:
listenin classAbstractTransportMapping<TcpAddress>- Throws:
java.io.IOException- if an IO operation exception occurs while starting the listener.
-
close
public abstract void close() throws java.io.IOExceptionDescription copied from interface:TransportMappingCloses the transport an releases all bound resources synchronously.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceTransportMapping<S extends AbstractSocketEntry>- Specified by:
closein classAbstractTransportMapping<TcpAddress>- Throws:
java.io.IOException- if any IO operation for the close fails.
-
getMessageLengthDecoder
public abstract MessageLengthDecoder getMessageLengthDecoder()
Returns theMessageLengthDecoderused by this transport mapping.- Specified by:
getMessageLengthDecoderin interfaceConnectionOrientedTransportMapping<S extends AbstractSocketEntry>- Returns:
- a MessageLengthDecoder instance.
- Since:
- 1.7
-
setMessageLengthDecoder
public abstract void setMessageLengthDecoder(MessageLengthDecoder messageLengthDecoder)
Sets theMessageLengthDecoderthat decodes the total message length from the header of a message.- Specified by:
setMessageLengthDecoderin interfaceConnectionOrientedTransportMapping<S extends AbstractSocketEntry>- Parameters:
messageLengthDecoder- a MessageLengthDecoder instance.- Since:
- 1.7
-
getConnectionTimeout
public long getConnectionTimeout()
Gets the connection timeout. This timeout specifies the time a connection may be idle before it is closed.- Specified by:
getConnectionTimeoutin interfaceConnectionOrientedTransportMapping<S extends AbstractSocketEntry>- Returns:
- long the idle timeout in milliseconds.
-
setConnectionTimeout
public void setConnectionTimeout(long connectionTimeout)
Sets the connection timeout. This timeout specifies the time a connection may be idle before it is closed.- Specified by:
setConnectionTimeoutin interfaceConnectionOrientedTransportMapping<S extends AbstractSocketEntry>- 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.
-
addTransportStateListener
public void addTransportStateListener(TransportStateListener l)
Description copied from interface:ConnectionOrientedTransportMappingAdds a transport state listener that is to be informed about connection state changes.- Specified by:
addTransportStateListenerin interfaceConnectionOrientedTransportMapping<S extends AbstractSocketEntry>- Parameters:
l- a TransportStateListener.
-
removeTransportStateListener
public void removeTransportStateListener(TransportStateListener l)
Description copied from interface:ConnectionOrientedTransportMappingRemoves the supplied transport state listener.- Specified by:
removeTransportStateListenerin interfaceConnectionOrientedTransportMapping<S extends AbstractSocketEntry>- Parameters:
l- a TransportStateListener.
-
fireConnectionStateChanged
protected void fireConnectionStateChanged(TransportStateEvent change)
-
setSocketOptions
protected void setSocketOptions(java.net.ServerSocket serverSocket)
Sets optional server socket options. The default implementation does nothing.- Parameters:
serverSocket- theServerSocketto apply additional non-default options.
-
getServer
public WorkerTask getServer()
-
-