|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.vodafone360.people.engine.BaseEngine com.vodafone360.people.engine.presence.PresenceEngine
public class PresenceEngine
Handles the Presence life cycle
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.vodafone360.people.engine.BaseEngine |
---|
BaseEngine.IEngineEventCallback |
Field Summary | |
---|---|
private static long |
CHECK_FREQUENCY
Check every 10 minutes. |
private static int |
IDLE
This state indicates there are no more pending presence payload information to be processed. |
private static int |
MAX_RETRY_COUNT
Max attempts to try. |
private boolean |
mContObsAdded
|
private DatabaseHelper |
mDbHelper
|
private java.util.List<ActivitiesTable.TimelineSummaryItem> |
mFailedMessagesList
|
private int |
mIterations
Number of pages of presence Updates done. |
private boolean |
mLoggedIn
Reconnecting before firing offline state to the handlers. |
private NetworkAgent.AgentState |
mNetworkAgentState
|
private long |
mNextRuntime
|
private int |
mRetryNumber
|
private java.util.Hashtable<java.lang.String,ChatMessage> |
mSendMessagesHash
|
private int |
mState
The state of the presence Engine. |
private java.util.List<User> |
mUsers
The list of Users still to be processed. |
private static int |
NOTIFY_AGENT_PAGE_INTERVAL
The number of pages after which the HandlerAgent is notified. |
private static int |
UPDATE_PRESENCE_PAGE_SIZE
The page size i.e the number of presence updates processed at a time. |
private static long |
UPDATE_PRESENCE_TIMEOUT_MILLS
Timeout between each presence update processing. |
private static int |
UPDATE_PROCESSING_GOING_ON
This state indicates there are some pending presence payload information to be processed. |
Fields inherited from class com.vodafone360.people.engine.BaseEngine |
---|
mActiveUiRequest, mCurrentTimeout, mEngineId, mEventCallback |
Constructor Summary | |
---|---|
PresenceEngine(BaseEngine.IEngineEventCallback eventCallback,
DatabaseHelper databaseHelper)
|
Method Summary | |
---|---|
private void |
addAsContactSyncObserver()
Add ActivitiesEngine as an observer of the ContactSyncEngine. |
private boolean |
canRun()
checks the external conditions which have to be happen before the engine can run |
private void |
createConversation(ChatMessage msg)
|
private User |
getMyAvailabilityStatusFromDatabase()
|
long |
getNextRunTime()
Return the absolute time in milliseconds when the engine needs to run (based on System.currentTimeMillis). |
void |
getPresenceList()
Initiate the "get presence list" request sending to server. |
private void |
handleNewConversationId(Conversation conversation)
|
private void |
handlePresenceList(PresenceList presenceList)
|
private void |
handlePushEvent(PushEvent event)
|
private void |
handleServerError(ServerError srvError)
|
private void |
handleServerResponse(java.util.List<BaseDataType> dataTypes)
This method handles incoming presence status change push events and the whole PresenceList |
private void |
handleSystemNotification(SystemNotification sn)
|
private void |
initSetMyAvailabilityRequest(User myself)
|
void |
onContactSyncStateChange(ContactSyncEngine.Mode mode,
ContactSyncEngine.State oldState,
ContactSyncEngine.State newState)
Called when the contact sync engine changes state or mode |
void |
onCreate()
This will be called immediately after creation. |
void |
onDestroy()
This will be called just before the engine is shutdown. |
void |
onLoginStateChanged(boolean loggedIn)
|
void |
onProgressEvent(ContactSyncEngine.State currentState,
int percent)
Called to update interested parties on contact sync progress. |
protected void |
onRequestComplete()
This function must be implemented in the derived engine implementation. |
void |
onSyncComplete(ServiceStatus status)
Called a contact sync finishes. |
protected void |
onTimeoutEvent()
The derived engine implementation must call the processTimeout() function (normally from within the run() implementation), otherwise this will not be called. |
protected 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 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. |
void |
run()
Do some work but anything that takes longer than 1 second must be broken up. |
void |
sendMessage(long toLocalContactId,
java.lang.String body,
int networkId)
This method should be used to send a message to a contact |
void |
setMyAvailability(java.util.Hashtable<java.lang.String,java.lang.String> myselfPresence)
Changes the state of the engine. |
private void |
setNextRuntime()
|
private void |
setPresenceOffline()
Set the Global presence status to offline. |
private void |
setRunNow()
|
private void |
showErrorNotification(ServiceUiRequest errorEvent,
ChatMessage msg)
|
private boolean |
uiRequestReady()
Helper function which returns true if a UI request is waiting on the queue and we are ready to process it. |
private void |
updateChatDatabase(ChatMessage message,
ActivitiesTable.TimelineSummaryItem.Type type)
Updates the database with the given ChatMessage and Type. |
private void |
updateMyPresenceInDatabase(User myself)
Here we update the PresenceTable, and the ContactSummaryTable afterwards the HandlerAgent receives the notification of presence states changes. |
private void |
updatePresenceDatabase(java.util.List<User> users)
Here we update the PresenceTable, and the ContactSummaryTable afterwards the HandlerAgent receives the notification of presence states changes. |
private void |
updatePresenceDatabaseNextPage()
This API makes the presence updates in pages of 10 with a timeout after each page. |
Methods inherited from class com.vodafone360.people.engine.BaseEngine |
---|
addUiRequestToQueue, clearTimeout, completeUiRequest, completeUiRequest, deactivateEngine, emptyUiRequestQueue, engineId, genericHandleResponseType, getCurrentTimeout, isCommsResponseOutstanding, isDeactivated, isUiRequestOutstanding, onCommsInMessage, onReset, processCommsInQueue, processTimeout, processUiQueue, setReqId, setTimeout |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final long CHECK_FREQUENCY
private static final int MAX_RETRY_COUNT
private boolean mLoggedIn
private long mNextRuntime
private NetworkAgent.AgentState mNetworkAgentState
private DatabaseHelper mDbHelper
private int mRetryNumber
private final java.util.Hashtable<java.lang.String,ChatMessage> mSendMessagesHash
private java.util.List<ActivitiesTable.TimelineSummaryItem> mFailedMessagesList
private boolean mContObsAdded
private java.util.List<User> mUsers
private static final int IDLE
private static final int UPDATE_PROCESSING_GOING_ON
private static final long UPDATE_PRESENCE_TIMEOUT_MILLS
private static final int UPDATE_PRESENCE_PAGE_SIZE
private static final int NOTIFY_AGENT_PAGE_INTERVAL
private int mState
private int mIterations
Constructor Detail |
---|
public PresenceEngine(BaseEngine.IEngineEventCallback eventCallback, DatabaseHelper databaseHelper)
eventCallback
- databaseHelper
- Method Detail |
---|
public void onCreate()
BaseEngine
onCreate
in class BaseEngine
public void onDestroy()
BaseEngine
onDestroy
in class BaseEngine
private boolean canRun()
public long getNextRunTime()
BaseEngine
getNextRunTime
in class BaseEngine
public void run()
BaseEngine
run
in class BaseEngine
private boolean uiRequestReady()
private User getMyAvailabilityStatusFromDatabase()
private void setNextRuntime()
private void setRunNow()
public void onLoginStateChanged(boolean loggedIn)
onLoginStateChanged
in interface LoginEngine.ILoginEventsListener
private void setPresenceOffline()
protected void onRequestComplete()
BaseEngine
onRequestComplete
in class BaseEngine
protected void onTimeoutEvent()
BaseEngine
onTimeoutEvent
in class BaseEngine
protected void processCommsResponse(ResponseQueue.Response resp)
BaseEngine
processCommsResponse
in class BaseEngine
resp
- The comms responseprivate void showErrorNotification(ServiceUiRequest errorEvent, ChatMessage msg)
private void updatePresenceDatabase(java.util.List<User> users)
users
- List of users that require updating.private void updatePresenceDatabaseNextPage()
private void updateChatDatabase(ChatMessage message, ActivitiesTable.TimelineSummaryItem.Type type)
message
- ChatMessage.type
- TimelineSummaryItem.Type.private void updateMyPresenceInDatabase(User myself)
users
- User that requires updating.private void handleServerResponse(java.util.List<BaseDataType> dataTypes)
dataTypes
- private void handlePresenceList(PresenceList presenceList)
private void handleServerError(ServerError srvError)
private void handleNewConversationId(Conversation conversation)
private void handlePushEvent(PushEvent event)
private void handleSystemNotification(SystemNotification sn)
protected void processUiRequest(ServiceUiRequest requestId, java.lang.Object data)
BaseEngine
processUiRequest
in class BaseEngine
requestId
- The UI request IDdata
- Request data (object type is request specific)public void getPresenceList()
private void initSetMyAvailabilityRequest(User myself)
public void setMyAvailability(java.util.Hashtable<java.lang.String,java.lang.String> myselfPresence)
accounts
- private void createConversation(ChatMessage msg)
public void sendMessage(long toLocalContactId, java.lang.String body, int networkId)
tos
- - tlocalContactId of ContactSummary items the message is
intended for. Current protocol version only supports a single
recipient.body
- the message textprivate void addAsContactSyncObserver()
public void onContactSyncStateChange(ContactSyncEngine.Mode mode, ContactSyncEngine.State oldState, ContactSyncEngine.State newState)
ContactSyncEngine.IContactSyncObserver
onContactSyncStateChange
in interface ContactSyncEngine.IContactSyncObserver
mode
- Current modeoldState
- Previous statenewState
- New statepublic void onProgressEvent(ContactSyncEngine.State currentState, int percent)
ContactSyncEngine.IContactSyncObserver
onProgressEvent
in interface ContactSyncEngine.IContactSyncObserver
currentState
- What the contact sync engine is currently doingpercent
- Percentage complete for the current taskpublic void onSyncComplete(ServiceStatus status)
ContactSyncEngine.IContactSyncObserver
onSyncComplete
in interface ContactSyncEngine.IContactSyncObserver
status
- SUCCESS if the sync was successful, a suitable error
code otherwise.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
JavaDoc