|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.funambol.syncclient.spds.source.FileSystemSyncSource
public class FileSystemSyncSource
This class implements a file system SyncSource. IMPORTANT NOTE: on FAT16/32 file system the last modified timestamp of a file is accurate with precision (...) of no more than 2 seconds (all timestamps have even seconds and no milliseconds). For instance, all times between 10:35:02,001 and 10:35:03,999 are rounded to 10:35:04,000. On this filesystem, the risk is to detect a change more times. On EXT2/3 file system the last modified timestamp of a file is accurate with precision (...) of no more than 1 seconds (all timestamps have not milliseconds). For instance, all times between 10:35:03,001 and 10:35:03,999 are truncated to 10:35:03,000. On this filesystem, the risk is to not detect a change because the update time is truncated. To avoid to detect a change more times (on FAT32) and to avoid to not detect a change (on EXT3), we round also the since timestamp according to the underlying FS.
Field Summary | |
---|---|
protected int |
counter
Counter used to create the name of the file created Adding an item |
static java.lang.String |
DATABASE_FILE_NAME
|
static java.lang.String |
DATABASE_HEADER
|
static java.lang.String |
FORMAT_BASE64
|
protected boolean |
isEXT3
|
protected boolean |
isFAT32
|
Constructor Summary | |
---|---|
FileSystemSyncSource()
Creates a new instance of FileSystemSyncSource |
Method Summary | |
---|---|
void |
beginSync(int type)
Called after SyncManager preparation and initialization just before start the synchronization of the SyncSource. |
void |
commitSync()
Called just before committing the synchronization process by the SyncManager. |
protected void |
emptyDataStore()
reset the syncDB removing all items |
void |
endSync()
|
protected SyncItem[] |
filterSyncItems(java.security.Principal principal,
java.util.Date since,
char state)
Filters the SyncItems in the synchronization database (after a refresh) based on the given principal, last sync timestamp and state (see SyncItemState). |
SyncItem[] |
getAllSyncItems(java.security.Principal principal)
Returns all items in the data store belonging to the given principal. |
SyncItem[] |
getDeletedSyncItems(java.security.Principal principal,
java.util.Date since)
Returns all deleted items belonging to the given principal and deleted after the given point in time. |
protected java.util.Vector |
getExistingFiles()
|
java.lang.String |
getName()
Returns the name of the source |
SyncItem[] |
getNewSyncItems(java.security.Principal principal,
java.util.Date since)
Returns all new items belonging to the given principal and created after the given point in time. |
java.lang.String |
getSourceDirectory()
|
java.lang.String |
getSourceDrive()
|
java.lang.String |
getSourceURI()
Getter for property uri. |
java.lang.String |
getType()
Returns the type of the source. |
protected java.lang.String |
getUniqueFileName()
Returns a unique filename created as: "timestamp-counter" |
SyncItem[] |
getUpdatedSyncItems(java.security.Principal principal,
java.util.Date since)
Returns all updated items belonging to the given principal and modified after the given point in time. |
boolean |
isEncode()
|
protected long |
lastModifiedFromStateString(java.lang.String state)
|
protected byte[] |
readFileContent(java.lang.String fileName)
Reads the content of the given file. |
protected void |
removeState(java.security.Principal principal,
java.lang.String file)
|
void |
removeSyncItem(java.security.Principal principal,
SyncItem syncItem)
Removes a SyncItem given its key. |
protected void |
restoreSyncDB()
remove old deleted files from syncDB |
protected long |
roundTime(long time)
Rounds the given time according to the underlying FS. |
protected long |
roundTimeEXT3(long time)
Rounds the given time according to the approximation done by the EXT3 filesystem. |
protected long |
roundTimeFAT32(long originalTime)
Rounds the given time according to the approximation done by the FAT32 filesystem. |
void |
setEncode(boolean encode)
|
void |
setEncode(java.lang.String encode)
|
void |
setName(java.lang.String name)
|
void |
setSourceDirectory(java.lang.String sourceDirectory)
|
void |
setSourceDrive(java.lang.String sourceDrive)
|
void |
setSourceURI(java.lang.String sourceURI)
Setter for property uri. |
protected void |
setState(java.security.Principal principal,
java.lang.String file,
char state,
long timestamp)
|
SyncItem |
setSyncItem(java.security.Principal principal,
SyncItem syncItem)
Replaces an existing SyncItem or adds a new SyncItem if it does not exist. |
void |
setType(java.lang.String type)
|
protected char |
stateFromStateString(java.lang.String state)
|
protected java.util.Properties |
updateSyncDatabase(java.security.Principal principal,
long since)
The synchronization database is stored in a file whose name is given by the value of the constant DATABASE_FILE_NAME prefixed by the user name and the device id. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DATABASE_FILE_NAME
public static final java.lang.String DATABASE_HEADER
public static final java.lang.String FORMAT_BASE64
protected int counter
protected boolean isFAT32
protected boolean isEXT3
Constructor Detail |
---|
public FileSystemSyncSource()
Method Detail |
---|
public void setSourceDrive(java.lang.String sourceDrive)
public java.lang.String getSourceDrive()
public void setSourceDirectory(java.lang.String sourceDirectory)
public java.lang.String getSourceDirectory()
public java.lang.String getName()
SyncSource
getName
in interface SyncSource
public void setName(java.lang.String name)
public java.lang.String getType()
SyncSource
getType
in interface SyncSource
public void setType(java.lang.String type)
public boolean isEncode()
public void setEncode(boolean encode)
public void setEncode(java.lang.String encode)
public java.lang.String getSourceURI()
getSourceURI
in interface SyncSource
public void setSourceURI(java.lang.String sourceURI)
sourceURI
- New value of property uri.public void beginSync(int type) throws SyncException
SyncSource
beginSync
in interface SyncSource
type
- the synchronization type: one of the values in
sync4j.framework.core.AlertCode
SyncException
- in case of error. This will stop the sync processpublic void endSync() throws SyncException
SyncException
public SyncItem[] getAllSyncItems(java.security.Principal principal) throws SyncException
SyncSource
getAllSyncItems
in interface SyncSource
principal
- not used, always null
SyncException
- in case of error (for instance if the
underlying data store runs into problems)public SyncItem[] getDeletedSyncItems(java.security.Principal principal, java.util.Date since) throws SyncException
SyncSource
getDeletedSyncItems
in interface SyncSource
principal
- the principal for which the data has to be considered
Null means all principalssince
- consider the changes since this point in time. Null means
all items regardless when they were changed.
SyncException
- in case of error (for instance if the
underlying data store runs into problems)public SyncItem[] getNewSyncItems(java.security.Principal principal, java.util.Date since) throws SyncException
SyncSource
getNewSyncItems
in interface SyncSource
principal
- not used, always nullsince
- consider the changes since this point in . Null means
all items regardless when they were changed.
SyncException
- in case of error (for instance if the
underlying data store runs into problems)public SyncItem[] getUpdatedSyncItems(java.security.Principal principal, java.util.Date since) throws SyncException
SyncSource
getUpdatedSyncItems
in interface SyncSource
principal
- not used, always nullsince
- consider the changes since this point in time. Null means
all items regardless when they were changed.
SyncException
public void removeSyncItem(java.security.Principal principal, SyncItem syncItem) throws SyncException
SyncSource
removeSyncItem
in interface SyncSource
principal
- not used, always nullsyncItem
- the item to remove
SyncException
- in case of error (for instance if the
underlying data store runs into problems)public SyncItem setSyncItem(java.security.Principal principal, SyncItem syncItem) throws SyncException
SyncSource
setSyncItem
in interface SyncSource
principal
- not used, always nullsyncItem
- the item to replace/add
SyncException
- in case of error (for instance if the
underlying data store runs into problems)public void commitSync()
SyncSource
commitSync
in interface SyncSource
protected java.util.Properties updateSyncDatabase(java.security.Principal principal, long since)
guest.FunambolTest.sync.dbThe database is a property file where each entry has the following format:
[filename]=[state][lastmodified_timestamp]For example:
readme.txt=U98928743098094
updateSyncDatabase works as follows:
1. Read the existing database (if it exists) 2. Scan the source directory getting all files in the directory 3. For each file f in the source directory 3.1. If f is already in the database 3.1.1. If f has been modified after the lastmodified_timestamp stored into the database 3.1.1.1. Set the state of the file to UPDATE and store the new lastmodified_timestamp 3.2. Else 3.2.1. Add f to the database setting its state to NEW and store the lastmodified_timestamp 3. End For each 4. For each file f in the database 4.1. If f does not exist in the source directory 4.1.1. Set the state to DELETED 5. End For each
At the end of the process, the updated database is saved and than returned.
protected long lastModifiedFromStateString(java.lang.String state)
protected char stateFromStateString(java.lang.String state)
protected java.util.Vector getExistingFiles() throws java.io.IOException
java.io.IOException
protected void setState(java.security.Principal principal, java.lang.String file, char state, long timestamp)
protected void removeState(java.security.Principal principal, java.lang.String file)
protected SyncItem[] filterSyncItems(java.security.Principal principal, java.util.Date since, char state) throws SyncException
principal
- principal. null means anysince
- last sync timestamp. null neans since everstate
- the state to use as filter
SyncException
protected byte[] readFileContent(java.lang.String fileName)
fileName
- the name of the file to read
protected void restoreSyncDB() throws SyncException
SyncException
protected void emptyDataStore() throws SyncException
SyncException
protected long roundTime(long time)
EXT3
the time is rounded
calling roundTimeEXT3
otherwise if this is
FAT32
the time is rounded calling
roundTimeFAT32
.
time
- the time to round
protected long roundTimeEXT3(long time)
time
- the time to round
protected long roundTimeFAT32(long originalTime)
time
- the time to round
protected java.lang.String getUniqueFileName()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |