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
-
-
-
- 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 super K, ? super V> 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 extends K, ? extends V> 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 extends K, ? extends V> entry : objs.entrySet())
- {
- map.put(entry.getKey(), entry.getValue());
- }
- cache.putAll(map);
- if(cache.getTransactionManager() != null) {
- cache.endBatch(true);
- }
- // End transaction
- for (Map.Entry extends K, ? extends V> 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 extends K, ? extends V> 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 extends K, ? extends V> entry : objs.entrySet())
- {
- map.put(entry.getKey(), entry.getValue());
- }
- cache.putAllAsync(map);
- // End transaction
- for (Map.Entry extends K, ? extends V> 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 super K, ? super V> selector) throws Exception
- {
- if (selector == null)
- {
- throw new IllegalArgumentException("No null selector");
- }
- for (Map.Entry extends K, ? extends V> 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 super K, ? super V> listener;
-
- public ListenerContext(CacheListener super K, ? super V> 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 extends ExoCacheConfig> 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 super K, ? super V> 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 extends K, ? extends V> 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 extends K, ? extends V> entry : objs.entrySet())
- {
- map.put(new CacheKey(fullName, entry.getKey()), entry.getValue());
- }
- cache.putAll(map);
- cache.endBatch(true);
- // End transaction
- for (Map.Entry extends K, ? extends V> 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 super K, ? super V> 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 super K, ? super V> listener;
-
- public ListenerContext(CacheListener super K, ? super V> 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 extends ExoCacheConfig> 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