context.arch.comm.clients
Class ClientsPool

java.lang.Object
  extended byjava.lang.Thread
      extended bycontext.arch.comm.clients.ClientsPool
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
Client

public class ClientsPool
extends java.lang.Thread

This class defines a pool of threads that can handle a communication. When a BaseObject wants to send an asynchronous message to another CTK object, it creates the RequestObject, added it to a IndependentCommunication object, which is the parameter of the BaseObject.independentUserRequest() call. This IndependentCommunication is added to a synchronized FIFO vector (SynchFIFO object) from which the ClientsPool get the request to send. Then, as soon as a IndependentCommunication is added to the SynchFIFO, the ClientsPool object removes it to give it to a thread (Client object) from the pool. When a Client object is asked to handle an IndependentCommunication, it is also removed from the pool. The Client object sends the request to the given CTK object, and get the reply and the exceptions. In order for the BaseObject to get the reply, the IndependentCommunication contains also 2 useful attributes : the DataObject reply and the Vector exceptions. Then the Client object adds the reply to the same object it gets as well as the exception it could have caught. After updating the IndependentCommunication object, the Client calls the BaseObject handleIndependentReply method with the parameter an object containing the same IndependentCommunication object. At the end of the communication, the IndependentCommunication object contains the original request, the reply (if any) and the exceptions that occured (if any); and is sent back to the BaseObject, that does nothing by default. If a widget or server or interpreter wants to handle the reply, it overrides the BaseObject handleIndependentReply method, and may check the reply for each request it has sent. In order to group a bunch of requests (for example, a widget sends many PINGs to its subscribers) we define a IndependentCommunications object to help handling the replies. Before sending the requests, the widget creates an IndependentCommunications object in which all IndependentCommunication objects will be added by the Client thread at the end of the communication. The IndependentCommunications object is specified while calling the BaseObject independentUserRequest. If it is null, the Client thread will create a new one, add the IndependentCommunication object in it, and send it to the BaseObject handleIndependentReply method.

Author:
Agathe
See Also:
Client, SynchFIFO

Field Summary
static int clientsNumber
          The number of authorized clients
 CommunicationsObject comm
          The Communications object
static boolean DEBUG
          Debug flag
static int DEFAULT_CLIENTS_NUMBER
          The default number of clients
protected  SynchFIFO fifo
          This FIFO object contains the IndependentCommunication object that contain the RequestObject to send
protected static SynchFIFO threads
          The synchronized vector of threads
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ClientsPool()
          Creates a new empty ClientsPool.
ClientsPool(CommunicationsObject commObject)
          Creates a ClientsPool with the default number of threads in the pool of threads.
ClientsPool(int numberOfClients, CommunicationsObject commObject)
          Creates a generic ClientsPool.
 
Method Summary
 void addRequest(IndependentCommunication request)
          This method is called to add an IndependentCommunication object containing the RequestObject to send, to the fifo object.
 void run()
          The run method called to start the thread.
 void stopAllIdleClients()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEBUG

public static boolean DEBUG
Debug flag


threads

protected static SynchFIFO threads
The synchronized vector of threads


clientsNumber

public static int clientsNumber
The number of authorized clients


DEFAULT_CLIENTS_NUMBER

public static int DEFAULT_CLIENTS_NUMBER
The default number of clients


comm

public CommunicationsObject comm
The Communications object


fifo

protected SynchFIFO fifo
This FIFO object contains the IndependentCommunication object that contain the RequestObject to send

Constructor Detail

ClientsPool

public ClientsPool(int numberOfClients,
                   CommunicationsObject commObject)
Creates a generic ClientsPool. It creates the pool of numberOfClients threads.

Parameters:
numberOfClients - The number of available clients in the pool

ClientsPool

public ClientsPool(CommunicationsObject commObject)
Creates a ClientsPool with the default number of threads in the pool of threads.


ClientsPool

public ClientsPool()
Creates a new empty ClientsPool.

Method Detail

run

public void run()
The run method called to start the thread. The ClientsPool waits for a new IndependentCommunication object in the fifo object. As soon as a new one is added, the ClientsPool waits for the next available Client to handle the request.

See Also:
SynchFIFO, Client

addRequest

public void addRequest(IndependentCommunication request)
This method is called to add an IndependentCommunication object containing the RequestObject to send, to the fifo object.

Parameters:
request - The IndependentCommunication object containing the RequestObject
See Also:
SynchFIFO

stopAllIdleClients

public void stopAllIdleClients()