Class ThreadedModelResolver

java.lang.Object
org.eclipse.emf.compare.ide.ui.logical.AbstractModelResolver
org.eclipse.emf.compare.ide.ui.internal.logical.resolver.ThreadedModelResolver
All Implemented Interfaces:
IModelResolver, IGraphConsumer

public class ThreadedModelResolver extends AbstractModelResolver implements IGraphConsumer
This implementation of an IModelResolver will look up all of the models located in a set container level of the "starting point" (by default, the containing project) to construct the graph of dependencies between these models.

Once this graph is created for the "local" resource, the right and origin (if any) resources will be inferred from the same traversal of resources, though this time expanded with a "top-down" approach : load all models of the traversal from the remote side, then resolve their containment tree to check whether there are other remote resources in the logical model that do not (or "that no longer) exist locally and thus couldn't be discovered in the first resolution phase. Note that this will be looped in order to determine whether the resource is really inexistent locally, or if on the contrary, it is a new dependency that's been added remotely; in which case we need to start from the local resolution again : the local resource may have changed locally and depend on other again.

All model loading will happen concurrently. At first, a distinct thread will be launched to resolve every model discovered in the container we're browsing. Then, each thread can and will launch separate threads to resolve the set of dependencies discovered "under" the model they are in charge of resolving.

No model will be loaded twice, since this will be aware of what models have already been resolved, thus ignoring duplicate resolving demands.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    canResolve(org.eclipse.core.resources.IStorage sourceStorage)
    This will be used in order to determine whether this resolver can be used for the given storage.
    createContext(com.google.common.eventbus.EventBus eventBus, IGraph<URI> aGraph)
    For testing purposes, this method is protected.
    void
    This will be called when the contributing plugin of this class is about to be stopped.
    Convert the dependency graph to its read-only version.
    Getter for the ID of the Resource Graph.
    void
    This will be called as soon as the class is created by the registry.
    resolveLocalModel(org.eclipse.core.resources.IResource start, org.eclipse.core.runtime.IProgressMonitor monitor)
    This will be called by Team in order to determine whether a given file can be compared alone, or if it needs to be compared along with others (and, thus, compared from the synchronize view).
    resolveLocalModels(org.eclipse.core.resources.IResource left, org.eclipse.core.resources.IResource right, org.eclipse.core.resources.IResource origin, org.eclipse.core.runtime.IProgressMonitor monitor)
    Called by EMF Compare in order to resolve the logical models corresponding to the given IResources.
    resolveModels(IStorageProviderAccessor storageAccessor, org.eclipse.core.resources.IStorage left, org.eclipse.core.resources.IStorage right, org.eclipse.core.resources.IStorage origin, org.eclipse.core.runtime.IProgressMonitor monitor)
    This will be called by EMF Compare in order to resolve the whole logical models containing the given storages.
    void
    Setter for the URI Graph istance.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • ThreadedModelResolver

      public ThreadedModelResolver()
  • Method Details

    • getGraphView

      public IGraphView<URI> getGraphView()
      Convert the dependency graph to its read-only version.
      Specified by:
      getGraphView in interface IGraphConsumer
      Returns:
      a read-only version of the dependency graph associated to this model resolver.
    • initialize

      public void initialize()
      This will be called as soon as the class is created by the registry. Clients can override if they need to set up their resolver for use. When initialized, the ThreadedModelResolver will:
      1. install a listener on the workspace to keep track of modified resources
      2. Register its #graphUpdater to its #eventBus
      3. initialize its #scheduler
      Specified by:
      initialize in interface IModelResolver
      Overrides:
      initialize in class AbstractModelResolver
      See Also:
    • dispose

      public void dispose()
      This will be called when the contributing plugin of this class is about to be stopped. Clients can override to get rid of any state they've maintained within their resolver.
      Specified by:
      dispose in interface IModelResolver
      Overrides:
      dispose in class AbstractModelResolver
      See Also:
    • createContext

      protected DefaultResolutionContext createContext(com.google.common.eventbus.EventBus eventBus, IGraph<URI> aGraph)
      For testing purposes, this method is protected.
      Parameters:
      eventBus -
      aGraph -
      Returns:
      The resolution context to use.
    • canResolve

      public boolean canResolve(org.eclipse.core.resources.IStorage sourceStorage)
      This will be used in order to determine whether this resolver can be used for the given storage. For each given storage, the resolver with the highest ranking will be selected for resolution. This test should be fast.
      Specified by:
      canResolve in interface IModelResolver
      Parameters:
      sourceStorage - The resource we're trying to resolve the logical model of. This will always be the "source" or "left" variant of the compared resource.
      Returns:
      true if this resolver is capable of handling the given storage, false otherwise.
    • resolveLocalModel

      public StorageTraversal resolveLocalModel(org.eclipse.core.resources.IResource start, org.eclipse.core.runtime.IProgressMonitor monitor) throws InterruptedException
      This will be called by Team in order to determine whether a given file can be compared alone, or if it needs to be compared along with others (and, thus, compared from the synchronize view). Note that only local data is available here.

      Note that no two threads will be able to resolve models at once : all three "resolve*" methods will lock internally to prevent multiple resolutions at once. Though this shouldn't happen unless the user calls multiple comparisons one after the other in quick succession, we use this locking to prevent potential unforeseen interactions.

      Specified by:
      resolveLocalModel in interface IModelResolver
      Parameters:
      start - The workspace resource for which we need a traversal.
      monitor - Monitor on which to report progress to the user.
      Returns:
      A traversal corresponding to all resources composing the given file's logical model.
      Throws:
      InterruptedException - Thrown if the resolution is cancelled or interrupted one way or another.
    • resolveLocalModels

      public SynchronizationModel resolveLocalModels(org.eclipse.core.resources.IResource left, org.eclipse.core.resources.IResource right, org.eclipse.core.resources.IResource origin, org.eclipse.core.runtime.IProgressMonitor monitor) throws InterruptedException
      Called by EMF Compare in order to resolve the logical models corresponding to the given IResources. Only local data is available.

      Note that no two threads will be able to resolve models at once : all three "resolve*" methods will lock internally to prevent multiple resolutions at once. Though this shouldn't happen unless the user calls multiple comparisons one after the other in quick succession, we use this locking to prevent potential unforeseen interactions.

      Specified by:
      resolveLocalModels in interface IModelResolver
      Parameters:
      left - The file that will be considered as the "starting point" of the traversal to resolve as the left logical model.
      right - "starting point" of the traversal to resolve as the right logical model.
      origin - "starting point" of the traversal to resolve as the origin logical model (common ancestor of left and right). Can be null.
      monitor - Monitor on which to report progress to the user.
      Returns:
      A traversal corresponding to all resources composing the given file's logical model.
      Throws:
      InterruptedException - Thrown if the resolution is cancelled or interrupted one way or another.
    • resolveModels

      public SynchronizationModel resolveModels(IStorageProviderAccessor storageAccessor, org.eclipse.core.resources.IStorage left, org.eclipse.core.resources.IStorage right, org.eclipse.core.resources.IStorage origin, org.eclipse.core.runtime.IProgressMonitor monitor) throws InterruptedException
      This will be called by EMF Compare in order to resolve the whole logical models containing the given storages. Since this may be either a local or remote model, all I/O should go through the given storage accessor.

      Note that no two threads will be able to resolve models at once : all three "resolve*" methods will lock internally to prevent multiple resolutions at once. Though this shouldn't happen unless the user calls multiple comparisons one after the other in quick succession, we use this locking to prevent potential unforeseen interactions.

      Specified by:
      resolveModels in interface IModelResolver
      Parameters:
      storageAccessor - The accessor that can be used to retrieve synchronization information between our resources.
      left - The storage that will be considered as the "starting point" of the traversal to resolve as the left logical model.
      right - "starting point" of the traversal to resolve as the right logical model.
      origin - "starting point" of the traversal to resolve as the origin logical model (common ancestor of left and right). Can be null.
      monitor - Monitor on which to report progress to the user.
      Returns:
      A traversal corresponding to all resources composing the given file's logical model.
      Throws:
      InterruptedException - Thrown if the resolution is cancelled or interrupted one way or another.
    • getId

      public String getId()
      Getter for the ID of the Resource Graph.
      Specified by:
      getId in interface IGraphConsumer
      Returns:
      the consumer id
    • setGraph

      public void setGraph(IGraph<URI> graph)
      Setter for the URI Graph istance.
      Specified by:
      setGraph in interface IGraphConsumer
      Parameters:
      graph - The URI Graph