|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Server
A Server represents a thread that waits for incoming connection requests and reacts to them by creating
new Connection objects, that represent the local endpoint of an incoming connection.
The Server is started by calling start() and stopped by calling either stop() or
stop(). This will also start or stop the corresponding server thread, respectively.
A NetConnectionHandler can be used to accept, reject, or alter an incoming connection. Once a new
Connection has been accepted it is added to the Server's list of connections.
There are two ways how a newly created Connection object can be configured by the user. Either, a
user-configured ConnectionConfigurator is set in a concrete subclass of the Server class. In
this case, the ConnectionFactory takes care of configuring the connection. Or, the user adds a
ServerListener that reacts to the ServerListener.onAcceptedConnection(Server, Connection)
method. This event method provides access to the newly created Connection, which can then be configured
within the said event method.
Moreover, ServerListeners can be added to react on Server events, like an incoming
Connection has been accepted, etc.
| Method Summary | |
|---|---|
void |
addServerListener(ServerListener listener)
Method to add a new listener for this server. |
int |
countConnections()
Returns the number of connections handled by this server. |
Collection<Connection> |
getConnections()
Returns a snapshot of current connections on this server. |
boolean |
hasConnections()
Returns true if this server has active connections. |
boolean |
isRunning()
Checks whenever the server thread is currently active. |
void |
removeServerListener(ServerListener listener)
Method to remove a ServerListener from internal list of listeners. |
void |
start()
Starts the server as a separate thread. |
void |
stop()
Stops the server closes all created connections listed in its internal list of connections. |
| Method Detail |
|---|
void addServerListener(ServerListener listener)
ServerListener will be notified upon events, which
occur at the server.
listener - The ServerListener to append to list of listeners.void removeServerListener(ServerListener listener)
ServerListener from internal list of listeners. If the ServerListener isn't in
its list. nothing would happen.
listener - The ServerListener which should be removed.Collection<Connection> getConnections()
The returned collection is an unmodifiable copy of the internally held collection of connections. The returned
collection can thus be used to inspect the state of the various connections, but it cannot be used to add or
remove connections from the server. If the collection of connections changes in the server these changes are not
reflected in the returned collection. If you need the number of connections use countConnections().
countConnections()int countConnections()
boolean hasConnections()
void start()
void stop()
boolean isRunning()
true if server thread is running, false otherwise.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||