com.kuka.comm.net
Class NetConnectionHandler<S extends Server,C extends NetConnection,T>

java.lang.Object
  extended by com.kuka.comm.net.NetConnectionHandler<S,C,T>
Type Parameters:
C - the type of connection this handler creates
S - the type of server this handler is for
T - a type to identify the incoming connection request (e.g. Socket for TCP or DatagramPacket for UDP)
Direct Known Subclasses:
TcpConnectionHandler, UdpConnectionHandler

public abstract class NetConnectionHandler<S extends Server,C extends NetConnection,T>
extends Object

Base class for handling incoming connection requests at a server. Instances of this class decide whether an incoming connection is accepted, which connection type is created and how the connection is configured.

Subclasses must specify the connection type to be created on an incoming request by implementing createConnection(Server, Object). By overriding acceptConnection(Server, Object) subclasses can decide whether an incoming request is accepted. The default implementation accepts all requests.


Constructor Summary
protected NetConnectionHandler(NetConnectionConfigurator<C> configurator)
          Creates a new connection handler that uses the given configurator to configure the connection and accepts an unlimited number of connections.
protected NetConnectionHandler(NetConnectionConfigurator<C> configurator, int maxConnections)
          Creates a new connection handler that uses the given configurator to configure incoming connections and limits the maximum number of active connections to maxConnections.
 
Method Summary
protected  boolean acceptConnection(S server, T identifier)
          Checks whether an incoming connection request is accepted.
protected abstract  C createConnection(S server, T identifier)
          Creates a new connection for an incoming connection request.
 NetConnectionConfigurator<C> getConfigurator()
           
 int getMaxConnections()
           
 C handleConnection(S server, T identifier)
          Creates a new connection for an incoming connection request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NetConnectionHandler

protected NetConnectionHandler(NetConnectionConfigurator<C> configurator)
Creates a new connection handler that uses the given configurator to configure the connection and accepts an unlimited number of connections.

Parameters:
configurator - the configurator used to configure incoming connections, must not be null

NetConnectionHandler

protected NetConnectionHandler(NetConnectionConfigurator<C> configurator,
                               int maxConnections)
Creates a new connection handler that uses the given configurator to configure incoming connections and limits the maximum number of active connections to maxConnections.

Parameters:
maxConnections - the maximum number of simultaneous connections, must be greater than 0
configurator - the configurator used to configure incoming connections, must not be null
Method Detail

handleConnection

public final C handleConnection(S server,
                                T identifier)
Creates a new connection for an incoming connection request. This method can be used by a server to retrieve a connection object.

If the number of currently active connection exceeds the maximum allowed number, or the incoming request is refused (i.e. acceptConnection(Server, Object) returns false) this method returns null.

Parameters:
server - the server receiving the incoming connection request
identifier - object that can be used to identify the incoming connection request
Returns:
a connection object managing the incoming request or null if the connection is refused

getMaxConnections

public final int getMaxConnections()
Returns:
the maximum number of allowed active connections.

getConfigurator

public final NetConnectionConfigurator<C> getConfigurator()
Returns:
the configurator used to configure incoming connections.

acceptConnection

protected boolean acceptConnection(S server,
                                   T identifier)
Checks whether an incoming connection request is accepted.

Parameters:
server - the server receiving the incoming connection request
identifier - object that can be used to identify the incoming connection request
Returns:
true if the incoming connection request was accepted, false otherwise.

createConnection

protected abstract C createConnection(S server,
                                      T identifier)
Creates a new connection for an incoming connection request.

Parameters:
server - the server receiving the incoming connection request
identifier - object that can be used to identify the incoming connection request
Returns:
a connection object managing the incoming request


Copyright © 2019. All rights reserved.