Top Description Inners Fields Constructors Methods
org.terracotta.context

public Class ContextManager

extends Object
Class Inheritance
Known Direct Subclasses
org.terracotta.statistics.StatisticsManager
Imports
java.lang.reflect.Field, java.util.Collection, .Collections, .Set, java.util.concurrent.CopyOnWriteArrayList, org.slf4j.Logger, .LoggerFactory, org.terracotta.context.annotations.ContextChild, .ContextParent, org.terracotta.context.extractor.ObjectContextExtractor, org.terracotta.context.query.Query, .QueryBuilder

A ContextManager instances allows for rooting, querying and access to select portions of the global context graph.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ContextManager.Association

Creates parent and child associations to the target context node.

public static interface
ContextManager.Dissociation

Removes existing parent and child associations from the target context node.

Field Summary

Modifier and TypeField and Description
private static final WeakIdentityHashMap<Object, MutableTreeNode>
private static final Collection<ContextCreationListener>
private static final Logger
private final RootNode

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static ContextManager.Association

Returns:

an association instance
associate
(final Object
the object to be associated
object
)

Create an Association instance for the supplied object.

private static void
associate(Object child, Object parent)

private static void
public static void
public void
deregisterContextListener(ContextListener
listener to be deregistered
listener
)

Removes a previously registered listener from the listener set.

private static void
public static ContextManager.Dissociation

Returns:

a dissociation instance
dissociate
(final Object
the object to be dissociated
object
)

Create a Dissociation instance for the supplied object.

private static void
dissociate(Object child, Object parent)

private static MutableTreeNode
private static MutableTreeNode
public static TreeNode

Returns:

TreeNode associated with this object
nodeFor
(Object
object to lookup node for
object
)

Return the TreeNode associated with this object.

public Set<TreeNode>

Returns:

the set of nodes selected by the query
query
(Query
the query to execute
query
)

Run the supplied Query against this ContextManager's root context.

public TreeNode

Returns:

the node selected by the query
queryForSingleton
(Query
the query to execute
query
)

Return the unique node selected by running this query against this ContextManager's root context.

public static void
public void
registerContextListener(ContextListener
listener to be registered
listener
)

Registers a listener for additions and removals to this ContextManager's context graph.

public void
root(Object
object whose context will be rooted
object
)

Root the given object's context node in this ContextManager instance.

public void
uproot(Object
object whose context will be uprooted
object
)

Remove the given object's context node from this ContextManager root set.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CONTEXT_OBJECTSback to summary
private static final WeakIdentityHashMap<Object, MutableTreeNode> CONTEXT_OBJECTS
contextCreationListenersback to summary
private static final Collection<ContextCreationListener> contextCreationListeners
LOGGERback to summary
private static final Logger LOGGER
rootback to summary
private final RootNode root

Constructor Detail

ContextManagerback to summary
public ContextManager()

Method Detail

associateback to summary
public static ContextManager.Association associate(final Object object)

Create an Association instance for the supplied object.

Parameters
object:Object

the object to be associated

Returns:ContextManager.Association

an association instance

associateback to summary
private static void associate(Object child, Object parent)
contextCreatedback to summary
private static void contextCreated(Object object)
deregisterContextCreationListenerback to summary
public static void deregisterContextCreationListener(ContextCreationListener listener)
deregisterContextListenerback to summary
public void deregisterContextListener(ContextListener listener)

Removes a previously registered listener from the listener set.

Parameters
listener:ContextListener

listener to be deregistered

discoverAssociationsback to summary
private static void discoverAssociations(Object origin)
dissociateback to summary
public static ContextManager.Dissociation dissociate(final Object object)

Create a Dissociation instance for the supplied object.

Parameters
object:Object

the object to be dissociated

Returns:ContextManager.Dissociation

a dissociation instance

dissociateback to summary
private static void dissociate(Object child, Object parent)
getOrCreateTreeNodeback to summary
private static MutableTreeNode getOrCreateTreeNode(Object object)
getTreeNodeback to summary
private static MutableTreeNode getTreeNode(Object object)
nodeForback to summary
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

object to lookup node for

Returns:TreeNode

TreeNode associated with this object

queryback to summary
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:Query

the query to execute

Returns:Set<TreeNode>

the set of nodes selected by the query

queryForSingletonback to summary
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:Query

the query to execute

Returns:TreeNode

the node selected by the query

Exceptions
IllegalStateException:
if the query does not select a unique node
See Also
query(Query), QueryBuilder#ensureUnique()
registerContextCreationListenerback to summary
public static void registerContextCreationListener(ContextCreationListener listener)
registerContextListenerback to summary
public void registerContextListener(ContextListener listener)

Registers a listener for additions and removals to this ContextManager's context graph.

Parameters
listener:ContextListener

listener to be registered

rootback to summary
public void root(Object object)

Root the given object's context node in this ContextManager instance.

Parameters
object:Object

object whose context will be rooted

uprootback to summary
public void uproot(Object object)

Remove the given object's context node from this ContextManager root set.

Parameters
object:Object

object whose context will be uprooted

org.terracotta.context back to summary

public Interface ContextManager.Association


Creates parent and child associations to the target context node.

Mutations performed to the parent and child node sets of the target node are also accompanied by the equivalent changes to the reverse relationship in the supplied object's context node. This ensures that parent/child relationships are properly consistent.

Method Summary

Modifier and TypeMethod and Description
public ContextManager.Association

Returns:

this association object
withChild
(Object
object whose context node will be associated
child
)

Adds the supplied object's context node as a child of the target context node.

public ContextManager.Association

Returns:

this association object
withParent
(Object
object whose context node will be associated
parent
)

Adds the supplied object's context node as a parent of the target context node.

Method Detail

withChildback to summary
public ContextManager.Association withChild(Object child)

Adds the supplied object's context node as a child of the target context node.

Parameters
child:Object

object whose context node will be associated

Returns:ContextManager.Association

this association object

withParentback to summary
public ContextManager.Association withParent(Object parent)

Adds the supplied object's context node as a parent of the target context node.

Parameters
parent:Object

object whose context node will be associated

Returns:ContextManager.Association

this association object

org.terracotta.context back to summary

public Interface ContextManager.Dissociation


Removes existing parent and child associations from the target context node.

Mutations performed to the parent and child node sets of the target node are also accompanied by the equivalent changes to the reverse relationship in the supplied object's context node. This ensures that parent/child relationships are properly consistent.

Method Summary

Modifier and TypeMethod and Description
public ContextManager.Dissociation

Returns:

this dissociation object
fromChild
(Object
object whose context node will be dissociated
child
)

Removes the supplied object's context from the child node set of the target context node.

public ContextManager.Dissociation

Returns:

this dissociation object
fromParent
(Object
object whose context node will be dissociated
parent
)

Removes the supplied object's context from the parent node set of the target context node.

Method Detail

fromChildback to summary
public ContextManager.Dissociation fromChild(Object child)

Removes the supplied object's context from the child node set of the target context node.

Parameters
child:Object

object whose context node will be dissociated

Returns:ContextManager.Dissociation

this dissociation object

fromParentback to summary
public ContextManager.Dissociation fromParent(Object parent)

Removes the supplied object's context from the parent node set of the target context node.

Parameters
parent:Object

object whose context node will be dissociated

Returns:ContextManager.Dissociation

this dissociation object