com.funambol.syncml.client
Class TrackableSyncSource

java.lang.Object
  extended by com.funambol.syncml.client.TrackableSyncSource
All Implemented Interfaces:
SyncSource
Direct Known Subclasses:
ConfigSyncSource, FileSyncSource

public abstract class TrackableSyncSource
extends java.lang.Object
implements SyncSource

An abstract implementation of SyncSource, providing the ability to use a ChangesTracker to automatically trace changes. This class needs a ChangesTracker to be able to track changes


Field Summary
protected  java.util.Enumeration allItems
          All items for slow syncs
protected  SourceConfig config
          SyncSource configuration
protected  java.util.Enumeration delItems
          Deleted items for fast syncs
protected  SyncFilter filter
          Synchronization filter
protected  int globalStatus
          Status of the sync source summarized in an integer value.
protected  java.util.Enumeration newItems
          New items for fast syncs
protected  int syncMode
          SyncMode, set by beginSync
protected  ChangesTracker tracker
           
protected  java.util.Enumeration updItems
          Updated items for fast syncs
 
Fields inherited from interface com.funambol.syncml.spds.SyncSource
ENCODING_B64, ENCODING_NONE, STATUS_CONNECTION_ERROR, STATUS_RECV_ERROR, STATUS_SEND_ERROR, STATUS_SERVER_ERROR, STATUS_SUCCESS
 
Constructor Summary
TrackableSyncSource(SourceConfig config, ChangesTracker tracker)
          TrackableSyncSource constructor: initialize source config
 
Method Summary
 int addItem(SyncItem item)
          The purpose of this implementation is simply to notify the tracker.
 void beginSync(int syncMode)
          Called after SyncManager preparation and initialization just before start the synchronization of the SyncSource.
 SyncItem createSyncItem(java.lang.String key, java.lang.String type, char state, java.lang.String parent, long size)
          Creates a new SyncItem for the engine to store incoming items
 void dataReceived(java.lang.String date, int size)
          Default implementation for
protected abstract  void deleteAllItems()
          Physically delete all items
 int deleteItem(java.lang.String key)
          The purpose of this implementation is simply to notify the tracker.
 void endSync()
          Called just before committing the synchronization process by the SyncManager.
protected abstract  java.util.Enumeration getAllItemsKeys()
           
 int getClientAddNumber()
          Return the number of new items (add) that the client will send during the session.
 int getClientDeleteNumber()
          Return the number of deleted items that the client will send during the session.
 int getClientItemsNumber()
          Return the number of changes that the client will send during the session.
 int getClientReplaceNumber()
          Return the number of replaced items that the client will send during the session.
 SourceConfig getConfig()
          Returns the config of the source.
 java.lang.String getEncoding()
          Returns the encoding of the source.
 SyncFilter getFilter()
          Returns the current filter for this SyncSource.
protected abstract  SyncItem getItemContent(SyncItem item)
           
 long getLastAnchor()
          Return the Last Anchor for this source
 SyncListener getListener()
          Returns the current listener (or null if not set)
 java.lang.String getName()
          Returns the name of the source
 long getNextAnchor()
          Return the Next Anchor for this source
 SyncItem getNextDeletedItem()
          Returns a SyncItem containing the key of the first/next deleted item of the store (locally removed after the last sync, but not yet deleted on server)
 SyncItem getNextItem()
          Returns the next item of the store (for slow sync).
 SyncItem getNextNewItem()
          Returns the first/next new item of the store.
 SyncItem getNextUpdatedItem()
          Returns the first/next updated item of the store (changed from the last sync)
 int getServerItemsNumber()
          Return the number of changes that the server will send during the session.
 java.lang.String getSourceUri()
          Returns the source URI
 int getStatus()
          Returns the status of the sync source.
 int getSyncMode()
          Returns the preferred sync mode of the source.
 ChangesTracker getTracker()
          Return the current tracker for this source
 java.lang.String getType()
          Returns the type of the source.
 void setConfig(SourceConfig config)
          Sets the config of the source.
 void setFilter(SyncFilter filter)
          Set a new filter for this SyncSource
 void setItemStatus(java.lang.String key, int status)
          Tell the SyncSource the status returned by the server for an Item previously sent.
 void setLastAnchor(long time)
          Set the value of the Last Anchor for this source
 void setListener(SyncListener listener)
          Set a sync listener.
 void setNextAnchor(long time)
          Set the value of the Next Anchor for this source
 void setServerItemsNumber(int number)
          Set the number of changes that the server will send during the session.
 void setTracker(ChangesTracker tracker)
          Re-sets the tracker.
 int updateItem(SyncItem item)
          The purpose of this implementation is simply to notify the tracker.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tracker

