Class w3c.jigsaw.http.socket.SocketClientFactory
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class w3c.jigsaw.http.socket.SocketClientFactory

java.lang.Object
   |
   +----w3c.jigsaw.http.socket.SocketClientFactory

public class SocketClientFactory
extends Object
implements ClientFactory, PropertyMonitoring
The client pool is a kind of client factory. Each time the server gets a new connection, it calls the client pool to bound a client object (newly created or spared) to handle it.

Variable Index

 o AVG_DEAD
 o AVG_HIGH
 o AVG_LIGHT
 o AVG_NORMAL
 o IDLETO
 o IDLETO_P
 o MAXCLIENTS
 o MAXCLIENTS_P
 o MAXSPARE_FREE
 o MAXSPARE_FREE_P
 o MAXSPARE_IDLE
 o MAXSPARE_IDLE_P
 o MAXTHREADS
 o MAXTHREADS_P
 o MINSPARE_FREE
 o MINSPARE_FREE_P

Constructor Index

 o SocketClientFactory()
Empty constructor for dynamic class instantiation.

Method Index

 o addClient(boolean)
Create a new client for this pool.
 o clientConnectionFinished(SocketClient)
Notify that this client has finished with its connection.
 o clientFinished(SocketClient)
Notify that this client has been killed.
 o createServerSocket()
Create the master socket for this client factory.
 o deleteClient(SocketClientState)
Remove this client state from the glohbal client list.
 o handleConnection(Socket)
Handle the given connection.
 o initialize(httpd)
Initialize the raw, client socket factory.
 o killClients(boolean)
 o killSomeClients()
 o killSomeClients(int)
 o notifyIdle(SocketClient)
The client notifies the pool that it enters idle state.
 o notifyUse(SocketClient)
The client notifies the pool that is has been activated.
 o propertyChanged(String)
Some property have changed, update our setting.
 o run(SocketClient)
 o shutdown(boolean)
Shutdown the client pool.

Variables

 o MINSPARE_FREE
  public final static int MINSPARE_FREE
 o MAXSPARE_FREE
  public final static int MAXSPARE_FREE
 o MAXSPARE_IDLE
  public final static int MAXSPARE_IDLE
 o MAXTHREADS
  public final static int MAXTHREADS
 o MAXCLIENTS
  public final static int MAXCLIENTS
 o IDLETO
  public final static int IDLETO
 o AVG_LIGHT
  public final static int AVG_LIGHT
 o AVG_NORMAL
  public final static int AVG_NORMAL
 o AVG_HIGH
  public final static int AVG_HIGH
 o AVG_DEAD
  public final static int AVG_DEAD
 o MINSPARE_FREE_P
  public final static String MINSPARE_FREE_P
 o MAXSPARE_FREE_P
  public final static String MAXSPARE_FREE_P
 o MAXSPARE_IDLE_P
  public final static String MAXSPARE_IDLE_P
 o MAXTHREADS_P
  public final static String MAXTHREADS_P
 o MAXCLIENTS_P
  public final static String MAXCLIENTS_P
 o IDLETO_P
  public final static String IDLETO_P

Constructors

 o SocketClientFactory
  public SocketClientFactory()
Empty constructor for dynamic class instantiation.

Methods

 o propertyChanged
  public boolean propertyChanged(String name)
Some property have changed, update our setting.
Parameters:
name - The name of the property that has changed.
Returns:
A boolean, true if we updated ourself successfully.
 o deleteClient
  protected synchronized void deleteClient(SocketClientState cs)
Remove this client state from the glohbal client list.
Parameters:
cs - The client state to remove from the list.
 o addClient
  protected synchronized SocketClientState addClient(boolean free)
Create a new client for this pool.
Parameters:
free - A boolean, if true the client is inserted straight into the free list, otherwise, it is not plugged into any list.
Returns:
A SocketClientState instance, if creation of a new client was allowed, null if no more clients could be created.
 o clientConnectionFinished
  protected boolean clientConnectionFinished(SocketClient client)
Notify that this client has finished with its connection. If the pool wants the client to be freed (because it has too many of them), it makes the client kill itself (which will trigger a call to the clientFinished method, were enventual cleanup is performed).
Parameters:
client - The client that is done with its connection.
 o clientFinished
  protected void clientFinished(SocketClient client)
Notify that this client has been killed.
Parameters:
client - The client that has terminate.
 o notifyUse
  protected void notifyUse(SocketClient client)
The client notifies the pool that is has been activated. The client state object is updated to unmark the client as idle.

This method needs not be synchronized, as it affect only the client state, not the client list.

Parameters:
client - The activated client.
 o notifyIdle
  protected boolean notifyIdle(SocketClient client)
The client notifies the pool that it enters idle state.

This method needs not be synchronized, as it affect only the client state, not the client list.

Parameters:
client - The client that is going to be idle.
 o killSomeClients
  protected void killSomeClients(int howmany)
 o killSomeClients
  protected final void killSomeClients()
 o run
  protected void run(SocketClient client)
 o handleConnection
  public void handleConnection(Socket socket)
Handle the given connection. Find a free client, bind it to the given socket, and run it. If we have reached our maximum allowed number of clients, kill some connections.

A client enters the LRU list (and become a candidate for kill) only after it has handle one request (or if some timeout expires). This is performed by the first call to notifyUse which will silently insert the client into the LRU if it was not there already.

This client pool does a lot of nice thinigs, but could probably be implemented in a much better way (while keeping the features it has). Contention arond the pool is probably concern number 1 of performances.

Parameters:
socket - The connection to handle.
 o killClients
  protected synchronized void killClients(boolean force)
 o shutdown
  public void shutdown(boolean force)
Shutdown the client pool. If force is true, kill all running clients right now, otherwise, wait for them to terminate gracefully, and return when done.
Parameters:
force - Should we interrupt running clients.
 o createServerSocket
  public ServerSocket createServerSocket() throws IOException
Create the master socket for this client factory.
Returns:
A ServerSocket instance.
Throws: IOException
If some IO error occurs while creating the server socket.
 o initialize
  public void initialize(httpd server)
Initialize the raw, client socket factory.
Parameters:
server - The server context we are attached to.

All Packages  Class Hierarchy  This Package  Previous  Next  Index