Class SyncInfoSet

java.lang.Object
org.eclipse.team.core.synchronize.SyncInfoSet
Direct Known Subclasses:
SyncInfoTree

public class SyncInfoSet extends Object
A dynamic collection of SyncInfo objects that provides change notification to registered listeners. Batching of change notifications can be accomplished using the beginInput/endInput methods.
Since:
3.0
See Also:
  • Constructor Details

    • SyncInfoSet

      public SyncInfoSet()
      Create an empty set.
    • SyncInfoSet

      public SyncInfoSet(SyncInfo[] infos)
      Create a SyncInfoSet containing the given SyncInfo instances.
      Parameters:
      infos - the SyncInfo instances to be contained by this set
  • Method Details

    • getSyncInfos

      public SyncInfo[] getSyncInfos()
      Return an array of SyncInfo for all out-of-sync resources that are contained by the set.
      Returns:
      an array of SyncInfo
    • getResources

      public IResource[] getResources()
      Return all out-of-sync resources contained in this set. The default implementation uses getSyncInfos() to determine the resources contained in the set. Subclasses may override to optimize.
      Returns:
      all out-of-sync resources contained in the set
    • getSyncInfo

      public SyncInfo getSyncInfo(IResource resource)
      Return the SyncInfo for the given resource or null if the resource is not contained in the set.
      Parameters:
      resource - the resource
      Returns:
      the SyncInfo for the resource or null if the resource is in-sync or doesn't have synchronization information in this set.
    • size

      public int size()
      Return the number of out-of-sync resources contained in this set.
      Returns:
      the size of the set.
      See Also:
    • countFor

      public long countFor(int kind, int mask)
      Return the number of out-of-sync resources in the given set whose sync kind matches the given kind and mask (e.g. (SyncInfo#getKind() & mask) == kind).

      For example, this will return the number of outgoing changes in the set:

       long outgoing = countFor(SyncInfo.OUTGOING, SyncInfo.DIRECTION_MASK);
       
      Parameters:
      kind - the sync kind
      mask - the sync kind mask
      Returns:
      the number of matching resources in the set.
    • hasConflicts

      public boolean hasConflicts()
      Returns true if there are any conflicting nodes in the set, and false otherwise.
      Returns:
      true if there are any conflicting nodes in the set, and false otherwise.
    • isEmpty

      public boolean isEmpty()
      Return whether the set is empty.
      Returns:
      true if the set is empty
    • internalAdd

      protected void internalAdd(SyncInfo info)
      Add the SyncInfo to the set, replacing any previously existing one.
      Parameters:
      info - the new SyncInfo
    • internalRemove

      protected SyncInfo internalRemove(IResource resource)
      Remove the resource from the set, updating all internal data structures.
      Parameters:
      resource - the resource to be removed
      Returns:
      the SyncInfo that was just removed
    • addSyncSetChangedListener

      public void addSyncSetChangedListener(ISyncInfoSetChangeListener listener)
      Registers the given listener for sync info set notifications. Has no effect if an identical listener is already registered.
      Parameters:
      listener - listener to register
    • removeSyncSetChangedListener

      public void removeSyncSetChangedListener(ISyncInfoSetChangeListener listener)
      Removes the given listener from participant notifications. Has no effect if listener is not already registered.
      Parameters:
      listener - listener to remove
    • clear

      public void clear()
      Reset the sync set so it is empty. Listeners are notified of the change.
    • connect

      public void connect(ISyncInfoSetChangeListener listener, IProgressMonitor monitor)
      Connect the listener to the sync set in such a fashion that the listener will be connected the the sync set using addChangeListener and issued a reset event. This is done to provide a means of connecting to the sync set and initializing a model based on the sync set without worrying about missing events.

      The reset event may be done in the context of this method invocation or may be done in another thread at the discretion of the SyncInfoSet implementation.

      Disconnecting is done by calling removeChangeListener. Once disconnected, a listener can reconnect to be re-initialized.

      Parameters:
      listener - the listener that should be connected to this set
      monitor - a progress monitor
    • add

      public void add(SyncInfo info)
      Add the given SyncInfo to the set. A change event will be generated unless the call to this method is nested in between calls to beginInput() and endInput(IProgressMonitor) in which case the event for this addition and any other sync set change will be fired in a batched event when endInput is invoked.

      Invoking this method outside of the above mentioned block will result in the endInput(IProgressMonitor) being invoked with a null progress monitor. If responsiveness is required, the client should always nest sync set modifications within beginInput/endInput.

      Parameters:
      info - the sync info to be added to this set.
    • addAll

      public void addAll(SyncInfoSet set)
      Add all the sync info from the given set to this set.
      Parameters:
      set - the set whose sync info should be added to this set
    • remove

      public void remove(IResource resource)
      Remove the given local resource from the set.
      Parameters:
      resource - the local resource to remove
    • removeAll

      public void removeAll(IResource[] resources)
      Remove all the given resources from the set.
      Parameters:
      resources - the resources to be removed
    • removeConflictingNodes

      public void removeConflictingNodes()
      Removes all conflicting nodes from this set.
    • removeOutgoingNodes

      public void removeOutgoingNodes()
      Removes all outgoing nodes from this set.
    • removeIncomingNodes

      public void removeIncomingNodes()
      Removes all incoming nodes from this set.
    • hasNodes

      public boolean hasNodes(FastSyncInfoFilter filter)
      Indicate whether the set has nodes matching the given filter.
      Parameters:
      filter - a sync info filter
      Returns:
      whether the set has nodes that match the filter
    • selectNodes

      public void selectNodes(FastSyncInfoFilter filter)
      Removes all nodes from this set that do not match the given filter leaving only those that do match the filter.
      Parameters:
      filter - a sync info filter
    • rejectNodes

      public void rejectNodes(FastSyncInfoFilter filter)
      Removes all nodes from this set that match the given filter leaving those that do not match the filter.
      Parameters:
      filter - a sync info filter
    • getNodes

      public SyncInfo[] getNodes(FastSyncInfoFilter filter)
      Return all nodes in this set that match the given filter.
      Parameters:
      filter - a sync info filter
      Returns:
      the nodes that match the filter
    • hasIncomingChanges

      public boolean hasIncomingChanges()
      Returns true if this sync set has incoming changes. Note that conflicts are not considered to be incoming changes.
      Returns:
      true if this sync set has incoming changes.
    • hasOutgoingChanges

      public boolean hasOutgoingChanges()
      Returns true if this sync set has outgoing changes. Note that conflicts are not considered to be outgoing changes.
      Returns:
      true if this sync set has outgoing changes.
    • beginInput

      public void beginInput()
      This method is used to obtain a lock on the set which ensures thread safety and batches change notification. If the set is locked by another thread, the calling thread will block until the lock becomes available. This method uses an org.eclipse.core.runtime.jobs.ILock.

      It is important that the lock is released after it is obtained. Calls to endInput should be done in a finally block as illustrated in the following code snippet.

       try {
              set.beginInput();
              // do stuff
       } finally {
              set.endInput(progress);
       }
       

      Calls to beginInput and endInput can be nested and must be matched.

    • endInput

      public void endInput(IProgressMonitor monitor)
      This method is used to release the lock on this set. The progress monitor is needed to allow listeners to perform long-running operations is response to the set change. The lock is held while the listeners are notified so listeners must be cautious in order to avoid deadlock.
      Parameters:
      monitor - a progress monitor
    • resetChanges

      protected void resetChanges()
      Reset the changes accumulated so far by this set. This method is not intended to be invoked or implemented by clients.
    • createEmptyChangeEvent

      protected SyncInfoSetChangeEvent createEmptyChangeEvent()
      Create an empty change event. Subclass may override to provided specialized event types
      Returns:
      an empty change event
      Since:
      3.5
    • getListeners

      protected ISyncInfoSetChangeListener[] getListeners()
      Return a copy of all the listeners registered with this set
      Returns:
      the listeners
    • getChangeEvent

      protected SyncInfoSetChangeEvent getChangeEvent()
      Return the change event that is accumulating the changes to the set. This can be called by subclasses to access the event.
      Returns:
      Returns the changes.
      Since:
      3.5
      Restriction:
      This method is not intended to be re-implemented or extended by clients.
    • addError

      public void addError(ITeamStatus status)
      Add the error to the set. Errors should be added to the set when the client populating the set cannot determine the SyncInfo for one or more resources due to an exception or some other problem. Listeners will be notified that an error occurred and can react accordingly.

      Only one error can be associated with a resource (which is obtained from the ITeamStatus). It is up to the client populating the set to ensure that the error associated with a resource contains all relevant information. The error will remain in the set until the set is reset.

      Parameters:
      status - the status that describes the error that occurred.
    • getErrors

      public ITeamStatus[] getErrors()
      Return an array of the errors the occurred while populating this set. The errors will remain with the set until it is reset.
      Returns:
      the errors
    • iterator

      public Iterator iterator()
      Return an iterator over all SyncInfo contained in this set.
      Returns:
      an iterator over all SyncInfo contained in this set.
      Since:
      3.1