com.flat502.rox.client
Class ClientResourcePool

java.lang.Object
  extended by com.flat502.rox.processing.ResourcePool
      extended by com.flat502.rox.client.ClientResourcePool

public class ClientResourcePool
extends ResourcePool


Constructor Summary
ClientResourcePool()
           
 
Method Summary
protected  void detach(HttpRpcClient client)
           
 java.lang.Object getNotifierMutex()
           
 long getRequestTimeout()
           
 com.flat502.rox.client.SharedSocketChannelPool getSocketChannelPool()
           
protected  java.lang.Thread newProcessingThread(java.lang.Runnable target)
          A factory method for creating the central HTTP processing thread.
protected  com.flat502.rox.client.SharedSocketChannelPool newSharedSocketChannelPool(java.lang.Object mutex, int limit, long timeout)
           
protected  HttpMessageHandler newWorker()
           
protected  void notifyUnownedChannelClosure(java.nio.channels.SocketChannel channel)
           
 void registerProfiler(Profiler p)
           
 void setConnectionPoolLimit(int limit)
          Configure a limit on the number of active connections provided at any given time by the underlying connection pool.
 void setConnectionPoolTimeout(long timeout)
          Configure a timeout value for the underlying connection pool.
 void setRequestTimeout(long timeout)
          Configure a default timeout value for RPC method calls.
 void shutdown()
           
 
Methods inherited from class com.flat502.rox.processing.ResourcePool
addWorker, addWorkers, detach, getChannelSelector, getProfilers, getQueue, getTimer, getWorkerCount, newChannelSelector, newQueue, removeWorker, startProcessingThread
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClientResourcePool

public ClientResourcePool()
Method Detail

registerProfiler

public void registerProfiler(Profiler p)
Overrides:
registerProfiler in class ResourcePool

getNotifierMutex

public java.lang.Object getNotifierMutex()

setConnectionPoolLimit

public void setConnectionPoolLimit(int limit)
Configure a limit on the number of active connections provided at any given time by the underlying connection pool.

If a non-zero limit is configured, any thread requesting a new connection that would cause this limit to be exceeded will be blocked until an existing connection is returned or until a timeout occurs (if a timeout has been set).

Care should be taken when using the asynchronous execution API without a limit on the connection pool. It's very easy to consume all available local connections like this.

If a non-zero limit is placed on the connection pool then you must be sure to set a timeout on the pool. Failure to do so will result in threads blocking indefinitely when the connection pool is exhausted.

Parameters:
limit - The maximum number of active connections allowed at any given moment. A value of 0 indicates no limit should be enforced (this is the default value).
Throws:
java.lang.IllegalArgumentException - If the timeout provided is negative.
java.lang.IllegalStateException - If any of the execute methods were invoked before this method was invoked.

setConnectionPoolTimeout

public void setConnectionPoolTimeout(long timeout)
Configure a timeout value for the underlying connection pool.

This timeout only applies if a limit has been set on the number of active connections (using setConnectionPoolLimit(int).

If a limit is configured this timeout controls how long a thread will be blocked waiting for a new connection before a ConnectionPoolTimeoutException is raised.

Parameters:
timeout - The timeout (in milliseconds). A value of 0 indicates no timeout should be enforced (this is the default value).
Throws:
java.lang.IllegalArgumentException - If the timeout provided is negative.
java.lang.IllegalStateException - If any of the execute methods were invoked before this method was invoked.

setRequestTimeout

public void setRequestTimeout(long timeout)
Configure a default timeout value for RPC method calls.

All HttpRpcClient instances sharing a resource pool "inherit" this timeout as their initial timeout value.

Parameters:
timeout - The timeout (in milliseconds). A value of 0 indicates no timeout should be enforced.
Throws:
java.lang.IllegalArgumentException - If the timeout provided is negative.
See Also:
HttpRpcClient.setRequestTimeout(long)

getRequestTimeout

public long getRequestTimeout()

getSocketChannelPool

public com.flat502.rox.client.SharedSocketChannelPool getSocketChannelPool()

newSharedSocketChannelPool

protected com.flat502.rox.client.SharedSocketChannelPool newSharedSocketChannelPool(java.lang.Object mutex,
                                                                                    int limit,
                                                                                    long timeout)

shutdown

public void shutdown()
Overrides:
shutdown in class ResourcePool

newWorker

protected HttpMessageHandler newWorker()
Specified by:
newWorker in class ResourcePool

newProcessingThread

protected java.lang.Thread newProcessingThread(java.lang.Runnable target)
Description copied from class: ResourcePool
A factory method for creating the central HTTP processing thread.

Sub-classes may override this method if an alternative implementation is required, or to alter properties of the thread that is created by default, but they should not invoke the Thread.start() method.

Overrides:
newProcessingThread in class ResourcePool
Returns:
This implementation returns a new instance of HttpRpcProcessor.

detach

protected void detach(HttpRpcClient client)
               throws java.io.IOException
Throws:
java.io.IOException

notifyUnownedChannelClosure

protected void notifyUnownedChannelClosure(java.nio.channels.SocketChannel channel)
Overrides:
notifyUnownedChannelClosure in class ResourcePool