org.modeshape.graph.connector.base.cache
Class InMemoryNodeCache<KeyType,NodeType extends Node>

java.lang.Object
  extended by org.modeshape.graph.connector.base.cache.InMemoryNodeCache<KeyType,NodeType>
Type Parameters:
KeyType - the key for the cache entries, normally the natural unique identifier for the node
NodeType - the node type that is being cached
All Implemented Interfaces:
NodeCache<KeyType,NodeType>
Direct Known Subclasses:
InMemoryNodeCache.MapCache, InMemoryNodeCache.PathCache

@ThreadSafe
public abstract class InMemoryNodeCache<KeyType,NodeType extends Node>
extends Object
implements NodeCache<KeyType,NodeType>

Implementation of NodeCache that stores all nodes in-memory.


Nested Class Summary
static class InMemoryNodeCache.MapCache<N extends MapNode>
           
static class InMemoryNodeCache.MapCachePolicy<NodeType extends MapNode>
          Path cache policy implementation that caches all nodes in an in-memory cache.
static class InMemoryNodeCache.PathCache
           
static class InMemoryNodeCache.PathCachePolicy
           
 
Field Summary
protected  ConcurrentMap<KeyType,org.modeshape.graph.connector.base.cache.InMemoryNodeCache.CacheEntry> entriesByKey
           
protected  NodeCachePolicy<KeyType,NodeType> policy
           
 
Constructor Summary
InMemoryNodeCache(NodeCachePolicy<KeyType,NodeType> policy)
           
 
Method Summary
 void assignPolicy(NodeCachePolicy<KeyType,NodeType> policy)
          Injects the cache policy into the cache
 void clearStatistics()
          Clears all statistics for this cache
 void close()
          Indicates that the cache is no longer in use and should relinquish any resources.
 NodeType get(KeyType path)
          Retrieves the cached node with the given path, it it exists and is valid
 CacheStatistics getStatistics()
           
 void put(KeyType key, NodeType node)
          Attempts to cache the given node.
 void remove(KeyType key)
          Removes the node with the given key from the cache, if it is in currently in the cache.
 void removeAll()
          Removes all nodes from the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entriesByKey

protected final ConcurrentMap<KeyType,org.modeshape.graph.connector.base.cache.InMemoryNodeCache.CacheEntry> entriesByKey

policy

protected NodeCachePolicy<KeyType,NodeType extends Node> policy
Constructor Detail

InMemoryNodeCache

public InMemoryNodeCache(NodeCachePolicy<KeyType,NodeType> policy)
Method Detail

assignPolicy

public void assignPolicy(NodeCachePolicy<KeyType,NodeType> policy)
Description copied from interface: NodeCache
Injects the cache policy into the cache

Specified by:
assignPolicy in interface NodeCache<KeyType,NodeType extends Node>
Parameters:
policy - the active cache policy for the repository source with which this cache is associated

clearStatistics

public void clearStatistics()
Description copied from interface: NodeCache
Clears all statistics for this cache

Specified by:
clearStatistics in interface NodeCache<KeyType,NodeType extends Node>

getStatistics

public CacheStatistics getStatistics()
Specified by:
getStatistics in interface NodeCache<KeyType,NodeType extends Node>
Returns:
the statistics since the most recent of the cache initialization or the last call to NodeCache.clearStatistics(); never null

get

public NodeType get(KeyType path)
Description copied from interface: NodeCache
Retrieves the cached node with the given path, it it exists and is valid

Specified by:
get in interface NodeCache<KeyType,NodeType extends Node>
Parameters:
path - the path for the node to be retrieved
Returns:
the cached node with the given path; may be null if no node with that path is cached or a node with that path is cached but is deemed invalid for implementation-specific reasons

put

public void put(KeyType key,
                NodeType node)
Description copied from interface: NodeCache
Attempts to cache the given node. Implementations must call NodeCachePolicy.shouldCache(Node) on the the assigned policy to determine if the node should be cached.

Specified by:
put in interface NodeCache<KeyType,NodeType extends Node>
Parameters:
key - the key for the node that is to be cached; may not be null
node - the node that is to be cached; may not be null

remove

public void remove(KeyType key)
Description copied from interface: NodeCache
Removes the node with the given key from the cache, if it is in currently in the cache. If no node with the given key is currently in the cache, this method returns silently.

Specified by:
remove in interface NodeCache<KeyType,NodeType extends Node>
Parameters:
key - the key for the node that is to be removed; may not be null

removeAll

public void removeAll()
Description copied from interface: NodeCache
Removes all nodes from the cache.

Specified by:
removeAll in interface NodeCache<KeyType,NodeType extends Node>

close

public void close()
Description copied from interface: NodeCache
Indicates that the cache is no longer in use and should relinquish any resources.

Specified by:
close in interface NodeCache<KeyType,NodeType extends Node>


Copyright © 2008-2012 JBoss, a division of Red Hat. All Rights Reserved.