Package org.terracotta.context
Class ContextManager
java.lang.Object
org.terracotta.context.ContextManager
- Direct Known Subclasses:
StatisticsManager
A
ContextManager instances allows for rooting, querying and access
to select portions of the global context graph.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCreates parent and child associations to the target context node.static interfaceRemoves existing parent and child associations from the target context node. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final WeakIdentityHashMap<Object,MutableTreeNode> private static final Collection<ContextCreationListener>private static final org.slf4j.Loggerprivate final RootNode -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ContextManager.AssociationCreate anAssociationinstance for the supplied object.private static voidprivate static voidcontextCreated(Object object) static voidvoidderegisterContextListener(ContextListener listener) Removes a previously registered listener from the listener set.private static voiddiscoverAssociations(Object origin) static ContextManager.Dissociationdissociate(Object object) Create aDissociationinstance for the supplied object.private static voiddissociate(Object child, Object parent) private static MutableTreeNodegetOrCreateTreeNode(Object object) private static MutableTreeNodegetTreeNode(Object object) static TreeNodeReturn theTreeNodeassociated with this object.Run the suppliedQueryagainst thisContextManager's root context.queryForSingleton(Query query) Return the unique node selected by running this query against thisContextManager's root context.static voidvoidregisterContextListener(ContextListener listener) Registers a listener for additions and removals to thisContextManager's context graph.voidRoot the given object's context node in thisContextManagerinstance.voidRemove the given object's context node from thisContextManagerroot set.
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
CONTEXT_OBJECTS
-
contextCreationListeners
-
root
-
-
Constructor Details
-
ContextManager
public ContextManager()
-
-
Method Details
-
associate
Create anAssociationinstance for the supplied object.- Parameters:
object- the object to be associated- Returns:
- an association instance
-
dissociate
Create aDissociationinstance for the supplied object.- Parameters:
object- the object to be dissociated- Returns:
- a dissociation instance
-
nodeFor
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
-
deregisterContextCreationListener
-
associate
-
dissociate
-
getTreeNode
-
getOrCreateTreeNode
-
discoverAssociations
-
contextCreated
-
root
Root the given object's context node in thisContextManagerinstance.- Parameters:
object- object whose context will be rooted
-
uproot
Remove the given object's context node from thisContextManagerroot set.- Parameters:
object- object whose context will be uprooted
-
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
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:
IllegalStateException- if the query does not select a unique node- See Also:
-
registerContextListener
Registers a listener for additions and removals to thisContextManager's context graph.- Parameters:
listener- listener to be registered
-
deregisterContextListener
Removes a previously registered listener from the listener set.- Parameters:
listener- listener to be deregistered
-