ikrs.yuccasrv.socketmngr
Class BindManager

java.lang.Object
  extended by ikrs.yuccasrv.socketmngr.BindManager
All Implemented Interfaces:
ServerSocketThreadObserver, java.lang.Runnable

public class BindManager
extends java.lang.Object
implements java.lang.Runnable, ServerSocketThreadObserver

Ths BindManager is the central entity that manages server sockets and their bindings to the system. It additionally accepts incoming connections and passes them to the installed BindListeners. If a server/socket was closed by any reason the manager frees bound resources and removes the socket from the inner table.


Constructor Summary
BindManager()
           
BindManager(CustomLogger logger)
           
 
Method Summary
 boolean addBindListener(BindListener l)
          This method adds a new BindListener to this BindManager.
 java.util.UUID bind(java.net.InetAddress address, int port, Environment<java.lang.String,BasicType> bindSettings)
          This method can be used to bind new server sockets to the system.
 void closeAllServerSockets()
           
 void finalize(long time, java.util.concurrent.TimeUnit unit)
           
protected  CustomLogger getLogger()
           
 java.util.Map<java.lang.String,BasicType> getServerSettings(java.util.UUID socketID)
           
 java.lang.String getStatusString()
           
 void incomingTCPConnection(ServerSocketThread t, java.net.Socket s)
          This method is called if a server socket successfully accepted an incoming TCP connection.
 void incomingUDPConnection(ServerSocketThread t, java.net.DatagramSocket s)
          This method is called if a server socket successfully accepted an incoming UDP 'connection'.
 void release(java.util.UUID socketID)
           
 boolean removeBindListener(BindListener l)
          This method removes a BindListener from this BindManager.
 void run()
           
 void serverSocketClosed(ServerSocketThread t)
          This method is called if a socket was closed by user/system request.
 void serverSocketException(ServerSocketThread t, java.nio.channels.IllegalBlockingModeException e)
          This method is called if a socket caused a IllegalBlockingModeException by any reason.
 void serverSocketException(ServerSocketThread t, java.io.IOException e)
          This method is called if a socket caused an IOException by any reason.
 void serverSocketException(ServerSocketThread t, java.lang.SecurityException e)
          This method is called if a socket caused a SecurityException by any reason.
 void serverSocketException(ServerSocketThread t, java.net.SocketTimeoutException e)
          This method is called if a socket caused a SocketTimeoutException.
 void setLogger(CustomLogger logger)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BindManager

public BindManager()

BindManager

public BindManager(CustomLogger logger)
Method Detail

setLogger

public void setLogger(CustomLogger logger)
               throws java.lang.NullPointerException
Throws:
java.lang.NullPointerException

getLogger

protected CustomLogger getLogger()

addBindListener

public boolean addBindListener(BindListener l)
                        throws java.lang.NullPointerException
This method adds a new BindListener to this BindManager.

Parameters:
l - The bind listener to be added (must not be null).
Returns:
true if the listener was not already in the listener list.
Throws:
java.lang.NullPointerException

removeBindListener

public boolean removeBindListener(BindListener l)
This method removes a BindListener from this BindManager.

Parameters:
l - The bind listener to be removed.
Returns:
true if the listener was found and removed from the listener list.

incomingTCPConnection

public void incomingTCPConnection(ServerSocketThread t,
                                  java.net.Socket s)
This method is called if a server socket successfully accepted an incoming TCP connection.

Specified by:
incomingTCPConnection in interface ServerSocketThreadObserver
Parameters:
t - The ServerSocketThread that created and holds the server.
s - The socket for the incoming connection.

incomingUDPConnection

public void incomingUDPConnection(ServerSocketThread t,
                                  java.net.DatagramSocket s)
This method is called if a server socket successfully accepted an incoming UDP 'connection'.

Specified by:
incomingUDPConnection in interface ServerSocketThreadObserver
Parameters:
t - The ServerSocketThread that created and holds the server.
s - The socket for the incoming connection.

serverSocketClosed

public void serverSocketClosed(ServerSocketThread t)
This method is called if a socket was closed by user/system request.

Specified by:
serverSocketClosed in interface ServerSocketThreadObserver
Parameters:
t - The ServerSocketThread that created and holds the server.

serverSocketException

public void serverSocketException(ServerSocketThread t,
                                  java.io.IOException e)
This method is called if a socket caused an IOException by any reason. Problably the socket will not be working properly if this event was fired. Note that SocketTimeoutExceptions are reported thorugh a different event.

Specified by:
serverSocketException in interface ServerSocketThreadObserver
Parameters:
t - The ServerSocketThread that created and holds the server.
e - The Exception that was fetched.
See Also:
serverSocketException( ServerSocketThread, SocketTimeoutException )

serverSocketException

public void serverSocketException(ServerSocketThread t,
                                  java.lang.SecurityException e)
This method is called if a socket caused a SecurityException by any reason.

Specified by:
serverSocketException in interface ServerSocketThreadObserver
Parameters:
t - The ServerSocketThread that created and holds the server.
e - The Exception that was fetched.

serverSocketException

public void serverSocketException(ServerSocketThread t,
                                  java.net.SocketTimeoutException e)
This method is called if a socket caused a SocketTimeoutException.

Specified by:
serverSocketException in interface ServerSocketThreadObserver
Parameters:
t - The ServerSocketThread that created and holds the server.
e - The Exception that was fetched.

serverSocketException

public void serverSocketException(ServerSocketThread t,
                                  java.nio.channels.IllegalBlockingModeException e)
This method is called if a socket caused a IllegalBlockingModeException by any reason.

Specified by:
serverSocketException in interface ServerSocketThreadObserver
Parameters:
t - The ServerSocketThread that created and holds the server.
e - The Exception that was fetched.

bind

public java.util.UUID bind(java.net.InetAddress address,
                           int port,
                           Environment<java.lang.String,BasicType> bindSettings)
                    throws java.io.IOException,
                           java.security.GeneralSecurityException
This method can be used to bind new server sockets to the system. It starts an asynchronous thread! You should install a BindListener before you call this method to be sure not to miss any socket events. Hint: the socket itself is initiated in synchronous mode, so if no no IOException was thrown when calling this method the binding process was successful. Though it is not guaranteed that the socket is already in listening mode [Socket.accept()] in the moment this method terminates. To ensure the socket IS in listening mode, you must have had a BindListener installed before to be sure not to miss the serverCreated(...) event!

Parameters:
address -
port -
bindSettings - This map may contain optional settings.
Throws:
java.io.IOException
java.security.GeneralSecurityException

release

public void release(java.util.UUID socketID)
             throws java.io.IOException
Throws:
java.io.IOException

getServerSettings

public java.util.Map<java.lang.String,BasicType> getServerSettings(java.util.UUID socketID)

closeAllServerSockets

public void closeAllServerSockets()

finalize

public void finalize(long time,
                     java.util.concurrent.TimeUnit unit)

run

public void run()
Specified by:
run in interface java.lang.Runnable

getStatusString

public java.lang.String getStatusString()