: Class SocketClientFactory

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.w3c.jigsaw.http.socket
Class SocketClientFactory

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

public class SocketClientFactory
extends java.lang.Object
implements ClientFactory, PropertyMonitoring, Status

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.

Field Summary
`static int` | `AVG_DEAD`
`static int` | `AVG_HIGH`
`static int` | `AVG_LIGHT`
`static int` | `AVG_NORMAL`
`static java.lang.String` | `BINDADDR_P`
`static int` | `IDLETO`
`static java.lang.String` | `IDLETO_P`
`static int` | `MAXCLIENTS`
`static java.lang.String` | `MAXCLIENTS_P`
`static int` | `MAXSPARE_FREE`
`static java.lang.String` | `MAXSPARE_FREE_P`
`static int` | `MAXSPARE_IDLE`
`static java.lang.String` | `MAXSPARE_IDLE_P`
`static int` | `MAXTHREADS`
`static java.lang.String` | `MAXTHREADS_P`
`static int` | `MINSPARE_FREE`
`static java.lang.String` | `MINSPARE_FREE_P`

Constructor Summary
`SocketClientFactory()` Empty constructor for dynamic class instantiation.

Method Summary
`protected org.w3c.jigsaw.http.socket.SocketClientState` | `addClient(boolean free)` Create a new client for this pool.
`protected boolean` | `clientConnectionFinished(SocketClient client)` Notify that this client has finished with its connection.
`protected void` | `clientFinished(SocketClient client)` Notify that this client has been killed.
`java.net.ServerSocket` | `createServerSocket()` Create the master socket for this client factory.
`protected void` | `deleteClient(org.w3c.jigsaw.http.socket.SocketClientState cs)` Remove this client state from the glohbal client list.
`java.lang.String` | `getHTMLStatus()` Give the status of this class as a partial HTML text which will be added into a block level element
`void` | `handleConnection(java.net.Socket socket)` Handle the given connection.
`protected boolean` | `idleClientRemove(SocketClient client)` Removes an idle client from the list, updates only the idle list as the free count has already be accessed
`void` | `initialize(httpd server)` Initialize the raw, client socket factory.
`protected void` | `killClients(boolean force)`
`protected void` | `killSomeClients()`
`protected void` | `killSomeClients(int howmany)`
`protected boolean` | `notifyIdle(SocketClient client)` The client notifies the pool that it enters idle state.
`protected void` | `notifyUse(SocketClient client)` The client notifies the pool that is has been activated.
`boolean` | `propertyChanged(java.lang.String name)` Some property have changed, update our setting.
`protected void` | `run(SocketClient client)`
`void` | `shutdown(boolean force)` Shutdown the client pool.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### MINSPARE_FREE

    public static final int MINSPARE_FREE

### MAXSPARE_FREE

    public static final int MAXSPARE_FREE

### MAXSPARE_IDLE

    public static final int MAXSPARE_IDLE

### MAXTHREADS

    public static final int MAXTHREADS

### MAXCLIENTS

    public static final int MAXCLIENTS

### IDLETO

    public static final int IDLETO

### AVG_LIGHT

    public static final int AVG_LIGHT

### AVG_NORMAL

    public static final int AVG_NORMAL

### AVG_HIGH

    public static final int AVG_HIGH

### AVG_DEAD

    public static final int AVG_DEAD

### MINSPARE_FREE_P

    public static final java.lang.String MINSPARE_FREE_P

### MAXSPARE_FREE_P

    public static final java.lang.String MAXSPARE_FREE_P

### MAXSPARE_IDLE_P

    public static final java.lang.String MAXSPARE_IDLE_P

### MAXTHREADS_P

    public static final java.lang.String MAXTHREADS_P

### MAXCLIENTS_P

    public static final java.lang.String MAXCLIENTS_P

### IDLETO_P

    public static final java.lang.String IDLETO_P

### BINDADDR_P

    public static final java.lang.String BINDADDR_P

Constructor Detail

### SocketClientFactory

    public SocketClientFactory()

  Empty constructor for dynamic class instantiation.

Method Detail

### getHTMLStatus

    public java.lang.String getHTMLStatus()

  Give the status of this class as a partial HTML text which will be added into a block level element
  Specified by:
    getHTMLStatus in interface Status
  Returns:
    a String, the generated HTML

### propertyChanged

    public boolean propertyChanged(java.lang.String name)

  Some property have changed, update our setting.
  Specified by:
    propertyChanged in interface PropertyMonitoring
  Parameters:
    `name` - The name of the property that has changed.
  Returns:
    A boolean, true if we updated ourself successfully.

### deleteClient

    protected void deleteClient(org.w3c.jigsaw.http.socket.SocketClientState cs)

  Remove this client state from the glohbal client list.
  Parameters:
    `cs` - The client state to remove from the list.

### addClient

    protected org.w3c.jigsaw.http.socket.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.

### idleClientRemove

    protected boolean idleClientRemove(SocketClient client)

  Removes an idle client from the list, updates only the idle list as the free count has already be accessed
  Parameters:
    `the` - socket client to remove from the idle list

### 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.

### clientFinished

    protected void clientFinished(SocketClient client)

  Notify that this client has been killed.
  Parameters:
    `client` - The client that has terminate.

### 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.

### 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.

### killSomeClients

    protected void killSomeClients(int howmany)

### killSomeClients

    protected final void killSomeClients()

### run

    protected void run(SocketClient client)

### handleConnection

    public void handleConnection(java.net.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.

  Specified by:
    handleConnection in interface ClientFactory
  Parameters:
    `socket` - The connection to handle.

### killClients

    protected void killClients(boolean force)

### 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.
  Specified by:
    shutdown in interface ClientFactory
  Parameters:
    `force` - Should we interrupt running clients.

### createServerSocket

    public java.net.ServerSocket createServerSocket()
                                             throws java.io.IOException

  Create the master socket for this client factory.
  Specified by:
    createServerSocket in interface ClientFactory
  Returns:
    A ServerSocket instance.
  Throws:
    java.io.IOException - If some IO error occurs while creating the server socket.

### initialize

    public void initialize(httpd server)

  Initialize the raw, client socket factory.
  Specified by:
    initialize in interface ClientFactory
  Parameters:
    `server` - The server context we are attached to.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD