Module org.snmp4j
Package org.snmp4j.transport
Class AbstractConnectionOrientedTransportMapping<A extends Address,S extends AbstractSocketEntry<A>>
java.lang.Object
org.snmp4j.transport.AbstractTransportMapping<A>
org.snmp4j.transport.AbstractConnectionOrientedTransportMapping<A,S>
- Type Parameters:
A- the address type.S- the socket entry type.
- All Implemented Interfaces:
Closeable,AutoCloseable,ConnectionOrientedTransportMapping<A>,TransportMapping<A>
- Direct Known Subclasses:
TcpTransportMapping
public abstract class AbstractConnectionOrientedTransportMapping<A extends Address,S extends AbstractSocketEntry<A>>
extends AbstractTransportMapping<A>
implements ConnectionOrientedTransportMapping<A>
The
AbstractConnectionOrientedTransportMapping implements generic functions for a connection
oriented transport mapping for server and client connections.- Since:
- 3.7.0
- Author:
- Frank Fock
-
Field Summary
FieldsFields inherited from class org.snmp4j.transport.AbstractTransportMapping
asyncMsgProcessingSupported, connectionTimeout, listenWorkerTask, maxInboundMessageSize, socketCleaner, suspendedAddresses, transportListener, transportStateListeners -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidvoidclose()Closes all open sockets and stops the internal server thread that processes messages.booleanCloses a connection to the supplied remote address, if it is open.protected voidcloseSockets(Map<A, S> sockets) longGets the connection timeout.protected intGets an unmodifiable map of theAbstractSocketEntryinstances associated with this transport mapping.booleanChecks whether a server for incoming requests is enabled.voidsetConnectionTimeout(long connectionTimeout) Sets the connection timeout.protected voidsetMaxBusyLoops(int maxBusyLoops) voidsetServerEnabled(boolean serverEnabled) Sets whether a server for incoming requests should be created when the transport is set into listen state.protected voidsetSocketOptions(ServerSocket serverSocket) Sets optional server socket options.protected voidtimeoutSocket(AbstractSocketEntry<A> entry) abstract voidMethods inherited from class org.snmp4j.transport.AbstractTransportMapping
addTransportListener, addTransportStateListener, fireConnectionStateChanged, fireProcessMessage, getListenAddress, getListenWorkerTask, getMaxInboundMessageSize, getPriority, getSocketCleaner, getSupportedAddressClass, getSuspendedAddresses, getThreadName, handleDroppedMessageToSend, isAsyncMsgProcessingSupported, isListening, listen, removeAllTransportListeners, removeTransportListener, removeTransportStateListener, resumeAddress, sendMessage, setAsyncMsgProcessingSupported, setPriority, setThreadName, suspendAddressMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.snmp4j.transport.ConnectionOrientedTransportMapping
addTransportStateListener, getMessageLengthDecoder, getSocketCleaner, removeTransportStateListener, resumeAddress, setMessageLengthDecoder, suspendAddressMethods inherited from interface org.snmp4j.TransportMapping
addTransportListener, getListenAddress, getMaxInboundMessageSize, getMaxOutboundMessageSize, getSupportedAddressClass, getSupportedAddressClasses, getSupportedTransportType, isAddressSupported, isAddressSupported, isListening, listen, removeTransportListener, sendMessage
-
Field Details
-
serverEnabled
protected boolean serverEnabled -
sockets
-
-
Constructor Details
-
AbstractConnectionOrientedTransportMapping
protected AbstractConnectionOrientedTransportMapping()
-
-
Method Details
-
timeoutSocket
-
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<A extends Address>- 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<A extends Address>- 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.
-
setSocketOptions
Sets optional server socket options. The default implementation does nothing.- Parameters:
serverSocket- theServerSocketto apply additional non-default options.
-
isServerEnabled
public boolean isServerEnabled()Description copied from interface:ConnectionOrientedTransportMappingChecks whether a server for incoming requests is enabled.- Specified by:
isServerEnabledin interfaceConnectionOrientedTransportMapping<A extends Address>- Returns:
- boolean
-
setServerEnabled
public void setServerEnabled(boolean serverEnabled) Description copied from interface:ConnectionOrientedTransportMappingSets whether a server for incoming requests should be created when the transport is set into listen state. Setting this value has no effect until theTransportMapping.listen()method is called (if the transport is already listening,TransportMapping.close()has to be called before).- Specified by:
setServerEnabledin interfaceConnectionOrientedTransportMapping<A extends Address>- Parameters:
serverEnabled- iftrueif the transport will listens for incoming requests afterTransportMapping.listen()has been called.
-
closeSockets
-
close
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<A extends Address>- Parameters:
remoteAddress- the address of the peer socket.- Returns:
trueif the connection has been closed andfalseif there was nothing to close.- Throws:
IOException- if the remote address cannot be closed due to an IO exception.- Since:
- 1.7.1
-
close
Closes all open sockets and stops the internal server thread that processes messages.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceTransportMapping<A extends Address>- Specified by:
closein classAbstractTransportMapping<A extends Address>- Throws:
IOException- if any IO operation for the close fails.
-
wakeupServerSelector
public abstract void wakeupServerSelector() -
getSockets
Gets an unmodifiable map of theAbstractSocketEntryinstances associated with this transport mapping.- Returns:
- an unmodifiable map from
AddresstoAbstractSocketEntry. - Since:
- 3.7.0
-
cancelNonServerSelectionKey
-
getMaxBusyLoops
protected int getMaxBusyLoops() -
setMaxBusyLoops
protected void setMaxBusyLoops(int maxBusyLoops)
-