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
FieldsModifier and TypeFieldDescriptionprotected booleanEnable or disable automatic (re)opening the communication socket when sending a messageprotected TcpAddressFields inherited from class org.snmp4j.transport.AbstractTransportMapping
asyncMsgProcessingSupported, maxInboundMessageSize, maxOutboundMessageSize, transportListener - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a transport state listener that is to be informed about connection state changes.protected voidabstract voidclose()Closes the transport an releases all bound resources synchronously.protected voidReturns 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 MessageLengthDecoderReturns theMessageLengthDecoderused by this transport mapping.Gets theAddressclass that is supported by this transport mapping.protected voidhandleDroppedMessageToSend(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.booleanIftrueand 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 voidlisten()Listen for incoming messages.voidRemoves the supplied transport state listener.booleanresumeAddress(TcpAddress addressToResumeSending) Resume sending of messages to the specified address.abstract voidsendMessage(TcpAddress address, byte[] message, TransportStateReference tmStateReference) Sends a message to the supplied address using this transport.abstract voidsetConnectionTimeout(long connectionTimeout) Sets the connection timeout.abstract voidsetMessageLengthDecoder(MessageLengthDecoder messageLengthDecoder) Sets theMessageLengthDecoderthat decodes the total message length from the header of a message.voidsetOpenSocketOnSending(boolean openSocketOnSending) Activate or deactivate autolisten()whensendMessage(TcpAddress, byte[], TransportStateReference)is called but there is no listening socket.voidsuspendAddress(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, setAsyncMsgProcessingSupportedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.snmp4j.transport.ConnectionOrientedTransportMapping
closeMethods 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:TransportMappingGets theAddressclass that is supported by this transport mapping.- Specified by:
 getSupportedAddressClassin interfaceTransportMapping<TcpAddress>- Specified by:
 getSupportedAddressClassin 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 
Addressused by this transport mapping. The returned instance must not be modified! 
 - 
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<TcpAddress>- Returns:
 - the address for incoming packets or 
nullthis 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:TransportMappingSends a message to the supplied address using this transport.- Specified by:
 sendMessagein interfaceTransportMapping<TcpAddress>- 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.- Throws:
 IOException- if any underlying IO operation fails.
 - 
listen
Description copied from interface:TransportMappingListen 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:
 listenin interfaceTransportMapping<TcpAddress>- Specified by:
 listenin classAbstractTransportMapping<TcpAddress>- Throws:
 IOException- if an IO operation exception occurs while starting the listener.
 - 
close
Description copied from interface:TransportMappingCloses the transport an releases all bound resources synchronously.- Specified by:
 closein interfaceTransportMapping<TcpAddress>- Specified by:
 closein classAbstractTransportMapping<TcpAddress>- Throws:
 IOException- if any IO operation for the close fails.
 - 
getMessageLengthDecoder
Returns theMessageLengthDecoderused by this transport mapping.- Specified by:
 getMessageLengthDecoderin interfaceConnectionOrientedTransportMapping<TcpAddress>- Returns:
 - a MessageLengthDecoder instance.
 - Since:
 - 1.7
 
 - 
setMessageLengthDecoder
Sets theMessageLengthDecoderthat decodes the total message length from the header of a message.- Specified by:
 setMessageLengthDecoderin 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:
 setConnectionTimeoutin 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:ConnectionOrientedTransportMappingAdds a transport state listener that is to be informed about connection state changes.- Specified by:
 addTransportStateListenerin interfaceConnectionOrientedTransportMapping<TcpAddress>- Parameters:
 l- a TransportStateListener.
 - 
removeTransportStateListener
Description copied from interface:ConnectionOrientedTransportMappingRemoves the supplied transport state listener.- Specified by:
 removeTransportStateListenerin interfaceConnectionOrientedTransportMapping<TcpAddress>- Parameters:
 l- a TransportStateListener.
 - 
fireConnectionStateChanged
 - 
isOpenSocketOnSending
public boolean isOpenSocketOnSending()Iftrueand 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:
 trueifsendMessage(TcpAddress, byte[], TransportStateReference)will ensure that a server socket is there for receiving responses,falseotherwise.- 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-trueifsendMessage(TcpAddress, byte[], TransportStateReference)should ensure that server socket is available for communication,falseiflisten()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:
 suspendAddressin 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:
 resumeAddressin 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:
 trueif the specified address was previously suspended and is now resumed to allow sending messages,falseotherwise.- 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- anAddressinstance 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
 
 -