com.kuka.comm
Interface Server

All Known Implementing Classes:
AbstractServer, AbstractThreadedServer, TcpServer, UdpServer

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

addServerListener

void addServerListener(ServerListener listener)
Method to add a new listener for this server. All ServerListener will be notified upon events, which occur at the server.

Parameters:
listener - The ServerListener to append to list of listeners.

removeServerListener

void removeServerListener(ServerListener listener)
Method to remove a ServerListener from internal list of listeners. If the ServerListener isn't in its list. nothing would happen.

Parameters:
listener - The ServerListener which should be removed.

getConnections

Collection<Connection> getConnections()
Returns a snapshot of current connections on this server.

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().

Returns:
a collection of connections
See Also:
countConnections()

countConnections

int countConnections()
Returns the number of connections handled by this server.

Returns:
the number of connections handled by this server

hasConnections

boolean hasConnections()
Returns true if this server has active connections.

Returns:
true if this server has active connections

start

void start()
Starts the server as a separate thread.


stop

void stop()
Stops the server closes all created connections listed in its internal list of connections.


isRunning

boolean isRunning()
Checks whenever the server thread is currently active.

Returns:
true if server thread is running, false otherwise.


Copyright © 2019. All rights reserved.