Class w3c.jigsaw.http.ClientPool
All Packages Class Hierarchy This Package Previous Next Index
Class w3c.jigsaw.http.ClientPool
java.lang.Object
|
+----w3c.jigsaw.http.ClientPool
- public class ClientPool
- extends Object
- implements 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.
-
MAX_CLIENT_P
- The name of the property giving the maximum number of allowed clients.
-
MIN_CLIENT_P
- The name of the property giving the number of clients to keep.
-
addClient(boolean)
- Create a new client for this pool.
-
cleanLRU()
-
-
clientConnectionFinished(Client)
- Notify that this client has finished with its connection.
-
clientFinished(Client)
- Notify that this client has been killed.
-
handleConnection(Socket)
- Handle the given connection.
-
killClients(boolean)
-
-
killSomeClients()
- Kill some client.
-
notifyIdle(Client)
- The client notifies the pool that it enters idle state.
-
notifyUse(Client)
- The client notifies the pool that is has been activated.
-
propertyChanged(String)
- Some property have changed, update our setting.
-
resizeClientArray(int)
- Resize our client array to the given number.
-
setMaxConnection()
-
-
shutdown(boolean)
- Shutdown the client pool.
MAX_CLIENT_P
public final static String MAX_CLIENT_P
- The name of the property giving the maximum number of allowed clients.
This property gives the maximum number of simultaneous connections to
the server. When this number is exceeded, any incomming connection
will be rejected.
MIN_CLIENT_P
public final static String MIN_CLIENT_P
- The name of the property giving the number of clients to keep.
The ClientPool object keep alive this number of clients, ready
to handle connections.
resizeClientArray
protected synchronized void resizeClientArray(int newmax)
- Resize our client array to the given number.
- Parameters:
- newmax - The new maximum size.
addClient
protected synchronized ClientState addClient(boolean locked)
- Create a new client for this pool.
- Parameters:
- locked - Mark this client as buzy.
setMaxConnection
protected void setMaxConnection()
killSomeClients
protected synchronized void killSomeClients()
- Kill some client.
Our buzy watermark exceeds the config given min spare client. Pick
clients in LRU and kill them until the buzy count reaches the
water mark again.
clientConnectionFinished
protected synchronized void clientConnectionFinished(Client 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.
clientFinished
protected synchronized void clientFinished(Client client)
- Notify that this client has been killed.
- Parameters:
- client - The client that has terminate.
notifyUse
protected void notifyUse(Client 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.
notifyIdle
protected void notifyIdle(Client 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.
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.
handleConnection
public synchronized 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.
killClients
protected synchronized void killClients(boolean force)
cleanLRU
protected synchronized void cleanLRU()
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.
All Packages Class Hierarchy This Package Previous Next Index