org.jboss.cache.search
Class SearchableCacheImpl<K,V>

java.lang.Object
  extended by org.jboss.cache.search.SearchableCacheImpl<K,V>
All Implemented Interfaces:
org.jboss.cache.Cache<K,V>, SearchableCache<K,V>

public class SearchableCacheImpl<K,V>
extends Object
implements SearchableCache<K,V>

Author:
Navin Surtani (nsurtani@redhat.com)

Implementation class for the SearchableCache interface.


Constructor Summary
SearchableCacheImpl(org.jboss.cache.Cache<K,V> cache, org.hibernate.search.engine.SearchFactoryImplementor searchFactory)
           
 
Method Summary
 void addCacheListener(Object listener)
          Adds a listener to the cache.
 void clearData(org.jboss.cache.Fqn<?> fqn)
          Removes the keys and properties from a named node.
 void clearData(String fqn)
          Removes the keys and properties from a named node.
 void create()
          Lifecycle method that initializes configuration state, the root node, etc.
 CacheQuery createQuery(org.apache.lucene.search.Query luceneQuery)
          Creates a CacheQuery object from a given Lucene Query.
 CacheQuery createQuery(org.apache.lucene.search.Query luceneQuery, Class... classes)
          Creates a CacheQuery object from a Lucene Query and a class array.
 void destroy()
          Lifecycle method that destroys the cache and removes any interceptors/configuration elements.
 void evict(org.jboss.cache.Fqn<?> fqn)
          Eviction call that evicts the specified Node from memory.
 void evict(org.jboss.cache.Fqn<?> fqn, boolean recursive)
          Eviction call that evicts the specified Node from memory.
 V get(org.jboss.cache.Fqn<?> fqn, K key)
          Convenience method that allows for direct access to the data in a Node.
 V get(String fqn, K key)
          Convenience method that allows for direct access to the data in a Node.
 Set getCacheListeners()
          Returns a set of listeners that the cache has.
 org.jboss.cache.CacheStatus getCacheStatus()
          Gets where the cache currently is its lifecycle transitions.
 org.jboss.cache.config.Configuration getConfiguration()
          Returns an org.jboss.cache.config.Configuration instance.
 Map getData(org.jboss.cache.Fqn<?> fqn)
          Retrieves a defensively copied data map of the underlying node.
 org.jboss.cache.InvocationContext getInvocationContext()
          The current invocation context for the current invocation and cache instance.
 Set getKeys(org.jboss.cache.Fqn<?> fqn)
          Returns a set of attribute keys for the Fqn.
 Set<K> getKeys(String fqn)
          Returns a set of attribute keys for the Fqn.
 org.jgroups.Address getLocalAddress()
          Returns the local address of this cache in a cluster, or null if running in local mode.
 List getMembers()
          Returns a list of members in the cluster, or null if running in local mode.
 org.jboss.cache.Node getNode(org.jboss.cache.Fqn<?> fqn)
          A convenience method to retrieve a node directly from the cache.
 org.jboss.cache.Node getNode(String fqn)
          Gets a node from a String representation of a Fqn
 org.jboss.cache.Region getRegion(org.jboss.cache.Fqn<?> fqn, boolean createIfAbsent)
          Retrieves a Region for a given Fqn.
 org.jboss.cache.Node getRoot()
          Returns an org.jboss.cache.Node instance.
 String getVersion()
          Returns the version of the cache as a string.
 void move(org.jboss.cache.Fqn<?> nodeToMove, org.jboss.cache.Fqn<?> newParent)
          Moves a part of the cache to a different subtree.
 void move(String nodeToMove, String newParent)
          Moves a part of the cache to a different subtree.
 V put(org.jboss.cache.Fqn<?> fqn, K key, V value)
          Associates the specified value with the specified key for a Node in this cache.
 void put(org.jboss.cache.Fqn<?> fqn, Map<K,V> data)
          Copies all of the mappings from the specified map to a Node.
 V put(String fqn, K key, V value)
          Puts something into the cache with a given Fqn, key and value.
 void put(String fqn, Map<K,V> data)
          Puts something into the cache with a given Fqn and Map instance.
 void putForExternalRead(org.jboss.cache.Fqn<?> fqn, K key, V value)
          Under special operating behavior, associates the value with the specified key for a node identified by the Fqn passed in.
 V remove(org.jboss.cache.Fqn<?> fqn, K key)
          Moves a part of the cache to a different subtree.
 V remove(String fqn, K key)
          Removes something from the cache with a given Fqn and key.
 void removeCacheListener(Object listener)
          Removes a listener from the cache.
 boolean removeNode(org.jboss.cache.Fqn<?> fqn)
          Removes a Node indicated by absolute Fqn.
 boolean removeNode(String fqn)
          Convenience method that takes a string representation of an Fqn.
 boolean removeRegion(org.jboss.cache.Fqn<?> fqn)
          Removes a region denoted by the Fqn passed in.
 void setInvocationContext(org.jboss.cache.InvocationContext ctx)
          Sets the passed in InvocationContext as current.
 void start()
          Lifecycle method that starts the cache loader, starts cache replication, starts the region manager, etc., and (if configured) warms the cache using a state transfer or cache loader preload.
 void stop()
          Lifecycle method that stops the cache, including replication, clustering, cache loading, notifications, etc., and clears all cache in-memory state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SearchableCacheImpl

