org.sourceforge.jemm.comm.server
Class ServerThread

java.lang.Object
  extended by org.sourceforge.jemm.comm.server.ServerThread
All Implemented Interfaces:
RPCHandlerListener

public class ServerThread
extends java.lang.Object
implements RPCHandlerListener

ServerThread is used by RPCServer for handling individual client connections.

Released under the Apache License V2.0 license by the JEMM Project

Author:
Rory Graves

Field Summary
protected  RPCClientId clientId
           
protected  boolean connected
           
protected  Connection connection
           
protected  RPCHandler rpcHandler
           
protected  RPCServer server
           
protected  java.util.concurrent.CountDownLatch shutdownLatch
           
 
Constructor Summary
ServerThread(RPCServer server, Connection connection, RPCClientId clientId, java.util.Map<java.lang.Class<?>,java.lang.Object> offeredIfs, java.util.concurrent.ExecutorService threadPool)
          Creates a server thread to handle a specific client connection.
 
Method Summary
 void connectionTerminated()
          Notification that the connection has been closed.
 java.lang.Object getClientIF(java.lang.Class<?> ifClass)
          Gets the proxy for the given client interface.
 void shutdown()
          Shutdown the thread by closing its socket connection.
 void start()
          Start the server thread, initialising the connection and listening to client requests.
 void waitForShutdown()
          Utility method to allow a thread to wait for this thread to have completely terminated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

shutdownLatch

protected java.util.concurrent.CountDownLatch shutdownLatch

connected

protected volatile boolean connected

clientId

protected RPCClientId clientId

server

protected RPCServer server

rpcHandler

protected RPCHandler rpcHandler

connection

protected Connection connection
Constructor Detail

ServerThread

public ServerThread(RPCServer server,
                    Connection connection,
                    RPCClientId clientId,
                    java.util.Map<java.lang.Class<?>,java.lang.Object> offeredIfs,
                    java.util.concurrent.ExecutorService threadPool)
Creates a server thread to handle a specific client connection.

Parameters:
server - The server instance this client belongs to
connection - The client socket
clientId - The server assigned client id;
offeredIfs - The interfaces offered to the client by the server
threadPool - The threadpool to use for servicing requests
Method Detail

start

public void start()
Start the server thread, initialising the connection and listening to client requests.


connectionTerminated

public void connectionTerminated()
Notification that the connection has been closed.

Specified by:
connectionTerminated in interface RPCHandlerListener

shutdown

public void shutdown()
Shutdown the thread by closing its socket connection.


waitForShutdown

public void waitForShutdown()
Utility method to allow a thread to wait for this thread to have completely terminated. This method will return immediately if the thread is already stopped, otherwise it will wait until all shutdown actions have completed before returning.


getClientIF

public java.lang.Object getClientIF(java.lang.Class<?> ifClass)
Gets the proxy for the given client interface.

Parameters:
ifClass - The requesting interface implementation.
Returns:
A proxy that implements the interface 'ifClass'


Copyright © 2009. All Rights Reserved.