public class Synchronizer extends Object implements IRemoteSynchronizer
Modifier and Type | Field and Description |
---|---|
static int |
ALWAYS |
int |
batchSize |
static int |
CANCELLED |
boolean |
dontSynchronizeDeletedItems
If this is true, then deleting an item on one database will not cause the item
to be deleted in the other.
|
boolean |
dontSyncJustDebug
This goes through the motion of synchronization but does not actually make any
changes to either database.
|
protected int |
lastConflictCommand |
static int |
LOCAL_TO_REMOTE |
int |
options |
static int |
REMOTE_TO_LOCAL |
boolean |
remoteToLocalOnly
If this is true then the local database will take entries from remote database
but not vice versa.
|
static int |
RESOLVE_LATER |
Time |
syncTime |
OPTION_SYNCHRONIZE_ALL_ENTRIES
Constructor and Description |
---|
Synchronizer(Database database) |
Modifier and Type | Method and Description |
---|---|
Handle |
actAsRemote(Object inputChannel,
Object outputChannel)
Setup this Synchronizer to act as the "Remote" portion of a synchronization
process, by accepting remote method calls over the specified channel.
|
void |
addEntries(Vector entries)
This marks the database as having being fully synchronized with another at a point in time.
|
static void |
addOrReplace(byte[] encodedEntry,
FoundEntries myEntriesSortedByOID)
Given an encoded remote entry, add or replace it in this database.
|
static void |
addOrReplace(DatabaseEntry entry,
FoundEntries myEntriesSortedByOID)
Given a remote entry, add or replace it in this database.
|
protected static int |
checkSort(Database database,
String sortName) |
void |
close()
This is called at the end of the syncrhonization.
|
int |
countDeletedEntries()
Returns the number of deleted entries.
|
int |
countRemoteDeletedEntries() |
int |
countRemoteUnsynchronizedEntries() |
int |
countUnsynchronizedEntries() |
void |
erase(long oid,
FoundEntries myEntriesSortedByOID)
Given the OID of an entry in the remote database, erase it completely from this database.
|
void |
eraseDeleted(int[] indexesToDelete,
int offset,
int length)
Erase the entries at the specified indexes.
|
void |
eraseDeleted(long oid)
This is called after an OID marked as deleted on this database has been
erased from the remote database.
|
void |
eraseDeletedOnRemote(int index) |
void |
eraseEntries(long[] oids,
int offset,
int length)
Erases the entries as specified by the OID values.
|
void |
eraseEntryOnRemote(long OID) |
static int |
findByOID(FoundEntries entries,
long oid)
This locates the entry with the specified OID.
|
FoundEntries |
getByOID(Handle h) |
static FoundEntries |
getByOID(Handle h,
Database database) |
long[] |
getDeletedEntries(int startIndex,
int count)
Returns an array of OID values for the specified deleted entries.
|
protected String |
getDisplayString(DatabaseEntry entry) |
static int |
getMatchingEntry(DatabaseEntry remoteEntry,
FoundEntries myEntriesSortedByOID) |
static long |
getOID(DatabaseEntry entry)
Get the OID for an entry.
|
long |
getRemoteDeletedEntry(int index) |
IRemoteSynchronizer |
getRemoteProxy(Object inputChannel,
Object outputChannel)
Get an IRemoteSynchronizer that is a proxy for a remote IRemoteSynchronizer
that is at the other end of the channel and which will receive remote method
calls over the channels.
|
byte[] |
getRemoteUnsynchronizedEntry(int index) |
protected String |
getResolveString(DatabaseEntry remote,
DatabaseEntry local) |
int |
getSetOptions(int toSet,
int toClear)
This will set the optionsToSet bits and clear the optionsToClear bits
and return the state of the options after the operation is done.
|
EntriesView |
getUnsynchronized(Handle h)
This gets all the unsynchronized entries, but not the deleted entries.
|
static EntriesView |
getUnsynchronized(Handle h,
Database database) |
static EntriesView |
getUnsynchronized(Handle h,
Database database,
int options) |
Vector |
getUnsynchronizedEntries(int startIndex,
int count)
Return a Vector containing byte[] values for each database entry
requested.
|
boolean |
isSynchronized(DatabaseEntry entry)
Returns the state of the synchronized flag.
|
static void |
markAsSynchronized(DatabaseEntry entry) |
static void |
markAsSynchronized(EntriesView entries,
int index)
This marks the entry at the specified index as being synchronized.
|
void |
markAsSynchronized(int[] indexes,
int offset,
int length)
Mark the entries in the unsynchronized list as being synchronized.
|
void |
markRemoteAsSynchronized(int index) |
int |
resolveConflict(DatabaseEntry remote,
DatabaseEntry local)
This must resolve a conflict when an item has been modified on both databases.
|
void |
sendEntryToRemote(DatabaseEntry de) |
Handle |
synchronize() |
boolean |
synchronize(Handle progress)
Deprecated.
use synchronize(Handle progress, IRemoteSynchronizer remote) instead.
|
boolean |
synchronize(Handle progress,
IRemoteSynchronizer remote) |
public Time syncTime
public int batchSize
public int options
protected int lastConflictCommand
public static final int REMOTE_TO_LOCAL
public static final int LOCAL_TO_REMOTE
public static final int RESOLVE_LATER
public static final int ALWAYS
public static final int CANCELLED
public boolean remoteToLocalOnly
public boolean dontSynchronizeDeletedItems
public boolean dontSyncJustDebug
public Synchronizer(Database database)
public int getSetOptions(int toSet, int toClear)
IRemoteSynchronizer
getSetOptions
in interface IRemoteSynchronizer
toSet
- any or none of the OPTION_XXX bits OR'ed together.toClear
- any or none of the OPTION_XXX bits OR'ed together.public Handle actAsRemote(Object inputChannel, Object outputChannel) throws IOException
After calling this method this Synchronizer will receive method calls in a separate Thread from the peer Synchronizer on the other side of the connection. This Thread should monitor the returned Handle and once it has stopped you can assume the synchronization is complete.
inputChannel
- this can be an InputStream, a BlockInputStream or
a Socket.outputChannel
- this can be an OutputStream, a BlockOutputStream or
a Socket.IOException
- on any IOException.public IRemoteSynchronizer getRemoteProxy(Object inputChannel, Object outputChannel) throws IOException
inputChannel
- this can be an InputStream, a BlockInputStream or
a Socket.outputChannel
- this can be an OutputStream, a BlockOutputStream or
a Socket.IOException
- on any IO error.protected static int checkSort(Database database, String sortName) throws IllegalStateException
IllegalStateException
public static EntriesView getUnsynchronized(Handle h, Database database) throws IOException, IllegalStateException
IOException
IllegalStateException
public static EntriesView getUnsynchronized(Handle h, Database database, int options) throws IOException, IllegalStateException
IOException
IllegalStateException
public EntriesView getUnsynchronized(Handle h) throws IOException, IllegalStateException
IOException
IllegalStateException
- If the database does not have the "_SortBySync" sortpublic static void markAsSynchronized(DatabaseEntry entry)
public static void markAsSynchronized(EntriesView entries, int index) throws IOException
IOException
public static FoundEntries getByOID(Handle h, Database database) throws IOException, IllegalStateException
IOException
IllegalStateException
public FoundEntries getByOID(Handle h) throws IOException, IllegalStateException
IOException
IllegalStateException
public static int findByOID(FoundEntries entries, long oid) throws IOException
entries
- The FoundEntries of all the entries.oid
- The oid looking for.IOException
public static long getOID(DatabaseEntry entry) throws IllegalStateException
entry
- The entry to look for.IllegalStateException
- if the entry does not have an OID assigned.public boolean isSynchronized(DatabaseEntry entry) throws IllegalStateException
entry
- The entry to check.IllegalStateException
- If synchronization data is not set in the entry.public static int getMatchingEntry(DatabaseEntry remoteEntry, FoundEntries myEntriesSortedByOID) throws IOException, IllegalStateException
IOException
IllegalStateException
public static void addOrReplace(byte[] encodedEntry, FoundEntries myEntriesSortedByOID) throws IOException, IllegalStateException
IOException
IllegalStateException
public static void addOrReplace(DatabaseEntry entry, FoundEntries myEntriesSortedByOID) throws IOException, IllegalStateException
IOException
IllegalStateException
public void eraseDeleted(long oid) throws IOException
oid
- The oid to erase.IOException
public void erase(long oid, FoundEntries myEntriesSortedByOID) throws IOException
IOException
public int countRemoteUnsynchronizedEntries() throws IOException
IOException
public int countRemoteDeletedEntries() throws IOException
IOException
public long getRemoteDeletedEntry(int index) throws IOException
IOException
public void eraseDeletedOnRemote(int index) throws IOException
IOException
public void eraseEntryOnRemote(long OID) throws IOException
IOException
public byte[] getRemoteUnsynchronizedEntry(int index) throws IOException
IOException
public void markRemoteAsSynchronized(int index) throws IOException
IOException
public void sendEntryToRemote(DatabaseEntry de) throws IOException
IOException
protected String getDisplayString(DatabaseEntry entry)
protected String getResolveString(DatabaseEntry remote, DatabaseEntry local)
public int resolveConflict(DatabaseEntry remote, DatabaseEntry local)
remote
- The remote entry.local
- The local entry.public void close()
public Handle synchronize()
public boolean synchronize(Handle progress) throws IOException
progress
- IOException
public boolean synchronize(Handle progress, IRemoteSynchronizer remote) throws IOException
IOException
public void addEntries(Vector entries) throws IOException
addEntries
in interface IRemoteSynchronizer
entries
- the list of entries, each one of which is a byte[].
Each of these is convereted to a DatabaseEntry using the decode()
method.IOException
public int countDeletedEntries() throws IOException
IRemoteSynchronizer
countDeletedEntries
in interface IRemoteSynchronizer
IOException
public int countUnsynchronizedEntries() throws IOException
countUnsynchronizedEntries
in interface IRemoteSynchronizer
IOException
public void eraseDeleted(int[] indexesToDelete, int offset, int length) throws IOException
IRemoteSynchronizer
eraseDeleted
in interface IRemoteSynchronizer
indexesToDelete
- the list of deleted intries to delete.offset
- the start of the indexes in the array.length
- the number of indexes to delete.IOException
public void eraseEntries(long[] oids, int offset, int length) throws IOException
IRemoteSynchronizer
eraseEntries
in interface IRemoteSynchronizer
oids
- the list entries to erase.offset
- the start of the OIDs in the array.length
- the number of OIDs to delete.IOException
public long[] getDeletedEntries(int startIndex, int count) throws IOException
IRemoteSynchronizer
getDeletedEntries
in interface IRemoteSynchronizer
startIndex
- the index of the first deleted entry.count
- the number of deleted entries to get.IOException
public Vector getUnsynchronizedEntries(int startIndex, int count) throws IOException
IRemoteSynchronizer
getUnsynchronizedEntries
in interface IRemoteSynchronizer
startIndex
- the first index in the unsynchronized list to get.count
- the number of database entries to get.IOException
public void markAsSynchronized(int[] indexes, int offset, int length) throws IOException
IRemoteSynchronizer
markAsSynchronized
in interface IRemoteSynchronizer
indexes
- the indexes to mark as synchronized.offset
- the start of the indexes in the array.length
- the number of indexes to delete.IOException