public SearchableCacheImpl(org.jboss.cache.Cache<K,V> cache,
                           org.hibernate.search.engine.SearchFactoryImplementor searchFactory)
Method Detail

createQuery

public CacheQuery createQuery(org.apache.lucene.search.Query luceneQuery)
Creates a CacheQuery object from a given Lucene Query.

Specified by:
createQuery in interface SearchableCache<K,V>
Parameters:
luceneQuery - - for lucene
Returns:
CacheQuery object

createQuery

public CacheQuery createQuery(org.apache.lucene.search.Query luceneQuery,
                              Class... classes)
Creates a CacheQuery object from a Lucene Query and a class array.

Specified by:
createQuery in interface SearchableCache<K,V>
Parameters:
luceneQuery - - for lucene
classes - array
Returns:
CacheQuery object.

getConfiguration

public org.jboss.cache.config.Configuration getConfiguration()
Returns an org.jboss.cache.config.Configuration instance.

Specified by:
getConfiguration in interface org.jboss.cache.Cache<K,V>
Returns:
org.jboss.cache.config.Configuration

getRoot

public org.jboss.cache.Node getRoot()
Returns an org.jboss.cache.Node instance.

Specified by:
getRoot in interface org.jboss.cache.Cache<K,V>
Returns:
org.jboss.cache.Node

addCacheListener

public void addCacheListener(Object listener)
Adds a listener to the cache.

Specified by:
addCacheListener in interface org.jboss.cache.Cache<K,V>
Parameters:
listener -

removeCacheListener

public void removeCacheListener(Object listener)
Removes a listener from the cache.

Specified by:
removeCacheListener in interface org.jboss.cache.Cache<K,V>
Parameters:
listener -

getCacheListeners

public Set getCacheListeners()
Returns a set of listeners that the cache has.

Specified by:
getCacheListeners in interface org.jboss.cache.Cache<K,V>
Returns:
A set of listeners.

put

public V put(String fqn,
             K key,
             V value)
Puts something into the cache with a given Fqn, key and value.

Specified by:
put in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -
key -
value -
Returns:

put

public void put(String fqn,
                Map<K,V> data)
Puts something into the cache with a given Fqn and Map instance.

Specified by:
put in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -
data -

remove

public V remove(String fqn,
                K key)
Removes something from the cache with a given Fqn and key.

Specified by:
remove in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -
key -
Returns:

removeNode

public boolean removeNode(String fqn)
Convenience method that takes a string representation of an Fqn. Otherwise identical to removeNode(Fqn)

Specified by:
removeNode in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -
Returns:
True if the node was removed, false if the node wasn't

getNode

public org.jboss.cache.Node getNode(String fqn)
Gets a node from a String representation of a Fqn

Specified by:
getNode in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -
Returns:

get

public V get(String fqn,
             K key)
Convenience method that allows for direct access to the data in a Node.

Specified by:
get in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -
key -
Returns:

create

public void create()
            throws org.jboss.cache.CacheException
Lifecycle method that initializes configuration state, the root node, etc.

Specified by:
create in interface org.jboss.cache.Cache<K,V>
Throws:
org.jboss.cache.CacheException

start

public void start()
           throws org.jboss.cache.CacheException
Lifecycle method that starts the cache loader, starts cache replication, starts the region manager, etc., and (if configured) warms the cache using a state transfer or cache loader preload.

Specified by:
start in interface org.jboss.cache.Cache<K,V>
Throws:
org.jboss.cache.CacheException

stop

public void stop()
Lifecycle method that stops the cache, including replication, clustering, cache loading, notifications, etc., and clears all cache in-memory state.

Specified by:
stop in interface org.jboss.cache.Cache<K,V>

destroy

public void destroy()
Lifecycle method that destroys the cache and removes any interceptors/configuration elements.

Specified by:
destroy in interface org.jboss.cache.Cache<K,V>

getCacheStatus

public org.jboss.cache.CacheStatus getCacheStatus()
Gets where the cache currently is its lifecycle transitions.

Specified by:
getCacheStatus in interface org.jboss.cache.Cache<K,V>
Returns:
the CacheStatus. Will not return null.

getInvocationContext

public org.jboss.cache.InvocationContext getInvocationContext()
The current invocation context for the current invocation and cache instance.

Specified by:
getInvocationContext in interface org.jboss.cache.Cache<K,V>
Returns:
the current invocation context for the current invocation and cache instance

setInvocationContext

public void setInvocationContext(org.jboss.cache.InvocationContext ctx)
Sets the passed in InvocationContext as current.

Specified by:
setInvocationContext in interface org.jboss.cache.Cache<K,V>
Parameters:
ctx -

getLocalAddress

public org.jgroups.Address getLocalAddress()
Returns the local address of this cache in a cluster, or null if running in local mode.

Specified by:
getLocalAddress in interface org.jboss.cache.Cache<K,V>
Returns:
Returns the local address of this cache in a cluster, or null if running in local mode.

getMembers

public List getMembers()
Returns a list of members in the cluster, or null if running in local mode.

Specified by:
getMembers in interface org.jboss.cache.Cache<K,V>
Returns:
Returns a list of members in the cluster, or null if running in local mode.

move

public void move(String nodeToMove,
                 String newParent)
          throws org.jboss.cache.NodeNotExistsException
Moves a part of the cache to a different subtree. Takes Strings for convenience.

Specified by:
move in interface org.jboss.cache.Cache<K,V>
Parameters:
nodeToMove -
newParent -
Throws:
org.jboss.cache.NodeNotExistsException

getVersion

public String getVersion()
Returns the version of the cache as a string.

Specified by:
getVersion in interface org.jboss.cache.Cache<K,V>
Returns:
Returns the version of the cache as a string.

getKeys

public Set<K> getKeys(String fqn)
Returns a set of attribute keys for the Fqn. Takes Strings for convenience.

Specified by:
getKeys in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -
Returns:
Returns a set of attribute keys for the Fqn.

clearData

public void clearData(String fqn)
Removes the keys and properties from a named node. Takes Strings for convenience.

Specified by:
clearData in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -

clearData

public void clearData(org.jboss.cache.Fqn<?> fqn)
Removes the keys and properties from a named node.

Specified by:
clearData in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -

getKeys

public Set getKeys(org.jboss.cache.Fqn<?> fqn)
Returns a set of attribute keys for the Fqn.

Specified by:
getKeys in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -
Returns:

getData

public Map getData(org.jboss.cache.Fqn<?> fqn)
Retrieves a defensively copied data map of the underlying node.

Specified by:
getData in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -
Returns:
a defensively copied data map of the underlying node.

move

public void move(org.jboss.cache.Fqn<?> nodeToMove,
                 org.jboss.cache.Fqn<?> newParent)
          throws org.jboss.cache.NodeNotExistsException
Moves a part of the cache to a different subtree.

Specified by:
move in interface org.jboss.cache.Cache<K,V>
Parameters:
nodeToMove -
newParent -
Throws:
org.jboss.cache.NodeNotExistsException

removeRegion

public boolean removeRegion(org.jboss.cache.Fqn<?> fqn)
Removes a region denoted by the Fqn passed in.

Specified by:
removeRegion in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -
Returns:
True if the region did exist and was removed, false otherwise.

getRegion

public org.jboss.cache.Region getRegion(org.jboss.cache.Fqn<?> fqn,
                                        boolean createIfAbsent)
Retrieves a Region for a given Fqn.

Specified by:
getRegion in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -
createIfAbsent -
Returns:
a MarshRegion. Null if none is found.

evict

public void evict(org.jboss.cache.Fqn<?> fqn)
Eviction call that evicts the specified Node from memory.

Specified by:
evict in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -

evict

public void evict(org.jboss.cache.Fqn<?> fqn,
                  boolean recursive)
Eviction call that evicts the specified Node from memory.

Specified by:
evict in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -
recursive -

get

public V get(org.jboss.cache.Fqn<?> fqn,
             K key)
Convenience method that allows for direct access to the data in a Node.

Specified by:
get in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -
key -
Returns:

getNode

public org.jboss.cache.Node getNode(org.jboss.cache.Fqn<?> fqn)
A convenience method to retrieve a node directly from the cache.

Specified by:
getNode in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -
Returns:

removeNode

public boolean removeNode(org.jboss.cache.Fqn<?> fqn)
Removes a Node indicated by absolute Fqn.

Specified by:
removeNode in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -
Returns:
True if the node was removed, false if the node was not found.

remove

public V remove(org.jboss.cache.Fqn<?> fqn,
                K key)
Moves a part of the cache to a different subtree.

Specified by:
remove in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -
key -
Returns:

put

public void put(org.jboss.cache.Fqn<?> fqn,
                Map<K,V> data)
Copies all of the mappings from the specified map to a Node.

Specified by:
put in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -
data -

putForExternalRead

public void putForExternalRead(org.jboss.cache.Fqn<?> fqn,
                               K key,
                               V value)
Under special operating behavior, associates the value with the specified key for a node identified by the Fqn passed in.

Specified by:
putForExternalRead in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -
key -
value -

put

public V put(org.jboss.cache.Fqn<?> fqn,
             K key,
             V value)
Associates the specified value with the specified key for a Node in this cache.

Specified by:
put in interface org.jboss.cache.Cache<K,V>
Parameters:
fqn -
key -
value -
Returns:


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