Class SyncInfoSet
- Direct Known Subclasses:
SyncInfoTree
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 Summary
ConstructorDescriptionCreate an empty set.SyncInfoSet
(SyncInfo[] infos) Create aSyncInfoSet
containing the givenSyncInfo
instances. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add the givenSyncInfo
to the set.void
addAll
(SyncInfoSet set) Add all the sync info from the given set to this set.void
addError
(ITeamStatus status) Add the error to the set.void
Registers the given listener for sync info set notifications.void
This method is used to obtain a lock on the set which ensures thread safety and batches change notification.void
clear()
Reset the sync set so it is empty.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 usingaddChangeListener
and issued a reset event.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.protected SyncInfoSetChangeEvent
Create an empty change event.void
endInput
(IProgressMonitor monitor) This method is used to release the lock on this set.protected SyncInfoSetChangeEvent
Return the change event that is accumulating the changes to the set.Return an array of the errors the occurred while populating this set.protected ISyncInfoSetChangeListener[]
Return a copy of all the listeners registered with this setSyncInfo[]
getNodes
(FastSyncInfoFilter filter) Return all nodes in this set that match the given filter.Return all out-of-sync resources contained in this set.getSyncInfo
(IResource resource) Return theSyncInfo
for the given resource ornull
if the resource is not contained in the set.SyncInfo[]
Return an array ofSyncInfo
for all out-of-sync resources that are contained by the set.boolean
Returnstrue
if there are any conflicting nodes in the set, andfalse
otherwise.boolean
Returnstrue
if this sync set has incoming changes.boolean
hasNodes
(FastSyncInfoFilter filter) Indicate whether the set has nodes matching the given filter.boolean
Returnstrue
if this sync set has outgoing changes.protected void
internalAdd
(SyncInfo info) Add theSyncInfo
to the set, replacing any previously existing one.protected SyncInfo
internalRemove
(IResource resource) Remove the resource from the set, updating all internal data structures.boolean
isEmpty()
Return whether the set is empty.iterator()
Return an iterator over allSyncInfo
contained in this set.void
rejectNodes
(FastSyncInfoFilter filter) Removes all nodes from this set that match the given filter leaving those that do not match the filter.void
Remove the given local resource from the set.void
Remove all the given resources from the set.void
Removes all conflicting nodes from this set.void
Removes all incoming nodes from this set.void
Removes all outgoing nodes from this set.void
Removes the given listener from participant notifications.protected void
Reset the changes accumulated so far by this set.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.int
size()
Return the number of out-of-sync resources contained in this set.
-
Constructor Details
-
SyncInfoSet
public SyncInfoSet()Create an empty set. -
SyncInfoSet
Create aSyncInfoSet
containing the givenSyncInfo
instances.- Parameters:
infos
- theSyncInfo
instances to be contained by this set
-
-
Method Details
-
getSyncInfos
Return an array ofSyncInfo
for all out-of-sync resources that are contained by the set.- Returns:
- an array of
SyncInfo
-
getResources
Return all out-of-sync resources contained in this set. The default implementation usesgetSyncInfos()
to determine the resources contained in the set. Subclasses may override to optimize.- Returns:
- all out-of-sync resources contained in the set
-
getSyncInfo
Return theSyncInfo
for the given resource ornull
if the resource is not contained in the set.- Parameters:
resource
- the resource- Returns:
- the
SyncInfo
for the resource ornull
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 kindmask
- the sync kind mask- Returns:
- the number of matching resources in the set.
-
hasConflicts
public boolean hasConflicts()Returnstrue
if there are any conflicting nodes in the set, andfalse
otherwise.- Returns:
true
if there are any conflicting nodes in the set, andfalse
otherwise.
-
isEmpty
public boolean isEmpty()Return whether the set is empty.- Returns:
true
if the set is empty
-
internalAdd
Add theSyncInfo
to the set, replacing any previously existing one.- Parameters:
info
- the newSyncInfo
-
internalRemove
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
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
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
Connect the listener to the sync set in such a fashion that the listener will be connected the the sync set usingaddChangeListener
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 setmonitor
- a progress monitor
-
add
Add the givenSyncInfo
to the set. A change event will be generated unless the call to this method is nested in between calls tobeginInput()
andendInput(IProgressMonitor)
in which case the event for this addition and any other sync set change will be fired in a batched event whenendInput
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 withinbeginInput/endInput
.- Parameters:
info
- the sync info to be added to this set.
-
addAll
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
Remove the given local resource from the set.- Parameters:
resource
- the local resource to remove
-
removeAll
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
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
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
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
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()Returnstrue
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()Returnstrue
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 anorg.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
andendInput
can be nested and must be matched. -
endInput
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
Create an empty change event. Subclass may override to provided specialized event types- Returns:
- an empty change event
- Since:
- 3.5
-
getListeners
Return a copy of all the listeners registered with this set- Returns:
- the listeners
-
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
Add the error to the set. Errors should be added to the set when the client populating the set cannot determine theSyncInfo
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
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
Return an iterator over allSyncInfo
contained in this set.- Returns:
- an iterator over all
SyncInfo
contained in this set. - Since:
- 3.1
-