Package naga
Interface NIOServerSocket
- All Superinterfaces:
NIOAbstractSocket
- All Known Subinterfaces:
NIOServerSocketSSL
Interface for the NIOServerSocket, which is
an asynchronous facade to an underlying ServerSocket.
The NIOServerSocket executes callbacks to a ServerSocket observer to react to new connections and other events.
- Author:
- Christoffer Lerno
-
Method Summary
Modifier and TypeMethodDescriptionlong
Returns the total number of accepted connections on this socket since it opened.long
Returns the total number of connections made on this socket since it opened.long
Returns the total number of failed connections on this socket since it opened.long
Returns the total number of refused connections on this socket since it opened.void
listen
(ServerSocketObserver observer) Associates a server socket observer with this server socket and starts accepting connections.void
setConnectionAcceptor
(ConnectionAcceptor acceptor) Sets the connection acceptor for this server socket.socket()
Allows access to the underlying server socket.Methods inherited from interface naga.NIOAbstractSocket
close, getAddress, getIp, getPort, getTag, isOpen, setTag
-
Method Details
-
getTotalConnections
long getTotalConnections()Returns the total number of connections made on this socket since it opened.This method is thread-safe.
- Returns:
- the total number of connections made on this server socket.
-
getTotalRefusedConnections
long getTotalRefusedConnections()Returns the total number of refused connections on this socket since it opened.This method is thread-safe.
- Returns:
- the total number of refused connections on this server socket.
-
getTotalAcceptedConnections
long getTotalAcceptedConnections()Returns the total number of accepted connections on this socket since it opened.This method is thread-safe.
- Returns:
- the total number of accepted connections on this server socket.
-
getTotalFailedConnections
long getTotalFailedConnections()Returns the total number of failed connections on this socket since it opened.This method is thread-safe.
- Returns:
- the total number of failed connections on this server socket.
-
listen
Associates a server socket observer with this server socket and starts accepting connections.This method is thread-safe, but may only be called once.
- Parameters:
observer
- the observer to receive callbacks from this socket.- Throws:
NullPointerException
- if the observer given is null.IllegalStateException
- if an observer has already been set.
-
setConnectionAcceptor
Sets the connection acceptor for this server socket.A connection acceptor determines if a connection should be disconnected or not after the initial accept is done.
For more information, see the documentation for
naga.ConnectionAcceptor
.This method is thread-safe.
- Parameters:
acceptor
- the acceptor to use, or null to default to ConnectorAcceptor.DENY.
-
socket
ServerSocket socket()Allows access to the underlying server socket.Note calling close and similar functions on this socket will put the NIOServerSocket in an undefined state
- Returns:
- return the underlying server socket.
-