public final class SyncClient extends java.lang.Object implements Observer, IOperationDelegate
SyncClient
enables clients to synchronize JSON-based data
with Software AGs Integration Server. The Mobile Data Sync Package allows
bidirectional synchronization. Local data is stored in a SQLite table to
enable offline support.
Call start()
to trigger a synchronization process. This method does
the following:
download()
), if the local data
is empty, orsync()
), if local data is stored.The client only starts if all necessary credentials has been set. Those are
appname
,version
,hostname
,port
,mscAlias
.Credentials
registered with the shared Session
. The download or sync operation's are only executed, if all credentials are
set. Calling start()
before all credentials are set does not trigger
to start the process. In this case, the client waits for all credentials and
restarts if all credentials are not empty. Credentials
are not
automatically published to the SyncClient.
The current synchronization process can be monitored by registering
ISyncClientListener
s. Therefore, each registered
ISyncClientListener
is informed on status changes and ongoing
operations.
In addition to this, any implementation of IListDatasource
can be
registered. The datasources are updated if the underlying data changes. Be
aware that the datasource must understand JSON.
This class is extensible. By subclassing, the
AbstractXXXApplicationControllerImpl#createSyncClient
method must be
overwritten to publish the custom SyncClient
.
Constructor and Description |
---|
SyncClient(java.lang.String appname,
java.lang.String version,
java.lang.String mscAlias,
java.lang.String hostname,
java.lang.String port)
Creates a new instance by passing all required properties and an update
interval of
60000L . |
SyncClient(java.lang.String appname,
java.lang.String version,
java.lang.String mscAlias,
java.lang.String hostname,
java.lang.String port,
long updateInterval)
Creates a new instance by passing all required properties.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(ISyncClientListener listener)
Adds the passed
ISyncClientListener . |
void |
download()
Starts a new download.
|
java.lang.String |
getAppname()
Sets the app name.
|
java.lang.String |
getDeviceType()
Returns the device type.
|
java.lang.String |
getHostname()
Returns the host name.
|
java.lang.String |
getMscAlias()
Returns the msc alias.
|
java.lang.String |
getPassword()
Returns the password.
|
java.lang.String |
getPort()
Returns the port.
|
ISQLiteConnector |
getSQLStore()
Returns the
ISQLiteConnector . |
long |
getUpdateInterval()
Returns the update interval for the
SyncOperation . |
java.lang.String |
getUsername()
Returns the user name.
|
java.lang.String |
getVersion()
Returns the version number.
|
void |
onOperationFailed(IOperation operation)
Notifies this listener that the watched
IOperation failed. |
void |
onOperationFinished(IOperation operation)
Notifies this listener that the watched
IOperation finished. |
void |
registerDatasource(IListDatasource datasource)
Adds a new datasource to be observed on data set changes.
|
void |
removeListener(ISyncClientListener listener)
Removes the passed
ISyncClientListener . |
void |
setAppname(java.lang.String appname)
Sets the app name.
|
void |
setDeviceType(java.lang.String deviceType)
Sets the device type.
|
void |
setHostname(java.lang.String hostname)
Sets the host name.
|
void |
setMscAlias(java.lang.String mscAlias)
Sets the msc alias.
|
void |
setPassword(java.lang.String password)
Sets the password.
|
void |
setPort(java.lang.String port)
Sets the port.
|
void |
setUpdateInterval(long updateInterval)
Sets the update interval for the
SyncOperation . |
void |
setUseHttps(boolean usesHttps)
Sets a boolean value indicating if a secure connection should be used.
|
void |
setUsername(java.lang.String username)
Sets the user name.
|
void |
setVersion(java.lang.String version)
Sets the version number.
|
void |
start()
Starts a new synchronization process:
Calls
handleReceivedData() and {link #sync()}, if the
underlying SQLite table has at least one item
Calls download() , if the underlying SQLite table has no item
|
void |
stop()
Stops the ongoing synchronization.
|
void |
sync()
Starts a new synchronization.
|
void |
unregisterDatasource(IListDatasource datasource)
Removes a datasource.
|
void |
update(Observable observable,
java.lang.Object object)
Empty implementation of
Observer.update(Observable, Object) to
allow subclasses to watch on Observer changes. |
void |
updateCredentials()
Validates the credentials and passes them to
Context#setInitializeConf(String, String, String, String, String, String)
if all required properties are not empty. |
boolean |
usesHttps()
Returns a boolean value indicating if a secure connection is used.
|
boolean |
usesSharedSession()
Returns true indicating that the credentials are used from the current
Session . |
public SyncClient(java.lang.String appname, java.lang.String version, java.lang.String mscAlias, java.lang.String hostname, java.lang.String port)
60000L
.appname
- Name of the application that is registered with the mobile
sync component.version
- Version of the application that is registered with the mobile
sync component.mscAlias
- hostname
- port
- updateInterval
- public SyncClient(java.lang.String appname, java.lang.String version, java.lang.String mscAlias, java.lang.String hostname, java.lang.String port, long updateInterval)
appname
- Name of the application that is registered with the mobile
sync component.version
- Version of the application that is registered with the mobile
sync component.mscAlias
- hostname
- port
- updateInterval
- public void updateCredentials()
Context#setInitializeConf(String, String, String, String, String, String)
if all required properties are not empty. username
password
hostname
port
public void registerDatasource(IListDatasource datasource)
datasource
- public void unregisterDatasource(IListDatasource datasource)
datasource
- public void start()
handleReceivedData()
and {link #sync()}, if the
underlying SQLite table has at least one itemdownload()
, if the underlying SQLite table has no item
public void stop()
start()
.public void download()
DownloadOperation
is only been created if:
stop()
was not called andpublic void sync()
SyncOperation
is only been created if:
stop()
was not called andpublic void onOperationFailed(IOperation operation)
IOperationDelegate
IOperation
failed. This
only indicates an exception during the execution and is independent from
the operation's result code.onOperationFailed
in interface IOperationDelegate
operation
- The watched IOperation
.public void onOperationFinished(IOperation operation)
IOperationDelegate
IOperation
finished. IOperation.getResultCode()
to validate the success of the
operation. E.g. for a remote operation:
switch (operation.getResultCode()) { caseHttpConnection.HTTP_OK
: break; caseHttpConnection.HTTP_FORBIDDEN
: break; }
onOperationFinished
in interface IOperationDelegate
operation
- The watched IOperation
.public void setAppname(java.lang.String appname)
port
- updateCredentials()
public void setVersion(java.lang.String version)
port
- updateCredentials()
public void setMscAlias(java.lang.String mscAlias)
port
- updateCredentials()
public void setUsername(java.lang.String username)
port
- updateCredentials()
public void setPassword(java.lang.String password)
port
- updateCredentials()
public void setHostname(java.lang.String hostname)
port
- updateCredentials()
public void setPort(java.lang.String port)
port
- updateCredentials()
public void setDeviceType(java.lang.String deviceType)
updateCredentials()
to
update the Context
.deviceType
- updateCredentials()
public void setUpdateInterval(long updateInterval)
SyncOperation
.updateInterval
- public void setUseHttps(boolean usesHttps)
useHttps
- public java.lang.String getAppname()
public java.lang.String getVersion()
public java.lang.String getMscAlias()
public java.lang.String getUsername()
public java.lang.String getPassword()
public java.lang.String getHostname()
public java.lang.String getPort()
public java.lang.String getDeviceType()
public long getUpdateInterval()
SyncOperation
.public boolean usesHttps()
public ISQLiteConnector getSQLStore()
ISQLiteConnector
. SyncClientSQLiteConnectorImpl
.public void update(Observable observable, java.lang.Object object)
Observer.update(Observable, Object)
to
allow subclasses to watch on Observer
changes. public void addListener(ISyncClientListener listener)
ISyncClientListener
.listener
- public void removeListener(ISyncClientListener listener)
ISyncClientListener
.listener
- public boolean usesSharedSession()
Session
.Session.get()
,
Session.getCredentials()