|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.vodafone360.people.engine.BaseEngine
public abstract class BaseEngine
Base-class for all Engines implemented by the People Client.
Nested Class Summary | |
---|---|
static interface |
BaseEngine.IEngineEventCallback
Interface which must be implemented by engine client. |
private static class |
BaseEngine.UiQueueItem
Class to encapsulate client request information. |
Field Summary | |
---|---|
private java.lang.Integer |
mActiveRequestId
Set by the setReqId(int) function to store the request ID when a
engine makes a request to the server. |
protected ServiceUiRequest |
mActiveUiRequest
Current UI Request if one is active, otherwise null. |
private java.lang.Boolean |
mCommsResponseOutstanding
true if a Comms response is waiting in the comms response queue for processing, false otherwise. |
protected java.lang.Long |
mCurrentTimeout
Current timeout based on current time in milliseconds if one is pending, otherwise null. |
private boolean |
mDeactivated
true if the engine is deactivated (for test purposes), false otherwise. |
protected EngineManager.EngineId |
mEngineId
All engines must set this field to a unique ID |
protected BaseEngine.IEngineEventCallback |
mEventCallback
Callback provided by EngineManager |
private java.lang.Object |
mMutex
mutex for thread synchronization |
private java.util.concurrent.ConcurrentLinkedQueue<BaseEngine.UiQueueItem> |
mUiQueue
Used to implement the UI request queue. |
private boolean |
mUiRequestOutstanding
true if a UI request is waiting in the UI request queue for processing, false otherwise. |
private boolean |
resetDone
Flag set when a request to reset the engine is made and the engine has performed its reset tasks. |
Constructor Summary | |
---|---|
BaseEngine(BaseEngine.IEngineEventCallback eventCallback)
Public constructor. |
Method Summary | |
---|---|
void |
addUiRequestToQueue(ServiceUiRequest request,
java.lang.Object data)
Helper function for use by the derived engine class to add a UI request to the queue. |
(package private) void |
clearReset()
Clears the reset flag. |
protected void |
clearTimeout()
Cancels the current timer (has no effect if the timer was not active). |
protected void |
completeUiRequest(ServiceStatus status)
A helper function that can be called by the derived engine implementation to complete the current UI request. |
protected void |
completeUiRequest(ServiceStatus status,
java.lang.Object data)
A helper function that can be called by the derived engine implementation to complete the current UI request. |
protected void |
deactivateEngine()
Called by the framework to deactivate the engine. |
protected void |
emptyUiRequestQueue()
Called by engines in the UI thread to cancel all UI requests. |
EngineManager.EngineId |
engineId()
Return id for this engine. |
private BaseEngine.UiQueueItem |
fetchNextUiRequest()
Helper function for use by the derived engine class to fetch the next UI request from the queue. |
static ServiceStatus |
genericHandleResponseType(java.lang.String requiredResp,
java.util.List<BaseDataType> data)
A helper function for the derived engine implementation to use. |
protected long |
getCurrentTimeout()
The result of this function must be returned by getNextRunTime() instead of -1 for the timer to work. |
abstract long |
getNextRunTime()
Return the absolute time in milliseconds when the engine needs to run (based on System.currentTimeMillis). |
(package private) boolean |
getReset()
Gets the reset flag. |
protected boolean |
isCommsResponseOutstanding()
Should be called by the getNextRunTime() and run() functions to check if there are any comms responses waiting to be processed. |
boolean |
isDeactivated()
Called by the framework to determine if the engine should run. |
protected boolean |
isUiRequestOutstanding()
Helper function to determine if there is any work outstanding in the UI request queue. |
void |
onCommsInMessage()
Called by the EngineManager when a comms response is received. |
abstract void |
onCreate()
This will be called immediately after creation. |
abstract void |
onDestroy()
This will be called just before the engine is shutdown. |
protected abstract void |
onRequestComplete()
This function must be implemented in the derived engine implementation. |
void |
onReset()
Engines can override this function to do any special handling when a reset is needed. |
protected abstract void |
onTimeoutEvent()
The derived engine implementation must call the processTimeout() function (normally from within the run() implementation), otherwise this will not be called. |
private void |
onUiRequestComplete(ServiceUiRequest request,
ServiceStatus status,
java.lang.Object data)
Helper function which must be called to complete a UI request. |
protected boolean |
processCommsInQueue()
Should be called by the run() function to process the comms in queue. |
protected abstract void |
processCommsResponse(ResponseQueue.Response resp)
The derived engine implementation must call the processCommsInQueue() function (normally from within the run() implementation), otherwise this will not be called. |
protected boolean |
processTimeout()
This function must be called by run() in the derived engine implementation for the timer to work. |
protected boolean |
processUiQueue()
Should be called by the run() function to process the UI request queue. |
protected abstract void |
processUiRequest(ServiceUiRequest requestId,
java.lang.Object data)
The derived engine implementation must call the processUiQueue() function (normally from within the run() implementation), otherwise this will not be called. |
abstract void |
run()
Do some work but anything that takes longer than 1 second must be broken up. |
protected boolean |
setReqId(int reqId)
Called by engines when an API call is made to ensure that the response processed matches the request. |
private void |
setReset(boolean value)
Sets the reset flag. |
protected void |
setTimeout(long timeoutVal)
Helper function that can be called by the derived engine implementation to start an asynchronous timer. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected EngineManager.EngineId mEngineId
protected BaseEngine.IEngineEventCallback mEventCallback
EngineManager
protected ServiceUiRequest mActiveUiRequest
ServiceUiRequest
protected volatile java.lang.Long mCurrentTimeout
private java.lang.Boolean mCommsResponseOutstanding
private java.lang.Integer mActiveRequestId
setReqId(int)
function to store the request ID when a
engine makes a request to the server. All responses received will then be
filtered by this value automatically inside the
processCommsInQueue()
function.
private boolean mUiRequestOutstanding
private boolean mDeactivated
private java.lang.Object mMutex
private boolean resetDone
private final java.util.concurrent.ConcurrentLinkedQueue<BaseEngine.UiQueueItem> mUiQueue
Constructor Detail |
---|
public BaseEngine(BaseEngine.IEngineEventCallback eventCallback)
eventCallback
- This interface must be implemented by the engine
clientMethod Detail |
---|
public abstract long getNextRunTime()
public abstract void run()
public abstract void onCreate()
public abstract void onDestroy()
public void addUiRequestToQueue(ServiceUiRequest request, java.lang.Object data)
public EngineManager.EngineId engineId()
private BaseEngine.UiQueueItem fetchNextUiRequest()
protected boolean isUiRequestOutstanding()
private void onUiRequestComplete(ServiceUiRequest request, ServiceStatus status, java.lang.Object data)
request
- The request Id to completestatus
- The ServiceStatus codedata
- Response data (object type is request specific)protected abstract void processCommsResponse(ResponseQueue.Response resp)
resp
- The comms responseprotected abstract void processUiRequest(ServiceUiRequest requestId, java.lang.Object data)
requestId
- The UI request IDdata
- Request data (object type is request specific)protected abstract void onTimeoutEvent()
public void onCommsInMessage()
protected boolean isCommsResponseOutstanding()
protected boolean processCommsInQueue()
public static ServiceStatus genericHandleResponseType(java.lang.String requiredResp, java.util.List<BaseDataType> data)
requiredResp
- The expected type namedata
- The data received from the comms response
protected boolean processUiQueue()
protected void completeUiRequest(ServiceStatus status)
status
- The result of the requestprotected abstract void onRequestComplete()
protected void completeUiRequest(ServiceStatus status, java.lang.Object data)
status
- The result of the requestdata
- Response data (object type is request specific)protected void setTimeout(long timeoutVal)
timeoutVal
- The timeout value (in milliseconds)protected void clearTimeout()
protected long getCurrentTimeout()
protected boolean processTimeout()
protected void deactivateEngine()
public boolean isDeactivated()
protected boolean setReqId(int reqId)
protected void emptyUiRequestQueue()
public void onReset()
private void setReset(boolean value)
value
- the reset state of the engine, true if reset, false if not.boolean getReset()
void clearReset()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
JavaDoc