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
ConstructorsConstructorDescriptionCreate an empty set.SyncInfoSet(SyncInfo[] infos) Create aSyncInfoSetcontaining the givenSyncInfoinstances. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd the givenSyncInfoto the set.voidaddAll(SyncInfoSet set) Add all the sync info from the given set to this set.voidaddError(ITeamStatus status) Add the error to the set.voidRegisters the given listener for sync info set notifications.voidThis method is used to obtain a lock on the set which ensures thread safety and batches change notification.voidclear()Reset the sync set so it is empty.voidconnect(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 usingaddChangeListenerand issued a reset event.longcountFor(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 SyncInfoSetChangeEventCreate an empty change event.voidendInput(IProgressMonitor monitor) This method is used to release the lock on this set.protected SyncInfoSetChangeEventReturn 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 theSyncInfofor the given resource ornullif the resource is not contained in the set.SyncInfo[]Return an array ofSyncInfofor all out-of-sync resources that are contained by the set.booleanReturnstrueif there are any conflicting nodes in the set, andfalseotherwise.booleanReturnstrueif this sync set has incoming changes.booleanhasNodes(FastSyncInfoFilter filter) Indicate whether the set has nodes matching the given filter.booleanReturnstrueif this sync set has outgoing changes.protected voidinternalAdd(SyncInfo info) Add theSyncInfoto the set, replacing any previously existing one.protected SyncInfointernalRemove(IResource resource) Remove the resource from the set, updating all internal data structures.booleanisEmpty()Return whether the set is empty.iterator()Return an iterator over allSyncInfocontained in this set.voidrejectNodes(FastSyncInfoFilter filter) Removes all nodes from this set that match the given filter leaving those that do not match the filter.voidRemove the given local resource from the set.voidRemove all the given resources from the set.voidRemoves all conflicting nodes from this set.voidRemoves all incoming nodes from this set.voidRemoves all outgoing nodes from this set.voidRemoves the given listener from participant notifications.protected voidReset the changes accumulated so far by this set.voidselectNodes(FastSyncInfoFilter filter) Removes all nodes from this set that do not match the given filter leaving only those that do match the filter.intsize()Return the number of out-of-sync resources contained in this set.
-
Constructor Details
-
SyncInfoSet
public SyncInfoSet()Create an empty set. -
SyncInfoSet
Create aSyncInfoSetcontaining the givenSyncInfoinstances.- Parameters:
infos- theSyncInfoinstances to be contained by this set
-
-
Method Details
-
getSyncInfos
Return an array ofSyncInfofor 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 theSyncInfofor the given resource ornullif the resource is not contained in the set.- Parameters:
resource- the resource- Returns:
- the
SyncInfofor the resource ornullif 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()Returnstrueif there are any conflicting nodes in the set, andfalseotherwise.- Returns:
trueif there are any conflicting nodes in the set, andfalseotherwise.
-
isEmpty
public boolean isEmpty()Return whether the set is empty.- Returns:
trueif the set is empty
-
internalAdd
Add theSyncInfoto 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
SyncInfothat 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 usingaddChangeListenerand 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
SyncInfoSetimplementation.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 givenSyncInfoto 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 whenendInputis 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()Returnstrueif this sync set has incoming changes. Note that conflicts are not considered to be incoming changes.- Returns:
trueif this sync set has incoming changes.
-
hasOutgoingChanges
public boolean hasOutgoingChanges()Returnstrueif this sync set has outgoing changes. Note that conflicts are not considered to be outgoing changes.- Returns:
trueif 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
endInputshould be done in a finally block as illustrated in the following code snippet.try { set.beginInput(); // do stuff } finally { set.endInput(progress); }Calls to
beginInputandendInputcan 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 theSyncInfofor 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 allSyncInfocontained in this set.- Returns:
- an iterator over all
SyncInfocontained in this set. - Since:
- 3.1
-