public final class BGSession extends java.lang.Object implements BGExceptionConstants, BGMessageConstants
Example:
BGSession sess = new BGSession(); try { sess.start(); sess.waitForStatus(BGAgentStatus.RUNNING); BGAgentStatus s = sess.getAgentStatus(); System.out.println("User name: " + s.clientId); sess.addMessageHandler(new MyMessageHandler()); ... } finally { sess.close(); }
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DISABLE_PROP |
ACTIVE_CONNECTIONS_PRESENT, AGENT_DEFUNCT, AGENT_DISABLED, AGENT_NOT_RUNNING, ANOTHER_INSTANCE, CONTROL_CONNECTION_CLOSED, INVALID_COMMAND, INVALID_COND_SUBTYPE, INVALID_COND_TYPE, INVALID_DATE_FORMAT, INVALID_EVENT_SUBTYPE, INVALID_EVENT_TYPE, INVALID_NUMERIC_PARAMETER, INVALID_PARAMETER, INVALID_RULE_CLASS, INVALID_RULE_SUBTYPE, INVALID_RULE_SUBTYPE_TYPE, INVALID_RULE_TYPE, INVALID_SESSION, INVALID_STRING_PARAMETER, INVALID_WAIT_STATUS, NO_BG_PUBS, OPERATION_NOT_ALLOWED, PAUSE_FAILED, READER_CANCELED, RESUME_FAILED, SQL_RULE_MISSING_QUERY, START_FAILED, STOP_FAILED, TOO_MANY_READERS, UNSUPPORTED, WAIT_TIMEOUT
AGENT_PAUSED, AGENT_RESUMED, AGENT_STARTED, AGENT_STOPPED, APPLY_FAILED, APPLY_FINISHED, APPLY_STARTED, BATTERY_LOW, COMPOSE_FAILED, COMPOSE_FINISHED, COMPOSE_STARTED, DUPLICATE_PLATFORM_DB, INTERNAL_ERROR, INVALID_SERVER_NOTIFICATION, MEMORY_LOW, NET_AUTODIAL_FAILED, NET_MANAGER_ERROR, NETWORK_CHANGED, NETWORK_EVAL, NO_NETWORK, PLAT_RULE_IN_NON_PLAT_DB, POWER_MANAGER_ERROR, RULE_EVAL_DB_LOCKED, RULE_EVAL_FAILED, RULE_LOAD_FAILED, SERVER_NOTIFICATION, SERVER_NOTIFICATION_FAILED, SYNC_FAILED, SYNC_FINISHED, SYNC_STARTED, TRACE, UNKNOWN
Constructor and Description |
---|
BGSession()
Create new session to interact with sync agent.
|
Modifier and Type | Method and Description |
---|---|
void |
addMessageHandler(BGMessageHandler h)
Add a custom message handler to sync agent
|
boolean |
agentEnabled()
Query whether sync agent is enabled.
|
void |
close()
Close the session and release all the resources used by the session.
|
void |
enableAgent(boolean on)
Enable or disable sync agent.
|
BGAgentStatus |
getAgentStatus()
Get current sync agent status information.
|
int |
getAgentStatusCode()
Get current sync agent status code constant.
|
BGException |
getFatalError()
If sync agent is in state DEFUNCT, retrieve the error information
that caused the bad internal state.
|
BGSyncStatus |
getSyncStatus()
Get current status of sync within sync agent
|
void |
pause()
Pause sync agent.
|
void |
removeMessageHandler(BGMessageHandler h)
Remove a custom message handler to sync agent
|
void |
resume()
Resume sync agent.
|
void |
showUI()
Bring up sync agent UI.
|
void |
start()
Start sync agent.
|
void |
stop()
Stop sync agent.
|
void |
waitForStatus(int statusCode)
Wait for sync agent to reached specified status.
|
boolean |
waitForStatus(int statusCode,
long timeOut)
Wait for sync agent to reach specified status.
|
public static final java.lang.String DISABLE_PROP
public BGSession() throws BGException
BGException
- - if the session could not be establishedpublic void addMessageHandler(BGMessageHandler h) throws BGException
h
- - a message handler object of a class that implements
BGMessageHandler
interfaceBGException
- - if sync agent is not runningpublic boolean agentEnabled() throws BGException
enableAgent(boolean)
to change this setting.BGException
- - if ose.ini file could not be readpublic void close()
public void enableAgent(boolean on) throws BGException
agentEnabled()
to query the current settingon
- - true to enable, false to disableBGException
- - if ose.ini file could not be modifiedpublic BGAgentStatus getAgentStatus() throws BGException
BGException
- - if the status could not be obtainedBGAgentStatus
public int getAgentStatusCode() throws BGException
BGException
- - if the status code could not be obtainedBGAgentStatus
public BGException getFatalError() throws BGException
BGException
- - if error occurred while retrieving informationBGAgentStatus
public BGSyncStatus getSyncStatus() throws BGException
BGException
- - if the sync status could not be obtainedBGSyncStatus
public void pause() throws BGException
waitForStatus(int, long)
to wait for sync agent.BGException
- - if sync agent is not in the state RUNNING, PAUSED,
or PAUSE_PENDING.BGAgentStatus
public void removeMessageHandler(BGMessageHandler h) throws BGException
h
- - a message handler object of a class that implements
BGMessageHandler
interface. If the handler h was not previously
added to sync agent via addMessageHandler(oracle.opensync.syncagent.BGMessageHandler)
, this call
has no effect.BGException
- - if sync agent is not runningpublic void resume() throws BGException
waitForStatus(int, long)
to wait for sync agent.BGException
- - if sync agent is not in the state PAUSED,
RESUME_PENDING, START_PENDING or RUNNING.BGAgentStatus
public void showUI() throws BGException
BGException
- - if sync agent is stopped or internal error
has occurredpublic void start() throws BGException
waitForStatus(int, long)
to wait for sync agent.BGException
- - if sync agent is not in the state STOPPED,
START_PENDING, RUNNING, PAUSED or RESUME_PENDING (that is the agent is
in the state PAUSE_PENDING or STOP_PENDING), or if sync agent is
disabledBGAgentStatus
,
agentEnabled()
public void stop() throws BGException
waitForStatus(int, long)
to wait for sync agent.BGException
- - if sync agent is not in the state RUNNING, PAUSED,
STOPPED or STOP_PENDING.BGAgentStatus
public void waitForStatus(int statusCode) throws BGException, java.lang.InterruptedException
statusCode
- - status to wait forBGException
java.lang.InterruptedException
public boolean waitForStatus(int statusCode, long timeOut) throws BGException, java.lang.InterruptedException
statusCode
- - the status to wait for. Only RUNNING, PAUSED or
STOPPED are accepted.timeOut
- - maximum time to wait for in millisecondsBGException
- - if the statusCode parameter is not one of
the values abovejava.lang.InterruptedException
- - if the current thread was interruptedBGAgentStatus