com.funambol.syncml.client
Class CacheTracker

java.lang.Object
  extended by com.funambol.syncml.client.CacheTracker
All Implemented Interfaces:
ChangesTracker

public class CacheTracker
extends java.lang.Object
implements ChangesTracker

This class implements a ChangesTracker and it is based on comparison of fingerprints. This means that the class can take a snapshot of the SyncSource and store it in a StringKeyValueStore (a parameter the client must provide). For each item in the SyncSource its fingerprint is stored in the store. When getNewItems, getUpdatedItems and getDeletedItems are invoked, they compare the SyncSource current state and the last snapshot and detect changes. By default MD5 is used to compute fingerprints, but the method can be redefined if a client wants to use a different method.


Field Summary
protected  java.util.Hashtable deletedItems
           
protected  java.util.Hashtable newItems
           
protected  TrackableSyncSource ss
           
protected  StringKeyValueStore status
           
protected  int syncMode
           
protected  java.util.Hashtable updatedItems
           
 
Constructor Summary
CacheTracker(StringKeyValueStore status)
          Creates a CacheTracker.
 
Method Summary
 void begin(int syncMode)
          This method allows implementations to get ready to return list of changes.
protected  java.lang.String computeFingerprint(SyncItem item)
           
 void empty()
          Empty the tracker status.
 void end()
          This method allows implementations to clean data.
protected  java.util.Hashtable getAllFilesFingerprint()
          Create an hashtable with all files and their fingerprints
 java.util.Enumeration getDeletedItems()
          Returns the list of deleted items.
 int getDeletedItemsCount()
          Returns the number of deleted items that will be returned by the getDeletedItems method
 java.util.Enumeration getNewItems()
          Returns the list of new items.
 int getNewItemsCount()
          Returns the number of new items that will be returned by the getNewItems method
 java.util.Enumeration getUpdatedItems()
          Returns the list of updated items.
 int getUpdatedItemsCount()
          Returns the number of deleted items that will be returned by the getDeletedItems method
protected  boolean isSuccess(int status)
           
 boolean removeItem(SyncItem item)
          Remove the given item from the list of changes
 void reset()
          This method cleans any pending change.
 void setItemStatus(java.lang.String key, int itemStatus)
          Set an item status returned by the server as result of the synchronization.
 void setSyncSource(TrackableSyncSource ss)
          Associates this tracker to the given sync source
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

newItems

protected java.util.Hashtable newItems

deletedItems

protected java.util.Hashtable deletedItems

updatedItems

protected java.util.Hashtable updatedItems

ss

protected TrackableSyncSource ss

status

protected StringKeyValueStore status

syncMode

protected int syncMode
Constructor Detail

CacheTracker

public CacheTracker(StringKeyValueStore status)
Creates a CacheTracker. The constructor detects changes so that the method to get the changes can be used right away

Parameters:
status - is the key value store with stored data
Method Detail

setSyncSource

public void setSyncSource(TrackableSyncSource ss)
Associates this tracker to the given sync source

Specified by:
setSyncSource in interface ChangesTracker
Parameters:
ss - the sync source

reset

public void reset()
           throws TrackerException
This method cleans any pending change. In the cache sync source this means that the fingerprint of each item is updated to its current value. The fingerprint tables will contain exactly the same items that are currently in the Sync source.

Specified by:
reset in interface ChangesTracker
Throws:
TrackerException

begin

public void begin(int syncMode)
           throws TrackerException
Description copied from interface: ChangesTracker
This method allows implementations to get ready to return list of changes. An implementation may decide to detect all changes at this point or not, the interface does not enforce any semantics on this. The only requirement is that any change made before this method is invoked must be part of the lists returned by other methods.

Specified by:
begin in interface ChangesTracker
Parameters:
syncMode - The sync mode
Throws:
TrackerException

end

public void end()
         throws TrackerException
Description copied from interface: ChangesTracker
This method allows implementations to clean data. After this method is invoked it is illegal to fetch list of changes. A new call to "begin" is required first.

Specified by:
end in interface ChangesTracker
Throws:
TrackerException

getNewItems

public java.util.Enumeration getNewItems()
                                  throws TrackerException
Returns the list of new items.

Specified by:
getNewItems in interface ChangesTracker
Returns:
the list of new items as an Enumeration of SyncItem
Throws:
TrackerException

getNewItemsCount

public int getNewItemsCount()
                     throws TrackerException
Returns the number of new items that will be returned by the getNewItems method

Specified by:
getNewItemsCount in interface ChangesTracker
Returns:
the number of items
Throws:
TrackerException

getUpdatedItems

public java.util.Enumeration getUpdatedItems()
                                      throws TrackerException
Returns the list of updated items.

Specified by:
getUpdatedItems in interface ChangesTracker
Returns:
the list of updated items as an Enumeration of SyncItem
Throws:
TrackerException

getUpdatedItemsCount

public int getUpdatedItemsCount()
                         throws TrackerException
Returns the number of deleted items that will be returned by the getDeletedItems method

Specified by:
getUpdatedItemsCount in interface ChangesTracker
Returns:
the number of items
Throws:
TrackerException

getDeletedItems

public java.util.Enumeration getDeletedItems()
                                      throws TrackerException
Returns the list of deleted items.

Specified by:
getDeletedItems in interface ChangesTracker
Returns:
the list of updated items as an Enumeration of strings (SyncItem's keys)
Throws:
TrackerException

getDeletedItemsCount

public int getDeletedItemsCount()
                         throws TrackerException
Returns the number of deleted items that will be returned by the getDeletedItems method

Specified by:
getDeletedItemsCount in interface ChangesTracker
Returns:
the number of items
Throws:
TrackerException

setItemStatus

public void setItemStatus(java.lang.String key,
                          int itemStatus)
                   throws TrackerException
Description copied from interface: ChangesTracker
Set an item status returned by the server as result of the synchronization. This method is needed by the tracker to decide if an item can be removed from the list of changes or it has to be kept for the next run

Specified by:
setItemStatus in interface ChangesTracker
Parameters:
key - the item key (cannot be null)
itemStatus - the syncml status for this item
Throws:
TrackerException

computeFingerprint

protected java.lang.String computeFingerprint(SyncItem item)

getAllFilesFingerprint

protected java.util.Hashtable getAllFilesFingerprint()
                                              throws SyncException
Create an hashtable with all files and their fingerprints

Returns:
Throws:
SyncException

isSuccess

protected boolean isSuccess(int status)

removeItem

public boolean removeItem(SyncItem item)
                   throws TrackerException
Description copied from interface: ChangesTracker
Remove the given item from the list of changes

Specified by:
removeItem in interface ChangesTracker
Parameters:
item - is the item to be removed
Returns:
true if an item was found and deleted
Throws:
TrackerException

empty

public void empty()
           throws TrackerException
Description copied from interface: ChangesTracker
Empty the tracker status. After this method is invoked all the items currently present will be reported as new items.

Specified by:
empty in interface ChangesTracker
Throws:
TrackerException


Copyright © 2001-2009 Funambol.