|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.funambol.push.CTPService
public class CTPService
This class implements the CTPService. A service which opens a CTP connection and communicates with the server via the CTP protocol (see CTP design document). The service is executed in a separate thread, and it can be stopped at any time. The service uses socket connection and therefore requires network access that may result in user questions. The service is implemented by two threads plus a Timer, and all threads can be created within a thread pool. The service shall never throw any exception (even runtime ones) and on errors it is implemented to retry connecting. If too many failures occurs then the service is stopped (at the moment no notification is sent). The class performs connection and MD5 authentication on startup and if this is succesfull then the listening/heartbeat phase starts. The main thread is controlled by the following FSM: open socket socket opened DISCONNECTED ---------------> CONNECTING ----------------> CONNECTED ^ | fail | | V | --------------------------------------------- | | | | send MD5 | ok | | auth LISTENING <--- AUTHENTICATED <---------> AUTHENTICATING <-----| fail
Nested Class Summary | |
---|---|
protected class |
CTPService.ConnectionTimer
This class is used (with a Timer) to monitor a connection and interrupt it if it hangs for more than command timeout. |
protected class |
CTPService.CTPMessage
This class represents a CTP message. |
protected class |
CTPService.HeartbeatGenerator
This class implements an hearbeat generator. |
Field Summary | |
---|---|
protected static int |
AUTHENTICATED
|
protected static int |
AUTHENTICATING
|
protected static int |
CM_AUTH
Commands |
protected static int |
CM_BYE
|
protected static int |
CM_READY
|
protected static int |
CONNECTED
|
protected static int |
CONNECTING
|
protected static int |
DISCONNECTED
CTP server thread state |
protected static int |
LISTENING
|
protected static int |
ST_ERROR
|
protected static int |
ST_FORBIDDEN
|
protected static int |
ST_JUMP
|
protected static int |
ST_NOT_AUTHENTICATED
|
protected static int |
ST_OK
Status |
protected static int |
ST_RETRY
|
protected static int |
ST_SYNC
|
protected static int |
ST_UNAUTHORIZED
|
protected int |
state
CTPService status |
Constructor Summary | |
---|---|
protected |
CTPService()
Builds an empty service. |
Method Summary | |
---|---|
protected int |
authenticate()
This method performs the CTP authentication. |
protected void |
closeConnection()
Close the connection, forcing exceptions if there are pending network IO operations. |
protected void |
connect(int retry)
Perform the CTP connecting phase. |
protected void |
disconnect()
Disconnect from server. |
void |
forceDisconnect()
force disconnection |
PushConfig |
getConfig()
make PushConfig available for CTPService clients |
java.lang.String |
getCTPStringState()
|
static CTPService |
getInstance()
Returns the instance of the CTPService. |
int |
getServiceState()
|
boolean |
isOfflineMode()
|
boolean |
isPushActive()
Returns true iff CTP is running and it is properly connected and authenticated to the CTP service. |
boolean |
isRunning()
Returns true iff an instance of CTP is already running |
protected CTPService.CTPMessage |
receiveMessage()
Receives a message from the server (wait till a message is received or an error is encountered). |
protected CTPService.CTPMessage |
receiveMessageWithTimeout()
Receives a message from the server. |
void |
restartService()
Restarts the service. |
void |
restartService(PushConfig config)
Restarts the service. |
void |
run()
This is the thread entry point. |
protected void |
sendMessage(CTPService.CTPMessage message)
Sends a message to the server and monitor the operation via a timer. |
void |
setConfig(PushConfig config)
set the push config |
void |
setCTPListener(CTPListener ctpListener)
|
void |
setOfflineMode(boolean mode)
turn offline mode on/off. |
void |
setPushNotificationListener(CTPNotificationListener pushListener)
Sets the push events listener. |
void |
setThreadPool(ThreadPool threadPool)
Sets the thread pool in which the CTP service will be started (has effect at the next start or restart) |
void |
startService()
|
void |
startService(PushConfig config)
Start the complete CTP service. |
void |
stopService()
Stops the service. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final int CM_AUTH
protected static final int CM_READY
protected static final int CM_BYE
protected static final int ST_OK
protected static final int ST_JUMP
protected static final int ST_ERROR
protected static final int ST_NOT_AUTHENTICATED
protected static final int ST_UNAUTHORIZED
protected static final int ST_FORBIDDEN
protected static final int ST_SYNC
protected static final int ST_RETRY
protected static final int DISCONNECTED
protected static final int CONNECTING
protected static final int CONNECTED
protected static final int AUTHENTICATING
protected static final int AUTHENTICATED
protected static final int LISTENING
protected int state
Constructor Detail |
---|
protected CTPService()
Method Detail |
---|
public void setCTPListener(CTPListener ctpListener)
public void startService()
public void setOfflineMode(boolean mode)
mode
- the new offline modepublic boolean isOfflineMode()
public static CTPService getInstance()
public void restartService(PushConfig config)
config
- the new push configurationpublic void restartService()
public void startService(PushConfig config)
config
- the Push configuration for this CTPService (cannot be null)public boolean isRunning()
public void setConfig(PushConfig config)
config
- the new configpublic boolean isPushActive()
public void setPushNotificationListener(CTPNotificationListener pushListener)
pushListener
- the listener or null to remove it.public void setThreadPool(ThreadPool threadPool)
threadPool
- the thread pool or null to disable thread poolpublic void stopService()
public void run()
run
in interface java.lang.Runnable
public int getServiceState()
public java.lang.String getCTPStringState()
protected void closeConnection()
protected void connect(int retry) throws java.io.IOException
retry
- the number of tentative
java.io.IOException
protected void disconnect()
public void forceDisconnect()
public PushConfig getConfig()
protected int authenticate() throws java.io.IOException
java.io.IOException
protected void sendMessage(CTPService.CTPMessage message) throws java.io.IOException
message
- the CTP message to be sent
java.io.IOException
- if the socket writing failsprotected CTPService.CTPMessage receiveMessageWithTimeout() throws java.io.IOException
java.io.IOException
- if the socket writing failsprotected CTPService.CTPMessage receiveMessage() throws java.io.IOException
java.io.IOException
- if the socket writing fails
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |