Class ContextManager

java.lang.Object
org.terracotta.context.ContextManager
Direct Known Subclasses:
StatisticsManager

public class ContextManager extends Object
A ContextManager instances allows for rooting, querying and access to select portions of the global context graph.
  • Field Details

  • Constructor Details

    • ContextManager

      public ContextManager()
  • Method Details

    • associate

      public static ContextManager.Association associate(Object object)
      Create an Association instance for the supplied object.
      Parameters:
      object - the object to be associated
      Returns:
      an association instance
    • dissociate

      public static ContextManager.Dissociation dissociate(Object object)
      Create a Dissociation instance for the supplied object.
      Parameters:
      object - the object to be dissociated
      Returns:
      a dissociation instance
    • nodeFor

      public static TreeNode nodeFor(Object object)
      Return the TreeNode associated with this object.

      Returns null if the supplied object has no associated context node.

      Parameters:
      object - object to lookup node for
      Returns:
      TreeNode associated with this object
    • registerContextCreationListener

      public static void registerContextCreationListener(ContextCreationListener listener)
    • deregisterContextCreationListener

      public static void deregisterContextCreationListener(ContextCreationListener listener)
    • associate

      private static void associate(Object child, Object parent)
    • dissociate

      private static void dissociate(Object child, Object parent)
    • getTreeNode

      private static MutableTreeNode getTreeNode(Object object)
    • getOrCreateTreeNode

      private static MutableTreeNode getOrCreateTreeNode(Object object)
    • discoverAssociations

      private static void discoverAssociations(Object origin)
    • contextCreated

      private static void contextCreated(Object object)
    • root

      public void root(Object object)
      Root the given object's context node in this ContextManager instance.
      Parameters:
      object - object whose context will be rooted
    • uproot

      public void uproot(Object object)
      Remove the given object's context node from this ContextManager root set.
      Parameters:
      object - object whose context will be uprooted
    • query

      public Set<TreeNode> query(Query query)
      Run the supplied Query against this ContextManager's root context.

      The initial node in the queries traversal will be the node whose children form the root set of this ContextManager. That is, the following code will select the root set of this instance.

       public static Set<TreeNode> roots(ContextManager manager) {
         return manager.query(QueryBuilder.queryBuilder().children().build());
       }
       
      Parameters:
      query - the query to execute
      Returns:
      the set of nodes selected by the query
    • queryForSingleton

      public TreeNode queryForSingleton(Query query) throws IllegalStateException
      Return the unique node selected by running this query against this ContextManager's root context.

      If this query does not return a single unique result then an IllegalStateException will be thrown. More details on the query execution context can be found in query(Query).

      Parameters:
      query - the query to execute
      Returns:
      the node selected by the query
      Throws:
      IllegalStateException - if the query does not select a unique node
      See Also:
    • registerContextListener

      public void registerContextListener(ContextListener listener)
      Registers a listener for additions and removals to this ContextManager's context graph.
      Parameters:
      listener - listener to be registered
    • deregisterContextListener

      public void deregisterContextListener(ContextListener listener)
      Removes a previously registered listener from the listener set.
      Parameters:
      listener - listener to be deregistered