public abstract class TcpTransportMapping extends AbstractTransportMapping<TcpAddress> implements ConnectionOrientedTransportMapping<TcpAddress>
TcpTransportMapping
is the abstract base class for
TCP transport mappings.Modifier and Type | Field and Description |
---|---|
protected boolean |
openSocketOnSending
Enable or disable automatic (re)opening the communication socket when sending a message
|
protected Set<Address> |
suspendedAddresses |
protected TcpAddress |
tcpAddress |
asyncMsgProcessingSupported, maxInboundMessageSize, transportListener
Constructor and Description |
---|
TcpTransportMapping(TcpAddress tcpAddress) |
Modifier and Type | Method and Description |
---|---|
void |
addTransportStateListener(TransportStateListener l)
Adds a transport state listener that is to be informed about connection
state changes.
|
protected void |
cancelNonServerSelectionKey(SelectionKey sk) |
abstract void |
close()
Closes the transport an releases all bound resources synchronously.
|
protected void |
fireConnectionStateChanged(TransportStateEvent change) |
TcpAddress |
getAddress()
Returns the transport address that is used by this transport mapping for
sending and receiving messages.
|
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. |
Class<? extends Address> |
getSupportedAddressClass()
Gets the
Address 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 |
isOpenSocketOnSending()
If
true and method listen() has not been called yet or the connection has been closed or reset,
then listen() will be called to open the communication socket when a message is being sent using
sendMessage(TcpAddress, byte[], TransportStateReference) . |
abstract void |
listen()
Listen for incoming messages.
|
void |
removeTransportStateListener(TransportStateListener l)
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 the
MessageLengthDecoder that decodes the total
message length from the header of a message. |
void |
setOpenSocketOnSending(boolean openSocketOnSending)
Activate or deactivate auto
listen() when
sendMessage(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.
|
addTransportListener, fireProcessMessage, getMaxInboundMessageSize, isAsyncMsgProcessingSupported, removeTransportListener, setAsyncMsgProcessingSupported
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close
addTransportListener, getMaxInboundMessageSize, isListening, removeTransportListener
protected TcpAddress tcpAddress
protected boolean openSocketOnSending
public TcpTransportMapping(TcpAddress tcpAddress)
public 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!public TcpAddress getListenAddress()
TransportMapping
getListenAddress
in interface TransportMapping<TcpAddress>
null
this transport
mapping is not configured to listen for incoming packets.public abstract void sendMessage(TcpAddress address, byte[] message, TransportStateReference tmStateReference) throws 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.IOException
- if any underlying IO operation fails.public abstract void listen() throws IOException
TransportMapping
TransportMapping.sendMessage(A, byte[], org.snmp4j.TransportStateReference)
is called for the
first time.listen
in interface TransportMapping<TcpAddress>
listen
in class AbstractTransportMapping<TcpAddress>
IOException
- if an IO operation exception occurs while starting the listener.public abstract void close() throws IOException
TransportMapping
close
in interface TransportMapping<TcpAddress>
close
in class AbstractTransportMapping<TcpAddress>
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 abstract 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)
public boolean isOpenSocketOnSending()
true
and method listen()
has not been called yet or the connection has been closed or reset,
then listen()
will be called to open the communication socket when a message is being sent using
sendMessage(TcpAddress, byte[], TransportStateReference)
.true
if sendMessage(TcpAddress, byte[], TransportStateReference)
will ensure that
a server socket is there for receiving responses, false
otherwise.public void setOpenSocketOnSending(boolean openSocketOnSending)
listen()
when
sendMessage(TcpAddress, byte[], TransportStateReference)
is called but there is no listening
socket.openSocketOnSending
- true
if sendMessage(TcpAddress, byte[], TransportStateReference)
should ensure
that server socket is available for communication, false
if listen()
must be called
explicitly.public void suspendAddress(TcpAddress addressToSuspendSending)
sendMessage(TcpAddress, byte[], TransportStateReference)
, call resumeAddress(org.snmp4j.smi.TcpAddress)
.suspendAddress
in interface ConnectionOrientedTransportMapping<TcpAddress>
addressToSuspendSending
- an arbitrary remote address for which any messages send by
sendMessage(TcpAddress, byte[], TransportStateReference)
should be dropped before sending
and reopening a connection to that address.public boolean resumeAddress(TcpAddress addressToResumeSending)
resumeAddress
in interface ConnectionOrientedTransportMapping<TcpAddress>
addressToResumeSending
- an arbitrary remote address for which any messages send by
sendMessage(TcpAddress, byte[], TransportStateReference)
should be dropped before sending
and reopening a connection to that address.true
if the specified address was previously suspended and is now resumed to allow sending messages,
false
otherwise.protected void handleDroppedMessageToSend(TcpAddress address, byte[] message, TransportStateReference transportStateReference)
address
- an Address
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.protected void cancelNonServerSelectionKey(SelectionKey sk)
Copyright © 2021 SNMP4J.org. All rights reserved.