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
ConstructorDescriptionCreate 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 TypeMethodDescriptionvoid
addListener
(ISynchronizerChangeListener listener) Adds a listener to this synchronizer.void
Flush 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 ornull
if no base is cached.byte[]
getRemoteBytes
(IResource resource) Return the remote bytes that are cached for the given resource ornull
if no remote is cached.boolean
hasSyncBytes
(IResource resource) Return whether the given resource has sync bytes in the synchronizer.boolean
Returns whether the resource has been marked as ignored usingsetIgnored(IResource)
.boolean
isLocallyModified
(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.void
removeListener
(ISynchronizerChangeListener listener) Removes a listener previously registered with this synchronizer.boolean
removeRemoteBytes
(IResource resource) Remove the remote bytes associated with the resource.void
run
(IResource resourceRule, IWorkspaceRunnable runnable, IProgressMonitor monitor) Perform multiple sync state modifications and fire only a single change notification at the end.void
setBaseBytes
(IResource resource, byte[] baseBytes) Set the base bytes for the given resource.void
setIgnored
(IResource resource) Mark the resource as being ignored.boolean
setRemoteBytes
(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 theIResource
delta 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 ornull
if 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 returnfalse
for ignored resources andtrue
for non-existant resources that have base bytes cached.- Parameters:
resource
- the resource- Returns:
true
if 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 ornull
if 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:
true
if 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:
true
if 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:
true
if the resource is ignored.- Throws:
TeamException
- if an error occurs
-
setIgnored
Mark the resource as being ignored. Ignored resources are not returned by themembers
method, 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
-