|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.vodafone360.people.service.utils.TimeOutWatcher
public class TimeOutWatcher
TimeOutWatcher utility... This is a utility class that is intended to dispatch time-outs for each sent request individually. The thread should be managing only the requests which can expire, i.e. don't add request with timeout "-1" TODO: Consider using the WorkerThread to check for timeouts, that would save us one thread! !!! Also ResponseQueue, RequestQueue and TimeOutWatcher should be managed together and used via a common mutex !!!
Field Summary | |
---|---|
private boolean |
mIsRunning
Flag to determine whether or not the watcher is running. |
private java.util.LinkedList<Request> |
mRequests
The list of watched requests sorted by their expiry dates in ascending order. |
private java.lang.Thread |
mThread
The thread watching for timed out requests. |
Constructor Summary | |
---|---|
TimeOutWatcher()
Constructor. |
Method Summary | |
---|---|
void |
addRequest(Request request)
Adds a request to be watched for timeouts. |
private void |
fireRequestExpired(Request request)
Creates a TimeOut event and adds it to the response queue. |
private long |
getNextRuntime()
Finds the closest time to perform a new check on timeouts. |
Request[] |
getRequestsArray()
Gets an array containing all the requests being watched for timeouts. |
int |
getRequestsCount()
Gets the current number of requests being watched for timeouts. |
private int |
insertRequestByExpiryDate(Request request)
Inserts a request in the requests list while maintaining it sorted by ascending order of expiry date. |
void |
invalidateAllRequests()
Sends a timeout event for all the requests. |
void |
kill()
Kills the TimeOutWatcher (releases memory and running thread). |
void |
removeRequest(Request request)
Removes a request from being watched for timeouts. |
void |
run()
TimeOutWatcher thread that checks for the next time to run, sleeps when not busy and sends timeouts. |
private void |
sendTimeoutEvent(long currentTime)
Sends a timeout event for all the expired requests. |
private void |
startThread()
Starts the TimeOutWatcher thread and performs initialization. |
private void |
stopThread()
Stops the TimeOutWatcher thread and releases the memory. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private boolean mIsRunning
private java.util.LinkedList<Request> mRequests
private java.lang.Thread mThread
Constructor Detail |
---|
public TimeOutWatcher()
Method Detail |
---|
public void run()
run
in interface java.lang.Runnable
private void startThread()
private void stopThread()
private long getNextRuntime()
private void sendTimeoutEvent(long currentTime)
currentTime
- the current time until when a timeout event needs to
be sentprivate int insertRequestByExpiryDate(Request request)
request
- the request to insertprivate void fireRequestExpired(Request request)
request
- the request that has timed outpublic void addRequest(Request request)
request
- the request to addpublic void removeRequest(Request request)
request
- the request to removepublic void kill()
public void invalidateAllRequests()
public int getRequestsCount()
public Request[] getRequestsArray()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
JavaDoc