com.kuka.comm
Class AbstractServer

java.lang.Object
  extended by com.kuka.comm.AbstractServer
All Implemented Interfaces:
Server
Direct Known Subclasses:
AbstractThreadedServer

public abstract class AbstractServer
extends Object
implements Server

Abstract base implementation of a Server. This class manages a collection of Connections and a collection of ServerListener.


Nested Class Summary
protected static interface AbstractServer.ConnectionConsumer
          Represents an operation on a connection that accepts a single input argument and returns no result.
 
Constructor Summary
AbstractServer()
           
 
Method Summary
protected  void addConnection(Connection connection)
          Adds a connection to the internal list of connections.
 void addServerListener(ServerListener listener)
          Method to add a new listener for this server.
protected  void closeAllConnections()
          Closes all connections currently in the list of known connections.
 int countConnections()
          Returns the number of connections handled by this server.
protected  void fireAcceptedConnection(Connection connection)
          Private method to notify listener about accepted connections.
protected  void fireIncomingConnection(Connection connection)
          Private method to notify listener about incoming connections.
protected  void fireRejectedConnection(Connection connection)
          Private method to notify listener about rejected connections.
protected  void forEachConnection(AbstractServer.ConnectionConsumer consumer)
          Iterates synchronized over all connections contained in this server and applies the given consumer.
 Collection<Connection> getConnections()
          Returns a snapshot of current connections on this server.
 boolean hasConnections()
          Returns true if this server has active connections.
protected  void removeConnection(Connection connection)
          Private method to remove connections from connection list.
 void removeServerListener(ServerListener listener)
          Method to remove a ServerListener from internal list of listeners.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.kuka.comm.Server
isRunning, start, stop
 

Constructor Detail

AbstractServer

public AbstractServer()
Method Detail

getConnections

public final Collection<Connection> getConnections()
Description copied from interface: Server
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 Server.countConnections().

Specified by:
getConnections in interface Server
Returns:
a collection of connections
See Also:
Server.countConnections()

countConnections

public final int countConnections()
Description copied from interface: Server
Returns the number of connections handled by this server.

Specified by:
countConnections in interface Server
Returns:
the number of connections handled by this server

hasConnections

public final boolean hasConnections()
Description copied from interface: Server
Returns true if this server has active connections.

Specified by:
hasConnections in interface Server
Returns:
true if this server has active connections

addServerListener

public final void addServerListener(ServerListener listener)
Description copied from interface: Server
Method to add a new listener for this server. All ServerListener will be notified upon events, which occur at the server.

Specified by:
addServerListener in interface Server
Parameters:
listener - The ServerListener to append to list of listeners.

removeServerListener

public final void removeServerListener(ServerListener listener)
Description copied from interface: Server
Method to remove a ServerListener from internal list of listeners. If the ServerListener isn't in its list. nothing would happen.

Specified by:
removeServerListener in interface Server
Parameters:
listener - The ServerListener which should be removed.

forEachConnection

protected final void forEachConnection(AbstractServer.ConnectionConsumer consumer)
Iterates synchronized over all connections contained in this server and applies the given consumer.

Parameters:
consumer - the consumer to apply to all connections

addConnection

protected final void addConnection(Connection connection)
Adds a connection to the internal list of connections.

Parameters:
connection - the connection to add

removeConnection

protected final void removeConnection(Connection connection)
Private method to remove connections from connection list.

Parameters:
connection - The Connection to remove.

closeAllConnections

protected final void closeAllConnections()
Closes all connections currently in the list of known connections. The access to the list of connections is thread-safe.


fireIncomingConnection

protected final void fireIncomingConnection(Connection connection)
Private method to notify listener about incoming connections.

Parameters:
connection - The Connection which has been income by the server.

fireAcceptedConnection

protected final void fireAcceptedConnection(Connection connection)
Private method to notify listener about accepted connections.

Parameters:
connection - The Connection which has been accepted by the server.

fireRejectedConnection

protected final void fireRejectedConnection(Connection connection)
Private method to notify listener about rejected connections.

Parameters:
connection - The Connection which has been rejected by the server.


Copyright © 2019. All rights reserved.