protected ChangesTracker tracker

allItems

protected java.util.Enumeration allItems
All items for slow syncs


newItems

protected java.util.Enumeration newItems
New items for fast syncs


updItems

protected java.util.Enumeration updItems
Updated items for fast syncs


delItems

protected java.util.Enumeration delItems
Deleted items for fast syncs


config

protected SourceConfig config
SyncSource configuration


filter

protected SyncFilter filter
Synchronization filter


syncMode

protected int syncMode
SyncMode, set by beginSync


globalStatus

protected int globalStatus
Status of the sync source summarized in an integer value. See constants defined in SyncSource

Constructor Detail

TrackableSyncSource

public TrackableSyncSource(SourceConfig config,
                           ChangesTracker tracker)
TrackableSyncSource constructor: initialize source config

Method Detail

setTracker

public void setTracker(ChangesTracker tracker)
Re-sets the tracker. Be careful when using this method. Any change tracked in the previous tracker is going to be lost.

Parameters:
tracker - the new tracker

getTracker

public final ChangesTracker getTracker()
Return the current tracker for this source


beginSync

public void beginSync(int syncMode)
               throws SyncException
Description copied from interface: SyncSource
Called after SyncManager preparation and initialization just before start the synchronization of the SyncSource. The implementation must reset the all/new/upd/del item lists when this method is called by the sync engine.

Specified by:
beginSync in interface SyncSource
Parameters:
syncMode - the synchronization type: one of the values in sync4j.framework.core.AlertCode
Throws:
SyncException - in case of error. This will stop the sync process

endSync

public void endSync()
             throws SyncException
Description copied from interface: SyncSource
Called just before committing the synchronization process by the SyncManager. The SyncSource can stop the commit phase raising an exception here.

Specified by:
endSync in interface SyncSource
Throws:
SyncException - in case of error, to stop the commit.

getNextItem

public SyncItem getNextItem()
                     throws SyncException
Description copied from interface: SyncSource
Returns the next item of the store (for slow sync).

The method returns the set of items in the source. This set can be frozen just after the beginSync is invoked or it can change as new changes are applied. The method only guarantees that it returns all the items that were in the store when beginSync got invoked. When an item is returned by this method it may be no longer in the source if it got deleted. In other words there is no guarantee an item returned is still in the source. This method acts as an iterator and is guaranteed to be initialized after beginSync.

Specified by:
getNextItem in interface SyncSource
Returns:
the current item or null if no more items
Throws:
SyncException

getNextNewItem

public SyncItem getNextNewItem()
                        throws SyncException
Description copied from interface: SyncSource
Returns the first/next new item of the store.

The implementation of this method must iterate on the items of the source not yet sent to the server, starting from the first one after a beginSync() call and returning null when no more items are available.

Specified by:
getNextNewItem in interface SyncSource
Returns:
the first new item, in a SyncItem object, or null if no new items are present.
Throws:
SyncException

getNextUpdatedItem

public SyncItem getNextUpdatedItem()
                            throws SyncException
Description copied from interface: SyncSource
Returns the first/next updated item of the store (changed from the last sync)

Specified by:
getNextUpdatedItem in interface SyncSource
Returns:
the first updated item, in a SyncItem object, or null if no updated items are present.
Throws:
SyncException

getNextDeletedItem

public SyncItem getNextDeletedItem()
                            throws SyncException
