com.vodafone360.people.service.io
Class QueueManager

java.lang.Object
  extended by com.vodafone360.people.service.io.QueueManager

public class QueueManager
extends java.lang.Object

A facade class used for adding and removing from the request and response queues. The methods used in this class are thread safe and should be used instead of using the queues directly.

Author:
Rudy Norff (rudy.norff@vodafone.com)

Nested Class Summary
private static class QueueManager.QueueManagerHolder
          Use Initialization on demand holder pattern
 
Field Summary
 java.lang.Object lock
           
private  RequestQueue mRequestQueue
           
private  ResponseQueue mResponseQueue
           
 
Constructor Summary
private QueueManager()
           
 
Method Summary
 void addQueueListener(IQueueListener listener)
          Adds a listener listening for RequestQueue changes.
 int addRequest(Request request)
          Adds a request to the queue without sending an event to the listeners
 int[] addRequest(Request[] requests)
          Adds requests to the queue.
 int addRequestAndNotify(Request request)
          Add request to queue and notify the queue listener.
 void addResponse(ResponseQueue.Response response)
          Adds a response to the response queue.
 void clearActiveRequests(boolean rpgOnly)
          Clear active requests (i.e add dummy response to response queue).
 void clearAllRequests()
          Clears all requests from the request queue and puts null responses on the response queue to tell the engines that they have been cleared.
 void clearRequestTimeouts()
          Clears all request timeouts that were added to the timeout watcher.
 void fireQueueStateChanged()
          Fire a manual queue state changed event to notify the queue listener that a request is on the request queue.
 java.util.List<Request> getAllRequests()
          Returns all requests from the queue.
 java.util.List<Request> getApiRequests()
          Returns all requests from the queue needing the API or both to work.
static QueueManager getInstance()
          Returns a single instance of the RequestResponseManager which holds the request and response queues.
 Request getRequest(int requestId)
          Return Request from specified request ID.
 TimeOutWatcher getRequestTimeoutWatcher()
          Returns a timeout-watcher of requests from the request queue.
 java.util.List<Request> getRpgRequests()
          Returns all requests from the queue needing the RPG or both to work.
 void removeQueueListener(IQueueListener listener)
          Remove RequestQueue listener from the list.
 boolean removeRequest(int requestId)
          Removes the request for the given request ID from the queue and searches the queue for requests older than Settings.REMOVE_REQUEST_FROM_QUEUE_MILLIS and removes them as well.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lock

public final java.lang.Object lock

mRequestQueue

private RequestQueue mRequestQueue

mResponseQueue

private ResponseQueue mResponseQueue
Constructor Detail

QueueManager

private QueueManager()
Method Detail

getInstance

public static QueueManager getInstance()
Returns a single instance of the RequestResponseManager which holds the request and response queues. Uses IDOH idiom.

Returns:
The RequestResponseManager object to use for adding and removing requests from the request and response queues.

addResponse

public void addResponse(ResponseQueue.Response response)
Adds a response to the response queue.

Parameters:
response - The response to add to the queue.

clearRequestTimeouts

public void clearRequestTimeouts()
Clears all request timeouts that were added to the timeout watcher.


getRequestTimeoutWatcher

public TimeOutWatcher getRequestTimeoutWatcher()
Returns a timeout-watcher of requests from the request queue.

Returns:
The timeout watcher inside the request queue.

clearAllRequests

public void clearAllRequests()
Clears all requests from the request queue and puts null responses on the response queue to tell the engines that they have been cleared. This should be called from the connection thread as soon as it is stopped.


clearActiveRequests

public void clearActiveRequests(boolean rpgOnly)
Clear active requests (i.e add dummy response to response queue).

Parameters:
rpgOnly - If true only RPG requests will be cleared.

removeRequest

public boolean removeRequest(int requestId)
Removes the request for the given request ID from the queue and searches the queue for requests older than Settings.REMOVE_REQUEST_FROM_QUEUE_MILLIS and removes them as well.

Parameters:
requestId - The ID of the request to remove.
Returns:
True if the request was found and removed.

getRequest

public Request getRequest(int requestId)
Return Request from specified request ID. Only used for unit tests.

Parameters:
requestId - Request Id of required request
Returns:
Request with or null if request does not exist

getApiRequests

public java.util.List<Request> getApiRequests()
Returns all requests from the queue needing the API or both to work.

Returns:
List of all requests needing the API or both (API or RPG) to function properly.

getRpgRequests

public java.util.List<Request> getRpgRequests()
Returns all requests from the queue needing the RPG or both to work.

Returns:
List of all requests needing the RPG or both (API or RPG) to function properly.

getAllRequests

public java.util.List<Request> getAllRequests()
Returns all requests from the queue. Regardless if they need to

Returns:
List of all requests.

addRequest

public int[] addRequest(Request[] requests)
Adds requests to the queue.

Parameters:
requests - The requests to add.
Returns:
The request IDs generated in an integer array or null if the requests array was null.

addRequest

public int addRequest(Request request)
Adds a request to the queue without sending an event to the listeners

Parameters:
request - The request to add
Returns:
The unique request ID TODO: What is with the method naming convention?

addRequestAndNotify

public int addRequestAndNotify(Request request)
Add request to queue and notify the queue listener.

Parameters:
request - The request to add to the queue.
Returns:
The request ID of the added request.

fireQueueStateChanged

public void fireQueueStateChanged()
Fire a manual queue state changed event to notify the queue listener that a request is on the request queue.


addQueueListener

public void addQueueListener(IQueueListener listener)
Adds a listener listening for RequestQueue changes. Events are sent when items are added to the queue (or in the case of batching when the last item is added to the queue).

Parameters:
listener - Listener to add to the list of request queue listeners.

removeQueueListener

public void removeQueueListener(IQueueListener listener)
Remove RequestQueue listener from the list.

Parameters:
listener - The listener to remove.


JavaDoc