diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/pom.xml b/exo.kernel.component.ext.cache.impl.infinispan.v8/pom.xml deleted file mode 100644 index 3560ac953..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/pom.xml +++ /dev/null @@ -1,155 +0,0 @@ - - - - - 4.0.0 - - io.meeds.kernel - kernel-parent - 7.0.x-meeds-qaui-SNAPSHOT - - exo.kernel.component.ext.cache.impl.infinispan.v8 - Meeds:: PLF:: Kernel :: Cache Extension :: Infinispan Implementation - Infinispan Implementation of Cache Service for Exoplatform SAS 'eXo Kernel' project. - - 0.6 - - - - io.meeds.kernel - exo.kernel.commons.test - test - - - io.meeds.kernel - exo.kernel.component.cache - - - io.meeds.kernel - exo.kernel.component.common - - - org.jgroups - jgroups - - - - - org.infinispan - infinispan-core - - - org.jboss.spec.javax.transaction - jboss-transaction-api_1.1_spec - - - org.jboss.logging - jboss-logging - - - org.jgroups - jgroups - - - - - org.jboss.logging - jboss-logging - - - org.jboss.jbossts - jbossjta - - - org.jgroups - jgroups - runtime - - - io.meeds.kernel - exo.kernel.container - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - @{argLine} @{surefire.argLine} -Djava.net.preferIPv4Stack=true - - - - jgroups.bind_addr - 127.0.0.1 - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - - - maven-antrun-plugin - - - prepare-test-policy - process-test-resources - - - Creating Access Policy for tests - - - - - - - - - - - - - - - - - run - - - - - - ant - ant-optional - 1.5.3-1 - - - - - - diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/AbstractExoCache.java b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/AbstractExoCache.java deleted file mode 100644 index 25b2d5c74..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/AbstractExoCache.java +++ /dev/null @@ -1,752 +0,0 @@ -/* - * Copyright (C) 2010 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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.exoplatform.services.cache.impl.infinispan; - -import org.exoplatform.services.cache.CacheInfo; -import org.exoplatform.services.cache.CacheListener; -import org.exoplatform.services.cache.CacheListenerContext; -import org.exoplatform.services.cache.CacheMode; -import org.exoplatform.services.cache.CachedObjectSelector; -import org.exoplatform.services.cache.ExoCache; -import org.exoplatform.services.cache.ExoCacheConfig; -import org.exoplatform.services.cache.ObjectCacheInfo; -import org.exoplatform.services.log.ExoLogger; -import org.exoplatform.services.log.Log; -import org.infinispan.AdvancedCache; -import org.infinispan.Cache; -import org.infinispan.container.entries.InternalCacheEntry; -import org.infinispan.context.Flag; -import org.infinispan.notifications.Listener; -import org.infinispan.notifications.cachelistener.annotation.CacheEntriesEvicted; -import org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated; -import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified; -import org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved; -import org.infinispan.notifications.cachelistener.event.CacheEntriesEvictedEvent; -import org.infinispan.notifications.cachelistener.event.CacheEntryCreatedEvent; -import org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent; -import org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * An {@link org.exoplatform.services.cache.ExoCache} implementation based on {@link Cache}. - * - * @author Nicolas Filotto - * @version $Id$ - * - */ -public abstract class AbstractExoCache implements ExoCache -{ - - /** - * Logger. - */ - private static final Log LOG = ExoLogger.getLogger(AbstractExoCache.class); - - private final AtomicInteger hits = new AtomicInteger(0); - - private final AtomicInteger misses = new AtomicInteger(0); - - private String label; - - private String name; - - private boolean distributed; - - private boolean replicated; - - private boolean asynchronous; - - private boolean logEnabled; - - private final CopyOnWriteArrayList> listeners; - - protected final AdvancedCache cache; - - public AbstractExoCache(ExoCacheConfig config, Cache cache) - { - this.cache = cache.getAdvancedCache(); - this.listeners = new CopyOnWriteArrayList>(); - setDistributed(config.isDistributed()); - setLabel(config.getLabel()); - setName(config.getName()); - setLogEnabled(config.isLogEnabled()); - setReplicated(config.isRepicated()); - CacheMode cacheMode = config.getCacheMode(); - setAsynchronous(cacheMode != null && !cacheMode.isSync()); - cache.addListener(new CacheEventListener()); - } - - /** - * {@inheritDoc} - */ - public void addCacheListener(CacheListener listener) - { - if (listener == null) - { - throw new IllegalArgumentException("The listener cannot be null"); - } - listeners.add(new ListenerContext(listener, this)); - } - - /** - * {@inheritDoc} - */ - public void clearCache() - { - cache.withFlags(Flag.CACHE_MODE_LOCAL).clear(); - onClearCache(); - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public V get(Serializable name) - { - if (name == null) - { - return null; - } - final V result = cache.get(name); - if (result == null) - { - misses.incrementAndGet(); - } - else - { - hits.incrementAndGet(); - } - onGet((K)name, result); - return result; - } - - /** - * {@inheritDoc} - */ - public int getCacheHit() - { - return hits.get(); - } - - /** - * {@inheritDoc} - */ - public int getCacheMiss() - { - return misses.get(); - } - - /** - * {@inheritDoc} - */ - public int getCacheSize() - { - return cache.withFlags(Flag.CACHE_MODE_LOCAL).size(); - } - - /** - * {@inheritDoc} - */ - public List getCachedObjects() - { - Collection values = cache.withFlags(Flag.CACHE_MODE_LOCAL).values(); - if (values == null || values.isEmpty()) - { - return Collections.emptyList(); - } - else - { - return new ArrayList(values); - } - } - - /** - * {@inheritDoc} - */ - public String getLabel() - { - return label; - } - - /** - * {@inheritDoc} - */ - public String getName() - { - return name; - } - - /** - * {@inheritDoc} - */ - public boolean isDistributed() - { - return distributed; - } - - /** - * {@inheritDoc} - */ - public boolean isLogEnabled() - { - return logEnabled; - } - - /** - * {@inheritDoc} - */ - public boolean isReplicated() - { - return replicated; - } - - public void setAsynchronous(boolean asynchronous) { - this.asynchronous = asynchronous; - } - - public boolean isAsynchronous() { - return asynchronous; - } - - private void putOnlyAsync(K key, V value) - { - cache.withFlags(Flag.SKIP_REMOTE_LOOKUP, Flag.IGNORE_RETURN_VALUES, Flag.FORCE_ASYNCHRONOUS).putAsync(key, value); - } - - - /** - * {@inheritDoc} - */ - public void put(final K key, final V value) throws IllegalArgumentException - { - if (key == null) - { - throw new IllegalArgumentException("No null cache key accepted"); - } - else if (value == null) - { - // ignore null values - return; - } - if(LOG.isDebugEnabled() && cache.getDataContainer().containsKey(key)) { - InternalCacheEntry internalCacheEntry = cache.getDataContainer().get(key); - if(internalCacheEntry != null) { - Object oldValue = internalCacheEntry.getValue(); - if(oldValue != null) { - if(oldValue.equals(value)) { - LOG.debug("Need to optimize top layer cache management propably (depends on ValueClass.equals method pertinence). The same value putted into cache, cache = " + cache.getName() + ", key : class= " + key.getClass() + ", hashcode= " + key.hashCode() + "/ old hashcode: " + internalCacheEntry.getKey().hashCode()); - } else { - try { - value.getClass().getDeclaredMethod("equals"); - } catch (NoSuchMethodException e) { - LOG.debug("Need to implement equals method in " + value.getClass().getCanonicalName() + ". cache = " + cache.getName() + ", key : class= " + key.getClass() + ", hashcode= " + key.hashCode() + "/ old hashcode: " + internalCacheEntry.getKey().hashCode()); - } - } - } - } - } - putOnly(key, value, false); - onPut(key, value); - } - - @Override - public void putLocal(final K key, final V value) throws IllegalArgumentException { - if (key == null) - { - throw new IllegalArgumentException("No null cache key accepted"); - } - else if (value == null) - { - // ignore null values - return; - } - - putOnly(key, value, true); - - onPutLocal(key, value); - } - - /** - * Only puts the data into the cache nothing more - */ - protected void putOnly(K key, V value, boolean isLocal) - { - if (isLocal) - { - if(isAsynchronous()) { - cache.withFlags(Flag.CACHE_MODE_LOCAL, Flag.SKIP_REMOTE_LOOKUP, Flag.IGNORE_RETURN_VALUES, Flag.FORCE_ASYNCHRONOUS).putAsync(key, value); - } else { - cache.withFlags(Flag.CACHE_MODE_LOCAL, Flag.SKIP_REMOTE_LOOKUP, Flag.IGNORE_RETURN_VALUES).put(key, value); - } - } - else - { - if(isAsynchronous()) { - cache.withFlags(Flag.SKIP_REMOTE_LOOKUP, Flag.IGNORE_RETURN_VALUES, Flag.FORCE_ASYNCHRONOUS).putAsync(key, value); - } else { - cache.withFlags(Flag.SKIP_REMOTE_LOOKUP, Flag.IGNORE_RETURN_VALUES).put(key, value); - } - } - } - - /** - * {@inheritDoc} - */ - public void putMap(final Map objs) throws IllegalArgumentException - { - if (objs == null) - { - throw new IllegalArgumentException("No null map accepted"); - } - for (Serializable name : objs.keySet()) - { - if (name == null) - { - throw new IllegalArgumentException("No null cache key accepted"); - } - } - // Start transaction - if(cache.getTransactionManager() != null) { - cache.startBatch(); - } - try - { - // Make sure that the key and the value are valid - Map map = new LinkedHashMap(); - for (Map.Entry entry : objs.entrySet()) - { - map.put(entry.getKey(), entry.getValue()); - } - cache.putAll(map); - if(cache.getTransactionManager() != null) { - cache.endBatch(true); - } - // End transaction - for (Map.Entry entry : objs.entrySet()) - { - onPut(entry.getKey(), entry.getValue()); - } - } - catch (Exception e) //NOSONAR - { - if(cache.getTransactionManager() != null) { - cache.endBatch(false); - } - LOG.warn("An error occurs while executing the putMap method", e); - } - } - - /** - * {@inheritDoc} - */ - public void putAsyncMap(final Map objs) throws IllegalArgumentException - { - if (objs == null) - { - throw new IllegalArgumentException("No null map accepted"); - } - for (Serializable name : objs.keySet()) - { - if (name == null) - { - throw new IllegalArgumentException("No null cache key accepted"); - } - } - try - { - // Make sure that the key and the value are valid - Map map = new LinkedHashMap(); - for (Map.Entry entry : objs.entrySet()) - { - map.put(entry.getKey(), entry.getValue()); - } - cache.putAllAsync(map); - // End transaction - for (Map.Entry entry : objs.entrySet()) - { - onPut(entry.getKey(), entry.getValue()); - } - } - catch (Exception e) //NOSONAR - { - LOG.warn("An error occurs while executing the putMap method", e); - } - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public V remove(final Serializable key) throws NullPointerException - { - if (key == null) - { - throw new IllegalArgumentException("No null cache key accepted"); - } - V result = cache.remove(key); - onRemove((K)key, result); - return result; - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public void removeLocal(final Serializable key) throws NullPointerException - { - if (key == null) - { - throw new IllegalArgumentException("No null cache key accepted"); - } - cache.withFlags(Flag.CACHE_MODE_LOCAL).removeAsync(key); - onRemove((K)key, null); - } - - /** - * {@inheritDoc} - */ - public List removeCachedObjects() - { - final List list = getCachedObjects(); - clearCache(); - return list; - } - - /** - * {@inheritDoc} - */ - public void select(CachedObjectSelector selector) throws Exception - { - if (selector == null) - { - throw new IllegalArgumentException("No null selector"); - } - for (Map.Entry entry : cache.withFlags(Flag.CACHE_MODE_LOCAL).entrySet()) - { - K key = entry.getKey(); - if (key == null) - { - continue; - } - final V value = entry.getValue(); - ObjectCacheInfo info = new ObjectCacheInfo() - { - public V get() - { - return value; - } - - public long getExpireTime() - { - // Cannot know: The expire time is managed by Infinispan itself - return -1; - } - }; - if (selector.select(key, info)) - { - selector.onSelect(this, key, info); - } - } - } - - /** - * {@inheritDoc} - */ - public void setDistributed(boolean distributed) - { - this.distributed = distributed; - } - - /** - * {@inheritDoc} - */ - public void setLabel(String label) - { - this.label = label; - } - - /** - * {@inheritDoc} - */ - public void setLogEnabled(boolean logEnabled) - { - this.logEnabled = logEnabled; - } - - /** - * {@inheritDoc} - */ - public void setName(String name) - { - this.name = name; - } - - /** - * {@inheritDoc} - */ - public void setReplicated(boolean replicated) - { - this.replicated = replicated; - } - - public void onExpire(K key, V obj) - { - if (listeners.isEmpty()) - { - return; - } - for (ListenerContext context : listeners) - { - try - { - context.onExpire(key, obj); - } - catch (Exception e)//NOSONAR - { - if (LOG.isWarnEnabled()) - LOG.warn("Cannot execute the CacheListener properly", e); - } - } - } - - public void onRemove(K key, V obj) - { - if (listeners.isEmpty()) - { - return; - } - for (ListenerContext context : listeners) - { - try - { - context.onRemove(key, obj); - } - catch (Exception e)//NOSONAR - { - if (LOG.isWarnEnabled()) - LOG.warn("Cannot execute the CacheListener properly", e); - } - } - } - - public void onPut(K key, V obj) - { - if (listeners.isEmpty()) - { - return; - } - for (ListenerContext context : listeners) - try - { - context.onPut(key, obj); - } - catch (Exception e)//NOSONAR - { - if (LOG.isWarnEnabled()) - LOG.warn("Cannot execute the CacheListener properly", e); - } - } - - public void onPutLocal(K key, V value) - { - if (listeners.isEmpty()) - { - return; - } - for (ListenerContext context : listeners) - try - { - context.onPutLocal(key, value); - } - catch (Exception e)//NOSONAR - { - if (LOG.isWarnEnabled()) - LOG.warn("Cannot execute the CacheListener properly", e); - } - } - - public void onGet(K key, V obj) - { - if (listeners.isEmpty()) - { - return; - } - for (ListenerContext context : listeners) - try - { - context.onGet(key, obj); - } - catch (Exception e)//NOSONAR - { - if (LOG.isWarnEnabled()) - LOG.warn("Cannot execute the CacheListener properly", e); - } - } - - public void onClearCache() - { - if (listeners.isEmpty()) - { - return; - } - for (ListenerContext context : listeners) - try - { - context.onClearCache(); - } - catch (Exception e)//NOSONAR - { - if (LOG.isWarnEnabled()) - LOG.warn("Cannot execute the CacheListener properly", e); - } - } - - @Listener - public class CacheEventListener - { - /** - * Warning Infinispan triggers a CacheEntryEvictedEvent only at explicit eviction - * that is done lazily which is not exactly what we expect, we still use it to be - * able to use it with avoidValueReplication set to true. - */ - @CacheEntriesEvicted - public void cacheEntryEvicted(CacheEntriesEvictedEvent evt) - { - if (evt.isPre()) - { - for (Map.Entry entry : evt.getEntries().entrySet()) - { - onExpire(entry.getKey(), entry.getValue()); - } - } - } - - @CacheEntryRemoved - public void cacheEntryRemoved(CacheEntryRemovedEvent evt) - { - if (evt.isPre() && !evt.isOriginLocal()) - { - final K key = evt.getKey(); - final V value = evt.getValue(); - onRemove(key, value); - } - } - - @CacheEntryModified - public void cacheEntryModified(CacheEntryModifiedEvent evt) - { - if (!evt.isOriginLocal() && !evt.isPre()) - { - final K key = evt.getKey(); - final V value = evt.getValue(); - onPut(key, value); - } - } - - @CacheEntryCreated - public void CacheEntryCreated(CacheEntryCreatedEvent event) { - if (!event.isOriginLocal() && !event.isPre()) - { - final K key = event.getKey(); - final V value = event.getValue(); - onPut(key, value);; - } - } - } - - private static class ListenerContext implements CacheListenerContext, CacheInfo - { - - /** . */ - private final ExoCache cache; - - /** . */ - final CacheListener listener; - - public ListenerContext(CacheListener listener, ExoCache cache) - { - this.listener = listener; - this.cache = cache; - } - - public CacheInfo getCacheInfo() - { - return this; - } - - public String getName() - { - return cache.getName(); - } - - public int getMaxSize() - { - return cache.getMaxSize(); - } - - public long getLiveTime() - { - return cache.getLiveTime(); - } - - public int getSize() - { - return cache.getCacheSize(); - } - - void onExpire(K key, V obj) throws Exception - { - listener.onExpire(this, key, obj); - } - - void onRemove(K key, V obj) throws Exception - { - listener.onRemove(this, key, obj); - } - - void onPut(K key, V obj) throws Exception - { - listener.onPut(this, key, obj); - } - - void onPutLocal(K key, V obj) throws Exception - { - listener.onPutLocal(this, key, obj); - } - - void onGet(K key, V obj) throws Exception - { - listener.onGet(this, key, obj); - } - - void onClearCache() throws Exception - { - listener.onClearCache(this); - } - } -} diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreator.java b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreator.java deleted file mode 100644 index 8c2f9f4d8..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreator.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2010 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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.exoplatform.services.cache.impl.infinispan; - -import org.exoplatform.services.cache.ExoCache; -import org.exoplatform.services.cache.ExoCacheConfig; -import org.exoplatform.services.cache.ExoCacheInitException; -import org.infinispan.Cache; -import org.infinispan.configuration.cache.ConfigurationBuilder; - -import java.io.Serializable; -import java.util.Set; -import java.util.concurrent.Callable; - -/** - * This class is used to create the cache according to the given - * configuration {@link org.exoplatform.services.cache.ExoCacheConfig} - * - * @author Nicolas Filotto - * @version $Id$ - */ -public interface ExoCacheCreator -{ - - /** - * Creates an eXo cache according to the given configuration {@link org.exoplatform.services.cache.ExoCacheConfig} - * @param config the configuration of the cache to apply - * @param confBuilder the configuration builder of the infinispan cache - * @param cacheGetter a {@link Callable} instance from which we can get the cache - * @exception ExoCacheInitException if an exception happens while initializing the cache - */ - public ExoCache create(ExoCacheConfig config, ConfigurationBuilder confBuilder, - Callable> cacheGetter) throws ExoCacheInitException; - - /** - * Returns the type of {@link org.exoplatform.services.cache.ExoCacheConfig} expected by the creator - * @return the expected type - */ - public Class getExpectedConfigType(); - - /** - * Returns a set of all the implementations expected by the creator. This is mainly used to be backward compatible - * @return the expected by the creator - */ - public Set getExpectedImplementations(); -} diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreatorPlugin.java b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreatorPlugin.java deleted file mode 100644 index bd772095e..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreatorPlugin.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2010 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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.exoplatform.services.cache.impl.infinispan; - -import org.exoplatform.container.component.BaseComponentPlugin; -import org.exoplatform.container.xml.InitParams; - -import java.util.ArrayList; -import java.util.List; - -/** - * This class allows us to define new creators - * @author Nicolas Filotto - * @version $Id$ - */ -public class ExoCacheCreatorPlugin extends BaseComponentPlugin -{ - - /** - * The list of all the creators defined for this ComponentPlugin - */ - private final List creators; - - public ExoCacheCreatorPlugin(InitParams params) - { - creators = new ArrayList(); - List configs = params.getObjectParamValues(ExoCacheCreator.class); - for (int i = 0; i < configs.size(); i++) - { - ExoCacheCreator config = (ExoCacheCreator)configs.get(i); - creators.add(config); - } - } - - /** - * Returns all the creators defined for this ComponentPlugin - */ - public List getCreators() - { - return creators; - } -} diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryConfigPlugin.java b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryConfigPlugin.java deleted file mode 100644 index 8cbaf5e77..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryConfigPlugin.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2010 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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.exoplatform.services.cache.impl.infinispan; - -import org.exoplatform.container.component.BaseComponentPlugin; -import org.exoplatform.container.xml.InitParams; -import org.exoplatform.container.xml.ValueParam; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -/** - * This class is used to define custom configurations - * - * @author Nicolas Filotto - * @version $Id$ - */ -public class ExoCacheFactoryConfigPlugin extends BaseComponentPlugin -{ - - /** - * The map of all the creators defined for this ComponentPlugin - */ - private final Map configs; - - public ExoCacheFactoryConfigPlugin(InitParams params) - { - configs = new HashMap(); - for (Iterator iterator = params.getValueParamIterator(); iterator.hasNext();) - { - ValueParam vParam = iterator.next(); - configs.put(vParam.getName(), vParam.getValue()); - } - } - - /** - * Returns all the configurations defined for this ComponentPlugin - */ - public Map getConfigs() - { - return configs; - } -} diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java deleted file mode 100644 index a6c41c80a..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java +++ /dev/null @@ -1,483 +0,0 @@ -/* - * Copyright (C) 2010 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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.exoplatform.services.cache.impl.infinispan; - -import org.exoplatform.container.ExoContainerContext; -import org.exoplatform.container.configuration.ConfigurationManager; -import org.exoplatform.container.xml.InitParams; -import org.exoplatform.container.xml.ValueParam; -import org.exoplatform.services.cache.ExoCache; -import org.exoplatform.services.cache.ExoCacheConfig; -import org.exoplatform.services.cache.ExoCacheFactory; -import org.exoplatform.services.cache.ExoCacheInitException; -import org.exoplatform.services.cache.impl.infinispan.distributed.DistributedExoCache; -import org.exoplatform.services.cache.impl.infinispan.generic.GenericExoCacheCreator; -import org.exoplatform.services.ispn.DistributedCacheManager; -import org.exoplatform.services.ispn.Utils; -import org.exoplatform.services.log.ExoLogger; -import org.exoplatform.services.log.Log; -import org.infinispan.Cache; -import org.infinispan.configuration.cache.CacheMode; -import org.infinispan.configuration.cache.Configuration; -import org.infinispan.configuration.cache.ConfigurationBuilder; -import org.infinispan.configuration.global.GlobalConfiguration; -import org.infinispan.configuration.global.GlobalConfigurationBuilder; -import org.infinispan.configuration.parsing.ConfigurationBuilderHolder; -import org.infinispan.configuration.parsing.ParserRegistry; -import org.infinispan.eviction.EvictionStrategy; -import org.infinispan.jmx.MBeanServerLookup; -import org.infinispan.manager.DefaultCacheManager; -import org.picocontainer.Startable; - -import java.io.InputStream; -import java.io.Serializable; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.Callable; - -import javax.management.MBeanServer; - -/** - * This class is the Infinispan implementation of the {@link org.exoplatform.services.cache.ExoCacheFactory} - * - * @author Nicolas Filotto - * @version $Id$ - * - */ -public class ExoCacheFactoryImpl implements ExoCacheFactory, Startable { - - /** - * The logger - */ - private static final Log LOG = ExoLogger.getLogger(ExoCacheFactoryImpl.class); - - /** - * The initial parameter key that defines the full path of the configuration template - */ - private static final String CACHE_CONFIG_TEMPLATE_KEY = "cache.config.template"; - - /** - * The initial parameter key that defines the full path of the optional async configuration template - */ - private static final String CACHE_ASYNC_TEMPLATE_KEY = "cache.async.config.template"; - - /** - * The cache manager for the distributed cache - */ - private final DistributedCacheManager distributedCacheManager; - - /** - * The current {@link ExoContainerContext} - */ - private final ExoContainerContext ctx; - - /** - * The configuration manager that allows us to retrieve a configuration file in several different - * manners - */ - private final ConfigurationManager configManager; - - /** - * The {@link DefaultCacheManager} used for all sync cache regions - */ - private final DefaultCacheManager cacheManager; - - /** - * The {@link DefaultCacheManager} used for all async cache regions - */ - private DefaultCacheManager asyncCacheManager = null; - - /** - * The mapping between the configuration types and the creators - */ - private final Map, ExoCacheCreator> mappingConfigTypeCreators = - new HashMap, ExoCacheCreator>(); - - /** - * The mapping between the implementations and the creators. This is mainly used for backward compatibility - */ - private final Map mappingImplCreators = new HashMap(); - - /** - * The mapping between the cache names and the configuration paths - */ - private final Map mappingCacheNameConfig = new HashMap(); - - /** - * The async cache template path - */ - private final String asyncCacheTemplate; - - /** - * The mapping between the cluster name and the cache managers - */ - private final Map mappingGlobalConfigCacheManager = - new HashMap(); - - /** - * The default creator - */ - private final ExoCacheCreator defaultCreator = new GenericExoCacheCreator(); - - private static final MBeanServerLookup MBEAN_SERVER_LOOKUP = new MBeanServerLookup() - { - public MBeanServer getMBeanServer(Properties properties) - { - return ExoContainerContext.getTopContainer().getMBeanServer(); - } - }; - - public ExoCacheFactoryImpl(ExoContainerContext ctx, InitParams params, ConfigurationManager configManager) - throws ExoCacheInitException - { - this(ctx, getValueParam(params, CACHE_CONFIG_TEMPLATE_KEY), getValueParam(params, CACHE_ASYNC_TEMPLATE_KEY), configManager, null); - } - - public ExoCacheFactoryImpl(ExoContainerContext ctx, InitParams params, ConfigurationManager configManager, - DistributedCacheManager dcm) throws ExoCacheInitException - { - this(ctx, getValueParam(params, CACHE_CONFIG_TEMPLATE_KEY), getValueParam(params, CACHE_ASYNC_TEMPLATE_KEY), configManager, dcm); - } - - public ExoCacheFactoryImpl(ExoContainerContext ctx, String cacheConfigTemplate, String cacheAsyncConfigTemplate, ConfigurationManager configManager, - DistributedCacheManager dcm) throws ExoCacheInitException - { - this.distributedCacheManager = dcm; - this.ctx = ctx; - this.configManager = configManager; - if (cacheConfigTemplate == null) - { - throw new IllegalArgumentException("The parameter '" + CACHE_CONFIG_TEMPLATE_KEY + "' must be set"); - } - // Initialize the main cache manager - this.cacheManager = initCacheManager(cacheConfigTemplate); - - this.asyncCacheTemplate = cacheAsyncConfigTemplate; - } - - /** - * Initializes the {@link DefaultCacheManager} - * @throws ExoCacheInitException if the cache manager cannot be initialized - */ - private DefaultCacheManager initCacheManager(final String cacheConfigTemplate) throws ExoCacheInitException - { - InputStream is = null; - try - { - // Read the configuration file of the cache - is = configManager.getInputStream(cacheConfigTemplate); - } - catch (Exception e)//NOSONAR - { - throw new ExoCacheInitException("The configuration of the CacheManager cannot be loaded from '" - + cacheConfigTemplate + "'", e); - } - if (is == null) - { - throw new ExoCacheInitException("The configuration of the CacheManager cannot be found at '" - + cacheConfigTemplate + "'"); - } - GlobalConfigurationBuilder configBuilder; - Configuration config; - try - { - ParserRegistry parser = new ParserRegistry(Thread.currentThread().getContextClassLoader()); - // Loads the configuration from the input stream - ConfigurationBuilderHolder holder = parser.parse(is); - configBuilder = holder.getGlobalConfigurationBuilder(); - config = holder.getDefaultConfigurationBuilder().build(); - } - catch (RuntimeException e) //NOSONAR - { - throw new ExoCacheInitException("Cannot parse the configuration '" + cacheConfigTemplate + "'", e); - } - configureCacheManager(configBuilder); - DefaultCacheManager cacheManager; - try - { - // Create the CacheManager from the new configuration - cacheManager = new DefaultCacheManager(configBuilder.build(), config); - } - catch (RuntimeException e) //NOSONAR - { - throw new ExoCacheInitException( - "Cannot initialize the CacheManager corresponding to the configuration '" + cacheConfigTemplate - + "'", e); - } - // Register the main cache manager - mappingGlobalConfigCacheManager.put(cacheManager.getCacheManagerConfiguration().transport().clusterName(), - cacheManager); - return cacheManager; - } - - /** - * Configure the cache manager - * - * @param configBuilder the configuration builder on which we applied all the required changes - * @throws ExoCacheInitException - */ - private void configureCacheManager(GlobalConfigurationBuilder configBuilder) throws ExoCacheInitException - { - GlobalConfiguration config = configBuilder.build(); - // Configure JGroups - configureJGroups(config, configBuilder); - // Configure the name of the cache manager - configBuilder.globalJmxStatistics().enable() - .cacheManagerName(config.globalJmxStatistics().cacheManagerName() + "_" + ctx.getName()). - // Configure the MBeanServerLookup - mBeanServerLookup(MBEAN_SERVER_LOOKUP); - } - - /** - * If some JGoups properties has been set, it will load the configuration and set - * the cluster name by adding as suffix the name of the {@link ExoContainerContext} - * - * @param config the global configuration from which the JGroups config will be extracted - * @param configBuilder the related configuration builder - * @throws ExoCacheInitException if any exception occurs while configuring JGroups - */ - private void configureJGroups(GlobalConfiguration config, GlobalConfigurationBuilder configBuilder) - throws ExoCacheInitException - { - if (loadJGroupsConfig(config, configBuilder)) - { - // The JGroups Config could be loaded which means that the configuration is for a cluster - configBuilder.transport().clusterName(config.transport().clusterName() + "-" + ctx.getName()); - } - } - - /** - * Load the JGroups configuration file thanks to the {@link ConfigurationManager} - * @param config the global configuration from which the JGroups config will be extracted - * @param configBuilder the related configuration builder - * @return true if the JGoups config could be loaded successfully, - * false if there were no JGroups config to load - * @throws ExoCacheInitException if the JGroups config could not be loaded - */ - private boolean loadJGroupsConfig(GlobalConfiguration config, GlobalConfigurationBuilder configBuilder) - throws ExoCacheInitException - { - return Utils.loadJGroupsConfig(configManager, config, configBuilder); - } - - /** - * To create a new cache instance according to the given configuration, we follow the steps below: - * - * We first try to find if a specific location of the cache configuration has been defined thanks - * to an external component plugin of type ExoCacheFactoryConfigPlugin. If so we use the default cache - * configuration defined in this file otherwise we use the default cache configuration defined in - * "${CACHE_CONFIG_TEMPLATE_KEY}" - */ - @SuppressWarnings({"rawtypes", "unchecked"}) - public ExoCache createCache(final ExoCacheConfig config) throws ExoCacheInitException - { - final String region = config.getName(); - String CacheConfig = mappingCacheNameConfig.get(region); - if(CacheConfig == null && config.isAsync() && asyncCacheTemplate !=null && asyncCacheManager == null) - { - //use async template if cache use async mode - this.asyncCacheManager = initCacheManager(asyncCacheTemplate); - } - final String customConfig = CacheConfig; - final ExoCache eXoCache; - final DefaultCacheManager cacheManager; - try - { - final ConfigurationBuilder confBuilder = new ConfigurationBuilder(); - if (customConfig != null) - { - // A custom configuration has been set - if (LOG.isInfoEnabled()) - LOG.info("A custom configuration has been set for the cache '" + region + "'."); - ParserRegistry parser = new ParserRegistry(Thread.currentThread().getContextClassLoader()); - // Load the configuration - ConfigurationBuilderHolder holder = parser.parse(configManager.getInputStream(customConfig)); - GlobalConfigurationBuilder configBuilder = holder.getGlobalConfigurationBuilder(); - // Configure JGroups and JMX since it could affect the state of the Global Config - configureCacheManager(configBuilder); - GlobalConfiguration gc = configBuilder.build(); - - // Check if a CacheManager with the same GlobalConfiguration exists - DefaultCacheManager currentCacheManager = - mappingGlobalConfigCacheManager.get(gc.transport().clusterName()); - if (currentCacheManager == null) - { - // Use a different cache manager name to prevent naming conflict - configBuilder.globalJmxStatistics().cacheManagerName( - gc.globalJmxStatistics().cacheManagerName() + "_" + region + "_" + ctx.getName()); - // No cache manager has been defined so far for this Cache Configuration - currentCacheManager = - new DefaultCacheManager(configBuilder.build(), holder.getDefaultConfigurationBuilder() - .build(), false); - for (Entry entry : holder.getNamedConfigurationBuilders().entrySet()) - { - currentCacheManager.defineConfiguration(entry.getKey(), entry.getValue().build()); - } - currentCacheManager.start(); - // We register this new cache manager - mappingGlobalConfigCacheManager.put(gc.transport().clusterName(), currentCacheManager); - } - cacheManager = currentCacheManager; - confBuilder.read(cacheManager.getDefaultCacheConfiguration()); - } - else if (config.isDistributed()) - { - // We expect a distributed cache - if (distributedCacheManager == null) - { - throw new IllegalArgumentException( - "The DistributedCacheManager has not been defined in the configuration," - + " please configure it at root container level if you want to use a distributed cache."); - } - return new DistributedExoCache(ctx, config, - distributedCacheManager.getCache(DistributedExoCache.CACHE_NAME)); - } - else - { - cacheManager = (config.isAsync() && asyncCacheManager != null) ? this.asyncCacheManager : this.cacheManager; - // No custom configuration has been found, a configuration template will be used - if (LOG.isInfoEnabled()) - LOG.info("The configuration template will be used for the cache '" + region + "'."); - confBuilder.read(cacheManager.getDefaultCacheConfiguration()); - if (!config.isRepicated()) - { - // The cache is local - confBuilder.clustering().cacheMode(CacheMode.LOCAL); - } - } - // Reset the configuration to avoid conflicts - resetConfiguration(confBuilder); - final ExoCacheCreator creator = getExoCacheCreator(config); - // Create the cache - eXoCache = creator.create(config, confBuilder, new Callable>() - { - public Cache call() throws Exception - { - cacheManager.defineConfiguration(region, confBuilder.build()); - // create and start the cache - return cacheManager.getCache(region); - } - }); - } - catch (Exception e) //NOSONAR - { - throw new ExoCacheInitException("The cache '" + region + "' could not be initialized", e); - } - return eXoCache; - } - - /** - * Add a list of creators to register - * @param plugin the plugin that contains the creators - */ - public void addCreator(ExoCacheCreatorPlugin plugin) - { - final List creators = plugin.getCreators(); - for (ExoCacheCreator creator : creators) - { - mappingConfigTypeCreators.put(creator.getExpectedConfigType(), creator); - Set implementations = creator.getExpectedImplementations(); - if (implementations == null) - { - throw new IllegalArgumentException("The set of implementations cannot be null"); - } - for (String imp : implementations) - { - mappingImplCreators.put(imp, creator); - } - } - } - - /** - * Add a list of custom configuration to register - * @param plugin the plugin that contains the configs - */ - public void addConfig(ExoCacheFactoryConfigPlugin plugin) - { - final Map configs = plugin.getConfigs(); - mappingCacheNameConfig.putAll(configs); - } - - @Override - public void start() { - // Nothing to start - } - - @Override - public void stop() { - if (cacheManager != null) { - cacheManager.stop(); - } - } - /** - * Returns the value of the ValueParam if and only if the value is not empty - */ - private static String getValueParam(InitParams params, String key) - { - if (params == null) - { - return null; - } - final ValueParam vp = params.getValueParam(key); - String result; - if (vp == null || (result = vp.getValue()) == null || (result = result.trim()).length() == 0) - { - return null; - } - return result; - } - - /** - * Returns the most relevant ExoCacheCreator according to the give configuration - */ - protected ExoCacheCreator getExoCacheCreator(ExoCacheConfig config) - { - ExoCacheCreator creator = mappingConfigTypeCreators.get(config.getClass()); - if (creator == null) - { - // No creator for this type has been found, let's try the implementation field - creator = mappingImplCreators.get(config.getImplementation()); - if (creator == null) - { - // No creator can be found, we will use the default creator - if (LOG.isInfoEnabled()) - LOG.info("No cache creator has been found for the cache '" + config.getName() - + "', the default one will be used."); - return defaultCreator; - } - } - if (LOG.isInfoEnabled()) - LOG.info("The cache '" + config.getName() + "' will be created with '" + creator.getClass() + "'."); - return creator; - } - - /** - * Clean the configuration template to prevent conflicts - */ - protected void resetConfiguration(ConfigurationBuilder confBuilder) - { - confBuilder.eviction().strategy(EvictionStrategy.NONE).size(-1).expiration() - .lifespan(-1L).maxIdle(-1L).wakeUpInterval(60000L); - } - -} diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/distributed/DistributedExoCache.java b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/distributed/DistributedExoCache.java deleted file mode 100644 index 1e74abb46..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/distributed/DistributedExoCache.java +++ /dev/null @@ -1,1126 +0,0 @@ -/* - * Copyright (C) 2011 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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.exoplatform.services.cache.impl.infinispan.distributed; - -import org.exoplatform.container.ExoContainer; -import org.exoplatform.container.ExoContainerContext; -import org.exoplatform.management.annotations.Managed; -import org.exoplatform.management.annotations.ManagedDescription; -import org.exoplatform.management.annotations.ManagedName; -import org.exoplatform.services.cache.CacheInfo; -import org.exoplatform.services.cache.CacheListener; -import org.exoplatform.services.cache.CacheListenerContext; -import org.exoplatform.services.cache.CachedObjectSelector; -import org.exoplatform.services.cache.ExoCache; -import org.exoplatform.services.cache.ExoCacheConfig; -import org.exoplatform.services.cache.ObjectCacheInfo; -import org.exoplatform.services.ispn.AbstractMapper; -import org.exoplatform.services.ispn.DistributedCacheManager; -import org.exoplatform.services.log.ExoLogger; -import org.exoplatform.services.log.Log; -import org.infinispan.AdvancedCache; -import org.infinispan.Cache; -import org.infinispan.context.Flag; -import org.infinispan.distexec.mapreduce.Collector; -import org.infinispan.distexec.mapreduce.MapReduceTask; -import org.infinispan.distexec.mapreduce.Reducer; -import org.infinispan.notifications.Listener; -import org.infinispan.notifications.cachelistener.annotation.CacheEntriesEvicted; -import org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated; -import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified; -import org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved; -import org.infinispan.notifications.cachelistener.event.CacheEntriesEvictedEvent; -import org.infinispan.notifications.cachelistener.event.CacheEntryCreatedEvent; -import org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent; -import org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @author Nicolas Filotto - * @version $Id$ - * - */ -public class DistributedExoCache implements ExoCache -{ - - /** - * Logger. - */ - private static final Log LOG = ExoLogger.getLogger(DistributedExoCache.class);//NOSONAR - - public static final String CACHE_NAME = "eXoCache"; - - private final AtomicInteger hits = new AtomicInteger(0); - - private final AtomicInteger misses = new AtomicInteger(0); - - private String label; - - private String name; - - private final String fullName; - - private boolean distributed; - - private boolean replicated; - - private boolean logEnabled; - - @SuppressWarnings("rawtypes") - private static final ConcurrentMap>> ALL_LISTENERS = - new ConcurrentHashMap>>(); - - protected final AdvancedCache, V> cache; - - @SuppressWarnings("unchecked") - public DistributedExoCache(ExoContainerContext ctx, ExoCacheConfig config, Cache cache) - { - this.fullName = ctx.getName() + "-" + config.getName(); - this.cache = (AdvancedCache, V>)cache.getAdvancedCache(); - setDistributed(config.isDistributed()); - setLabel(config.getLabel()); - setName(config.getName()); - setLogEnabled(config.isLogEnabled()); - setReplicated(config.isRepicated()); - } - - AdvancedCache, V> getCache() - { - return cache; - } - - /** - * @return the fullName - */ - String getFullName() - { - return fullName; - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("rawtypes") - public void addCacheListener(CacheListener listener) - { - if (listener == null) - { - throw new IllegalArgumentException("The listener cannot be null"); - } - List lListeners = getListeners(fullName); - if (lListeners == null) - { - lListeners = new CopyOnWriteArrayList(); - boolean alreadyAdded = false; - ConcurrentMap> listeners = getOrCreateListeners(); - if (listeners.isEmpty()) - { - synchronized (listeners) - { - if (listeners.isEmpty()) - { - // Ensure that the listener is added only once - cache.addListener(new CacheEventListener()); - listeners.put(fullName, lListeners); - alreadyAdded = true; - } - } - } - if (!alreadyAdded) - { - List oldValue = listeners.putIfAbsent(fullName, lListeners); - if (oldValue != null) - { - lListeners = oldValue; - } - } - } - lListeners.add(new ListenerContext(listener, this)); - } - - @SuppressWarnings("rawtypes") - private ConcurrentMap> getOrCreateListeners() - { - ConcurrentMap> listeners = ALL_LISTENERS.get(cache); - if (listeners == null) - { - listeners = new ConcurrentHashMap>(); - ConcurrentMap> oldValue = ALL_LISTENERS.putIfAbsent(cache, listeners); - if (oldValue != null) - { - listeners = oldValue; - } - } - return listeners; - } - - @SuppressWarnings("rawtypes") - private List getListeners(String fullName) - { - ConcurrentMap> listeners = ALL_LISTENERS.get(cache); - return listeners == null ? null : listeners.get(fullName); - } - - /** - * {@inheritDoc} - */ - public void clearCache() - { - MapReduceTask, V, Void, Void> task = new MapReduceTask, V, Void, Void>(cache); - task.mappedWith(new ClearCacheMapper(fullName)).reducedWith(new ClearCacheReducer()); - task.execute(); - onClearCache(); - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public V get(Serializable name) - { - if (name == null) - { - return null; - } - @SuppressWarnings("rawtypes") - final CacheKey key = new CacheKey(fullName, name); - final V result = cache.get(key); - if (result == null) - { - misses.incrementAndGet(); - } - else - { - hits.incrementAndGet(); - } - onGet(key, result); - return result; - } - - /** - * {@inheritDoc} - */ - public int getCacheHit() - { - return hits.get(); - } - - /** - * {@inheritDoc} - */ - public int getCacheMiss() - { - return misses.get(); - } - - /** - * {@inheritDoc} - */ - public int getCacheSize() - { - MapReduceTask, V, String, Integer> task = new MapReduceTask, V, String, Integer>(cache); - task.mappedWith(new GetSizeMapper(fullName)).reducedWith(new GetSizeReducer()); - Map map = task.execute(); - int sum = 0; - for (Integer i : map.values()) - { - sum += i; - } - return sum; - } - - /** - * {@inheritDoc} - */ - public List getCachedObjects() - { - MapReduceTask, V, String, List> task = - new MapReduceTask, V, String, List>(cache); - task.mappedWith(new GetCachedObjectsMapper(fullName)).reducedWith( - new GetCachedObjectsReducer()); - Map> map = task.execute(); - List result = new ArrayList(); - for (List vals : map.values()) - { - result.addAll(vals); - } - return result; - } - - /** - * {@inheritDoc} - */ - public String getLabel() - { - return label; - } - - /** - * {@inheritDoc} - */ - public String getName() - { - return name; - } - - /** - * {@inheritDoc} - */ - public boolean isDistributed() - { - return distributed; - } - - /** - * {@inheritDoc} - */ - public boolean isLogEnabled() - { - return logEnabled; - } - - /** - * {@inheritDoc} - */ - public boolean isReplicated() - { - return replicated; - } - - /** - * {@inheritDoc} - */ - public void put(final K key, final V value) throws IllegalArgumentException - { - if (key == null) - { - throw new IllegalArgumentException("No null cache key accepted"); - } - else if (value == null) - { - // ignore null values - return; - } - putOnly(key, value); - onPut(key, value); - } - - /** - * Only puts the data into the cache nothing more - */ - protected void putOnly(K key, V value) - { - cache.withFlags(Flag.SKIP_REMOTE_LOOKUP, Flag.IGNORE_RETURN_VALUES).put(new CacheKey(fullName, key), value); - } - - /** - * {@inheritDoc} - */ - public void putMap(final Map objs) throws IllegalArgumentException - { - if (objs == null) - { - throw new IllegalArgumentException("No null map accepted"); - } - for (Serializable name : objs.keySet()) - { - if (name == null) - { - throw new IllegalArgumentException("No null cache key accepted"); - } - } - // Start transaction - cache.startBatch(); - try - { - // Wrap the key into a CacheKey and make sure that the key and the value - // are valid - Map, V> map = new LinkedHashMap, V>(); - for (Map.Entry entry : objs.entrySet()) - { - map.put(new CacheKey(fullName, entry.getKey()), entry.getValue()); - } - cache.putAll(map); - cache.endBatch(true); - // End transaction - for (Map.Entry entry : objs.entrySet()) - { - onPut(entry.getKey(), entry.getValue()); - } - } - catch (Exception e)//NOSONAR - { - cache.endBatch(false); - LOG.warn("An error occurs while executing the putMap method", e); - } - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public V remove(Serializable name) throws IllegalArgumentException - { - if (name == null) - { - throw new IllegalArgumentException("No null cache key accepted"); - } - @SuppressWarnings("rawtypes") - final CacheKey key = new CacheKey(fullName, name); - V result = cache.remove(key); - onRemove(key, result); - return result; - } - - /** - * {@inheritDoc} - */ - public List removeCachedObjects() - { - final List list = getCachedObjects(); - clearCache(); - return list; - } - - /** - * {@inheritDoc} - */ - public void select(CachedObjectSelector selector) throws Exception - { - if (selector == null) - { - throw new IllegalArgumentException("No null selector"); - } - MapReduceTask, V, K, V> task = new MapReduceTask, V, K, V>(cache); - task.mappedWith(new GetEntriesMapper(fullName)).reducedWith(new GetEntriesReducer()); - Map map = task.execute(); - - for (K key : map.keySet()) - { - if (key == null) - { - continue; - } - final V value = map.get(key); - ObjectCacheInfo info = new ObjectCacheInfo() - { - public V get() - { - return value; - } - - public long getExpireTime() - { - // Cannot know: The expire time is managed by Infinispan itself - return -1; - } - }; - if (selector.select(key, info)) - { - selector.onSelect(this, key, info); - } - } - } - - /** - * {@inheritDoc} - */ - public void setDistributed(boolean distributed) - { - this.distributed = distributed; - } - - /** - * {@inheritDoc} - */ - public void setLabel(String label) - { - this.label = label; - } - - /** - * {@inheritDoc} - */ - public void setLogEnabled(boolean logEnabled) - { - this.logEnabled = logEnabled; - } - - /** - * {@inheritDoc} - */ - public void setName(String name) - { - this.name = name; - } - - /** - * {@inheritDoc} - */ - public void setReplicated(boolean replicated) - { - this.replicated = replicated; - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - void onExpire(CacheKey key, V obj) - { - List listeners = getListeners(key.getFullName()); - if (listeners == null || listeners.isEmpty()) - { - return; - } - for (ListenerContext context : listeners) - { - try - { - context.onExpire(key.getKey(), obj); - } - catch (Exception e)//NOSONAR - { - if (LOG.isWarnEnabled()) - LOG.warn("Cannot execute the CacheListener properly", e); - } - } - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - void onRemove(CacheKey key, V obj) - { - List listeners = getListeners(key.getFullName()); - if (listeners == null || listeners.isEmpty()) - { - return; - } - for (ListenerContext context : listeners) - { - try - { - context.onRemove(key, obj); - } - catch (Exception e)//NOSONAR - { - if (LOG.isWarnEnabled()) - LOG.warn("Cannot execute the CacheListener properly", e); - } - } - } - - void onPut(CacheKey key, V obj) - { - onPut(key.getFullName(), key.getKey(), obj); - } - - public void onPut(K key, V obj) - { - onPut(fullName, key, obj); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - void onPut(String fullName, K key, V obj) - { - List listeners = getListeners(fullName); - if (listeners == null || listeners.isEmpty()) - { - return; - } - for (ListenerContext context : listeners) - { - try - { - context.onPut(key, obj); - } - catch (Exception e)//NOSONAR - { - if (LOG.isWarnEnabled()) - LOG.warn("Cannot execute the CacheListener properly", e); - } - } - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - void onGet(CacheKey key, V obj) - { - List listeners = getListeners(key.getFullName()); - if (listeners == null || listeners.isEmpty()) - { - return; - } - for (ListenerContext context : listeners) - { - try - { - context.onGet(key, obj); - } - catch (Exception e)//NOSONAR - { - if (LOG.isWarnEnabled()) - LOG.warn("Cannot execute the CacheListener properly", e); - } - } - } - - @SuppressWarnings("rawtypes") - public void onClearCache() - { - List listeners = getListeners(fullName); - if (listeners == null || listeners.isEmpty()) - { - return; - } - for (ListenerContext context : listeners) - { - try - { - context.onClearCache(); - } - catch (Exception e)//NOSONAR - { - if (LOG.isWarnEnabled()) - LOG.warn("Cannot execute the CacheListener properly", e); - } - } - } - - @Listener - public class CacheEventListener - { - /** - * Warning Infinispan triggers a CacheEntryEvictedEvent only at explicit eviction - * that is done lazily which is not exactly what we expect, we still use it to be - * able to use it with avoidValueReplication set to true. - */ - @CacheEntriesEvicted - public void cacheEntryEvicted(CacheEntriesEvictedEvent, V> evt) - { - if (evt.isPre()) - { - for (Map.Entry, V> entry : evt.getEntries().entrySet()) - { - onExpire(entry.getKey(), entry.getValue()); - } - } - } - - @CacheEntryRemoved - public void cacheEntryRemoved(CacheEntryRemovedEvent, V> evt) - { - if (evt.isPre() && !evt.isOriginLocal()) - { - final CacheKey key = evt.getKey(); - final V value = evt.getValue(); - onRemove(key, value); - } - } - - @CacheEntryModified - public void cacheEntryModified(CacheEntryModifiedEvent, V> evt) - { - if (!evt.isOriginLocal() && !evt.isPre()) - { - final CacheKey key = evt.getKey(); - final V value = evt.getValue(); - onPut(key, value); - } - } - - @CacheEntryCreated - public void cacheEntrCreated(CacheEntryCreatedEvent, V> evt) - { - if (!evt.isOriginLocal() && !evt.isPre()) - { - final CacheKey key = evt.getKey(); - final V value = evt.getValue(); - onPut(key, value); - } - } - } - - private static class ListenerContext implements CacheListenerContext, CacheInfo - { - - /** . */ - private final ExoCache cache; - - /** . */ - final CacheListener listener; - - public ListenerContext(CacheListener listener, ExoCache cache) - { - this.listener = listener; - this.cache = cache; - } - - public CacheInfo getCacheInfo() - { - return this; - } - - public String getName() - { - return cache.getName(); - } - - public int getMaxSize() - { - return cache.getMaxSize(); - } - - public long getLiveTime() - { - return cache.getLiveTime(); - } - - public int getSize() - { - return cache.getCacheSize(); - } - - void onExpire(K key, V obj) throws Exception - { - listener.onExpire(this, key, obj); - } - - void onRemove(K key, V obj) throws Exception - { - listener.onRemove(this, key, obj); - } - - void onPut(K key, V obj) throws Exception - { - listener.onPut(this, key, obj); - } - - void onGet(K key, V obj) throws Exception - { - listener.onGet(this, key, obj); - } - - void onClearCache() throws Exception - { - listener.onClearCache(this); - } - } - - public void setMaxSize(int max) - { - throw new UnsupportedOperationException("The configuration of the cache cannot not be modified"); - } - - public void setLiveTime(long period) - { - throw new UnsupportedOperationException("The configuration of the cache cannot not be modified"); - } - - @ManagedName("MaxEntries") - @ManagedDescription("Maximum number of entries in a cache instance. -1 means no limit.") - public int getMaxSize() - { - return Math.toIntExact(cache.getCacheConfiguration().eviction().maxEntries()); - } - - @ManagedName("Lifespan") - @ManagedDescription("Maximum lifespan of a cache entry, after which the entry is expired cluster-wide." - + " -1 means the entries never expire.") - public long getLiveTime() - { - return cache.getCacheConfiguration().expiration().lifespan(); - } - - @Managed - @ManagedName("MaxIdle") - @ManagedDescription("Maximum idle time a cache entry will be maintained in the cache. " - + "If the idle time is exceeded, the entry will be expired cluster-wide. -1 means the entries never expire.") - public long getMaxIdle() - { - return cache.getCacheConfiguration().expiration().maxIdle(); - } - - @Managed - @ManagedName("WakeUpInterval") - @ManagedDescription("Interval between subsequent eviction runs. If you wish to disable the periodic eviction " - + "process altogether, set wakeupInterval to -1.") - public long getWakeUpInterval() - { - return cache.getCacheConfiguration().expiration().wakeUpInterval(); - } - - public static class CacheKey implements Externalizable - { - private K key; - - private String fullName; - - public CacheKey() - { - } - - public CacheKey(String fullName, K key) - { - this.fullName = fullName; - this.key = key; - } - - /** - * @return the nested key - */ - K getKey() - { - return key; - } - - /** - * @return the fullName - */ - String getFullName() - { - return fullName; - } - - /** - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + ((fullName == null) ? 0 : fullName.hashCode()); - result = prime * result + ((key == null) ? 0 : key.hashCode()); - return result; - } - - /** - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) - { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - @SuppressWarnings("rawtypes") - CacheKey other = (CacheKey)obj; - if (fullName == null) - { - if (other.fullName != null) - return false; - } - else if (!fullName.equals(other.fullName)) - return false; - if (key == null) - { - if (other.key != null) - return false; - } - else if (!key.equals(other.key)) - return false; - return true; - } - - /** - * @see java.lang.Object#toString() - */ - @Override - public String toString() - { - return "CacheKey [fullName=" + fullName + ", key=" + key + "]"; - } - - /** - * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput) - */ - public void writeExternal(ObjectOutput out) throws IOException - { - byte[] buf = fullName.getBytes("UTF-8"); - out.writeInt(buf.length); - out.write(buf); - out.writeObject(key); - } - - /** - * @see java.io.Externalizable#readExternal(java.io.ObjectInput) - */ - @SuppressWarnings("unchecked") - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException - { - byte[] buf = new byte[in.readInt()]; - in.readFully(buf); - fullName = new String(buf, "UTF-8"); - key = (K)in.readObject(); - } - } - - private abstract static class AbstractExoCacheMapper extends - AbstractMapper, V, KOut, VOut> implements Externalizable - { - /** - * The full name of the cache instance - */ - private String fullName; - - public AbstractExoCacheMapper() - { - } - - public AbstractExoCacheMapper(String fullName) - { - this.fullName = fullName; - } - - /** - * The serial version UID - */ - private static final long serialVersionUID = 7962676854308932222L; - - /** - * @see org.exoplatform.services.ispn.AbstractMapper#isValid(java.lang.Object) - */ - @Override - protected boolean isValid(CacheKey key) - { - return fullName.equals(key.getFullName()); - } - - /** - * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput) - */ - public void writeExternal(ObjectOutput out) throws IOException - { - byte[] buf = fullName.getBytes("UTF-8"); - out.writeInt(buf.length); - out.write(buf); - } - - /** - * @see java.io.Externalizable#readExternal(java.io.ObjectInput) - */ - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException - { - byte[] buf = new byte[in.readInt()]; - in.readFully(buf); - fullName = new String(buf, "UTF-8"); - } - } - - public static class GetSizeMapper extends AbstractExoCacheMapper - { - - public GetSizeMapper() - { - } - - public GetSizeMapper(String fullName) - { - super(fullName); - } - - /** - * {@inheritDoc} - */ - @Override - protected void _map(CacheKey key, V value, Collector collector) - { - collector.emit("total", Integer.valueOf(1)); - } - - } - - public static class GetSizeReducer implements Reducer - { - - /** - * The serial version UID - */ - private static final long serialVersionUID = -5264142863835473112L; - - /** - * @see org.infinispan.distexec.mapreduce.Reducer#reduce(java.lang.Object, java.util.Iterator) - */ - @Override - public Integer reduce(K reducedKey, Iterator iter) - { - int sum = 0; - while (iter.hasNext()) - { - Integer i = iter.next(); - sum += i; - } - return sum; - } - } - - public static class GetCachedObjectsMapper extends AbstractExoCacheMapper> - { - - public GetCachedObjectsMapper() - { - } - - public GetCachedObjectsMapper(String fullName) - { - super(fullName); - } - - /** - * {@inheritDoc} - */ - @Override - protected void _map(CacheKey key, V value, Collector> collector) - { - collector.emit("values", Collections.singletonList(value)); - } - - } - - public static class GetCachedObjectsReducer implements Reducer> - { - - /** - * The serial version UID - */ - private static final long serialVersionUID = 8069024420056440405L; - - /** - * @see org.infinispan.distexec.mapreduce.Reducer#reduce(java.lang.Object, java.util.Iterator) - */ - @Override - public List reduce(K reducedKey, Iterator> iter) - { - List values = new ArrayList(); - while (iter.hasNext()) - { - List vals = iter.next(); - values.addAll(vals); - } - return values; - } - } - - public static class ClearCacheMapper extends AbstractExoCacheMapper - { - - public ClearCacheMapper() - { - } - - public ClearCacheMapper(String fullName) - { - super(fullName); - } - - /** - * {@inheritDoc} - */ - @Override - protected void _map(CacheKey key, V value, Collector collector) - { - ExoContainer container = ExoContainerContext.getTopContainer(); - if (container == null) - { - LOG.error("The top container could not be found"); - return; - } - DistributedCacheManager dcm = - (DistributedCacheManager)container.getComponentInstanceOfType(DistributedCacheManager.class); - if (dcm == null) - { - LOG.error("The DistributedCacheManager could not be found at top container level, please configure it."); - return; - } - Cache, V> cache = dcm.getCache(CACHE_NAME); - cache.getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP, Flag.FAIL_SILENTLY).remove(key); - } - } - - public static class ClearCacheReducer implements Reducer - { - - /** - * The serial version UID - */ - private static final long serialVersionUID = -8111087186325793256L; - - /** - * @see org.infinispan.distexec.mapreduce.Reducer#reduce(java.lang.Object, java.util.Iterator) - */ - @Override - public Void reduce(Void reducedKey, Iterator iter) - { - return null; - } - } - - public static class GetEntriesMapper extends AbstractExoCacheMapper - { - public GetEntriesMapper() - { - } - - public GetEntriesMapper(String fullName) - { - super(fullName); - } - - /** - * {@inheritDoc} - */ - @Override - protected void _map(CacheKey key, V value, Collector collector) - { - collector.emit(key.getKey(), value); - } - } - - public static class GetEntriesReducer implements Reducer - { - - /** - * The serial version UID - */ - private static final long serialVersionUID = 5153826700048219537L; - - /** - * @see org.infinispan.distexec.mapreduce.Reducer#reduce(java.lang.Object, java.util.Iterator) - */ - @Override - public V reduce(K reducedKey, Iterator iter) - { - return iter == null || !iter.hasNext() ? null : iter.next(); - } - } -} diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheConfig.java b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheConfig.java deleted file mode 100644 index a2556e3bd..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheConfig.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2010 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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.exoplatform.services.cache.impl.infinispan.generic; - -import org.exoplatform.services.cache.ExoCacheConfig; - -/** - * The {@link org.exoplatform.services.cache.ExoCacheConfig} for all the eviction algorithms - * available in infinispan - * - * @author Nicolas Filotto - * @version $Id$ - * - */ -public class GenericExoCacheConfig extends ExoCacheConfig -{ - - private String strategy; - - private long maxIdle; - - private long wakeUpInterval; - - /** - * @return the strategy - */ - public String getStrategy() - { - return strategy; - } - - /** - * @param strategy the strategy to set - */ - public void setStrategy(String strategy) - { - this.strategy = strategy; - } - - /** - * @return the wakeUpInterval - */ - public long getWakeUpInterval() - { - return wakeUpInterval; - } - - /** - * @param wakeUpInterval the wakeUpInterval to set - */ - public void setWakeUpInterval(long wakeUpInterval) - { - this.wakeUpInterval = wakeUpInterval; - } - - /** - * @return the maxIdle - */ - public long getMaxIdle() - { - return maxIdle; - } - - /** - * @param maxIdle the maxIdle to set - */ - public void setMaxIdle(long maxIdle) - { - this.maxIdle = maxIdle; - } -} \ No newline at end of file diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java deleted file mode 100644 index 6e4a90a4b..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (C) 2010 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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.exoplatform.services.cache.impl.infinispan.generic; - -import org.exoplatform.management.annotations.Managed; -import org.exoplatform.management.annotations.ManagedDescription; -import org.exoplatform.management.annotations.ManagedName; -import org.exoplatform.services.cache.ExoCache; -import org.exoplatform.services.cache.ExoCacheConfig; -import org.exoplatform.services.cache.ExoCacheInitException; -import org.exoplatform.services.cache.impl.infinispan.AbstractExoCache; -import org.exoplatform.services.cache.impl.infinispan.ExoCacheCreator; -import org.infinispan.Cache; -import org.infinispan.configuration.cache.ConfigurationBuilder; -import org.infinispan.eviction.EvictionStrategy; - -import java.io.Serializable; -import java.util.Locale; -import java.util.Set; -import java.util.concurrent.Callable; - -/** - * The generic {@link ExoCacheCreator} for all the expiration available in infinispan. - * - * @author Nicolas Filotto - * @version $Id$ - * - */ -public class GenericExoCacheCreator implements ExoCacheCreator -{ - - /** - * The default value for the eviction strategy - */ - protected String defaultStrategy = "LRU"; - - /** - * The default value for maxIdle - */ - protected long defaultMaxIdle = -1; - - /** - * The default value for wakeUpInterval - */ - protected long defaultWakeUpInterval = 5000; - - /** - * A set of all the implementations supported by this creator - */ - protected Set implementations; - - /** - * {@inheritDoc} - */ - public Set getExpectedImplementations() - { - return implementations; - } - - /** - * {@inheritDoc} - */ - public Class getExpectedConfigType() - { - return GenericExoCacheConfig.class; - } - - /** - * {@inheritDoc} - */ - public ExoCache create(ExoCacheConfig config, ConfigurationBuilder confBuilder, - Callable> cacheGetter) throws ExoCacheInitException - { - if (config instanceof GenericExoCacheConfig) - { - final GenericExoCacheConfig gConfig = (GenericExoCacheConfig)config; - return create(config, confBuilder, cacheGetter, gConfig.getStrategy(), gConfig.getMaxSize(), - gConfig.getLiveTime(), gConfig.getMaxIdle() == 0 ? defaultMaxIdle : gConfig.getMaxIdle(), - gConfig.getWakeUpInterval() == 0 ? defaultWakeUpInterval : gConfig.getWakeUpInterval()); - } - else - { - final long period = config.getLiveTime(); - return create(config, confBuilder, cacheGetter, - config.getImplementation() == null ? defaultStrategy : config.getImplementation(), config.getMaxSize(), - period > 0 ? period * 1000 : -1, defaultMaxIdle, defaultWakeUpInterval); - } - } - - /** - * Creates a new ExoCache instance with the relevant parameters - * @throws ExoCacheInitException If any exception occurs while creating the cache - */ - private ExoCache create(ExoCacheConfig config, ConfigurationBuilder confBuilder, - Callable> cacheGetter, String strategy, int maxEntries, long lifespan, long maxIdle, - long wakeUpInterval) throws ExoCacheInitException - { - EvictionStrategy es = - strategy == null || strategy.length() == 0 ? null : EvictionStrategy.valueOf(strategy - .toUpperCase(Locale.ENGLISH)); - if (es == null) - { - es = EvictionStrategy.LRU; - } - confBuilder.eviction().strategy(EvictionStrategy.valueOf(strategy)).maxEntries(maxEntries).expiration() - .lifespan(lifespan).maxIdle(maxIdle).wakeUpInterval(wakeUpInterval); - try - { - return new GenericExoCache(config, cacheGetter.call()); - } - catch (Exception e)//NOSONAR - { - throw new ExoCacheInitException("Cannot create the cache '" + config.getName() + "'", e); - } - } - - /** - * The Generic implementation of an ExoCache - */ - public static class GenericExoCache extends AbstractExoCache - { - - public GenericExoCache(ExoCacheConfig config, Cache cache) - { - super(config, cache); - } - - public void setMaxSize(int max) - { - throw new UnsupportedOperationException("The configuration of the cache cannot not be modified"); - } - - public void setLiveTime(long period) - { - throw new UnsupportedOperationException("The configuration of the cache cannot not be modified"); - } - - public int getMaxSize() - { - return Math.toIntExact(cache.getCacheConfiguration().eviction().maxEntries()); - } - - public long getLiveTime() - { - return cache.getCacheConfiguration().expiration().lifespan(); - } - - @Managed - @ManagedName("MaxIdle") - @ManagedDescription("Maximum idle time a cache entry will be maintained in the cache. " - + "If the idle time is exceeded, the entry will be expired cluster-wide. -1 means the entries never expire.") - public long getMaxIdle() - { - return cache.getCacheConfiguration().expiration().maxIdle(); - } - - @Managed - @ManagedName("WakeUpInterval") - @ManagedDescription("Interval between subsequent eviction runs. If you wish to disable the periodic eviction " - + "process altogether, set wakeupInterval to -1.") - public long getWakeUpInterval() - { - return cache.getCacheConfiguration().expiration().wakeUpInterval(); - } - } -} \ No newline at end of file diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/ispn/AbstractMapper.java b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/ispn/AbstractMapper.java deleted file mode 100644 index ecd304554..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/ispn/AbstractMapper.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2011 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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.exoplatform.services.ispn; - -import org.infinispan.distexec.mapreduce.Collector; -import org.infinispan.distexec.mapreduce.Mapper; - -/** - * The main class of all the mappers. - * - * @author Nicolas Filotto - * @version $Id$ - * - */ -public abstract class AbstractMapper implements Mapper -{ - - /** - * The serial version UID - */ - private static final long serialVersionUID = 7118530772747505976L; - - /** - * {@inheritDoc} - */ - @Override - public void map(KIn key, VIn value, Collector collector) - { - if (isValid(key)) - { - _map(key, value, collector); - } - } - - /** - * This method is in fact an internal mapping, it will be called by the map method in - * case the given key matches with the context - */ - protected abstract void _map(KIn key, VIn value, Collector collector); - - /** - * Indicates if the given key matches with the current context, indeed as the cache instances are - * shared it is needed to check each key to know if it is part of the targeted scope or not. - * - * @param key the key to check - * @return true if the key matches with the scope, false otherwise. - */ - protected abstract boolean isValid(KIn key); - -} diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/ispn/DistributedCacheManager.java b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/ispn/DistributedCacheManager.java deleted file mode 100644 index 570c53652..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/ispn/DistributedCacheManager.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (C) 2011 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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.exoplatform.services.ispn; - -import org.exoplatform.container.ExoContainer; -import org.exoplatform.container.configuration.ConfigurationManager; -import org.exoplatform.container.util.TemplateConfigurationHelper; -import org.exoplatform.container.xml.InitParams; -import org.exoplatform.container.xml.PropertiesParam; -import org.exoplatform.container.xml.ValueParam; -import org.exoplatform.services.log.ExoLogger; -import org.exoplatform.services.log.Log; -import org.exoplatform.services.transaction.TransactionService; -import org.infinispan.Cache; -import org.infinispan.configuration.cache.ConfigurationBuilder; -import org.infinispan.configuration.global.GlobalConfigurationBuilder; -import org.infinispan.configuration.parsing.ConfigurationBuilderHolder; -import org.infinispan.configuration.parsing.ParserRegistry; -import org.infinispan.manager.DefaultCacheManager; -import org.infinispan.manager.EmbeddedCacheManager; -import org.infinispan.transaction.lookup.TransactionManagerLookup; -import org.picocontainer.Startable; - -import java.util.Map; -import java.util.Map.Entry; - -import javax.transaction.TransactionManager; - -/** - * This class is used to allow to use infinispan in distribution mode with - * the ability to launch infinispan instances in standalone mode, in other - * words outside an application server. To make it possible we will need to share - * the same cache instance whatever the related {@link ExoContainer} because - * to be able to launch ispn instances in standalone mode we need to have a static - * configuration file. - * - * @author Nicolas Filotto - * @version $Id$ - * - */ -public class DistributedCacheManager implements Startable -{ - /** - * The logger - */ - private static final Log LOG = ExoLogger //NOSONAR - .getLogger("exo.kernel.component.ext.cache.impl.infinispan.v8.DistributedCacheManager");//NOSONAR - - /** - * The parameter name corresponding to the infinispan configuration - */ - private static final String CONFIG_FILE_PARAMETER_NAME = "infinispan-configuration"; - - /** - * The parameter name corresponding to the parameters to inject - * into the infinispan configuration file - */ - private static final String PARAMS_PARAMETER_NAME = "parameters"; - - /** - * The infinispan cache manager - */ - protected final EmbeddedCacheManager manager; - - /** - * Default constructor - */ - public DistributedCacheManager(String configurationFile, Map parameters, - ConfigurationManager configManager) - { - this.manager = init(configurationFile, parameters, configManager, null); - } - - /** - * Default constructor - */ - public DistributedCacheManager(InitParams params, ConfigurationManager configManager) - { - this(params, configManager, null); - } - - /** - * Default constructor - */ - public DistributedCacheManager(InitParams params, ConfigurationManager configManager, TransactionService ts) - { - ValueParam vp; - final String result; - if (params != null && (vp = params.getValueParam(CONFIG_FILE_PARAMETER_NAME)) != null - && (result = vp.getValue()) != null && !result.isEmpty()) - { - PropertiesParam pp = params.getPropertiesParam(PARAMS_PARAMETER_NAME); - this.manager = - init(result, pp == null ? null : pp.getProperties(), configManager, - ts == null ? null : ts.getTransactionManager()); - } - else - { - throw new IllegalArgumentException("The parameter '" + CONFIG_FILE_PARAMETER_NAME + "' must be set"); - } - } - - /** - * Initializes and created the CacheManager - * @param configurationFile the path of the configuration file - * @param parameters the parameters to inject into the configuration file - * @param configManager the configuration manager used to get the configuration file - * @param tm the transaction manager - * @return the CacheManager initialized - */ - private EmbeddedCacheManager init(final String configurationFile, final Map parameters, - final ConfigurationManager configManager, final TransactionManager tm) - { - try - { - if (configurationFile == null || configurationFile.isEmpty()) - { - throw new IllegalArgumentException("The parameter 'configurationFile' must be set"); - } - if (LOG.isDebugEnabled()) - { - LOG.debug("The configuration file of the DistributedCacheManager will be loaded from " + configurationFile); - } - final TemplateConfigurationHelper helper = - new TemplateConfigurationHelper(new String[]{"^.*"}, new String[]{}, configManager); - if (LOG.isDebugEnabled() && parameters != null && !parameters.isEmpty()) - { - LOG.debug("The parameters to use while processing the configuration file are " + parameters); - } - ParserRegistry parser = new ParserRegistry(Thread.currentThread().getContextClassLoader()); - // Load the configuration - ConfigurationBuilderHolder holder = parser.parse(helper.fillTemplate(configurationFile, parameters)); - GlobalConfigurationBuilder configBuilder = holder.getGlobalConfigurationBuilder(); - Utils.loadJGroupsConfig(configManager, configBuilder.build(), configBuilder); - // Create the CacheManager from the new configuration - EmbeddedCacheManager manager = - new DefaultCacheManager(configBuilder.build(), holder.getDefaultConfigurationBuilder().build()); - TransactionManagerLookup tml = new TransactionManagerLookup() - { - public TransactionManager getTransactionManager() throws Exception - { - return tm; - } - }; - for (Entry entry : holder.getNamedConfigurationBuilders().entrySet()) - { - ConfigurationBuilder b = entry.getValue(); - if (tm != null) - { - b.transaction().transactionManagerLookup(tml); - } - manager.defineConfiguration(entry.getKey(), b.build()); - } - for( String cacheName : manager.getCacheNames()) - { - manager.getCache(cacheName); - } - return manager; - } - catch (Exception e)//NOSONAR - { - throw new IllegalStateException( - "Could not initialize the cache manager corresponding to the configuration file " + configurationFile, e); - } - } - - /** - * Gives the cache corresponding to the given name if it doesn't exist - * a {@link NullPointerException} will be thrown - */ - public Cache getCache(String cacheName) - { - Cache cache = manager.getCache(cacheName); - if (cache == null) - { - throw new IllegalArgumentException("The expected cache named '" + cacheName - + "' has not been defined in the configuration of infinispan as named cache."); - } - return cache; - } - - /** - * @see org.picocontainer.Startable#start() - */ - @Override - public void start() - { - } - - /** - * @see org.picocontainer.Startable#stop() - */ - @Override - public void stop() - { - manager.stop(); - } -} diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/ispn/Utils.java b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/ispn/Utils.java deleted file mode 100644 index c8b31d9f1..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/ispn/Utils.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2011 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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.exoplatform.services.ispn; - -import org.exoplatform.container.configuration.ConfigurationManager; -import org.exoplatform.container.util.TemplateConfigurationHelper; -import org.exoplatform.services.cache.ExoCacheInitException; -import org.infinispan.configuration.global.GlobalConfiguration; -import org.infinispan.configuration.global.GlobalConfigurationBuilder; -import org.infinispan.remoting.transport.jgroups.JGroupsTransport; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -/** - * @author Nicolas Filotto - * @version $Id$ - * - */ -public class Utils -{ - - private Utils() - { - } - - /** - * Load the JGroups configuration file thanks to the {@link ConfigurationManager} - * @param config the global configuration from which the JGroups config will be extracted - * @param configBuilder the related configuration builder - * @return true if the JGoups config could be loaded successfully, - * false if there were no JGroups config to load - * @throws IllegalStateException if the JGroups config could not be loaded - */ - public static boolean loadJGroupsConfig(ConfigurationManager cfm, GlobalConfiguration config, - GlobalConfigurationBuilder configBuilder) throws ExoCacheInitException - { - Properties properties = config.transport().properties(); - if (properties == null || !properties.containsKey(JGroupsTransport.CONFIGURATION_FILE)) - { - return false; - } - String filename = properties.getProperty(JGroupsTransport.CONFIGURATION_FILE); - InputStream inputStream = TemplateConfigurationHelper.getInputStream(cfm, filename); - - // inputStream still remains null, so file was not opened - if (inputStream == null) - { - throw new IllegalStateException("The jgroups configuration cannot be loaded from '" + filename + "'"); - } - try - { - // Set the jgroups configuration as XML - properties.setProperty(JGroupsTransport.CONFIGURATION_XML, - org.exoplatform.container.util.Utils.readStream(inputStream)); - } - catch (IOException e) - { - throw new IllegalStateException("The jgroups configuration cannot be read from '" + filename + "'", e); - } - // Remove the property corresponding to the configuration file - properties.remove(JGroupsTransport.CONFIGURATION_FILE); - configBuilder.transport().withProperties(properties); - return true; - } -} diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/transaction/infinispan/GenericTransactionService.java b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/transaction/infinispan/GenericTransactionService.java deleted file mode 100644 index 646ce67b5..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/transaction/infinispan/GenericTransactionService.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2010 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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.exoplatform.services.transaction.infinispan; - -import org.exoplatform.container.xml.InitParams; -import org.exoplatform.services.transaction.impl.AbstractTransactionService; -import org.infinispan.transaction.lookup.TransactionManagerLookup; - -import javax.transaction.TransactionManager; - -/** - * @author Dmytro Katayev - * @version $Id: GenericTransactionService.java -1 $ - */ -public class GenericTransactionService extends AbstractTransactionService -{ - - /** - * TransactionManagerLookup. - */ - protected final TransactionManagerLookup tmLookup; - - /** - * JBossTransactionManagerLookup constructor. - * - * @param tmLookup TransactionManagerLookup - */ - public GenericTransactionService(TransactionManagerLookup tmLookup) - { - this(tmLookup, null); - } - - public GenericTransactionService(TransactionManagerLookup tmLookup, InitParams params) - { - super(params); - this.tmLookup = tmLookup; - } - - /** - * {@inheritDoc} - */ - public TransactionManager findTransactionManager() throws Exception - { - return tmLookup.getTransactionManager(); - } -} diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/transaction/infinispan/JBossStandaloneJTAManagerLookup.java b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/transaction/infinispan/JBossStandaloneJTAManagerLookup.java deleted file mode 100644 index a9b62a7b0..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/transaction/infinispan/JBossStandaloneJTAManagerLookup.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2011 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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.exoplatform.services.transaction.infinispan; - -import org.exoplatform.commons.utils.ClassLoading; -import org.exoplatform.services.log.ExoLogger; -import org.exoplatform.services.log.Log; -import org.exoplatform.services.transaction.TransactionService; -import org.infinispan.transaction.lookup.TransactionManagerLookup; - -import java.lang.reflect.Method; - -import javax.transaction.TransactionManager; -import javax.transaction.UserTransaction; - -/** - * This class is used to replace the one provided by default in ISPN 5.0 since - * it implicitly requires that ISPN is initialized before the rest which is actually - * the exact opposite. Indeed Arjuna accessors are initialized in the init method which is - * called at ISPN initialization but we expect to get the {@link TransactionManager} - * from it through the {@link TransactionService} before initializing the JCR so before - * initializing ISPN. - * - * The code below is a simple copy/paste of the code of - * {@link org.infinispan.transaction.lookup.JBossStandaloneJTAManagerLookup} of ISPN 4. - * - * @author Nicolas Filotto - * @version $Id$ - * - */ -public class JBossStandaloneJTAManagerLookup implements TransactionManagerLookup -{ - /** - * The logger - */ - private static final Log LOG = //NOSONAR - ExoLogger.getLogger("exo.jcr.component.core.JBossStandaloneJTAManagerLookup");//NOSONAR - - private Method manager, user; - - public JBossStandaloneJTAManagerLookup() - { - try - { - manager = loadClassStrict("com.arjuna.ats.jta.TransactionManager").getMethod("transactionManager"); - user = loadClassStrict("com.arjuna.ats.jta.UserTransaction").getMethod("userTransaction"); - } - catch (ClassNotFoundException e) - { - throw new RuntimeException(e);//NOSONAR - } - catch (SecurityException e) - { - throw new RuntimeException(e);//NOSONAR - } - catch (NoSuchMethodException e) - { - throw new RuntimeException(e);//NOSONAR - } - } - - public TransactionManager getTransactionManager() throws Exception - { - TransactionManager tm = (TransactionManager)manager.invoke(null); - if (tm == null && LOG.isWarnEnabled()) - { - LOG.warn("The transaction manager could not be found"); - } - return tm; - } - - public UserTransaction getUserTransaction() throws Exception - { - UserTransaction ut = (UserTransaction)user.invoke(null); - if (ut == null && LOG.isWarnEnabled()) - { - LOG.warn("The user transaction could not be found"); - } - return ut; - } - - /** - * Loads the specified class using this class's classloader, or, if it is null (i.e. this class was - * loaded by the bootstrap classloader), the system classloader.
If loadtime instrumentation via - * GenerateInstrumentedClassLoader is used, this class may be loaded by the bootstrap classloader.
- * - * @param classname name of the class to load - * @return the class - * @throws ClassNotFoundException - */ - private static Class loadClassStrict(String classname) throws ClassNotFoundException - { - return ClassLoading.loadClass(classname, JBossStandaloneJTAManagerLookup.class); - } -} diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/transaction/infinispan/JBossTransactionsService.java b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/transaction/infinispan/JBossTransactionsService.java deleted file mode 100644 index 64a550154..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/java/org/exoplatform/services/transaction/infinispan/JBossTransactionsService.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2010 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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.exoplatform.services.transaction.infinispan; - -import org.exoplatform.container.xml.InitParams; -import org.infinispan.transaction.lookup.TransactionManagerLookup; - -import javax.transaction.UserTransaction; - -/** - * Add the specific part for Arjuna - * - * @author Nicolas Filotto - * @version $Id$ - * - */ -public class JBossTransactionsService extends GenericTransactionService -{ - - public JBossTransactionsService(TransactionManagerLookup tmLookup) - { - super(tmLookup); - } - - public JBossTransactionsService(TransactionManagerLookup tmLookup, InitParams params) - { - super(tmLookup, params); - } - - /** - * {@inheritDoc} - */ - @Override - protected UserTransaction findUserTransaction() throws Exception - { - return com.arjuna.ats.jta.UserTransaction.userTransaction(); - } -} diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/resources/conf/portal/cache-configuration-template.xml b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/resources/conf/portal/cache-configuration-template.xml deleted file mode 100644 index ca8d883b1..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/resources/conf/portal/cache-configuration-template.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/resources/conf/portal/configuration.xml b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/resources/conf/portal/configuration.xml deleted file mode 100644 index b9783cdb3..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/main/resources/conf/portal/configuration.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - org.exoplatform.services.cache.ExoCacheFactory - org.exoplatform.services.cache.impl.infinispan.ExoCacheFactoryImpl - - - cache.config.template - jar:/conf/portal/cache-configuration-template.xml - - - - diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestAbstractExoCache.java b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestAbstractExoCache.java deleted file mode 100644 index 5bc85214c..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestAbstractExoCache.java +++ /dev/null @@ -1,692 +0,0 @@ -/* - * Copyright (C) 2010 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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.exoplatform.services.cache.impl.infinispan; - -import junit.framework.TestCase; - -import org.exoplatform.container.ExoContainer; -import org.exoplatform.container.ExoContainerContext; -import org.exoplatform.container.PortalContainer; -import org.exoplatform.container.RootContainer; -import org.exoplatform.container.configuration.ConfigurationManager; -import org.exoplatform.services.cache.CacheListener; -import org.exoplatform.services.cache.CacheListenerContext; -import org.exoplatform.services.cache.CacheService; -import org.exoplatform.services.cache.CachedObjectSelector; -import org.exoplatform.services.cache.ExoCache; -import org.exoplatform.services.cache.ExoCacheConfig; -import org.exoplatform.services.cache.ExoCacheFactory; -import org.exoplatform.services.cache.ExoCacheInitException; -import org.exoplatform.services.cache.ObjectCacheInfo; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @author Nicolas Filotto - * @version $Id$ - * - */ -public class TestAbstractExoCache extends TestCase -{ - - PortalContainer container; - - CacheService service; - - AbstractExoCache cache; - - public TestAbstractExoCache(String name) - { - super(name); - } - - public void setUp() throws Exception - { - - ExoContainer topContainer = ExoContainerContext.getTopContainer(); - if(topContainer != null) { - topContainer.stop(); - } - RootContainer.setInstance(null); - ExoContainerContext.setCurrentContainer(null); - - this.container = PortalContainer.getInstance(); - this.service = container.getComponentInstanceOfType(CacheService.class); - this.cache = (AbstractExoCache)service.getCacheInstance("myCache"); - } - - public void testGet() throws Exception - { - cache.put(new MyKey("a"), "a"); - assertEquals("a", cache.get(new MyKey("a"))); - cache.put(new MyKey("a"), "c"); - assertEquals("c", cache.get(new MyKey("a"))); - cache.remove(new MyKey("a")); - assertEquals(null, cache.get(new MyKey("a"))); - assertEquals(null, cache.get(new MyKey("x"))); - - cache.clearCache(); - } - - public void testRemove() throws Exception - { - cache.put(new MyKey("a"), 1); - cache.put(new MyKey("b"), 2); - cache.put(new MyKey("c"), 3); - assertEquals(3, cache.getCacheSize()); - assertEquals(1, cache.remove(new MyKey("a"))); - assertEquals(2, cache.getCacheSize()); - assertEquals(2, cache.remove(new MyKey("b"))); - assertEquals(1, cache.getCacheSize()); - assertEquals(null, cache.remove(new MyKey("x"))); - assertEquals(1, cache.getCacheSize()); - - cache.clearCache(); - } - - public void testPutMap() throws Exception - { - Map values = new HashMap(); - values.put(new MyKey("a"), "a"); - values.put(new MyKey("b"), "b"); - assertEquals(0, cache.getCacheSize()); - cache.putMap(values); - assertEquals(2, cache.getCacheSize()); - values = new HashMap() - { - private static final long serialVersionUID = 1L; - - public Set> entrySet() - { - Set> set = new LinkedHashSet>(super.entrySet()); - set.add(new Entry() - { - - public Object setValue(Object paramV) - { - return null; - } - - public Object getValue() - { - throw new RuntimeException("An exception"); - } - - public Serializable getKey() - { - return "c"; - } - }); - return set; - } - }; - values.put(new MyKey("e"), "e"); - values.put(new MyKey("d"), "d"); - cache.putMap(values); - assertEquals(2, cache.getCacheSize()); - - cache.clearCache(); - } - - public void testGetCachedObjects() throws Exception - { - cache.put(new MyKey("a"), "a"); - cache.put(new MyKey("b"), "b"); - cache.put(new MyKey("c"), "c"); - cache.put(new MyKey("d"), null); - assertEquals(3, cache.getCacheSize()); - List values = cache.getCachedObjects(); - assertEquals(3, values.size()); - assertTrue(values.contains("a")); - assertTrue(values.contains("b")); - assertTrue(values.contains("c")); - - cache.clearCache(); - } - - public void testRemoveCachedObjects() throws Exception - { - cache.put(new MyKey("a"), "a"); - cache.put(new MyKey("b"), "b"); - cache.put(new MyKey("c"), "c"); - cache.put(new MyKey("d"), null); - assertEquals(3, cache.getCacheSize()); - List values = cache.removeCachedObjects(); - assertEquals(3, values.size()); - assertTrue(values.contains("a")); - assertTrue(values.contains("b")); - assertTrue(values.contains("c")); - assertEquals(0, cache.getCacheSize()); - - cache.clearCache(); - } - - public void testSelect() throws Exception - { - cache.put(new MyKey("a"), 1); - cache.put(new MyKey("b"), 2); - cache.put(new MyKey("c"), 3); - final AtomicInteger count = new AtomicInteger(); - CachedObjectSelector selector = new CachedObjectSelector() - { - - public void onSelect(ExoCache cache, Serializable key, - ObjectCacheInfo ocinfo) throws Exception - { - assertTrue(key.equals(new MyKey("a")) || key.equals(new MyKey("b")) || key.equals(new MyKey("c"))); - assertTrue(ocinfo.get().equals(1) || ocinfo.get().equals(2) || ocinfo.get().equals(3)); - count.incrementAndGet(); - } - - public boolean select(Serializable key, ObjectCacheInfo ocinfo) - { - return true; - } - }; - cache.select(selector); - assertEquals(3, count.intValue()); - - cache.clearCache(); - } - - public void testGetHitsNMisses() throws Exception - { - int hits = cache.getCacheHit(); - int misses = cache.getCacheMiss(); - cache.put(new MyKey("a"), "a"); - cache.get(new MyKey("a")); - cache.remove(new MyKey("a")); - cache.get(new MyKey("a")); - cache.get(new MyKey("z")); - assertEquals(1, cache.getCacheHit() - hits); - assertEquals(2, cache.getCacheMiss() - misses); - - cache.clearCache(); - } - - private ExoCacheFactory getExoCacheFactoryInstance() throws ExoCacheInitException - { - PortalContainer pc = PortalContainer.getInstance(); - return new ExoCacheFactoryImpl((ExoContainerContext)pc.getComponentInstanceOfType(ExoContainerContext.class), - "jar:/conf/portal/cache-configuration-template.xml", null, (ConfigurationManager)pc - .getComponentInstanceOfType(ConfigurationManager.class), null); - } - - public void testMultiThreading() throws Exception - { - final ExoCache cache = service.getCacheInstance("test-multi-threading"); - final int totalElement = 100; - final int totalTimes = 20; - int reader = 20; - int writer = 10; - int remover = 5; - int cleaner = 1; - final CountDownLatch startSignalWriter = new CountDownLatch(1); - final CountDownLatch startSignalOthers = new CountDownLatch(1); - final CountDownLatch doneSignal = new CountDownLatch(reader + writer + remover); - final List errors = Collections.synchronizedList(new ArrayList()); - for (int i = 0; i < writer; i++) - { - final int index = i; - Thread thread = new Thread() - { - public void run() - { - try - { - startSignalWriter.await(); - for (int j = 0; j < totalTimes; j++) - { - for (int i = 0; i < totalElement; i++) - { - cache.put(new MyKey("key" + i), "value" + i); - } - if (index == 0 && j == 0) - { - // The cache is full, we can launch the others - startSignalOthers.countDown(); - } - sleep(50); - } - } - catch (Exception e) - { - errors.add(e); - } - finally - { - doneSignal.countDown(); - } - } - }; - thread.start(); - } - startSignalWriter.countDown(); - for (int i = 0; i < reader; i++) - { - Thread thread = new Thread() - { - public void run() - { - try - { - startSignalOthers.await(); - for (int j = 0; j < totalTimes; j++) - { - for (int i = 0; i < totalElement; i++) - { - cache.get(new MyKey("key" + i)); - } - sleep(50); - } - } - catch (Exception e) - { - errors.add(e); - } - finally - { - doneSignal.countDown(); - } - } - }; - thread.start(); - } - for (int i = 0; i < remover; i++) - { - Thread thread = new Thread() - { - public void run() - { - try - { - startSignalOthers.await(); - for (int j = 0; j < totalTimes; j++) - { - for (int i = 0; i < totalElement; i++) - { - cache.remove(new MyKey("key" + i)); - } - sleep(50); - } - } - catch (Exception e) - { - errors.add(e); - } - finally - { - doneSignal.countDown(); - } - } - }; - thread.start(); - } - doneSignal.await(); - for (int i = 0; i < totalElement; i++) - { - cache.put(new MyKey("key" + i), "value" + i); - } - assertEquals(totalElement, cache.getCacheSize()); - final CountDownLatch startSignal = new CountDownLatch(1); - final CountDownLatch doneSignal2 = new CountDownLatch(writer + cleaner); - for (int i = 0; i < writer; i++) - { - Thread thread = new Thread() - { - public void run() - { - try - { - startSignal.await(); - for (int j = 0; j < totalTimes; j++) - { - for (int i = 0; i < totalElement; i++) - { - cache.put(new MyKey("key" + i), "value" + i); - } - sleep(50); - } - } - catch (Exception e) - { - errors.add(e); - } - finally - { - doneSignal2.countDown(); - } - } - }; - thread.start(); - } - for (int i = 0; i < cleaner; i++) - { - Thread thread = new Thread() - { - public void run() - { - try - { - startSignal.await(); - for (int j = 0; j < totalTimes; j++) - { - sleep(150); - cache.clearCache(); - } - } - catch (Exception e) - { - errors.add(e); - } - finally - { - doneSignal2.countDown(); - } - } - }; - thread.start(); - } - cache.clearCache(); - assertEquals(0, cache.getCacheSize()); - if (!errors.isEmpty()) - { - for (Exception e : errors) - { - e.printStackTrace(); - } - throw errors.get(0); - } - cache.clearCache(); - } - - public static class MyCacheListener implements CacheListener - { - - public int clearCache; - - public int expire; - - public int get; - - public int put; - - public int remove; - - public void onClearCache(CacheListenerContext context) throws Exception - { - clearCache++; - } - - public void onExpire(CacheListenerContext context, Serializable key, Object obj) throws Exception - { - expire++; - } - - public void onGet(CacheListenerContext context, Serializable key, Object obj) throws Exception - { - get++; - } - - public void onPut(CacheListenerContext context, Serializable key, Object obj) throws Exception - { - put++; - } - - public void onRemove(CacheListenerContext context, Serializable key, Object obj) throws Exception - { - remove++; - } - } - - public static class MyKey implements Serializable - { - private static final long serialVersionUID = 1L; - - public String value; - - public MyKey(String value) - { - this.value = value; - } - - @Override - public boolean equals(Object paramObject) - { - return paramObject instanceof MyKey && ((MyKey)paramObject).value.equals(value); - } - - @Override - public int hashCode() - { - return value.hashCode(); - } - - @Override - public String toString() - { - return value; - } - } - - /** - * WARNING: For Linux distributions the following JVM parameter must be set to true: java.net.preferIPv4Stack - */ - @SuppressWarnings("unchecked") - public void testDistributedCache() throws Exception - { - // If the cache is still alive this test fails due to a TimeoutException. -// cache.cache.getCacheManager().stop(); - ExoCacheConfig config = new ExoCacheConfig(); - config.setName("MyCacheDistributed"); - config.setMaxSize(8); - config.setLiveTime(1); - config.setImplementation("LRU"); - config.setReplicated(true); - ExoCacheConfig config2 = new ExoCacheConfig(); - config2.setName("MyCacheDistributed2"); - config2.setMaxSize(8); - config2.setLiveTime(1); - config2.setImplementation("LRU"); - config2.setReplicated(true); - AbstractExoCache cache1 = - (AbstractExoCache)getExoCacheFactoryInstance().createCache(config); - MyCacheListener listener1 = new MyCacheListener(); - cache1.addCacheListener(listener1); - AbstractExoCache cache2 = - (AbstractExoCache)getExoCacheFactoryInstance().createCache(config); - MyCacheListener listener2 = new MyCacheListener(); - cache2.addCacheListener(listener2); - try - { - cache1.put(new MyKey("a"), "b"); - assertEquals(1, cache1.getCacheSize()); - assertEquals("b", cache2.get(new MyKey("a"))); - assertEquals(1, cache2.getCacheSize()); - assertEquals(1, listener1.put); - assertEquals(1, listener2.put); - assertEquals(0, listener1.get); - assertEquals(1, listener2.get); - cache2.put(new MyKey("b"), "c"); - assertEquals(2, cache1.getCacheSize()); - assertEquals(2, cache2.getCacheSize()); - assertEquals("c", cache1.get(new MyKey("b"))); - assertEquals(2, listener1.put); - assertEquals(2, listener2.put); - assertEquals(1, listener1.get); - assertEquals(1, listener2.get); - assertEquals(2, cache1.getCacheSize()); - assertEquals(2, cache2.getCacheSize()); - assertEquals(2, listener1.put); - assertEquals(2, listener2.put); - assertEquals(1, listener1.get); - assertEquals(1, listener2.get); - cache2.put(new MyKey("a"), "a"); - assertEquals(2, cache1.getCacheSize()); - assertEquals(2, cache2.getCacheSize()); - assertEquals("a", cache1.get(new MyKey("a"))); - assertEquals(3, listener1.put); - assertEquals(3, listener2.put); - assertEquals(2, listener1.get); - assertEquals(1, listener2.get); - cache2.remove(new MyKey("a")); - assertEquals(1, cache1.getCacheSize()); - assertEquals(1, cache2.getCacheSize()); - assertEquals(3, listener1.put); - assertEquals(3, listener2.put); - assertEquals(2, listener1.get); - assertEquals(1, listener2.get); - assertEquals(1, listener1.remove); - assertEquals(1, listener2.remove); - cache1.put(new MyKey("c"), "c"); - cache1.clearCache(); - assertEquals(0, cache1.getCacheSize()); - assertEquals(null, cache1.get(new MyKey("b"))); - assertEquals("c", cache2.get(new MyKey("b"))); - assertEquals("c", cache2.get(new MyKey("c"))); - assertEquals(2, cache2.getCacheSize()); - assertEquals(4, listener1.put); - assertEquals(4, listener2.put); - assertEquals(3, listener1.get); - assertEquals(3, listener2.get); - assertEquals(1, listener1.remove); - assertEquals(1, listener2.remove); - assertEquals(1, listener1.clearCache); - assertEquals(0, listener2.clearCache); - Map values = new HashMap(); - values.put(new MyKey("a"), "a"); - values.put(new MyKey("b"), "b"); - cache1.putMap(values); - assertEquals(2, cache1.getCacheSize()); - Thread.sleep(40); - assertEquals("a", cache2.get(new MyKey("a"))); - assertEquals("b", cache2.get(new MyKey("b"))); - assertEquals(3, cache2.getCacheSize()); - assertEquals(6, listener1.put); - assertEquals(6, listener2.put); - assertEquals(3, listener1.get); - assertEquals(5, listener2.get); - assertEquals(1, listener1.remove); - assertEquals(1, listener2.remove); - assertEquals(1, listener1.clearCache); - assertEquals(0, listener2.clearCache); - values = new HashMap() - { - private static final long serialVersionUID = 1L; - - public Set> entrySet() - { - Set> set = new LinkedHashSet>(super.entrySet()); - set.add(new Entry() - { - - public Object setValue(Object paramV) - { - return null; - } - - public Object getValue() - { - throw new RuntimeException("An exception"); - } - - public Serializable getKey() - { - return "c"; - } - }); - return set; - } - }; - values.put(new MyKey("e"), "e"); - values.put(new MyKey("d"), "d"); - cache1.putMap(values); - assertEquals(2, cache1.getCacheSize()); - assertEquals(3, cache2.getCacheSize()); - assertEquals(6, listener1.put); - assertEquals(6, listener2.put); - assertEquals(3, listener1.get); - assertEquals(5, listener2.get); - assertEquals(1, listener1.remove); - assertEquals(1, listener2.remove); - assertEquals(1, listener1.clearCache); - assertEquals(0, listener2.clearCache); - assertEquals(0, listener1.expire); - assertEquals(0, listener2.expire); - Thread.sleep(5600); - // The values are evicted lazily when we call it - cache1.get(new MyKey("a")); - cache1.get(new MyKey("b")); - cache2.get(new MyKey("a")); - cache2.get(new MyKey("b")); - cache2.get(new MyKey("c")); - assertEquals(0, cache1.getCacheSize()); - assertEquals(0, cache2.getCacheSize()); - assertEquals(6, listener1.put); - assertEquals(6, listener2.put); - assertEquals(5, listener1.get); - assertEquals(8, listener2.get); - assertEquals(1, listener1.remove); - assertEquals(1, listener2.remove); - assertEquals(1, listener1.clearCache); - assertEquals(0, listener2.clearCache); - } - finally - { - cache1.cache.getCacheManager().stop(); - cache2.cache.getCacheManager().stop(); - } - } - public void testPut() throws Exception - { - cache.put(new MyKey("a"), "a"); - cache.put(new MyKey("b"), "b"); - cache.put(new MyKey("c"), "c"); - assertEquals(3, cache.getCacheSize()); - cache.put(new MyKey("a"), "c"); - assertEquals(3, cache.getCacheSize()); - cache.put(new MyKey("d"), "c"); - assertEquals(4, cache.getCacheSize()); - - cache.clearCache(); - } - - public void testClearCache() throws Exception - { - cache.put(new MyKey("a"), "a"); - cache.put(new MyKey("b"), "b"); - cache.put(new MyKey("c"), "c"); - assertTrue(cache.getCacheSize() > 0); - cache.clearCache(); - assertTrue(cache.getCacheSize() == 0); - - cache.clearCache(); - } - -} diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheConfig.java b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheConfig.java deleted file mode 100644 index 37d6836d9..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheConfig.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2010 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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.exoplatform.services.cache.impl.infinispan; - -import org.exoplatform.services.cache.ExoCacheConfig; - -/** - * @author Nicolas Filotto - * @version $Id$ - * - */ -public class TestExoCacheConfig extends ExoCacheConfig -{ - -} diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheCreator.java b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheCreator.java deleted file mode 100644 index b6545562d..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheCreator.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (C) 2010 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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.exoplatform.services.cache.impl.infinispan; - -import org.exoplatform.services.cache.CacheListener; -import org.exoplatform.services.cache.CachedObjectSelector; -import org.exoplatform.services.cache.ExoCache; -import org.exoplatform.services.cache.ExoCacheConfig; -import org.exoplatform.services.cache.ExoCacheInitException; -import org.infinispan.Cache; -import org.infinispan.configuration.cache.ConfigurationBuilder; - -import java.io.Serializable; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.Callable; - -/** - * @author Nicolas Filotto - * @version $Id$ - * - */ -public class TestExoCacheCreator implements ExoCacheCreator -{ - - /** - * {@inheritDoc} - */ - @Override - public ExoCache create(ExoCacheConfig config, ConfigurationBuilder confBuilder, - Callable> cacheGetter) throws ExoCacheInitException - { - return new TestExoCache(); - } - - public Class getExpectedConfigType() - { - return TestExoCacheConfig.class; - } - - public Set getExpectedImplementations() - { - return Collections.singleton("TEST"); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public static class TestExoCache implements ExoCache - { - - public void addCacheListener(CacheListener listener) - { - } - - public int getCacheHit() - { - return 0; - } - - public int getCacheMiss() - { - return 0; - } - - public int getCacheSize() - { - return 0; - } - - public List getCachedObjects() - { - return null; - } - - public String getLabel() - { - return null; - } - - public long getLiveTime() - { - return 0; - } - - public int getMaxSize() - { - return 0; - } - - public String getName() - { - return "name"; - } - - public boolean isDistributed() - { - return false; - } - - public boolean isLogEnabled() - { - return false; - } - - public boolean isReplicated() - { - return false; - } - - public void select(CachedObjectSelector selector) throws Exception - { - - } - - public void setDistributed(boolean b) - { - - } - - public void setLabel(String s) - { - - } - - public void setLiveTime(long period) - { - - } - - public void setLogEnabled(boolean b) - { - - } - - public void setMaxSize(int max) - { - - } - - public void setName(String name) - { - - } - - public void setReplicated(boolean b) - { - - } - - public void clearCache() - { - - } - - public Object get(Serializable key) - { - return null; - } - - public void put(Serializable key, Object value) throws NullPointerException - { - - } - - public void putMap(Map objs) throws NullPointerException, IllegalArgumentException - { - - } - - public Object remove(Serializable key) throws NullPointerException - { - return null; - } - - public List removeCachedObjects() - { - return null; - } - - } -} diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java deleted file mode 100644 index fbfcbcacb..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) 2010 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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.exoplatform.services.cache.impl.infinispan; - -import junit.framework.TestCase; - -import org.exoplatform.container.PortalContainer; -import org.exoplatform.services.cache.CacheService; -import org.exoplatform.services.cache.ExoCache; -import org.exoplatform.services.cache.impl.infinispan.TestExoCacheCreator.TestExoCache; -import org.infinispan.configuration.cache.CacheMode; -import org.infinispan.manager.CacheContainer; - -/** - * @author Nicolas Filotto - * @version $Id$ - * - */ -@SuppressWarnings("rawtypes") -public class TestExoCacheFactoryImpl extends TestCase -{ - - CacheService service_; - - public TestExoCacheFactoryImpl(String name) - { - super(name); - } - - public void setUp() throws Exception - { - service_ = (CacheService)PortalContainer.getInstance().getComponentInstanceOfType(CacheService.class); - } - - public void testCacheFactory() - { - ExoCache cache = service_.getCacheInstance("myCache"); - assertTrue("expect an instance of AbstractExoCache", cache instanceof AbstractExoCache); - AbstractExoCache aCache = (AbstractExoCache)cache; - assertTrue("expect a local cache", - aCache.cache.getCacheConfiguration().clustering().cacheMode() == CacheMode.LOCAL); - aCache.cache.stop(); - cache = service_.getCacheInstance("cacheDistributed"); - assertTrue("expect an instance of AbstractExoCache", cache instanceof AbstractExoCache); - aCache = (AbstractExoCache)cache; - assertTrue("expect a distributed cache", - aCache.cache.getCacheConfiguration().clustering().cacheMode() == CacheMode.REPL_SYNC); - aCache.cache.stop(); - cache = service_.getCacheInstance("myCustomCache"); - assertTrue("expect an instance of AbstractExoCache", cache instanceof AbstractExoCache); - aCache = (AbstractExoCache)cache; - assertTrue("expect a distributed cache", - aCache.cache.getCacheConfiguration().clustering().cacheMode() == CacheMode.REPL_SYNC); - aCache.cache.stop(); - } - - public void testExoCacheCreator() - { - ExoCache cache = service_.getCacheInstance("test-default-impl"); - assertTrue("expect an instance of AbstractExoCache", cache instanceof AbstractExoCache); - AbstractExoCache aCache = (AbstractExoCache)cache; - aCache.cache.stop(); - cache = service_.getCacheInstance("test-custom-impl-with-old-config"); - assertTrue("expect an instance of TestExoCache", cache instanceof TestExoCache); - cache = service_.getCacheInstance("test-custom-impl-with-new-config"); - assertTrue("expect an instance of TestExoCache", cache instanceof TestExoCache); - } - - public void testSameCacheManager() - { - ExoCache cache1 = service_.getCacheInstance("myCustomCache"); - assertTrue("expect an instance of AbstractExoCache", cache1 instanceof AbstractExoCache); - AbstractExoCache aCache1 = (AbstractExoCache)cache1; - CacheContainer cacheContainer1 = aCache1.cache.getCacheManager(); - - ExoCache cache2 = service_.getCacheInstance("myCustomCache-Bis"); - assertTrue("expect an instance of AbstractExoCache", cache2 instanceof AbstractExoCache); - AbstractExoCache aCache2 = (AbstractExoCache)cache2; - CacheContainer cacheContainer2 = aCache2.cache.getCacheManager(); - assertTrue("The CacheContainer should be the same", cacheContainer1 == cacheContainer2); - - ExoCache cache3 = service_.getCacheInstance("myCustomCache-Bis2"); - assertTrue("expect an instance of AbstractExoCache", cache3 instanceof AbstractExoCache); - AbstractExoCache aCache3 = (AbstractExoCache)cache3; - CacheContainer cacheContainer3 = aCache3.cache.getCacheManager(); - assertTrue("The CacheContainer should be the same", cacheContainer1 == cacheContainer3); - - aCache1.cache.stop(); - aCache2.cache.stop(); - } -} diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/java/org/exoplatform/services/cache/impl/infinispan/distributed/TestDistributedExoCache.java b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/java/org/exoplatform/services/cache/impl/infinispan/distributed/TestDistributedExoCache.java deleted file mode 100644 index 632f16447..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/java/org/exoplatform/services/cache/impl/infinispan/distributed/TestDistributedExoCache.java +++ /dev/null @@ -1,858 +0,0 @@ -/* - * Copyright (C) 2010 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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.exoplatform.services.cache.impl.infinispan.distributed; - -import junit.framework.TestCase; - -import org.exoplatform.container.ExoContainerContext; -import org.exoplatform.container.PortalContainer; -import org.exoplatform.container.configuration.ConfigurationManager; -import org.exoplatform.services.cache.CacheListener; -import org.exoplatform.services.cache.CacheListenerContext; -import org.exoplatform.services.cache.CacheService; -import org.exoplatform.services.cache.CachedObjectSelector; -import org.exoplatform.services.cache.ExoCache; -import org.exoplatform.services.cache.ExoCacheConfig; -import org.exoplatform.services.cache.ExoCacheFactory; -import org.exoplatform.services.cache.ObjectCacheInfo; -import org.exoplatform.services.cache.impl.infinispan.ExoCacheFactoryImpl; -import org.exoplatform.services.ispn.DistributedCacheManager; -import org.infinispan.affinity.KeyAffinityService; -import org.infinispan.affinity.KeyAffinityServiceFactory; -import org.infinispan.affinity.KeyGenerator; -import org.infinispan.distribution.DistributionManager; -import org.junit.Ignore; -import org.junit.Test; - - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.Set; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @author Nicolas Filotto - * @version $Id$ - * - */ -public class TestDistributedExoCache extends TestCase -{ - - CacheService service; - - DistributedExoCache cache; - - DistributedExoCache cache2; - - public TestDistributedExoCache(String name) - { - super(name); - } - - public void setUp() throws Exception - { - this.service = (CacheService)PortalContainer.getInstance().getComponentInstanceOfType(CacheService.class); - this.cache = (DistributedExoCache)service.getCacheInstance("cache-distributed"); - this.cache2 = (DistributedExoCache)service.getCacheInstance("cache-distributed2"); - cache2.put(new MyKey("a"), "a"); - } - - protected void tearDown() throws Exception - { - cache.clearCache(); - cache2.clearCache(); - } - - public void testPut() throws Exception - { - cache.put(new MyKey("a"), "a"); - cache.put(new MyKey("b"), "b"); - cache.put(new MyKey("c"), "c"); - assertEquals(3, cache.getCacheSize()); - cache.put(new MyKey("a"), "c"); - assertEquals(3, cache.getCacheSize()); - cache.put(new MyKey("d"), "c"); - assertEquals(4, cache.getCacheSize()); - } - - public void testClearCache() throws Exception - { - cache.put(new MyKey("a"), "a"); - cache.put(new MyKey("b"), "b"); - cache.put(new MyKey("c"), "c"); - assertTrue(cache.getCacheSize() > 0); - cache.clearCache(); - assertTrue(cache.getCacheSize() == 0); - } - - public void testGet() throws Exception - { - cache.put(new MyKey("a"), "a"); - assertEquals("a", cache.get(new MyKey("a"))); - cache.put(new MyKey("a"), "c"); - assertEquals("c", cache.get(new MyKey("a"))); - cache.remove(new MyKey("a")); - assertEquals(null, cache.get(new MyKey("a"))); - assertEquals(null, cache.get(new MyKey("x"))); - } - - public void testRemove() throws Exception - { - cache.put(new MyKey("a"), 1); - cache.put(new MyKey("b"), 2); - cache.put(new MyKey("c"), 3); - assertEquals(3, cache.getCacheSize()); - assertEquals(1, cache.remove(new MyKey("a"))); - assertEquals(2, cache.getCacheSize()); - assertEquals(2, cache.remove(new MyKey("b"))); - assertEquals(1, cache.getCacheSize()); - assertEquals(null, cache.remove(new MyKey("x"))); - assertEquals(1, cache.getCacheSize()); - } - - public void testPutMap() throws Exception - { - Map values = new HashMap(); - values.put(new MyKey("a"), "a"); - values.put(new MyKey("b"), "b"); - assertEquals(0, cache.getCacheSize()); - cache.putMap(values); - assertEquals(2, cache.getCacheSize()); - values = new HashMap() - { - private static final long serialVersionUID = 1L; - - public Set> entrySet() - { - Set> set = new LinkedHashSet>(super.entrySet()); - set.add(new Entry() - { - - public Object setValue(Object paramV) - { - return null; - } - - public Object getValue() - { - throw new RuntimeException("An exception"); - } - - public Serializable getKey() - { - return "c"; - } - }); - return set; - } - }; - values.put(new MyKey("e"), "e"); - values.put(new MyKey("d"), "d"); - cache.putMap(values); - assertEquals(2, cache.getCacheSize()); - } - - public void testGetCachedObjects() throws Exception - { - cache.put(new MyKey("a"), "a"); - cache.put(new MyKey("b"), "b"); - cache.put(new MyKey("c"), "c"); - cache.put(new MyKey("d"), null); - assertEquals(3, cache.getCacheSize()); - List values = cache.getCachedObjects(); - assertEquals(3, values.size()); - assertTrue(values.contains("a")); - assertTrue(values.contains("b")); - assertTrue(values.contains("c")); - } - - public void testRemoveCachedObjects() throws Exception - { - cache.put(new MyKey("a"), "a"); - cache.put(new MyKey("b"), "b"); - cache.put(new MyKey("c"), "c"); - cache.put(new MyKey("d"), null); - assertEquals(3, cache.getCacheSize()); - List values = cache.removeCachedObjects(); - assertEquals(3, values.size()); - assertTrue(values.contains("a")); - assertTrue(values.contains("b")); - assertTrue(values.contains("c")); - assertEquals(0, cache.getCacheSize()); - } - - public void testSelect() throws Exception - { - cache.put(new MyKey("a"), 1); - cache.put(new MyKey("b"), 2); - cache.put(new MyKey("c"), 3); - final AtomicInteger count = new AtomicInteger(); - CachedObjectSelector selector = new CachedObjectSelector() - { - - public void onSelect(ExoCache cache, Serializable key, - ObjectCacheInfo ocinfo) throws Exception - { - assertTrue(key.equals(new MyKey("a")) || key.equals(new MyKey("b")) || key.equals(new MyKey("c"))); - assertTrue(ocinfo.get().equals(1) || ocinfo.get().equals(2) || ocinfo.get().equals(3)); - count.incrementAndGet(); - } - - public boolean select(Serializable key, ObjectCacheInfo ocinfo) - { - return true; - } - }; - cache.select(selector); - assertEquals(3, count.intValue()); - } - - public void testGetHitsNMisses() throws Exception - { - int hits = cache.getCacheHit(); - int misses = cache.getCacheMiss(); - cache.put(new MyKey("a"), "a"); - cache.get(new MyKey("a")); - cache.remove(new MyKey("a")); - cache.get(new MyKey("a")); - cache.get(new MyKey("z")); - assertEquals(1, cache.getCacheHit() - hits); - assertEquals(2, cache.getCacheMiss() - misses); - } - - public void testMultiThreading() throws Exception - { - final int totalElement = 100; - final int totalTimes = 20; - int reader = 20; - int writer = 10; - int remover = 5; - int cleaner = 1; - final CountDownLatch startSignalWriter = new CountDownLatch(1); - final CountDownLatch startSignalOthers = new CountDownLatch(1); - final CountDownLatch doneSignal = new CountDownLatch(reader + writer + remover); - final List errors = Collections.synchronizedList(new ArrayList()); - for (int i = 0; i < writer; i++) - { - final int index = i; - Thread thread = new Thread() - { - public void run() - { - try - { - startSignalWriter.await(); - for (int j = 0; j < totalTimes; j++) - { - for (int i = 0; i < totalElement; i++) - { - cache.put(new MyKey("key" + i), "value" + i); - } - if (index == 0 && j == 0) - { - // The cache is full, we can launch the others - startSignalOthers.countDown(); - } - sleep(50); - } - } - catch (Exception e) - { - errors.add(e); - } - finally - { - doneSignal.countDown(); - } - } - }; - thread.start(); - } - startSignalWriter.countDown(); - for (int i = 0; i < reader; i++) - { - Thread thread = new Thread() - { - public void run() - { - try - { - startSignalOthers.await(); - for (int j = 0; j < totalTimes; j++) - { - for (int i = 0; i < totalElement; i++) - { - cache.get(new MyKey("key" + i)); - } - sleep(50); - } - } - catch (Exception e) - { - errors.add(e); - } - finally - { - doneSignal.countDown(); - } - } - }; - thread.start(); - } - for (int i = 0; i < remover; i++) - { - Thread thread = new Thread() - { - public void run() - { - try - { - startSignalOthers.await(); - for (int j = 0; j < totalTimes; j++) - { - for (int i = 0; i < totalElement; i++) - { - cache.remove(new MyKey("key" + i)); - } - sleep(50); - } - } - catch (Exception e) - { - errors.add(e); - } - finally - { - doneSignal.countDown(); - } - } - }; - thread.start(); - } - doneSignal.await(); - for (int i = 0; i < totalElement; i++) - { - cache.put(new MyKey("key" + i), "value" + i); - } - assertEquals(totalElement, cache.getCacheSize()); - final CountDownLatch startSignal = new CountDownLatch(1); - final CountDownLatch doneSignal2 = new CountDownLatch(writer + cleaner); - for (int i = 0; i < writer; i++) - { - Thread thread = new Thread() - { - public void run() - { - try - { - startSignal.await(); - for (int j = 0; j < totalTimes; j++) - { - for (int i = 0; i < totalElement; i++) - { - cache.put(new MyKey("key" + i), "value" + i); - } - sleep(50); - } - } - catch (Exception e) - { - errors.add(e); - } - finally - { - doneSignal2.countDown(); - } - } - }; - thread.start(); - } - for (int i = 0; i < cleaner; i++) - { - Thread thread = new Thread() - { - public void run() - { - try - { - startSignal.await(); - for (int j = 0; j < totalTimes; j++) - { - sleep(150); - cache.clearCache(); - } - } - catch (Exception e) - { - errors.add(e); - } - finally - { - doneSignal2.countDown(); - } - } - }; - thread.start(); - } - cache.clearCache(); - assertEquals(0, cache.getCacheSize()); - if (!errors.isEmpty()) - { - for (Exception e : errors) - { - e.printStackTrace(); - } - throw errors.get(0); - } - } - - public static class MyCacheListener implements CacheListener - { - - public int clearCache; - - public int expire; - - public int get; - - public int put; - - public int remove; - - public void onClearCache(CacheListenerContext context) throws Exception - { - clearCache++; - } - - public void onExpire(CacheListenerContext context, Serializable key, Object obj) throws Exception - { - expire++; - } - - public void onGet(CacheListenerContext context, Serializable key, Object obj) throws Exception - { - get++; - } - - public void onPut(CacheListenerContext context, Serializable key, Object obj) throws Exception - { - put++; - } - - public void onRemove(CacheListenerContext context, Serializable key, Object obj) throws Exception - { - remove++; - } - } - - public static class MyKey implements Serializable - { - private static final long serialVersionUID = 1L; - - public Object value; - - public String displayValue; - - public MyKey() - { - } - - public MyKey(Object value) - { - this.value = value; - } - - public MyKey(String displayValue, Object value) - { - this.displayValue = displayValue; - this.value = value; - } - - @Override - public boolean equals(Object paramObject) - { - return paramObject instanceof MyKey && ((MyKey)paramObject).value.equals(value); - } - - @Override - public int hashCode() - { - return value.hashCode(); - } - - @Override - public String toString() - { - return displayValue == null ? value.toString() : displayValue; - } - } - - public static class MyKeyGenerator implements KeyGenerator> - { - - public static final Random rnd = new Random(); - - private String fullName; - - public MyKeyGenerator(String fullName) - { - this.fullName = fullName; - } - - @Override - public DistributedExoCache.CacheKey getKey() - { - return new DistributedExoCache.CacheKey(fullName, new MyKey(rnd.nextLong())); - } - } - - /** - * WARNING: For Linux distributions the following JVM parameter must be set to true: java.net.preferIPv4Stack. - * - * @throws Exception - */ - @SuppressWarnings({"rawtypes", "unchecked"}) - public void testDistributedCache() throws Exception - { - PortalContainer pc = PortalContainer.getInstance(); - ExoCacheConfig config = new ExoCacheConfig(); - config.setName("MyCacheDistributed"); - config.setMaxSize(5); - config.setLiveTime(1); - config.setImplementation("LRU"); - config.setDistributed(true); - Map params = new HashMap(); - params.put("infinispan-num-owners", "1"); - ConfigurationManager cm = (ConfigurationManager)pc.getComponentInstanceOfType(ConfigurationManager.class); - DistributedCacheManager dcm2 = - new DistributedCacheManager("jar:/conf/portal/distributed-cache-configuration.xml", params, cm); - - DistributedExoCache cache1 = - (DistributedExoCache)((ExoCacheFactory)pc - .getComponentInstanceOfType(ExoCacheFactory.class)).createCache(config); - DistributionManager dm = cache1.getCache().getDistributionManager(); - DistributedExoCache cache2 = - (DistributedExoCache)new ExoCacheFactoryImpl( - (ExoContainerContext)pc.getComponentInstanceOfType(ExoContainerContext.class), - "jar:/conf/portal/cache-configuration-template.xml", null, cm, dcm2).createCache(config); - KeyAffinityService kas1 = - KeyAffinityServiceFactory.newLocalKeyAffinityService(cache1.getCache(), - new MyKeyGenerator(cache1.getFullName()), Executors.newSingleThreadExecutor(), 100); - KeyAffinityService kas2 = - KeyAffinityServiceFactory.newLocalKeyAffinityService(cache2.getCache(), - new MyKeyGenerator(cache1.getFullName()), Executors.newSingleThreadExecutor(), 100); - - try - { - Object a, b, c; - for (int i = 0; i < 2; i++) - { - if (i == 0) - { - a = - new MyKey("a", ((DistributedExoCache.CacheKey)kas1.getKeyForAddress(cache1.getCache() - .getRpcManager().getAddress())).getKey().value); - } - else - { - a = - new MyKey("a", ((DistributedExoCache.CacheKey)kas2.getKeyForAddress(cache2.getCache() - .getRpcManager().getAddress())).getKey().value); - } - for (int j = 0; j < 2; j++) - { - if (j == 0) - { - b = - new MyKey("b", ((DistributedExoCache.CacheKey)kas1.getKeyForAddress(cache1.getCache() - .getRpcManager().getAddress())).getKey().value); - } - else - { - b = - new MyKey("b", ((DistributedExoCache.CacheKey)kas2.getKeyForAddress(cache2.getCache() - .getRpcManager().getAddress())).getKey().value); - } - for (int k = 0; k < 2; k++) - { - if (k == 0) - { - c = - new MyKey("c", ((DistributedExoCache.CacheKey)kas1.getKeyForAddress(cache1.getCache() - .getRpcManager().getAddress())).getKey().value); - } - else - { - c = - new MyKey("c", ((DistributedExoCache.CacheKey)kas2.getKeyForAddress(cache2.getCache() - .getRpcManager().getAddress())).getKey().value); - } - checkUseCase(cache1, cache2, dm, a, b, c); - } - } - } - } - finally - { - dcm2.stop(); - } - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private void checkUseCase(DistributedExoCache cache1, - DistributedExoCache cache2, DistributionManager dm, Object a, Object b, Object c) - throws InterruptedException - { - MyCacheListener listener1 = new MyCacheListener(); - cache1.addCacheListener(listener1); - MyCacheListener listener2 = new MyCacheListener(); - cache2.addCacheListener(listener2); - boolean isALocal = dm.getLocality(new DistributedExoCache.CacheKey(cache1.getFullName(), new MyKey(a))).isLocal(); - boolean isBLocal = dm.getLocality(new DistributedExoCache.CacheKey(cache1.getFullName(), new MyKey(b))).isLocal(); - boolean isCLocal = dm.getLocality(new DistributedExoCache.CacheKey(cache1.getFullName(), new MyKey(c))).isLocal(); - MyKey key = new MyKey(a); - cache1.put(key, "b"); - assertEquals(1, cache1.getCacheSize()); - assertEquals("b", cache2.get(new MyKey(a))); - assertEquals(1, cache2.getCacheSize()); - - int put1 = 1; - int put2 = isALocal ? 0 : 1; - - assertEquals(put1, listener1.put); - assertEquals(put2, listener2.put); - - assertEquals(0, listener1.get); - assertEquals(1, listener2.get); - - MyKey key2 = new MyKey(b); - cache2.put(key2, "c"); - assertEquals(2, cache1.getCacheSize()); - assertEquals(2, cache2.getCacheSize()); - assertEquals("c", cache1.get(new MyKey(b))); - - put1 += isBLocal ? 1 : 0; - put2++; - - assertEquals(put1, listener1.put); - assertEquals(put2, listener2.put); - - assertEquals(1, listener1.get); - assertEquals(1, listener2.get); - - assertEquals(2, cache1.getCacheSize()); - assertEquals(2, cache2.getCacheSize()); - - assertEquals(put1, listener1.put); - assertEquals(put2, listener2.put); - - assertEquals(1, listener1.get); - assertEquals(1, listener2.get); - - key = new MyKey(a); - cache2.put(key, "a"); - assertEquals(2, cache1.getCacheSize()); - assertEquals(2, cache2.getCacheSize()); - assertEquals("a", cache1.get(new MyKey(a))); - - put1 += isALocal ? 1 : 0; - put2++; - - assertEquals(put1, listener1.put); - assertEquals(put2, listener2.put); - - assertEquals(2, listener1.get); - assertEquals(1, listener2.get); - - key = new MyKey(a); - cache2.remove(key); - assertEquals(1, cache1.getCacheSize()); - assertEquals(1, cache2.getCacheSize()); - - assertEquals(put1, listener1.put); - assertEquals(put2, listener2.put); - - assertEquals(2, listener1.get); - assertEquals(1, listener2.get); - - int remove1 = isALocal ? 1 : 0; - int remove2 = 1; - - assertEquals(remove1, listener1.remove); - assertEquals(remove2, listener2.remove); - - key = new MyKey(c); - cache1.put(key, "c"); - assertEquals(2, cache1.getCacheSize()); - assertEquals(2, cache2.getCacheSize()); - assertEquals("c", cache2.get(new MyKey(c))); - - put1++; - put2 += isCLocal ? 0 : 1; - - assertEquals(put1, listener1.put); - assertEquals(put2, listener2.put); - - assertEquals(2, listener1.get); - assertEquals(2, listener2.get); - - assertEquals(remove1, listener1.remove); - assertEquals(remove2, listener2.remove); - - assertEquals(0, listener1.clearCache); - assertEquals(0, listener2.clearCache); - - cache1.clearCache(); - assertEquals(0, cache1.getCacheSize()); - assertNull(cache1.get(new MyKey(b))); - assertNull(cache1.get(new MyKey(c))); - assertNull(cache2.get(new MyKey(b))); - assertNull(cache2.get(new MyKey(c))); - assertEquals(0, cache2.getCacheSize()); - - assertEquals(put1, listener1.put); - assertEquals(put2, listener2.put); - - assertEquals(4, listener1.get); - assertEquals(4, listener2.get); - - // Since the clear cache map/reduce can only find cache1, - // the remove calls will be applied to cache1 so cache2 - // will be notified on its entries, this is due to the - // hack used to apply modifications within a map/reduce - remove2 += (isBLocal ? 0 : 1) + (isCLocal ? 0 : 1); - - assertEquals(remove1, listener1.remove); - assertEquals(remove2, listener2.remove); - - assertEquals(1, listener1.clearCache); - assertEquals(0, listener2.clearCache); - - Map values = new HashMap(); - key = new MyKey(a); - key2 = new MyKey(b); - values.put(key, "a"); - values.put(key2, "b"); - cache1.putMap(values); - assertEquals(2, cache1.getCacheSize()); - Thread.sleep(40); - assertEquals("a", cache1.get(new MyKey(a))); - assertEquals("b", cache1.get(new MyKey(b))); - assertEquals("a", cache2.get(new MyKey(a))); - assertEquals("b", cache2.get(new MyKey(b))); - assertEquals(2, cache2.getCacheSize()); - - put1 += 2; - put2 += (isALocal ? 0 : 1) + (isBLocal ? 0 : 1); - - assertEquals(put1, listener1.put); - assertEquals(put2, listener2.put); - - assertEquals(6, listener1.get); - assertEquals(6, listener2.get); - - assertEquals(remove1, listener1.remove); - assertEquals(remove2, listener2.remove); - - assertEquals(1, listener1.clearCache); - assertEquals(0, listener2.clearCache); - - values = new HashMap() - { - private static final long serialVersionUID = 1L; - - public Set> entrySet() - { - Set> set = new LinkedHashSet>(super.entrySet()); - set.add(new Entry() - { - - public Object setValue(Object paramV) - { - return null; - } - - public Object getValue() - { - throw new RuntimeException("An exception"); - } - - public Serializable getKey() - { - return "c"; - } - }); - return set; - } - }; - values.put(new MyKey("e"), "e"); - values.put(new MyKey("d"), "d"); - cache1.putMap(values); - assertEquals(2, cache1.getCacheSize()); - assertEquals(2, cache2.getCacheSize()); - - assertEquals(put1, listener1.put); - assertEquals(put2, listener2.put); - - assertEquals(6, listener1.get); - assertEquals(6, listener2.get); - - assertEquals(remove1, listener1.remove); - assertEquals(remove2, listener2.remove); - - assertEquals(1, listener1.clearCache); - assertEquals(0, listener2.clearCache); - - assertEquals(0, listener1.expire); - assertEquals(0, listener2.expire); - - cache2.clearCache(); - assertEquals(0, cache1.getCacheSize()); - assertEquals(0, cache2.getCacheSize()); - - assertEquals(put1, listener1.put); - assertEquals(put2, listener2.put); - - assertEquals(6, listener1.get); - assertEquals(6, listener2.get); - - // Since the clear cache map/reduce can only find cache1, - // the remove calls will be applied to cache1 so cache2 - // will be notified on its entries, this is due to the - // hack used to apply modifications within a map/reduce - remove2 += (isALocal ? 0 : 1) + (isBLocal ? 0 : 1); - - assertEquals(remove1, listener1.remove); - assertEquals(remove2, listener2.remove); - - assertEquals(1, listener1.clearCache); - assertEquals(1, listener2.clearCache); - - assertEquals(0, listener1.expire); - assertEquals(0, listener2.expire); - } -} diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/conf/configuration.xml b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/conf/configuration.xml deleted file mode 100644 index f65a8b475..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/conf/configuration.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - org.exoplatform.services.ispn.DistributedCacheManager - - - infinispan-configuration - jar:/conf/portal/distributed-cache-configuration.xml - - - parameters - The parameters of the configuration - - - - - diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/conf/jgroups/udp.xml b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/conf/jgroups/udp.xml deleted file mode 100644 index 6eccfebf1..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/conf/jgroups/udp.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/conf/portal/cache-configuration-template.xml b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/conf/portal/cache-configuration-template.xml deleted file mode 100644 index 4df9457bc..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/conf/portal/cache-configuration-template.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/conf/portal/distributed-cache-configuration-template.xml b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/conf/portal/distributed-cache-configuration-template.xml deleted file mode 100644 index 41abb89de..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/conf/portal/distributed-cache-configuration-template.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/conf/portal/distributed-cache-configuration.xml b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/conf/portal/distributed-cache-configuration.xml deleted file mode 100644 index 5bec6064f..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/conf/portal/distributed-cache-configuration.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/conf/portal/test-configuration.xml b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/conf/portal/test-configuration.xml deleted file mode 100644 index 3945a3a62..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/conf/portal/test-configuration.xml +++ /dev/null @@ -1,179 +0,0 @@ - - - - - - org.exoplatform.services.cache.CacheService - org.exoplatform.services.cache.impl.CacheServiceImpl - - - - cache.config.default - The default cache configuration - - default - 10 - 2 - - - - cache-distributed - The default cache configuration - - cache-distributed - 5 - 2 - true - - - - cache-distributed2 - The default cache configuration - - cache-distributed2 - 5 - 2 - true - - - test-multi-threading - The default cache configuration - - test-multi-threading - NONE - -1 - -1 - - - - cacheDistributed - The default cache configuration - - cacheDistributed - 5 - 2 - true - - - - test-default-impl - The default cache configuration - - test-default-impl - 5 - 2 - - - - test-custom-impl-with-old-config - The default cache configuration - - test-custom-impl-with-old-config - 5 - 2 - TEST - - - - test-custom-impl-with-new-config - The default cache configuration - - test-custom-impl-with-new-config - 5 - 2 - - - - - - org.exoplatform.services.cache.ExoCacheFactory - org.exoplatform.services.cache.impl.infinispan.ExoCacheFactoryImpl - - - cache.config.template - jar:/conf/portal/cache-configuration-template.xml - - - - - - org.exoplatform.services.cache.ExoCacheFactory - - addConfig - addConfig - org.exoplatform.services.cache.impl.infinispan.ExoCacheFactoryConfigPlugin - add Custom Configurations - - - myCustomCache - jar:/conf/portal/distributed-cache-configuration-template.xml - - - myCustomCache-Bis - classpath:/conf/portal/distributed-cache-configuration-template.xml - - - - - addCreator - addCreator - org.exoplatform.services.cache.impl.infinispan.ExoCacheCreatorPlugin - add Exo Cache Creator - - - Test - The cache creator for testing purpose - - - - GENERIC - The generic cache creator - - - - - NONE - - - FIFO - - - LRU - - - UNORDERED - - - LIRS - - - - LRU - -1 - 500 - - - - - - diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/test.policy b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/test.policy deleted file mode 100644 index 28ff5d11a..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/test.policy +++ /dev/null @@ -1,30 +0,0 @@ -grant codeBase "@MAVEN_REPO@-"{ - permission java.security.AllPermission; -}; - -grant codeBase "@MAIN_CLASSES@-"{ - permission java.security.AllPermission; -}; - -grant codeBase "@TEST_CLASSES@-"{ -}; - -grant codeBase "@MAIN_CLASSES@../../../exo.kernel.commons.test/-"{ - permission java.security.AllPermission; -}; - -grant codeBase "@MAIN_CLASSES@../../../exo.kernel.commons/-"{ - permission java.security.AllPermission; -}; - -grant codeBase "@MAIN_CLASSES@../../../exo.kernel.container/-"{ - permission java.security.AllPermission; -}; - -grant codeBase "@MAIN_CLASSES@../../../exo.kernel.component.cache/-"{ - permission java.security.AllPermission; -}; - -grant codeBase "@MAIN_CLASSES@../../../exo.kernel.component.ext.cache.impl.infinispan.v8/-"{ - permission java.security.AllPermission; -}; diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/tsm-excludes.properties b/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/tsm-excludes.properties deleted file mode 100644 index 9a2417667..000000000 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/src/test/resources/tsm-excludes.properties +++ /dev/null @@ -1 +0,0 @@ -org.exoplatform.services.cache.impl.infinispan.distributed.TestDistributedExoCache.testDistributedCache=stop \ No newline at end of file diff --git a/pom.xml b/pom.xml index da491aef2..313c73348 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,6 @@ exo.kernel.commons.test exo.kernel.component.common exo.kernel.component.cache - exo.kernel.component.ext.cache.impl.infinispan.v8 exo.kernel.component.command @@ -118,11 +117,6 @@ exo.kernel.component.cache ${project.version} - - ${project.groupId} - exo.kernel.component.ext.cache.impl.infinispan.v8 - ${project.version} - ${project.groupId} exo.kernel.component.command