Description copied from interface: SyncSource
Returns a SyncItem containing the key of the first/next deleted item of the store (locally removed after the last sync, but not yet deleted on server)

Specified by:
getNextDeletedItem in interface SyncSource
Returns:
the first deleted item, in a SyncItem object, or null if no deleted items are present.
Throws:
SyncException

setItemStatus

public void setItemStatus(java.lang.String key,
                          int status)
                   throws SyncException
Description copied from interface: SyncSource
Tell the SyncSource the status returned by the server for an Item previously sent.

Specified by:
setItemStatus in interface SyncSource
Parameters:
key - the key of the item
status - the status code received for that item
Throws:
SyncException - if the SyncSource wants to stop the sync

createSyncItem

public SyncItem createSyncItem(java.lang.String key,
                               java.lang.String type,
                               char state,
                               java.lang.String parent,
                               long size)
Creates a new SyncItem for the engine to store incoming items

Specified by:
createSyncItem in interface SyncSource
Parameters:
key - is the item key
type - is the item type
state - this item's state
parent - is the item's parent
size - is the item size

addItem

public int addItem(SyncItem item)
            throws SyncException
The purpose of this implementation is simply to notify the tracker. Classes that extends the TrackableSyncSource should invoke this method at the end of their processing in the addItem so that the tracker is properly updated. Otherwise they are in charge of notifying the tracker.

Specified by:
addItem in interface SyncSource
Parameters:
item - is the item being added
Returns:
SUCCESS if the tracker was successfully updated, GENERIC_ERROR otherwise
Throws:
SyncException - if an unrecoverable error occur, to stop the sync

updateItem

public int updateItem(SyncItem item)
               throws SyncException
The purpose of this implementation is simply to notify the tracker. Classes that extends the TrackableSyncSource should invoke this method at the end of their processing in the updateItem so that the tracker is properly updated. Otherwise they are in charge of notifying the tracker.

Specified by:
updateItem in interface SyncSource
Parameters:
item - is the item being updated
Returns:
SUCCESS if the tracker was successfully updated, GENERIC_ERROR otherwise
Throws:
SyncException - if an unrecoverable error occur, to stop the sync

deleteItem

public int deleteItem(java.lang.String key)
               throws SyncException
The purpose of this implementation is simply to notify the tracker. Classes that extends the TrackableSyncSource should invoke this method at the end of their processing in the updateItem so that the tracker is properly updated. Otherwise they are in charge of notifying the tracker.

Specified by:
deleteItem in interface SyncSource
Parameters:
key - is the key of the item being deleted
Returns:
SUCCESS if the tracker was successfully updated, GENERIC_ERROR otherwise
Throws:
SyncException - if an unrecoverable error occur, to stop the sync

getConfig

public SourceConfig getConfig()
Returns the config of the source. The client can use this method to obtain the config object and change some parameter. A setConfig() must be called to actually change the source configuration.

Specified by:
getConfig in interface SyncSource
Returns:
the config of the source

setConfig

public void setConfig(SourceConfig config)
Sets the config of the source. The client can use this method to change the config of the source configuration. This operation should not be done while the sync is in progress.

Specified by:
setConfig in interface SyncSource

getStatus

public int getStatus()
Returns the status of the sync source. The status is encoded as a bit mask of the STATUS_* values

Specified by:
getStatus in interface SyncSource

setListener

public void setListener(SyncListener listener)
Set a sync listener.

Specified by:
setListener in interface SyncSource
Parameters:
listener - the listener or null to remove it

getListener

public SyncListener getListener()
Returns the current listener (or null if not set)

Specified by:
getListener in interface SyncSource

getName

public java.lang.String getName()
Returns the name of the source

Specified by:
getName in interface SyncSource
Returns:
the name of the source

getSourceUri

public java.lang.String getSourceUri()
Returns the source URI

Specified by:
getSourceUri in interface SyncSource
Returns:
the absolute URI of the source

getType

public java.lang.String getType()
Returns the type of the source. The types are defined as mime-types, for instance * text/x-vcard).

