[infinispan-commits] Infinispan SVN: r517 - in branches/ISPN-32: core/src/main/java/org/infinispan/factories and 1 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Mon Jul 6 01:57:38 EDT 2009
Author: navssurtani
Date: 2009-07-06 01:57:38 -0400 (Mon, 06 Jul 2009)
New Revision: 517
Modified:
branches/ISPN-32/core/src/main/java/org/infinispan/factories/InterceptorChainFactory.java
branches/ISPN-32/pom.xml
branches/ISPN-32/query/src/main/java/org/infinispan/query/CacheEntityId.java
branches/ISPN-32/query/src/main/java/org/infinispan/query/EntityId.java
branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCache.java
branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCacheFactory.java
branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCacheImpl.java
branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCoreInterceptor.java
branches/ISPN-32/query/src/main/java/org/infinispan/query/TransactionalEventTransactionContext.java
branches/ISPN-32/query/src/main/java/org/infinispan/query/TreeEntityId.java
Log:
[ISPN-32] Need someone to have a look at the interceptor TODO's.
Modified: branches/ISPN-32/core/src/main/java/org/infinispan/factories/InterceptorChainFactory.java
===================================================================
--- branches/ISPN-32/core/src/main/java/org/infinispan/factories/InterceptorChainFactory.java 2009-07-03 08:30:47 UTC (rev 516)
+++ branches/ISPN-32/core/src/main/java/org/infinispan/factories/InterceptorChainFactory.java 2009-07-06 05:57:38 UTC (rev 517)
@@ -39,7 +39,7 @@
*/
@DefaultFactoryFor(classes = InterceptorChain.class)
public class InterceptorChainFactory extends AbstractNamedCacheComponentFactory implements AutoInstantiableFactory {
- private CommandInterceptor createInterceptor(Class<? extends CommandInterceptor> clazz) throws IllegalAccessException, InstantiationException {
+ public CommandInterceptor createInterceptor(Class<? extends CommandInterceptor> clazz) throws IllegalAccessException, InstantiationException {
CommandInterceptor chainedInterceptor = componentRegistry.getComponent(clazz);
if (chainedInterceptor == null) {
chainedInterceptor = clazz.newInstance();
Modified: branches/ISPN-32/pom.xml
===================================================================
--- branches/ISPN-32/pom.xml 2009-07-03 08:30:47 UTC (rev 516)
+++ branches/ISPN-32/pom.xml 2009-07-06 05:57:38 UTC (rev 517)
@@ -30,6 +30,7 @@
<module>jopr-plugin</module>
<module>gui-demo</module>
<module>tools</module>
+ <module>query</module>
</modules>
<profiles>
Modified: branches/ISPN-32/query/src/main/java/org/infinispan/query/CacheEntityId.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/CacheEntityId.java 2009-07-03 08:30:47 UTC (rev 516)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/CacheEntityId.java 2009-07-06 05:57:38 UTC (rev 517)
@@ -22,24 +22,30 @@
package org.infinispan.query;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.infinispan.util.logging.Log;
/**
*
* This class is used to store keys which are the same as documentId's.
+ *
+ * //TODO: navssurtani --> Document this.
+ *
* <p/>
* @author Navin Surtani
*/
public class CacheEntityId implements EntityId
{
- private static final Log log = LogFactory.getLog(CacheEntityId.class);
+ private Log log;
- protected String key;
+ private Object key;
+ private String documentId;
- public CacheEntityId(String key)
+ public CacheEntityId(Object key)
{
this.key = key;
+
+ // TODO: navssurtani --> Write up a proper override of toString().
+ this.documentId = key.toString();
}
/**
@@ -48,10 +54,19 @@
* @return Key from the instance of CacheEntityId.
*/
- public String getKey()
+ public Object getKey()
{
return key;
}
+ /**
+ * Gets the key from the instance of CacheEntityId.
+ *
+ * @return Key from the instance of CacheEntityId.
+ */
+ public String getDocumentId()
+ {
+ return documentId;
+ }
}
Modified: branches/ISPN-32/query/src/main/java/org/infinispan/query/EntityId.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/EntityId.java 2009-07-03 08:30:47 UTC (rev 516)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/EntityId.java 2009-07-06 05:57:38 UTC (rev 517)
@@ -2,10 +2,15 @@
/**
- * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ * //TODO: navssurtani --> Document this.
+ *
+ * @author Navin Surtani
*/
public interface EntityId
{
- public String getKey();
+ public Object getKey();
+ public String getDocumentId();
+
+
}
Modified: branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCache.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCache.java 2009-07-03 08:30:47 UTC (rev 516)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCache.java 2009-07-06 05:57:38 UTC (rev 517)
@@ -31,7 +31,7 @@
* will use to build their Hibernate Search queries from a luceneQuery - Hibernate Search users will be very familiar
* with this.
*
- * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ * @author Navin Surtani
* <p/>
*/
public interface SearchableCache<K, V> extends Cache<K, V>
Modified: branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCacheFactory.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCacheFactory.java 2009-07-03 08:30:47 UTC (rev 516)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCacheFactory.java 2009-07-06 05:57:38 UTC (rev 517)
@@ -22,12 +22,13 @@
package org.infinispan.query;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.hibernate.search.cfg.SearchConfiguration;
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.impl.SearchFactoryImpl;
import org.infinispan.Cache;
+import org.infinispan.factories.ComponentRegistry;
+import org.infinispan.factories.InterceptorChainFactory;
+import org.infinispan.interceptors.LockingInterceptor;
import java.lang.reflect.Field;
import java.util.Properties;
@@ -40,13 +41,11 @@
* <p/>
* <p/>
*
- * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ * @author Navin Surtani
*/
-public class SearchableCacheFactory
-{
- private static final Log log = LogFactory.getLog(SearchableCacheFactory.class);
+public class SearchableCacheFactory {
+ org.infinispan.util.logging.Log log;
-
/**
* Creates a searchable cache from a cache object and a class array, without the properties object.
*
@@ -54,8 +53,7 @@
* @param classes - Class array to be added
* @return a SearchableCache
*/
- public SearchableCache createSearchableCache(Cache<?, ?> c, Class... classes)
- {
+ public SearchableCache createSearchableCache(Cache<?, ?> c, Class[] classes) throws IllegalAccessException, InstantiationException {
return createSearchableCache(c, null, classes);
}
@@ -67,8 +65,7 @@
* @param classes - a class array
* @return a SearchableCache
*/
- public SearchableCache createSearchableCache(Cache<?, ?> c, Properties properties, Class... classes)
- {
+ public SearchableCache createSearchableCache(Cache<?, ?> c, Properties properties, Class[] classes) throws IllegalAccessException, InstantiationException {
//validate the classes first. make sure the correct annotations are put in.
@@ -76,14 +73,12 @@
// assume cache is already created and running.
// otherwise, start the cache!!
- if (c.getCacheStatus() != CacheStatus.STARTED)
- {
- if (log.isInfoEnabled()) log.info("Cache not started. Starting cache first.");
+ if (c.getStatus().needToInitializeBeforeStart()) {
+ log.debug("Cache not started. Starting cache first.");
c.start();
}
- if (classes.length == 0)
- {
+ if (classes.length == 0) {
throw new IllegalArgumentException("You haven't passed in any classes to index.");
}
@@ -95,90 +90,33 @@
// Okay, create the core listener
- SearchableCoreListener coreListener = new SearchableCoreListener(searchFactory);
- c.addCacheListener(coreListener);
+// SearchableCoreListener coreListener = new SearchableCoreListener(searchFactory);
+// c.addCacheListener(coreListener);
- //Create secondary listener
-// SearchableCoreRemover remover = new SearchableCoreRemover(searchFactory);
-// c.addCacheListener(remover);
+ ComponentRegistry cr = c.getAdvancedCache().getComponentRegistry();
+ cr.registerComponent(searchFactory, SearchFactoryImplementor.class);
+ InterceptorChainFactory icf = cr.getComponent(InterceptorChainFactory.class);
+ // Don't like this cast :-(.
+ SearchableCoreInterceptor inter = (SearchableCoreInterceptor) icf.createInterceptor(SearchableCoreInterceptor.class);
+
+ c.getAdvancedCache().addInterceptorAfter(inter, LockingInterceptor.class);
+
//Create the searchableCache and pass it on.
SearchableCache sc = new SearchableCacheImpl(c, searchFactory);
return sc;
}
-
- /**
- * This method creates a searchable cache as well but requires the properties object.
- *
- * @param pojo - the pojoCache
- * @param properties - java.util.properties
- * @param classes - a class array
- * @return a SearchableCache
- */
-
- public SearchableCache createSearchableCache(PojoCache pojo, Properties properties, Class... classes)
- {
-
- System.out.println("create searchable cache called with pojo cache");
- validateClasses(classes);
-
- Cache coreCache = pojo.getCache();
- if (coreCache.getCacheStatus() != CacheStatus.STARTED)
- {
- if (log.isInfoEnabled()) log.info("Cache not started. Starting cache first.");
- pojo.start();
- }
-
- if (classes.length == 0)
- {
- throw new IllegalArgumentException("You haven't passed in any classes to index.");
- }
-
- // step 1: create hibernate search searchFactory
- SearchConfiguration cfg = new SearchableCacheConfiguration(classes, properties);
- // set classes in the cfg
-
- SearchFactoryImplementor searchFactory = new SearchFactoryImpl(cfg);
-
- //Now create the pojoListener
- SearchablePojoListener pojoListener = new SearchablePojoListener(searchFactory);
- pojo.addListener(pojoListener);
- pojo.getCache().addCacheListener(pojoListener);
-
- SearchableCache sc = new SearchableCachePojoImpl(pojo, searchFactory);
- return sc;
- }
-
- /**
- * Creates a searchable cache from a cache object and a class array, without the properties object.
- *
- * @param pojo - the pojoCache
- * @param classes - Class array to be added
- * @return a SearchableCache
- */
-
-
- public SearchableCache createSearchableCache(PojoCache pojo, Class... classes)
- {
- return createSearchableCache(pojo, null, classes);
- }
-
//This is to check that both the @ProvidedId is present and the the @DocumentId is not present. This is because
// don't want both of these 2 annotations used at the same time.
- private void validateClasses(Class... classes)
- {
- for (Class c : classes)
- {
- if (!c.isAnnotationPresent(org.hibernate.search.annotations.ProvidedId.class))
- {
+ private void validateClasses(Class... classes) {
+ for (Class c : classes) {
+ if (!c.isAnnotationPresent(org.hibernate.search.annotations.ProvidedId.class)) {
throw new IllegalArgumentException("There is no provided id on " + c.getName() + " class");
}
- for (Field field : c.getFields())
- {
- if (field.getAnnotation(org.hibernate.search.annotations.DocumentId.class) != null)
- {
+ for (Field field : c.getFields()) {
+ if (field.getAnnotation(org.hibernate.search.annotations.DocumentId.class) != null) {
throw new IllegalArgumentException("Please remove the documentId annotation in " + c.getName());
}
}
Modified: branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCacheImpl.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCacheImpl.java 2009-07-03 08:30:47 UTC (rev 516)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCacheImpl.java 2009-07-06 05:57:38 UTC (rev 517)
@@ -24,39 +24,35 @@
import org.apache.lucene.search.Query;
import org.hibernate.search.engine.SearchFactoryImplementor;
-import org.jboss.cache.Cache;
-import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheStatus;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.InvocationContext;
-import org.jboss.cache.Node;
-import org.jboss.cache.NodeNotExistsException;
-import org.jboss.cache.Region;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.interceptors.base.CommandInterceptor;
-import org.jgroups.Address;
+import org.infinispan.AdvancedCache;
+import org.infinispan.Cache;
+import org.infinispan.CacheException;
+import org.infinispan.lifecycle.ComponentStatus;
+import org.infinispan.manager.CacheManager;
+import org.infinispan.util.concurrent.NotifyingFuture;
-import java.util.List;
+import java.util.Collection;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.TimeUnit;
/**
* Implementation class for the SearchableCache interface.
* <p/>
*
+ * //TODO: navssurtani --> Document this class properly.
+ *
* @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
*/
-public class SearchableCacheImpl<K, V> implements SearchableCache<K, V>
-{
+public class SearchableCacheImpl<K, V> implements SearchableCache<K, V> {
// this is the ACTUAL cache. that does all the work.
- // protected fields for Pojo subclass
- protected Cache<K, V> cache;
- protected SearchFactoryImplementor searchFactory;
+ private Cache<K, V> cache;
+ private SearchFactoryImplementor searchFactory;
- public SearchableCacheImpl(Cache<K, V> cache, SearchFactoryImplementor searchFactory)
- {
+
+ public SearchableCacheImpl(Cache<K, V> cache, SearchFactoryImplementor searchFactory) {
if (cache == null) throw new NullPointerException("Cache is null");
if (searchFactory == null) throw new NullPointerException("searchFactory is null");
this.cache = cache;
@@ -73,8 +69,7 @@
*/
- public CacheQuery createQuery(Query luceneQuery, Class... classes)
- {
+ public CacheQuery createQuery(Query luceneQuery, Class[] classes) {
return new CacheQueryImpl(luceneQuery, searchFactory, cache, classes);
}
@@ -85,40 +80,30 @@
* @return org.jboss.cache.config.Configuration
*/
- public Configuration getConfiguration()
- {
+ public org.infinispan.config.Configuration getConfiguration() {
return cache.getConfiguration();
}
/**
- * Returns an org.jboss.cache.Node instance.
+ * Adds a listener to the cache.
*
- * @return org.jboss.cache.Node<K,V>
+ * @param listener to be removed
*/
-
- public Node getRoot()
- {
- return cache.getRoot();
+ public void addListenter(Object listener) {
+ cache.addListener(listener);
}
- /**
- * Adds a listener to the cache.
- *
- * @param listener
- */
- public void addCacheListener(Object listener)
- {
- cache.addCacheListener(listener);
+ public void addListener(Object listener) {
+ cache.addListener(listener);
}
/**
* Removes a listener from the cache.
*
- * @param listener
+ * @param listener to be removed
*/
- public void removeCacheListener(Object listener)
- {
- cache.removeCacheListener(listener);
+ public void removeListener(Object listener) {
+ cache.removeListener(listener);
}
/**
@@ -127,330 +112,257 @@
* @return A set of listeners.
*/
- public Set getCacheListeners()
- {
- return cache.getCacheListeners();
+ public Set<Object> getListeners() {
+ return cache.getListeners();
}
- public V put(Fqn fqn, K key, V value)
- {
- return cache.put(fqn, key, value);
+ public int size() {
+ return cache.size();
}
+ public boolean isEmpty() {
+ return cache.isEmpty();
+ }
+ public boolean containsKey(Object key) {
+ return cache.containsKey(key);
+ }
+
+ public boolean containsValue(Object value) {
+ return cache.containsValue(value);
+ }
+
+ public V get(Object key) {
+ return cache.get(key);
+ }
+
/**
* Puts something into the cache with a given Fqn, key and value.
*
- * @param fqn
* @param key
* @param value
* @return
*/
- public V put(String fqn, K key, V value)
- {
- return cache.put(fqn, key, value);
+ public V put(K key, V value) {
+ return cache.put(key, value);
}
- public void putForExternalRead(Fqn fqn, K key, V value)
- {
- cache.put(fqn, key, value);
+ public V remove(Object key) {
+ return cache.remove(key);
}
- public void put(Fqn fqn, Map<? extends K, ? extends V> data)
- {
- cache.put(fqn, data);
+ public void putAll(Map<? extends K, ? extends V> t) {
+ cache.putAll(t);
}
- public void put(String fqn, Map<? extends K, ? extends V> data)
- {
- cache.put(fqn, data);
+ public void clear() {
+ cache.clear();
}
- public V remove(Fqn fqn, K key)
- {
- return cache.remove(fqn, key);
+ public void putForExternalRead(K key, V value) {
+ cache.putForExternalRead(key, value);
}
- public V remove(String fqn, K key)
- {
- return cache.remove(fqn, key);
+ public void evict(K key) {
+ cache.evict(key);
}
- public boolean removeNode(Fqn fqn)
- {
- return cache.removeNode(fqn);
- }
-
/**
- * Convenience method that takes a string representation of an Fqn. Otherwise identical to removeNode(Fqn)
+ * 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.
*
- * @param fqn
- * @return True if the node was removed, false if the node wasn't
+ * @throws CacheException
*/
- public boolean removeNode(String fqn)
- {
- return cache.removeNode(fqn);
+ public void start() throws CacheException {
+ cache.start();
}
- public Node<K, V> getNode(Fqn fqn)
- {
- return cache.getNode(fqn);
+ /**
+ * Lifecycle method that stops the cache, including replication, clustering, cache loading, notifications, etc., and
+ * clears all cache in-memory state.
+ */
+
+ public void stop() {
+ cache.stop();
}
/**
- * Gets a node from a String representation of a Fqn
+ * Returns the version of the cache as a string.
*
- * @param fqn
- * @return
+ * @return Returns the version of the cache as a string.
*/
+ public String getVersion() {
+ return cache.getVersion();
+ }
- public Node getNode(String fqn)
- {
- return cache.getNode(fqn);
+ public CacheManager getCacheManager() {
+ return cache.getCacheManager();
}
- public Set<Object> getChildrenNames(Fqn fqn)
- {
- return cache.getChildrenNames(fqn);
+ public V put(K key, V value, long lifespan, TimeUnit unit) {
+ return cache.put(key, value, lifespan, unit);
}
- public Set<String> getChildrenNames(String fqn)
- {
- return cache.getChildrenNames(fqn);
+ public V putIfAbsent(K key, V value, long lifespan, TimeUnit unit) {
+ return cache.putIfAbsent(key, value, lifespan, unit);
}
- public boolean isLeaf(Fqn fqn)
- {
- return cache.isLeaf(fqn);
+ public void putAll(Map<? extends K, ? extends V> map, long lifespan, TimeUnit unit) {
+ cache.putAll(map, lifespan, unit);
}
- public boolean isLeaf(String fqn)
- {
- return cache.isLeaf(fqn);
+ public V replace(K key, V value, long lifespan, TimeUnit unit) {
+ return cache.replace(key, value, lifespan, unit);
}
- public V get(Fqn fqn, K key)
- {
- return cache.get(fqn, key);
+ public boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit unit) {
+ return cache.replace(key, oldValue, value, lifespan, unit);
}
- /**
- * Convenience method that allows for direct access to the data in a Node.
- *
- * @param fqn
- * @param key
- * @return
- */
- public V get(String fqn, K key)
- {
- return cache.get(fqn, key);
+ public V put(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
+ return cache.put(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
}
- public void evict(Fqn fqn, boolean recursive)
- {
- cache.evict(fqn, recursive);
+ public V putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
+ return cache.putIfAbsent(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
}
- public void evict(Fqn fqn)
- {
- cache.evict(fqn);
+ public void putAll(Map<? extends K, ? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
+ cache.putAll(map, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
}
- public Region getRegion(Fqn fqn, boolean createIfAbsent)
- {
- return cache.getRegion(fqn, createIfAbsent);
+ public V replace(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
+ return cache.replace(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
}
- public boolean removeRegion(Fqn fqn)
- {
- return cache.removeRegion(fqn);
+ public boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
+ return cache.replace(key, oldValue, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
}
- /**
- * Lifecycle method that initializes configuration state, the root node, etc.
- *
- * @throws CacheException
- */
+ public NotifyingFuture<V> putAsync(K key, V value) {
+ return cache.putAsync(key, value);
+ }
- public void create() throws CacheException
- {
- cache.create();
+ public NotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit unit) {
+ return cache.putAsync(key, value, lifespan, unit);
}
- /**
- * 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.
- *
- * @throws CacheException
- */
+ public NotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
+ return cache.putAsync(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
+ }
- public void start() throws CacheException
- {
- cache.start();
+ public NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> data) {
+ return cache.putAllAsync(data);
}
- /**
- * Lifecycle method that stops the cache, including replication, clustering, cache loading, notifications, etc.,
- * and clears all cache in-memory state.
- */
+ public NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> data, long lifespan, TimeUnit unit) {
+ return cache.putAllAsync(data, lifespan, unit);
+ }
- public void stop()
- {
- cache.stop();
+ public NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> data, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
+ return cache.putAllAsync(data, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
}
- /**
- * Lifecycle method that destroys the cache and removes any interceptors/configuration elements.
- */
+ public NotifyingFuture<Void> clearAsync() {
+ return cache.clearAsync();
+ }
- public void destroy()
- {
- cache.destroy();
+ public NotifyingFuture<V> putIfAbsentAsync(K key, V value) {
+ return cache.putIfAbsentAsync(key, value);
}
- /**
- * Gets where the cache currently is its lifecycle transitions.
- *
- * @return the CacheStatus. Will not return null.
- */
+ public NotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit unit) {
+ return cache.putIfAbsentAsync(key, value, lifespan, unit);
+ }
- public CacheStatus getCacheStatus()
- {
- return cache.getCacheStatus();
+ public NotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
+ return cache.putIfAbsentAsync(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
}
- /**
- * The current invocation context for the current invocation and cache instance.
- *
- * @return the current invocation context for the current invocation and cache instance
- */
- public InvocationContext getInvocationContext()
- {
- return cache.getInvocationContext();
+ public NotifyingFuture<V> removeAsync(Object key) {
+ return cache.removeAsync(key);
}
- /**
- * Sets the passed in InvocationContext as current.
- *
- * @param ctx
- */
+ public NotifyingFuture<Boolean> removeAsync(Object key, Object value) {
+ return cache.removeAsync(key, value);
+ }
- public void setInvocationContext(InvocationContext ctx)
- {
- cache.setInvocationContext(ctx);
+ public NotifyingFuture<V> replaceAsync(K key, V value) {
+ return cache.replaceAsync(key, value);
}
- /**
- * Returns the local address of this cache in a cluster, or null if running in local mode.
- *
- * @return Returns the local address of this cache in a cluster, or null if running in local mode.
- */
- public Address getLocalAddress()
- {
- return cache.getLocalAddress();
+ public NotifyingFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit unit) {
+ return cache.replaceAsync(key, value, lifespan, unit);
}
- /**
- * Returns a list of members in the cluster, or null if running in local mode.
- *
- * @return Returns a list of members in the cluster, or null if running in local mode.
- */
+ public NotifyingFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
+ return cache.replaceAsync(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
+ }
-
- public List getMembers()
- {
- return cache.getMembers();
+ public NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue) {
+ return cache.replaceAsync(key, oldValue, newValue);
}
- public void move(Fqn nodeToMove, Fqn newParent) throws NodeNotExistsException
- {
- cache.move(nodeToMove, newParent);
+ public NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit unit) {
+ return cache.replaceAsync(key, oldValue, newValue, lifespan, unit);
}
- /**
- * Moves a part of the cache to a different subtree. Takes Strings for convenience.
- *
- * @param nodeToMove
- * @param newParent
- * @throws NodeNotExistsException
- */
- public void move(String nodeToMove, String newParent) throws NodeNotExistsException
- {
- cache.move(nodeToMove, newParent);
+ public NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
+ return cache.replaceAsync(key, oldValue, newValue, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
}
- /**
- * Returns the version of the cache as a string.
- *
- * @return Returns the version of the cache as a string.
- */
- public String getVersion()
- {
- return cache.getVersion();
+ public AdvancedCache<K, V> getAdvancedCache() {
+ return cache.getAdvancedCache();
}
- public Map<K, V> getData(Fqn fqn)
- {
- return cache.getData(fqn);
+ public void compact() {
+ cache.compact();
}
- /**
- * Returns a set of attribute keys for the Fqn. Takes Strings for convenience.
- *
- * @param fqn
- * @return Returns a set of attribute keys for the Fqn.
- */
-
- public Set<K> getKeys(String fqn)
- {
- return cache.getKeys(fqn);
+ public ComponentStatus getStatus() {
+ return cache.getStatus();
}
- public Set<K> getKeys(Fqn fqn)
- {
- return cache.getKeys(fqn);
+ public Set<K> keySet() {
+ return cache.keySet();
}
- public void clearData(String fqn)
- {
- cache.clearData(fqn);
+ public Collection<V> values() {
+ return cache.values();
}
- public void clearData(Fqn fqn)
- {
- cache.clearData(fqn);
+ public Set<Entry<K, V>> entrySet() {
+ return cache.entrySet();
}
- public void startBatch()
- {
- cache.startBatch();
+ public boolean startBatch() {
+ return cache.startBatch();
}
- public void endBatch(boolean successful)
- {
+ public void endBatch(boolean successful) {
cache.endBatch(successful);
}
- public void removeInterceptor(Class<? extends CommandInterceptor> interceptorType)
- {
- cache.removeInterceptor(interceptorType);
+ public String getName() {
+ return cache.getName();
}
- public void removeInterceptor(int position)
- {
- cache.removeInterceptor(position);
+ public V putIfAbsent(K key, V value) {
+ return cache.putIfAbsent(key, value);
}
- public void addInterceptor(CommandInterceptor i, Class<? extends CommandInterceptor> afterInterceptor)
- {
- cache.addInterceptor(i, afterInterceptor);
+ public boolean remove(Object key, Object value) {
+ return cache.remove(key, value);
}
- public void addInterceptor(CommandInterceptor i, int position)
- {
- cache.addInterceptor(i, position);
+ public boolean replace(K key, V oldValue, V newValue) {
+ return cache.replace(key, oldValue, newValue);
}
+
+ public V replace(K key, V value) {
+ return cache.replace(key, value);
+ }
+
}
Modified: branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCoreInterceptor.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCoreInterceptor.java 2009-07-03 08:30:47 UTC (rev 516)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/SearchableCoreInterceptor.java 2009-07-06 05:57:38 UTC (rev 517)
@@ -1,12 +1,24 @@
package org.infinispan.query;
+import org.hibernate.search.backend.TransactionContext;
+import org.hibernate.search.backend.Work;
+import org.hibernate.search.backend.WorkType;
import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.infinispan.commands.write.EvictCommand;
import org.infinispan.commands.write.PutKeyValueCommand;
+import org.infinispan.commands.write.PutMapCommand;
+import org.infinispan.commands.write.RemoveCommand;
+import org.infinispan.commands.write.ReplaceCommand;
import org.infinispan.context.InvocationContext;
+import org.infinispan.factories.annotations.Inject;
import org.infinispan.interceptors.base.CommandInterceptor;
+import javax.transaction.TransactionManager;
+import java.util.Map;
+
/**
- * // TODO: Document this
+ * // TODO: navssurtani --> Document this
+ * // TODO: Do I need a method for visitClearCommand()? How can I deal with it?
*
* @author Navin Surtani
* @since 4.0
@@ -15,24 +27,125 @@
public class SearchableCoreInterceptor extends CommandInterceptor {
private SearchFactoryImplementor searchFactory;
+ private TransactionManager transactionManager;
- public SearchableCoreInterceptor(SearchFactoryImplementor searchFactory){
+ @Inject
+ public void init(SearchFactoryImplementor searchFactory, TransactionManager transactionManager) {
+
+ log.debug("Entered SearchableCoreInterceptor.init()");
+
this.searchFactory = searchFactory;
+ this.transactionManager = transactionManager;
}
+ // This method will get the put() calls on the cache and then send them into Lucene once it's successful.
+
@Override
public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable {
log.debug("Entered the searchable core interceptor visitPutKeyValueCommand()");
- // I think this is the equivalent of event.isPre()?
- invokeNextInterceptor(ctx, command);
+ // do the actual put first.
+ Object toReturn = invokeNextInterceptor(ctx, command);
+ addToIndexes(command.getValue(), command.getKey().toString());
+ return toReturn;
+ }
- // getting the data of the put() command
+ @Override
+ public Object visitRemoveCommand(InvocationContext ctx, RemoveCommand command) throws Throwable {
+ log.debug("Entered the searchable core interceptor visitRemoveCommand()");
+ // remove the object out of the cache first.
+ Object valueRemoved = invokeNextInterceptor(ctx, command);
+
+ if (valueRemoved != null) {
+ removeFromIndexes(valueRemoved, command.getKey().toString());
+ }
+
+ return valueRemoved;
+
}
+
@Override
- public Object
+ public Object visitReplaceCommand(InvocationContext ctx, ReplaceCommand command) throws Throwable {
+ log.debug("Entered the searchable core interceptor visitReplaceCommand()");
+
+ Object valueReplaced = invokeNextInterceptor(ctx, command);
+ if (valueReplaced != null) {
+
+ //TODO: navssurtani --> find out from someone if this method is actually coded correctly in terms of dealing with the array.
+
+ // This is an array of parameters and we know that the array is of the form key, oldValue, newValue,
+ // lifeSpanMillis, maxIdleTimeMillis
+ Object[] parameters = command.getParameters();
+ String keyString = parameters[0].toString();
+
+ removeFromIndexes(parameters[1], keyString);
+ addToIndexes(parameters[2], keyString);
+ }
+
+ return valueReplaced;
+ }
+
+ @Override
+ public Object visitPutMapCommand(InvocationContext ctx, PutMapCommand command) throws Throwable{
+
+ //TODO: navssurtani --> Find out if that when a map gets put into the cache, if each key, value pairing in the map gets its own pairing in the cahe, or if the map is stored as a value in a key, value pair in the cache.
+
+ log.debug("Entered searchable core interceptor visitPutMapCommand()");
+
+ Object mapPut = invokeNextInterceptor(ctx, command);
+
+ Map<Object, Object> dataMap = command.getMap();
+
+ // Loop through all the keys and put those key, value pairings into lucene.
+
+ for(Object key : dataMap.keySet()){
+ addToIndexes(dataMap.get(key), key.toString());
+ }
+ return mapPut;
+ }
+
+
+ @Override
+ public Object visitEvictCommand(InvocationContext ctx, EvictCommand command) throws Throwable{
+
+ //TODO: navssurtani --> Should I be getting rid of stuff from lucene just because an object has been removed from the local cache?
+
+ log.debug("Entered searchable core interceptor visitPutMapCommand()");
+
+ Object objectEvicted = invokeNextInterceptor(ctx, command);
+
+ if (objectEvicted != null){
+ removeFromIndexes(objectEvicted, command.getKey().toString());
+ }
+ return objectEvicted;
+ }
+
+
+ // Method that will be called when data needs to be added into Lucene.
+ private void addToIndexes(Object value, String key) {
+
+ // The key here is the String representation of the key that is stored in the cache.
+ // The key is going to be the documentID for Lucene.
+ // The object parameter is the actual value that needs to be put into lucene.
+
+ TransactionContext transactionContext = new TransactionalEventTransactionContext(transactionManager);
+ searchFactory.getWorker().performWork(new Work(value, key, WorkType.ADD), transactionContext);
+ }
+
+
+ // Method that will be called when data needs to be removed from Lucene.
+ private void removeFromIndexes(Object value, String key) {
+
+ // The key here is the String representation of the key that is stored in the cache.
+ // The key is going to be the documentID for Lucene.
+ // The object parameter is the actual value that needs to be removed from lucene.
+
+ TransactionContext transactionContext = new TransactionalEventTransactionContext(transactionManager);
+ searchFactory.getWorker().performWork(new Work(value, key, WorkType.DELETE), transactionContext);
+ }
+
}
Modified: branches/ISPN-32/query/src/main/java/org/infinispan/query/TransactionalEventTransactionContext.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/TransactionalEventTransactionContext.java 2009-07-03 08:30:47 UTC (rev 516)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/TransactionalEventTransactionContext.java 2009-07-06 05:57:38 UTC (rev 517)
@@ -18,86 +18,105 @@
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+ */
-package org.jboss.cache.search;
+package org.infinispan.query;
import org.hibernate.search.backend.TransactionContext;
-import org.jboss.cache.notifications.event.TransactionalEvent;
+import org.infinispan.util.logging.Log;
import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
/**
- * This class implements the {@link org.hibernate.search.backend.TransactionContext} interface. It
- * retrieves transaction context information from the {@link org.jboss.cache.notifications.event.NodeModifiedEvent} that gets passed in.
- * <p />
- * It is used by the {@link SearchableCoreListener} to pass transaction information to a Hibernate Search {@link org.hibernate.search.backend.Work} object.
- * <p />
- * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
- * @see SearchableCoreListener
+ * This class implements the {@link org.hibernate.search.backend.TransactionContext} interface. It retrieves
+ * transaction context information from the {@link javax.transaction.TransactionManager} that gets passed in as a
+ * parameter upon instantiation.
+ * <p/>
+ * It is used by the {@link org.infinispan.query.SearchableCoreInterceptor} to pass transaction information to a
+ * Hibernate Search {@link org.hibernate.search.backend.Work} object.
+ * <p/>
+ * <p/>
+ * // TODO: navssurtani--> Document up this class. Clean up old JBCS stuff etc etc.
+ *
+ * @author Navin Surtani
+ * @see org.infinispan.query.SearchableCoreInterceptor
*/
-public class TransactionalEventTransactionContext implements TransactionContext
-{
+public class TransactionalEventTransactionContext implements TransactionContext {
- TransactionalEvent event;
+ TransactionManager transactionManager;
+ Log log;
/**
* Creates a new instance of NodeModifiedTransactionContext.
- * <p />
- * @param event a NodeModifiedEvent to wrap. Should not be null.
+ * <p/>
+ *
+ * @param transactionManager a NodeModifiedEvent to wrap. Should not be null.
* @throws NullPointerException if event is null.
*/
- public TransactionalEventTransactionContext(TransactionalEvent event)
- {
- if (event == null) throw new NullPointerException("event cannot be null");
- this.event = event;
+ public TransactionalEventTransactionContext(TransactionManager transactionManager) {
+ if (transactionManager == null) throw new NullPointerException("event cannot be null");
+ this.transactionManager = transactionManager;
}
/**
- * Returns a boolean value whether or not a transaction is in progress (JTA transaction and in this case *not*
- * an org.hibernate transaction).
+ * Returns a boolean value whether or not a transaction is in progress (JTA transaction and in this case *not* an
+ * org.hibernate transaction).
+ *
* @return true if a transaction is in progress, false otherwise.
*/
- public boolean isTransactionInProgress()
- {
- return (event.getTransaction() != null);
+ public boolean isTransactionInProgress() {
+ Transaction transaction = null;
+ try {
+ transaction = transactionManager.getTransaction();
+ }
+ catch (SystemException e) {
+ log.debug("Caught SystemException in TransactionalEventTransactionContext", e);
+ }
+ return (transaction != null);
}
/**
* Returns a JTA transaction.
+ *
* @return a JTA transaction if one is available, or a null otherwise.
- * @see org.jboss.cache.notifications.event.NodeModifiedEvent#getTransaction()
+ * @see javax.transaction.TransactionManager
*/
- public Object getTransactionIdentifier()
- {
- return event.getTransaction();
+ public Object getTransactionIdentifier() {
+
+ Transaction transaction = null;
+ try {
+ transaction = transactionManager.getTransaction();
+ }
+ catch (SystemException e) {
+ log.debug("Caught SystemException in TransactionalEventTransactionContext", e);
+ }
+
+ return transaction;
}
/**
* Registers the synchronization passed in as a parameter with the ongoing transaction.
- * <p />
+ * <p/>
* If there is no ongoing transaction, then this method will do nothing and simply return.
- * <p />
+ * <p/>
+ *
* @param synchronization synchronization to register. Must not be null.
* @throws NullPointerException if the synchronization is null.
*/
- public void registerSynchronization(Synchronization synchronization)
- {
+ public void registerSynchronization(Synchronization synchronization) {
if (synchronization == null) throw new NullPointerException("Synchronization passed in is null!");
- Transaction transaction = event.getTransaction();
- if (transaction != null)
- {
- try
- {
- transaction.registerSynchronization(synchronization);
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
+ try {
+ Transaction transaction = transactionManager.getTransaction();
+ transaction.registerSynchronization(synchronization);
}
+ catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
}
}
Modified: branches/ISPN-32/query/src/main/java/org/infinispan/query/TreeEntityId.java
===================================================================
--- branches/ISPN-32/query/src/main/java/org/infinispan/query/TreeEntityId.java 2009-07-03 08:30:47 UTC (rev 516)
+++ branches/ISPN-32/query/src/main/java/org/infinispan/query/TreeEntityId.java 2009-07-06 05:57:38 UTC (rev 517)
@@ -15,5 +15,4 @@
public Fqn getFqn();
- public String getDocumentId();
}
More information about the infinispan-commits
mailing list