Package org.terracotta.context
Class ContextManager
- java.lang.Object
-
- org.terracotta.context.ContextManager
-
- Direct Known Subclasses:
StatisticsManager
public class ContextManager extends java.lang.ObjectAContextManagerinstances allows for rooting, querying and access to select portions of the global context graph.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceContextManager.AssociationCreates parent and child associations to the target context node.static interfaceContextManager.DissociationRemoves existing parent and child associations from the target context node.
-
Field Summary
Fields Modifier and Type Field Description private static WeakIdentityHashMap<java.lang.Object,MutableTreeNode>CONTEXT_OBJECTSprivate static java.util.Collection<ContextCreationListener>contextCreationListenersprivate static org.slf4j.LoggerLOGGERprivate RootNoderoot
-
Constructor Summary
Constructors Constructor Description ContextManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ContextManager.Associationassociate(java.lang.Object object)Create anAssociationinstance for the supplied object.private static voidassociate(java.lang.Object child, java.lang.Object parent)private static voidcontextCreated(java.lang.Object object)static voidderegisterContextCreationListener(ContextCreationListener listener)voidderegisterContextListener(ContextListener listener)Removes a previously registered listener from the listener set.private static voiddiscoverAssociations(java.lang.Object origin)static ContextManager.Dissociationdissociate(java.lang.Object object)Create aDissociationinstance for the supplied object.private static voiddissociate(java.lang.Object child, java.lang.Object parent)private static MutableTreeNodegetOrCreateTreeNode(java.lang.Object object)private static MutableTreeNodegetTreeNode(java.lang.Object object)static TreeNodenodeFor(java.lang.Object object)Return theTreeNodeassociated with this object.java.util.Set<TreeNode>query(Query query)Run the suppliedQueryagainst thisContextManager's root context.TreeNodequeryForSingleton(Query query)Return the unique node selected by running this query against thisContextManager's root context.static voidregisterContextCreationListener(ContextCreationListener listener)voidregisterContextListener(ContextListener listener)Registers a listener for additions and removals to thisContextManager's context graph.voidroot(java.lang.Object object)Root the given object's context node in thisContextManagerinstance.voiduproot(java.lang.Object object)Remove the given object's context node from thisContextManagerroot set.
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
CONTEXT_OBJECTS
private static final WeakIdentityHashMap<java.lang.Object,MutableTreeNode> CONTEXT_OBJECTS
-
contextCreationListeners
private static final java.util.Collection<ContextCreationListener> contextCreationListeners
-
root
private final RootNode root
-
-
Method Detail
-
associate
public static ContextManager.Association associate(java.lang.Object object)
Create anAssociationinstance for the supplied object.- Parameters:
object- the object to be associated- Returns:
- an association instance
-
dissociate
public static ContextManager.Dissociation dissociate(java.lang.Object object)
Create aDissociationinstance for the supplied object.- Parameters:
object- the object to be dissociated- Returns:
- a dissociation instance
-
nodeFor
public static TreeNode nodeFor(java.lang.Object object)
Return theTreeNodeassociated with this object.Returns
nullif the supplied object has no associated context node.- Parameters:
object- object to lookup node for- Returns:
TreeNodeassociated with this object
-
registerContextCreationListener
public static void registerContextCreationListener(ContextCreationListener listener)
-
deregisterContextCreationListener
public static void deregisterContextCreationListener(ContextCreationListener listener)
-
associate
private static void associate(java.lang.Object child, java.lang.Object parent)
-
dissociate
private static void dissociate(java.lang.Object child, java.lang.Object parent)
-
getTreeNode
private static MutableTreeNode getTreeNode(java.lang.Object object)
-
getOrCreateTreeNode
private static MutableTreeNode getOrCreateTreeNode(java.lang.Object object)
-
discoverAssociations
private static void discoverAssociations(java.lang.Object origin)
-
contextCreated
private static void contextCreated(java.lang.Object object)
-
root
public void root(java.lang.Object object)
Root the given object's context node in thisContextManagerinstance.- Parameters:
object- object whose context will be rooted
-
uproot
public void uproot(java.lang.Object object)
Remove the given object's context node from thisContextManagerroot set.- Parameters:
object- object whose context will be uprooted
-
query
public java.util.Set<TreeNode> query(Query query)
Run the suppliedQueryagainst thisContextManager'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 java.lang.IllegalStateException
Return the unique node selected by running this query against thisContextManager's root context.If this query does not return a single unique result then an
IllegalStateExceptionwill be thrown. More details on the query execution context can be found inquery(Query).- Parameters:
query- the query to execute- Returns:
- the node selected by the query
- Throws:
java.lang.IllegalStateException- if the query does not select a unique node- See Also:
query(Query),QueryBuilder.ensureUnique()
-
registerContextListener
public void registerContextListener(ContextListener listener)
Registers a listener for additions and removals to thisContextManager'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
-
-