Specified by:
getType in interface SyncSource
Returns:
the type of the source

getEncoding

public java.lang.String getEncoding()
Returns the encoding of the source. The encoding can be 'b64' or 'none' only. The standard defines also 'des' and '3des' but they are not implemented in this version of the APIs.

Specified by:
getEncoding in interface SyncSource
Returns:
the encoding of the source

getSyncMode

public int getSyncMode()
Returns the preferred sync mode of the source. The preferred sync mode is the one that the SyncManager sends to the server in the initialization phase. The server can respond with a different alert code, to force, for instance, a slow.

Specified by:
getSyncMode in interface SyncSource
Returns:
the preferred sync mode for this source

getFilter

public SyncFilter getFilter()
Returns the current filter for this SyncSource.

Specified by:
getFilter in interface SyncSource

setFilter

public void setFilter(SyncFilter filter)
Set a new filter for this SyncSource

Specified by:
setFilter in interface SyncSource

getClientItemsNumber

public int getClientItemsNumber()
Return the number of changes that the client will send during the session. This method, after the beginSync() call, should return the number of items to be sent to the server. The number of changes is computed by initXXXItems() during beginSync().

Specified by:
getClientItemsNumber in interface SyncSource
Returns:
number of items to sent, or -1 if unknown

getClientAddNumber

public int getClientAddNumber()
Return the number of new items (add) that the client will send during the session. This method, after the beginSync() call, should return the number of new items to be sent to the server. The number of changes is computed by initXXXItems() during beginSync().

Specified by:
getClientAddNumber in interface SyncSource
Returns:
number of items to sent, or -1 if unknown

getClientReplaceNumber

public int getClientReplaceNumber()
Return the number of replaced items that the client will send during the session. This method, after the beginSync() call, should return the number of replaced items to be sent to the server. The number of changes is computed by initXXXItems() during beginSync().

Specified by:
getClientReplaceNumber in interface SyncSource
Returns:
number of items to sent, or -1 if unknown

getClientDeleteNumber

public int getClientDeleteNumber()
Return the number of deleted items that the client will send during the session. This method, after the beginSync() call, should return the number of delted items to be sent to the server. The number of changes is computed by initXXXItems() during beginSync().

Specified by:
getClientDeleteNumber in interface SyncSource
Returns:
number of items to sent, or -1 if unknown

getServerItemsNumber

public int getServerItemsNumber()
Return the number of changes that the server will send during the session. This method, after the beginSync() call, should return the number of items to be sent to the server.

Specified by:
getServerItemsNumber in interface SyncSource
Returns:
number of changes from the server, or -1 if not announced.

setServerItemsNumber

public void setServerItemsNumber(int number)
Set the number of changes that the server will send during the session. This method is called by the engine to notify the Source of the number of changes announced by the server. If the server does not announce the number of changes, the engine will call this method with parameter -1.

Specified by:
setServerItemsNumber in interface SyncSource
Parameters:
number - of changes from the server, or -1 if not announced.

dataReceived

public void dataReceived(java.lang.String date,
                         int size)
Default implementation for

Specified by:
dataReceived in interface SyncSource

getLastAnchor

public long getLastAnchor()
Return the Last Anchor for this source

Specified by:
getLastAnchor in interface SyncSource

setLastAnchor

public void setLastAnchor(long time)
Set the value of the Last Anchor for this source

Specified by:
setLastAnchor in interface SyncSource

getNextAnchor

public long getNextAnchor()
Return the Next Anchor for this source

Specified by:
getNextAnchor in interface SyncSource

setNextAnchor

public void setNextAnchor(long time)
Set the value of the Next Anchor for this source

Specified by:
setNextAnchor in interface SyncSource

getAllItemsKeys

protected abstract java.util.Enumeration getAllItemsKeys()

getItemContent

protected abstract SyncItem getItemContent(SyncItem item)
                                    throws SyncException
Throws:
SyncException

deleteAllItems

protected abstract void deleteAllItems()
Physically delete all items



Copyright © 2001-2009 Funambol.