com.ibm.xcap.client
Class ThreadedRequestHandler

java.lang.Object
  extended by com.ibm.xcap.client.ThreadedRequestHandler

public class ThreadedRequestHandler
extends java.lang.Object


Field Summary
static java.lang.String CLASSNAME
          Classname
protected  java.lang.Object lock
          Lock for the request counter int
static java.util.logging.Logger LOGGER
          Logger for this class
protected static int maxSize
           
protected static int minSize
          ThreadPool size
protected  int requestCounter
          Counter for the number of requests received
protected static int responseListSize
          Initial size of the responce vector.
protected  java.util.Vector<XcapClientResponse> responses
          Container for responses received from worker threads
protected static WorkerThreadPool threadPool
          Worker Threads
 
Constructor Summary
ThreadedRequestHandler()
           
ThreadedRequestHandler(int responseListSize)
          Creates an object that uses the static threadPool to service RequestTasks via the executeRequest(XcapClientRequest request) method
 
Method Summary
static void destroyThreadPool()
          Clean up the thread pool resources.
 void executeRequest(XcapClientRequest request)
          Convenience method to execute this#executeRequest(XcapClientRequest, boolean) with the parameter set to true.
 void executeRequest(XcapClientRequest request, boolean useThreadpool)
          Execute a XcapClientRequest attempting to obtain a worker thread rather than using the current thread as directed by the boolean attemptSpinoff paramater.
 java.util.Vector getResponses()
          Get the Vector containing all of the responses from requests sent through this instance.
 void notifyListener(XcapClientResponse response)
          Add a XcapClientResponse to the response list.
static void setThreadPoolSize(int maxSize)
          Set the maximum number of worker threads allowed to be created by the threadpool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASSNAME

public static final java.lang.String CLASSNAME
Classname


LOGGER

public static final java.util.logging.Logger LOGGER
Logger for this class


minSize

protected static int minSize
ThreadPool size


maxSize

protected static int maxSize

threadPool

protected static WorkerThreadPool threadPool
Worker Threads


responseListSize

protected static int responseListSize
Initial size of the responce vector. Should be equal to the expected number of requests/batch


responses

protected java.util.Vector<XcapClientResponse> responses
Container for responses received from worker threads


requestCounter

protected int requestCounter
Counter for the number of requests received


lock

protected java.lang.Object lock
Lock for the request counter int

Constructor Detail

ThreadedRequestHandler

public ThreadedRequestHandler()

ThreadedRequestHandler

public ThreadedRequestHandler(int responseListSize)
Creates an object that uses the static threadPool to service RequestTasks via the executeRequest(XcapClientRequest request) method

Parameters:
responseListSize - initial size of response Vector
Method Detail

executeRequest

public void executeRequest(XcapClientRequest request)
Convenience method to execute this#executeRequest(XcapClientRequest, boolean) with the parameter set to true. This will handle a request by attempting to obtain a worker thread from the threadpool. If no worker thread is available because the threadpool is depleated, the calling thread is used to handle the request. This avoids the possibility of starvation.

Parameters:
request - the request to process
See Also:
#executeRequest(XcapClientRequest, boolean)}

executeRequest

public void executeRequest(XcapClientRequest request,
                           boolean useThreadpool)
Execute a XcapClientRequest attempting to obtain a worker thread rather than using the current thread as directed by the boolean attemptSpinoff paramater. If no worker thread is available because the threadpool is depleated, the calling thread is used to handle the request. This avoids the possibility of starvation. Callers wishing to use their current thread to process the request should pass a false boolean for the second paramater to force the use of the current thread for request handling.

Parameters:
request - the request to process
useThreadpool - boolean indicating if an attempt should be made to use a thread from the thread pool to handle request
See Also:
XcapClientRequest

notifyListener

public void notifyListener(XcapClientResponse response)
Add a XcapClientResponse to the response list. This method is automatically called by a RequestTask when a response is recieved from sending a request.

Parameters:
response - the response to process
See Also:
XcapClientResponse

getResponses

public java.util.Vector getResponses()
Get the Vector containing all of the responses from requests sent through this instance. This method blocks until all responses are received.


setThreadPoolSize

public static void setThreadPoolSize(int maxSize)
Set the maximum number of worker threads allowed to be created by the threadpool. This should be set at init-time of the first servlet using the threadpool.


destroyThreadPool

public static void destroyThreadPool()
Clean up the thread pool resources. This should be called at the distruction of the servlet last using the thread pool.