Class UnixSocketStreamTransportMapping
- All Implemented Interfaces:
Closeable, AutoCloseable, org.snmp4j.transport.ConnectionOrientedTransportMapping<UnixDomainAddress>, org.snmp4j.TransportMapping<UnixDomainAddress>
The class allows for sending and receiving messages, setting socket options, and managing Unix domain socket communication-specific behaviors. It supports asynchronous message handling and can handle multiple concurrent Unix domain socket-based connections.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PathThe socket path that has been bound by this transport mapping and that therefore has to be removed when this transport mapping is closed, ornullif this transport mapping has not created a socket file.protected UnixDomainAddressThe Unix domain socket address to which this transport mapping is bound.The server thread responsible for handling incoming connections.Fields inherited from class org.snmp4j.transport.AbstractConnectionOrientedTransportMapping
gracefulShutdownTimeoutMillis, maxInboundConnections, serverEnabled, socketsFields inherited from class org.snmp4j.transport.AbstractTransportMapping
asyncMsgProcessingSupported, connectionTimeout, listenWorkerTask, maxInboundMessageSize, socketCleaner, suspendedAddresses, transportAuditListeners, transportListener, transportStateListeners -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a UnixSocketStreamTransportMapping without specifying a Unix domain socket address.UnixSocketStreamTransportMapping(UnixDomainAddress listenAddress) Constructs a UnixSocketStreamTransportMapping with the specified Unix domain socket address and server mode enabled, that is, incoming connections on that address are accepted.UnixSocketStreamTransportMapping(UnixDomainAddress listenAddress, boolean serverEnabled) Constructs a UnixSocketStreamTransportMapping with the specified Unix domain socket address and enables server mode on request. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()booleanclose(UnixDomainAddress remoteAddress) org.snmp4j.transport.MessageLengthDecoderClass<? extends org.snmp4j.smi.Address> booleanvoidlisten()protected Optional<ByteBuffer> readNextInPacket(SocketChannel socketChannel) Read the next network packet for the application.protected voidRemoves the socket file that this transport mapping has created, if any.voidsendMessage(UnixDomainAddress address, byte[] message, org.snmp4j.TransportStateReference tmStateReference, long timeoutMillis, int maxRetries) voidsetMessageLengthDecoder(org.snmp4j.transport.MessageLengthDecoder messageLengthDecoder) protected <T> voidsetSocketOption(SocketOption<T> socketOption, T value) voidMethods inherited from class org.snmp4j.transport.AbstractConnectionOrientedTransportMapping
cancelNonServerSelectionKey, close, closeSockets, getConnectionTimeout, getGracefulShutdownTimeoutMillis, getMaxBusyLoops, getMaxInboundConnections, getSockets, isInboundConnectionAcceptable, isServerEnabled, setConnectionTimeout, setGracefulShutdownTimeoutMillis, setMaxBusyLoops, setMaxInboundConnections, setServerEnabled, setSocketOptions, timeoutSocketMethods inherited from class org.snmp4j.transport.AbstractTransportMapping
addTransportAuditListener, addTransportListener, addTransportStateListener, fireConnectionStateChanged, fireProcessMessage, fireTransportAuditEvent, getAuditListenAddress, getListenWorkerTask, getMaxInboundMessageSize, getPriority, getSocketCleaner, getSuspendedAddresses, getThreadName, handleDroppedMessageToSend, isAsyncMsgProcessingSupported, isTransportAudit, removeAllTransportAuditListeners, removeAllTransportListeners, removeTransportAuditListener, removeTransportListener, removeTransportStateListener, resumeAddress, setAsyncMsgProcessingSupported, setPriority, setThreadName, suspendAddressMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.snmp4j.transport.ConnectionOrientedTransportMapping
addTransportStateListener, getSocketCleaner, removeTransportStateListener, resumeAddress, suspendAddressMethods inherited from interface org.snmp4j.TransportMapping
addTransportListener, getMaxInboundMessageSize, getMaxOutboundMessageSize, getSupportedTransportType, isAddressSupported, isAddressSupported, removeTransportListener
-
Field Details
-
listenAddress
The Unix domain socket address to which this transport mapping is bound. -
serverThread
The server thread responsible for handling incoming connections. -
boundSocketPath
The socket path that has been bound by this transport mapping and that therefore has to be removed when this transport mapping is closed, ornullif this transport mapping has not created a socket file. Only a socket file that has been created by this transport mapping is ever removed, so that the socket of another SNMP entity that uses the same path is left alone.- Since:
- 1.2.2
-
-
Constructor Details
-
UnixSocketStreamTransportMapping
Constructs a UnixSocketStreamTransportMapping with the specified Unix domain socket address and server mode enabled, that is, incoming connections on that address are accepted.- Parameters:
listenAddress- the Unix domain socket address to which this transport mapping is bound.
-
UnixSocketStreamTransportMapping
Constructs a UnixSocketStreamTransportMapping with the specified Unix domain socket address and enables server mode on request.In client mode (
serverEnabledisfalse) no socket is bound to listen for incoming connections. Unlike an IP based transport mapping, which can bind an ephemeral port for its outgoing connections, a Unix domain socket path is the address itself: listening on it in client mode would occupy the path of the transport mapping that serves incoming connections on it and fail with "Address already in use". The outgoing socket of a client mode transport mapping is bound to the given address instead, so that the peer can tell this SNMP entity apart from other entities that connect to it - an unbound Unix domain socket has no address at all, thus all peers that connect without binding their socket look alike to the entity that accepts their connections. SeeUnixSocketStreamTransportMapping.ServerThread.bindOutgoingSocket(SocketChannel).- Parameters:
listenAddress- the Unix domain socket address to which this transport mapping is bound.serverEnabled- iftruethe server mode is enabled and incoming new connections are accepted. Usefalseto allow outgoing messages and their responses only (client mode).- Since:
- 1.2.2
-
UnixSocketStreamTransportMapping
public UnixSocketStreamTransportMapping()Constructs a UnixSocketStreamTransportMapping without specifying a Unix domain socket address. This constructor is useful when the address will be set later.
-
-
Method Details
-
setSocketOption
- Specified by:
setSocketOptionin classorg.snmp4j.transport.AbstractConnectionOrientedTransportMapping<UnixDomainAddress, UnixSocketStreamTransportMapping.SocketEntry>- Throws:
IOException
-
getMessageLengthDecoder
public org.snmp4j.transport.MessageLengthDecoder getMessageLengthDecoder() -
setMessageLengthDecoder
public void setMessageLengthDecoder(org.snmp4j.transport.MessageLengthDecoder messageLengthDecoder) -
getSupportedAddressClass
- Specified by:
getSupportedAddressClassin interfaceorg.snmp4j.TransportMapping<UnixDomainAddress>- Specified by:
getSupportedAddressClassin classorg.snmp4j.transport.AbstractTransportMapping<UnixDomainAddress>
-
getSupportedAddressClasses
-
getListenAddress
- Specified by:
getListenAddressin interfaceorg.snmp4j.TransportMapping<UnixDomainAddress>- Specified by:
getListenAddressin classorg.snmp4j.transport.AbstractTransportMapping<UnixDomainAddress>
-
sendMessage
public void sendMessage(UnixDomainAddress address, byte[] message, org.snmp4j.TransportStateReference tmStateReference, long timeoutMillis, int maxRetries) throws IOException - Specified by:
sendMessagein interfaceorg.snmp4j.TransportMapping<UnixDomainAddress>- Specified by:
sendMessagein classorg.snmp4j.transport.AbstractTransportMapping<UnixDomainAddress>- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceorg.snmp4j.TransportMapping<UnixDomainAddress>- Overrides:
closein classorg.snmp4j.transport.AbstractConnectionOrientedTransportMapping<UnixDomainAddress, UnixSocketStreamTransportMapping.SocketEntry>- Throws:
IOException
-
removeBoundSocketFile
Removes the socket file that this transport mapping has created, if any. A socket file that has not been created by this transport mapping is never removed, because it may belong to another SNMP entity that is listening on the same path.- Throws:
IOException- if the socket file exists but could not be removed.- Since:
- 1.2.2
-
close
- Specified by:
closein interfaceorg.snmp4j.transport.ConnectionOrientedTransportMapping<UnixDomainAddress>- Overrides:
closein classorg.snmp4j.transport.AbstractConnectionOrientedTransportMapping<UnixDomainAddress, UnixSocketStreamTransportMapping.SocketEntry>- Throws:
IOException
-
listen
- Specified by:
listenin interfaceorg.snmp4j.TransportMapping<UnixDomainAddress>- Specified by:
listenin classorg.snmp4j.transport.AbstractTransportMapping<UnixDomainAddress>- Throws:
IOException
-
isListening
public boolean isListening()- Specified by:
isListeningin interfaceorg.snmp4j.TransportMapping<UnixDomainAddress>- Overrides:
isListeningin classorg.snmp4j.transport.AbstractTransportMapping<UnixDomainAddress>
-
wakeupServerSelector
public void wakeupServerSelector()- Specified by:
wakeupServerSelectorin classorg.snmp4j.transport.AbstractConnectionOrientedTransportMapping<UnixDomainAddress, UnixSocketStreamTransportMapping.SocketEntry>
-
readNextInPacket
Read the next network packet for the application.- Parameters:
socketChannel- the socket channel to read the data from.- Returns:
- a byte buffer with the application data of the packet.
- Throws:
IOException- if there occurs an IO exception during preparation.- Since:
- 3.7
-