Package biz.onixs.util.network
Interface Acceptor
-
- All Superinterfaces:
AutoCloseable
public interface Acceptor extends AutoCloseable
The interface provides methods for maintaining multiple listening ports. It allows to add/remove listening port and calls the specified listener when a new connection is accepted via an added listening port.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceAcceptor.ListenerThe interface represents a listener for handling accept events.
-
Field Summary
Fields Modifier and Type Field Description static Acceptor.ListenerNULL_LISTENERThis field represents a null implementation of theAcceptor.Listenerinterface.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddListeningPort(InetSocketAddress bindAddress, Object attachment)Creates a server-socket bound to the specified address.intgetBacklog()Returns the maximum number of pending connections on listen ports.Acceptor.ListenergetListener()Returns the listener which will be called in case there is a new connection accepted on a listening port.booleanremoveListeningPort(int port)Removes the server-socket corresponding to the port number.voidsetBacklog(int backlog)Sets the maximum number of pending connections on listen ports.voidsetListener(Acceptor.Listener listener)Sets the listener which will be called in case there is a new connection accepted on a listening port.-
Methods inherited from interface java.lang.AutoCloseable
close
-
-
-
-
Field Detail
-
NULL_LISTENER
static final Acceptor.Listener NULL_LISTENER
This field represents a null implementation of theAcceptor.Listenerinterface.
-
-
Method Detail
-
getListener
Acceptor.Listener getListener()
Returns the listener which will be called in case there is a new connection accepted on a listening port.- Returns:
- the listener which will be called in case there is a new connection accepted on a listening port.
-
setListener
void setListener(Acceptor.Listener listener)
Sets the listener which will be called in case there is a new connection accepted on a listening port. By default, NULL_LISTENER is specified.- Parameters:
listener- listener to be used when a new connection accepted.
-
addListeningPort
void addListeningPort(InetSocketAddress bindAddress, Object attachment) throws IOException
Creates a server-socket bound to the specified address. In case there will be a new connection accepted on the port the specified Acceptor listener will be fired with accepted socket and the specified attachment.- Parameters:
bindAddress- address created server-socket will be bound.attachment- attachment which will be returned when a new connection will be accepted.- Throws:
IOException- will be thrown in case there is a exception while binding/configuring server-socket.
-
removeListeningPort
boolean removeListeningPort(int port) throws IOExceptionRemoves the server-socket corresponding to the port number.- Parameters:
port- port number- Returns:
truein case corresponding server-socket is removed,falseotherwise.- Throws:
IOException- will be thrown in case there is a exception while unbinding/closing server-socket.
-
getBacklog
int getBacklog()
Returns the maximum number of pending connections on listen ports.- Returns:
- the maximum number of pending connections on listen ports.
-
setBacklog
void setBacklog(int backlog)
Sets the maximum number of pending connections on listen ports.- Parameters:
backlog- the maximum number of pending connections
-
-