Package org.eclipse.team.core.variants
Class ThreeWaySynchronizer
java.lang.Object
org.eclipse.team.core.variants.ThreeWaySynchronizer
This class manages the synchronization between local resources and their
corresponding resource variants. It provides the following:
- Three way synchronization (set base, set remote, ignored)
- Resource traversal (members)
- Change events and event batching (run)
- Thread-safety
- Since:
- 3.0
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a three-way synchronizer that uses a persistent byte store with the given qualified name as its unique identifier.Create a three-way synchronizer that uses the given byte store as its underlying byte cache. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(ISynchronizerChangeListener listener) Adds a listener to this synchronizer.voidFlush any cached bytes for the given resource to the depth specified.byte[]getBaseBytes(IResource resource) Return the base bytes that are cached for the given resource ornullif no base is cached.byte[]getRemoteBytes(IResource resource) Return the remote bytes that are cached for the given resource ornullif no remote is cached.booleanhasSyncBytes(IResource resource) Return whether the given resource has sync bytes in the synchronizer.booleanReturns whether the resource has been marked as ignored usingsetIgnored(IResource).booleanisLocallyModified(IResource resource) Return whether the local resource has been modified since the last time the base bytes were set.Return the members of the local resource that either have sync bytes or exist locally and are not ignored.voidremoveListener(ISynchronizerChangeListener listener) Removes a listener previously registered with this synchronizer.booleanremoveRemoteBytes(IResource resource) Remove the remote bytes associated with the resource.voidrun(IResource resourceRule, IWorkspaceRunnable runnable, IProgressMonitor monitor) Perform multiple sync state modifications and fire only a single change notification at the end.voidsetBaseBytes(IResource resource, byte[] baseBytes) Set the base bytes for the given resource.voidsetIgnored(IResource resource) Mark the resource as being ignored.booleansetRemoteBytes(IResource resource, byte[] remoteBytes) Set the remote bytes for the given resource.
-
Constructor Details
-
ThreeWaySynchronizer
Create a three-way synchronizer that uses a persistent byte store with the given qualified name as its unique identifier.- Parameters:
name- the unique identifier for the persistent store
-
ThreeWaySynchronizer
Create a three-way synchronizer that uses the given byte store as its underlying byte cache.- Parameters:
store- the byte store this synchronizer uses to cache its bytes
-
-
Method Details
-
addListener
Adds a listener to this synchronizer. Listeners will be notified when the synchronization state of a resource changes. Listeners are not notified when files are modified locally. Clients can make use of theIResourcedelta mechanism if they need to know about local modifications. Has no effect if an identical listener is already registered.Team resource change listeners are informed about state changes that affect the resources supervised by this subscriber.
- Parameters:
listener- a synchronizer change listener
-
removeListener
Removes a listener previously registered with this synchronizer. Has no effect if an identical listener is not registered.- Parameters:
listener- a synchronizer change listener
-
getBaseBytes
Return the base bytes that are cached for the given resource ornullif no base is cached. The returned bytes should uniquely identify the resource variant that is the base for the given local resource.- Parameters:
resource- the resource- Returns:
- the base bytes cached with the resource or
null - Throws:
TeamException- if an error occurs
-
setBaseBytes
Set the base bytes for the given resource. The provided bytes should encode enough information to uniquely identify (and possibly recreate) the resource variant that is the base for the given local resource. In essence, setting the base bytes is equivalent to marking the file as in-sync. As such, setting the base bytes will also set the remote bytes and mark the file as clean (i.e. having no outgoing changes).- Parameters:
resource- the resourcebaseBytes- the base bytes that identify the base resource variant- Throws:
TeamException- if an error occurs
-
isLocallyModified
Return whether the local resource has been modified since the last time the base bytes were set. This method will returnfalsefor ignored resources andtruefor non-existant resources that have base bytes cached.- Parameters:
resource- the resource- Returns:
trueif the resource has been modified since the last time the base bytes were set.- Throws:
TeamException- if an error occurs
-
getRemoteBytes
Return the remote bytes that are cached for the given resource ornullif no remote is cached. The returned bytes should uniquely identify the resource variant that is the remote for the given local resource.- Parameters:
resource- the resource- Returns:
- the remote bytes cached with the resource or
null - Throws:
TeamException- if an error occurs
-
setRemoteBytes
Set the remote bytes for the given resource. The provided bytes should encode enough information to uniquely identify (and possibly recreate) the resource variant that is the remote for the given local resource. If the remote for a resource no longer exists,removeRemoteBytes(IResource)should be called.- Parameters:
resource- the resourceremoteBytes- the base bytes that identify the remote resource variant- Returns:
trueif the remote bytes changed as a result of the set- Throws:
TeamException- if an error occurs
-
removeRemoteBytes
Remove the remote bytes associated with the resource. This is typically done when the corresponding remote resource variant no longer exists.- Parameters:
resource- the resource- Returns:
trueif the remote bytes changed as a result of the removal- Throws:
TeamException- if an error occurs
-
hasSyncBytes
Return whether the given resource has sync bytes in the synchronizer.- Parameters:
resource- the local resource- Returns:
- whether there are sync bytes cached for the local resources.
- Throws:
TeamException- if an error occurs
-
isIgnored
Returns whether the resource has been marked as ignored usingsetIgnored(IResource).- Parameters:
resource- the resource- Returns:
trueif the resource is ignored.- Throws:
TeamException- if an error occurs
-
setIgnored
Mark the resource as being ignored. Ignored resources are not returned by themembersmethod, are never dirty (seeisLocallyModified) and do not have base or remote bytes cached for them.- Parameters:
resource- the resource to be ignored- Throws:
TeamException- if an error occurs
-
members
Return the members of the local resource that either have sync bytes or exist locally and are not ignored.- Parameters:
resource- the local resource- Returns:
- the children of the local resource that have cached sync bytes or are not ignored
- Throws:
TeamException- if an error occurs
-
flush
Flush any cached bytes for the given resource to the depth specified.- Parameters:
resource- the resourcedepth- the depth of the flush (one ofIResource.DEPTH_ZERO,IResource.DEPTH_ONE, orIResource.DEPTH_INFINITE)- Throws:
TeamException- if an error occurs
-
run
public void run(IResource resourceRule, IWorkspaceRunnable runnable, IProgressMonitor monitor) throws TeamException Perform multiple sync state modifications and fire only a single change notification at the end.- Parameters:
resourceRule- the scheduling rule that encompasses all modificationsrunnable- the runnable that performs the sync state modificationsmonitor- a progress monitor- Throws:
TeamException- if an error occurs
-