Class ThreeWaySynchronizer

java.lang.Object
org.eclipse.team.core.variants.ThreeWaySynchronizer

public class ThreeWaySynchronizer extends Object
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 Details

    • ThreeWaySynchronizer

      public ThreeWaySynchronizer(QualifiedName name)
      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

      public ThreeWaySynchronizer(ResourceVariantByteStore store)
      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

      public void addListener(ISynchronizerChangeListener listener)
      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 the IResource 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

      public void removeListener(ISynchronizerChangeListener listener)
      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

      public byte[] getBaseBytes(IResource resource) throws TeamException
      Return the base bytes that are cached for the given resource or null 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

      public void setBaseBytes(IResource resource, byte[] baseBytes) throws TeamException
      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 resource
      baseBytes - the base bytes that identify the base resource variant
      Throws:
      TeamException - if an error occurs
    • isLocallyModified

      public boolean isLocallyModified(IResource resource) throws TeamException
      Return whether the local resource has been modified since the last time the base bytes were set. This method will return false for ignored resources and true 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

      public byte[] getRemoteBytes(IResource resource) throws TeamException
      Return the remote bytes that are cached for the given resource or null 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

      public boolean setRemoteBytes(IResource resource, byte[] remoteBytes) throws TeamException
      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 resource
      remoteBytes - 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

      public boolean removeRemoteBytes(IResource resource) throws TeamException
      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

      public boolean hasSyncBytes(IResource resource) throws TeamException
      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

      public boolean isIgnored(IResource resource) throws TeamException
      Returns whether the resource has been marked as ignored using setIgnored(IResource).
      Parameters:
      resource - the resource
      Returns:
      true if the resource is ignored.
      Throws:
      TeamException - if an error occurs
    • setIgnored

      public void setIgnored(IResource resource) throws TeamException
      Mark the resource as being ignored. Ignored resources are not returned by the members method, are never dirty (see isLocallyModified) 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

      public IResource[] members(IResource resource) throws TeamException
      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

      public void flush(IResource resource, int depth) throws TeamException
      Flush any cached bytes for the given resource to the depth specified.
      Parameters:
      resource - the resource
      depth - the depth of the flush (one of IResource.DEPTH_ZERO, IResource.DEPTH_ONE, or IResource.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 modifications
      runnable - the runnable that performs the sync state modifications
      monitor - a progress monitor
      Throws:
      TeamException - if an error occurs