exo-jcr SVN: r2786 - jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command.
by do-not-reply@jboss.org
Author: vparfonov
Date: 2010-07-14 09:08:08 -0400 (Wed, 14 Jul 2010)
New Revision: 2786
Modified:
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java
Log:
EXOJCR-857 : ad test for reproduce bug
Modified: jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java 2010-07-14 10:22:15 UTC (rev 2785)
+++ jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java 2010-07-14 13:08:08 UTC (rev 2786)
@@ -30,6 +30,8 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
import javax.jcr.Node;
import javax.ws.rs.core.HttpHeaders;
@@ -154,6 +156,29 @@
assertTrue(find.contains(authorProp));
assertTrue(find.contains(author));
}
+
+
+
+
+
+ public void _testPropWithPercent() throws Exception
+ {
+ String content = TestUtils.getFileContent();
+ String file = TestUtils.getFileName();
+ TestUtils.addContent(session, file, new ByteArrayInputStream(content.getBytes()), nt_webdave_file, "");
+ TestUtils.addNodeProperty(session, file, authorProp, "bla % bla");
+ ContainerResponse responseFind =
+ service(WebDAVMethods.PROPFIND, getPathWS() + file, "", null, allPropsXML.getBytes());
+ assertEquals(HTTPStatus.MULTISTATUS, responseFind.getStatus());
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ PropFindResponseEntity entity = (PropFindResponseEntity)responseFind.getEntity();
+ entity.write(outputStream);
+ String find = outputStream.toString();
+ assertTrue(find.contains("D:getlastmodified"));
+ assertTrue(find.contains(authorProp));
+ assertTrue(find.contains(author));
+ }
+
@Override
protected String getRepositoryName()
13 years, 11 months
exo-jcr SVN: r2785 - jcr/branches/1.14-ISPN.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-07-14 06:22:15 -0400 (Wed, 14 Jul 2010)
New Revision: 2785
Modified:
jcr/branches/1.14-ISPN/pom.xml
Log:
EXOJCR-854: change JGroup version from 2.6.13.GA to 2.9.0.GA
Modified: jcr/branches/1.14-ISPN/pom.xml
===================================================================
--- jcr/branches/1.14-ISPN/pom.xml 2010-07-14 10:03:27 UTC (rev 2784)
+++ jcr/branches/1.14-ISPN/pom.xml 2010-07-14 10:22:15 UTC (rev 2785)
@@ -349,7 +349,7 @@
<dependency>
<groupId>jgroups</groupId>
<artifactId>jgroups</artifactId>
- <version>2.6.13.GA</version>
+ <version>2.9.0.GA</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
13 years, 11 months
exo-jcr SVN: r2784 - in jcr/branches/1.14-ISPN: exo.jcr.component.core and 1 other directory.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-07-14 06:03:27 -0400 (Wed, 14 Jul 2010)
New Revision: 2784
Modified:
jcr/branches/1.14-ISPN/exo.jcr.component.core/pom.xml
jcr/branches/1.14-ISPN/pom.xml
Log:
EXOJCR-837: add missed dependency for CacheLoader
Modified: jcr/branches/1.14-ISPN/exo.jcr.component.core/pom.xml
===================================================================
--- jcr/branches/1.14-ISPN/exo.jcr.component.core/pom.xml 2010-07-14 08:49:41 UTC (rev 2783)
+++ jcr/branches/1.14-ISPN/exo.jcr.component.core/pom.xml 2010-07-14 10:03:27 UTC (rev 2784)
@@ -210,7 +210,10 @@
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
</dependency>
-
+ <dependency>
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-cachestore-jdbc</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-jcr-tests</artifactId>
Modified: jcr/branches/1.14-ISPN/pom.xml
===================================================================
--- jcr/branches/1.14-ISPN/pom.xml 2010-07-14 08:49:41 UTC (rev 2783)
+++ jcr/branches/1.14-ISPN/pom.xml 2010-07-14 10:03:27 UTC (rev 2784)
@@ -396,6 +396,11 @@
<artifactId>infinispan-core</artifactId>
<version>4.1.0.CR1</version>
</dependency>
+ <dependency>
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-cachestore-jdbc</artifactId>
+ <version>4.1.0.CR1</version>
+ </dependency>
</dependencies>
</dependencyManagement>
<dependencies>
13 years, 11 months
exo-jcr SVN: r2783 - jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-07-14 04:49:41 -0400 (Wed, 14 Jul 2010)
New Revision: 2783
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java
Log:
EXOJCR-482
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java 2010-07-14 08:17:47 UTC (rev 2782)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java 2010-07-14 08:49:41 UTC (rev 2783)
@@ -373,6 +373,24 @@
// Add script from configuration files to JCR.
addScripts();
+ if (addRepoPlugins != null && addRepoPlugins.size() > 0)
+ {
+ try
+ {
+ Set<URL> repos = new HashSet<URL>();
+ for (GroovyScriptAddRepoPlugin pl : addRepoPlugins)
+ {
+ repos.addAll(pl.getRepositories());
+ }
+ this.groovyPublisher.getGroovyClassLoader().setResourceLoader(
+ new JcrGroovyResourceLoader(repos.toArray(new URL[repos.size()])));
+ }
+ catch (MalformedURLException e)
+ {
+ LOG.error("Unable add groovy script repository. ", e);
+ }
+ }
+
if (observationListenerConfiguration != null)
{
try
@@ -417,24 +435,6 @@
}
}
- if (addRepoPlugins != null && addRepoPlugins.size() > 0)
- {
- try
- {
- Set<URL> repos = new HashSet<URL>();
- for (GroovyScriptAddRepoPlugin pl : addRepoPlugins)
- {
- repos.addAll(pl.getRepositories());
- }
- this.groovyPublisher.getGroovyClassLoader().setResourceLoader(
- new JcrGroovyResourceLoader(repos.toArray(new URL[repos.size()])));
- }
- catch (MalformedURLException e)
- {
- LOG.error("Unable add groovy script repository. ", e);
- }
- }
-
// Finally bind this object as RESTful service.
// NOTE this service does not implement ResourceContainer, as usually
// done for this type of services. It can't be binded in common way cause
13 years, 11 months
exo-jcr SVN: r2782 - jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-07-14 04:17:47 -0400 (Wed, 14 Jul 2010)
New Revision: 2782
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java
Log:
EXOJCR-482
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java 2010-07-14 07:13:40 UTC (rev 2781)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java 2010-07-14 08:17:47 UTC (rev 2782)
@@ -1544,16 +1544,23 @@
URL[] res = new URL[src.length];
for (int i = 0; i < src.length; i++)
{
- String ref = src[i].getRef();
- if (ref == null)
+ if ("jcr".equals(src[i].getProtocol()))
{
- ref = "/";
+ String ref = src[i].getRef();
+ if (ref == null)
+ {
+ ref = "/";
+ }
+ else if (ref.charAt(ref.length() - 1) != '/')
+ {
+ ref = ref + "/";
+ }
+ res[i] = new URL(src[i], "#" + ref);
}
- else if (ref.charAt(ref.length() - 1) != '/')
+ else
{
- ref = ref + "/";
+ res[i] = src[i];
}
- res[i] = new URL(src[i], "#" + ref);
}
return res;
}
13 years, 11 months
exo-jcr SVN: r2781 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc.
by do-not-reply@jboss.org
Author: dkatayev
Date: 2010-07-14 03:13:40 -0400 (Wed, 14 Jul 2010)
New Revision: 2781
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java
Log:
EXOJCR-783 query execute wrapped with 'do privileged' block
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java 2010-07-13 16:53:30 UTC (rev 2780)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java 2010-07-14 07:13:40 UTC (rev 2781)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.jcr.impl.util.jdbc;
+import org.exoplatform.services.jcr.impl.util.SecurityHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -26,6 +27,7 @@
import java.io.InputStreamReader;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
@@ -205,7 +207,9 @@
{
if (irs.getShort("TYPE") != DatabaseMetaData.tableIndexStatistic
&& irs.getString("INDEX_NAME").equalsIgnoreCase(indexName))
+ {
res = true; // check for index params matching etc.
+ }
}
return res;
}
@@ -246,7 +250,9 @@
if (isTableExists(conn, tableName))
{
if (LOG.isDebugEnabled())
+ {
LOG.debug("Table is already exists " + tableName);
+ }
return true;
}
}
@@ -262,7 +268,9 @@
if (isTableExists(conn, tableName))
{
if (LOG.isDebugEnabled())
+ {
LOG.debug("View is already exists " + tableName);
+ }
return true;
}
}
@@ -284,7 +292,9 @@
if (isIndexExists(conn, tableName, indexName))
{
if (LOG.isDebugEnabled())
+ {
LOG.debug("Index is already exists " + indexName);
+ }
return true;
}
}
@@ -313,7 +323,9 @@
if (isSequenceExists(conn, sequenceName))
{
if (LOG.isDebugEnabled())
+ {
LOG.debug("Sequence is already exists " + sequenceName);
+ }
return true;
}
}
@@ -328,7 +340,9 @@
if (isTriggerExists(conn, triggerName))
{
if (LOG.isDebugEnabled())
+ {
LOG.debug("Trigger is already exists " + triggerName);
+ }
return true;
}
}
@@ -336,7 +350,9 @@
else
{
if (LOG.isDebugEnabled())
+ {
LOG.debug("Command is not detected for check '" + sql + "'");
+ }
}
return false;
@@ -383,14 +399,23 @@
if (s.length() > 0)
{
if (isObjectExists(connection, sql = s))
+ {
continue;
+ }
if (LOG.isDebugEnabled())
{
LOG.debug("Execute script: \n[" + sql + "]");
}
-
- st.executeUpdate(sql);
+ final Statement finalSt = st;
+ final String finalSql = sql;
+ SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Object>(){
+ public Object run() throws Exception
+ {
+ finalSt.executeUpdate(finalSql);
+ return null;
+ }
+ });
}
}
13 years, 11 months
exo-jcr SVN: r2780 - in kernel/branches/2.3-ISPN: exo.kernel.component.ext.cache.impl.infinispan.v4 and 24 other directories.
by do-not-reply@jboss.org
Author: nfilotto
Date: 2010-07-13 12:53:30 -0400 (Tue, 13 Jul 2010)
New Revision: 2780
Added:
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/pom.xml
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/AbstractExoCache.java
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreator.java
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreatorPlugin.java
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryConfigPlugin.java
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheConfig.java
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/resources/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/resources/conf/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/resources/conf/portal/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/resources/conf/portal/cache-configuration-template.xml
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/resources/conf/portal/configuration.xml
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestAbstractExoCache.java
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheConfig.java
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheCreator.java
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/cache-configuration-template.xml
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/distributed-cache-configuration-template.xml
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/test-configuration.xml
Modified:
kernel/branches/2.3-ISPN/pom.xml
Log:
EXOJCR-802: First implementation
Added: kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/pom.xml
===================================================================
--- kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/pom.xml (rev 0)
+++ kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/pom.xml 2010-07-13 16:53:30 UTC (rev 2780)
@@ -0,0 +1,80 @@
+
+ <!--
+
+ Copyright (C) 2009 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>kernel-parent</artifactId>
+ <version>2.3-ISPN-SNAPSHOT</version>
+ </parent>
+ <artifactId>exo.kernel.component.ext.cache.impl.infinispan.v4</artifactId>
+ <name>eXo Kernel :: Cache Extension :: Infinispan Implementation</name>
+ <description>Infinispan Implementation for the Cache Service</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.cache</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemProperties>
+ <!--
+ We add this system property due to some incompatibility between
+ IPv6 and some JVM of Linux distributions such as Ubuntu and
+ Fedora
+ -->
+ <property>
+ <name>java.net.preferIPv4Stack</name>
+ <value>true</value>
+ </property>
+ <!-- Avoid the firewall -->
+ <property>
+ <name>bind.address</name>
+ <value>127.0.0.1</value>
+ </property>
+ <property>
+ <name>jgroups.stack</name>
+ <value>udp</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/AbstractExoCache.java
===================================================================
--- kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/AbstractExoCache.java (rev 0)
+++ kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/AbstractExoCache.java 2010-07-13 16:53:30 UTC (rev 2780)
@@ -0,0 +1,576 @@
+/*
+ * 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.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.context.Flag;
+import org.infinispan.notifications.Listener;
+import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
+import org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved;
+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.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 <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ *
+ */
+public abstract class AbstractExoCache<K extends Serializable, V> implements ExoCache<K, V>
+{
+
+ /**
+ * Logger.
+ */
+ private static final Log LOG = ExoLogger.getLogger("exo.kernel.component.ext.cache.impl.infinispan.v4.AbstractExoCache");
+
+ 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 logEnabled;
+
+ private final CopyOnWriteArrayList<ListenerContext<K, V>> listeners;
+
+ protected final AdvancedCache<K, V> cache;
+
+ public AbstractExoCache(ExoCacheConfig config, Cache<K, V> cache)
+ {
+ this.cache = cache.getAdvancedCache();
+ this.listeners = new CopyOnWriteArrayList<ListenerContext<K, V>>();
+ setDistributed(config.isDistributed());
+ setLabel(config.getLabel());
+ setName(config.getName());
+ setLogEnabled(config.isLogEnabled());
+ setReplicated(config.isRepicated());
+ cache.addListener(new CacheEventListener());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addCacheListener(CacheListener<? super K, ? super V> listener)
+ {
+ if (listener == null)
+ {
+ throw new NullPointerException();
+ }
+ listeners.add(new ListenerContext<K, V>(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.size();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<V> getCachedObjects()
+ {
+ Collection<V> values = cache.values();
+ if (values == null || values.isEmpty())
+ {
+ return Collections.emptyList();
+ }
+ else
+ {
+ return new ArrayList<V>(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;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void put(K key, V value) throws NullPointerException
+ {
+ if (key == null)
+ {
+ throw new NullPointerException("No null cache key accepted");
+ }
+ 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).put(key, value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void putMap(Map<? extends K, ? extends V> objs) throws NullPointerException, IllegalArgumentException
+ {
+ if (objs == null)
+ {
+ throw new NullPointerException("No null map accepted");
+ }
+ for (Serializable name : objs.keySet())
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException("No null cache key accepted");
+ }
+ }
+ cache.startBatch();
+ try
+ {
+ // Start transaction
+ for (Map.Entry<? extends K, ? extends V> entry : objs.entrySet())
+ {
+ putOnly(entry.getKey(), entry.getValue());
+ }
+ cache.endBatch(true);
+ // End transaction
+ for (Map.Entry<? extends K, ? extends V> entry : objs.entrySet())
+ {
+ onPut(entry.getKey(), entry.getValue());
+ }
+ }
+ catch (Exception e)
+ {
+ cache.endBatch(false);
+ LOG.warn("An error occurs while executing the putMap method", e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ public V remove(Serializable name) throws NullPointerException
+ {
+ if (name == null)
+ {
+ throw new NullPointerException("No null cache key accepted");
+ }
+ V result = cache.remove(name);
+ onRemove((K)name, result);
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<V> removeCachedObjects()
+ {
+ final List<V> 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 (K key : cache.keySet())
+ {
+ if (key == null)
+ {
+ continue;
+ }
+ final V value = cache.withFlags(Flag.SKIP_LOCKING).get(key);
+ ObjectCacheInfo<V> info = new ObjectCacheInfo<V>()
+ {
+ 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;
+ }
+
+ void onExpire(K key, V obj)
+ {
+ if (listeners.isEmpty())
+ {
+ return;
+ }
+ for (ListenerContext<K, V> context : listeners)
+ {
+ try
+ {
+ context.onExpire(key, obj);
+ }
+ catch (Exception e)
+ {
+ if (LOG.isWarnEnabled())
+ LOG.warn("Cannot execute the CacheListener properly", e);
+ }
+ }
+ }
+
+ void onRemove(K key, V obj)
+ {
+ if (listeners.isEmpty())
+ {
+ return;
+ }
+ for (ListenerContext<K, V> context : listeners)
+ {
+ try
+ {
+ context.onRemove(key, obj);
+ }
+ catch (Exception e)
+ {
+ if (LOG.isWarnEnabled())
+ LOG.warn("Cannot execute the CacheListener properly", e);
+ }
+ }
+ }
+
+ void onPut(K key, V obj)
+ {
+ if (listeners.isEmpty())
+ {
+ return;
+ }
+ for (ListenerContext<K, V> context : listeners)
+ try
+ {
+ context.onPut(key, obj);
+ }
+ catch (Exception e)
+ {
+ if (LOG.isWarnEnabled())
+ LOG.warn("Cannot execute the CacheListener properly", e);
+ }
+ }
+
+ void onGet(K key, V obj)
+ {
+ if (listeners.isEmpty())
+ {
+ return;
+ }
+ for (ListenerContext<K, V> context : listeners)
+ try
+ {
+ context.onGet(key, obj);
+ }
+ catch (Exception e)
+ {
+ if (LOG.isWarnEnabled())
+ LOG.warn("Cannot execute the CacheListener properly", e);
+ }
+ }
+
+ void onClearCache()
+ {
+ if (listeners.isEmpty())
+ {
+ return;
+ }
+ for (ListenerContext<K, V> context : listeners)
+ try
+ {
+ context.onClearCache();
+ }
+ catch (Exception e)
+ {
+ if (LOG.isWarnEnabled())
+ LOG.warn("Cannot execute the CacheListener properly", e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Listener
+ public class CacheEventListener
+ {
+// Infinispan triggers a CacheEntryEvictedEvent only at explicit eviction which is
+// not what we want here. So it will be considered as non supported
+// @CacheEntryEvicted
+// public void cacheEntryEvicted(CacheEntryEvictedEvent evt)
+// {
+// if (evt.isPre())
+// {
+// final K key = (K)evt.getKey();
+// final V value = cache.withFlags(Flag.SKIP_LOCKING).get(key);
+// onExpire(key, value);
+// }
+// }
+
+ @CacheEntryRemoved
+ public void cacheEntryRemoved(CacheEntryRemovedEvent evt)
+ {
+ if (evt.isPre() && !evt.isOriginLocal())
+ {
+ final K key = (K)evt.getKey();
+ final V value = (V)evt.getValue();
+ onRemove(key, value);
+ }
+ }
+
+ @CacheEntryModified
+ public void cacheEntryModified(CacheEntryModifiedEvent evt)
+ {
+ if (!evt.isOriginLocal() && !evt.isPre())
+ {
+ final K key = (K)evt.getKey();
+ final V value = (V)evt.getValue();
+ onPut(key, value);
+ }
+ }
+ }
+
+ private static class ListenerContext<K extends Serializable, V> implements CacheListenerContext, CacheInfo
+ {
+
+ /** . */
+ private final ExoCache<K, V> cache;
+
+ /** . */
+ final CacheListener<? super K, ? super V> listener;
+
+ public ListenerContext(CacheListener<? super K, ? super V> listener, ExoCache<K, V> 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);
+ }
+ }
+}
\ No newline at end of file
Added: kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreator.java
===================================================================
--- kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreator.java (rev 0)
+++ kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreator.java 2010-07-13 16:53:30 UTC (rev 2780)
@@ -0,0 +1,61 @@
+/*
+ * 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.config.Configuration;
+
+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 <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas Filotto</a>
+ * @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 cacheConfig the configuration 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<Serializable, Object> create(ExoCacheConfig config, Configuration cacheConfig, Callable<Cache<Serializable, Object>> 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<String> getExpectedImplementations();
+}
Added: kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreatorPlugin.java
===================================================================
--- kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreatorPlugin.java (rev 0)
+++ kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreatorPlugin.java 2010-07-13 16:53:30 UTC (rev 2780)
@@ -0,0 +1,58 @@
+/*
+ * 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 <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ */
+public class ExoCacheCreatorPlugin extends BaseComponentPlugin
+{
+
+ /**
+ * The list of all the creators defined for this ComponentPlugin
+ */
+ private final List<ExoCacheCreator> creators;
+
+ public ExoCacheCreatorPlugin(InitParams params)
+ {
+ creators = new ArrayList<ExoCacheCreator>();
+ 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<ExoCacheCreator> getCreators()
+ {
+ return creators;
+ }
+}
Added: kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryConfigPlugin.java
===================================================================
--- kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryConfigPlugin.java (rev 0)
+++ kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryConfigPlugin.java 2010-07-13 16:53:30 UTC (rev 2780)
@@ -0,0 +1,60 @@
+/*
+ * 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 <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ */
+public class ExoCacheFactoryConfigPlugin extends BaseComponentPlugin
+{
+
+ /**
+ * The map of all the creators defined for this ComponentPlugin
+ */
+ private final Map<String, String> configs;
+
+ public ExoCacheFactoryConfigPlugin(InitParams params)
+ {
+ configs = new HashMap<String, String>();
+ for (Iterator<ValueParam> 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<String, String> getConfigs()
+ {
+ return configs;
+ }
+}
Added: kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java
===================================================================
--- kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java (rev 0)
+++ kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java 2010-07-13 16:53:30 UTC (rev 2780)
@@ -0,0 +1,373 @@
+/*
+ * 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.generic.GenericExoCacheCreator;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+import org.infinispan.config.GlobalConfiguration;
+import org.infinispan.config.Configuration.CacheMode;
+import org.infinispan.eviction.EvictionStrategy;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.remoting.transport.jgroups.JGroupsTransport;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.Callable;
+
+/**
+ * This class is the Infinispan implementation of the {@link org.exoplatform.services.cache.ExoCacheFactory}
+ *
+ * @author <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ *
+ */
+public class ExoCacheFactoryImpl implements ExoCacheFactory
+{
+
+ /**
+ * The logger
+ */
+ private static final Log LOG =
+ ExoLogger.getLogger("exo.kernel.component.ext.cache.impl.infinispan.v4.ExoCacheFactoryImpl");
+
+ /**
+ * 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 configuration manager that allows us to retrieve a configuration file in several different
+ * manners
+ */
+ private final ConfigurationManager configManager;
+
+ /**
+ * The {@link DefaultCacheManager} used for all the cache regions
+ */
+ private final DefaultCacheManager cacheManager;
+
+ /**
+ * The mapping between the configuration types and the creators
+ */
+ private final Map<Class<? extends ExoCacheConfig>, ExoCacheCreator> mappingConfigTypeCreators =
+ new HashMap<Class<? extends ExoCacheConfig>, ExoCacheCreator>();
+
+ /**
+ * The mapping between the implementations and the creators. This is mainly used for backward compatibility
+ */
+ private final Map<String, ExoCacheCreator> mappingImplCreators = new HashMap<String, ExoCacheCreator>();
+
+ /**
+ * The mapping between the cache names and the configuration paths
+ */
+ private final Map<String, String> mappingCacheNameConfig = new HashMap<String, String>();
+
+ /**
+ * The default creator
+ */
+ private final ExoCacheCreator defaultCreator = new GenericExoCacheCreator();
+
+ public ExoCacheFactoryImpl(ExoContainerContext ctx, InitParams params, ConfigurationManager configManager)
+ throws ExoCacheInitException
+ {
+ this(ctx, getValueParam(params, CACHE_CONFIG_TEMPLATE_KEY), configManager);
+ }
+
+ ExoCacheFactoryImpl(ExoContainerContext ctx, String cacheConfigTemplate, ConfigurationManager configManager)
+ throws ExoCacheInitException
+ {
+ this.configManager = configManager;
+ if (cacheConfigTemplate == null)
+ {
+ throw new RuntimeException("The parameter '" + CACHE_CONFIG_TEMPLATE_KEY + "' must be set");
+ }
+
+ this.cacheManager = initCacheManager(ctx, cacheConfigTemplate);
+ }
+
+ /**
+ * Initializes the {@link DefaultCacheManager}
+ * @throws ExoCacheInitException if the cache manager cannot be initialized
+ */
+ private DefaultCacheManager initCacheManager(ExoContainerContext ctx, String cacheConfigTemplate)
+ throws ExoCacheInitException
+ {
+ InputStream is = null;
+ try
+ {
+ // Read the configuration file of the cache
+ is = configManager.getInputStream(cacheConfigTemplate);
+ }
+ catch (Exception e)
+ {
+ 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 + "'");
+ }
+ DefaultCacheManager cacheManager = null;
+ try
+ {
+ // Create the CacheManager from the input stream
+ cacheManager = new DefaultCacheManager(is, false);
+ }
+ catch (Exception e)
+ {
+ throw new ExoCacheInitException("Cannot initialize the CacheManager corresponding to the configuration '"
+ + cacheConfigTemplate + "'", e);
+ }
+
+ GlobalConfiguration config = cacheManager.getGlobalConfiguration();
+ Properties properties = config.getTransportProperties();
+ if (properties == null || !properties.containsKey(JGroupsTransport.CONFIGURATION_FILE))
+ {
+ return cacheManager;
+ }
+ String jgroupsFileLocation = properties.getProperty(JGroupsTransport.CONFIGURATION_FILE);
+ try
+ {
+ // Read the jgroups configuration file
+ URL url = configManager.getURL(jgroupsFileLocation);
+ is = url == null ? null : url.openStream();
+ }
+ catch (Exception e)
+ {
+ throw new ExoCacheInitException("The jgroups configuration cannot be loaded from '" + jgroupsFileLocation
+ + "'", e);
+ }
+ if (is != null)
+ {
+ try
+ {
+ // Set the jgroups configuration as XML
+ properties.setProperty(JGroupsTransport.CONFIGURATION_XML, readStream(is));
+ }
+ catch (IOException e)
+ {
+ throw new ExoCacheInitException("The jgroups configuration cannot be read from '" + jgroupsFileLocation
+ + "'");
+ }
+ // Remove the property corresponding to the configuration file
+ properties.remove(JGroupsTransport.CONFIGURATION_FILE);
+ }
+ // Set the cluster name
+ config.setClusterName(ctx.getName() + "-cluster");
+ return cacheManager;
+ }
+
+ /**
+ * Reads bytes from input stream and builds a string from them
+ *
+ * @param inputStream
+ * @return
+ * @throws IOException
+ */
+ protected String readStream(InputStream inputStream) throws IOException
+ {
+ StringBuilder out = new StringBuilder(4096);
+ byte[] b = new byte[4096];
+ try
+ {
+ for (int length; (length = inputStream.read(b)) != -1;)
+ {
+ out.append(new String(b, 0, length));
+ }
+ }
+ finally
+ {
+ try
+ {
+ inputStream.close();
+ }
+ catch (Exception e)
+ {
+ LOG.debug("Cannot close stream", e);
+ }
+ }
+ return out.toString();
+ }
+
+ /**
+ * 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}"
+ */
+ public ExoCache<Serializable, Object> createCache(ExoCacheConfig config) throws ExoCacheInitException
+ {
+ final String region = config.getName();
+ final String customConfig = mappingCacheNameConfig.get(region);
+ final ExoCache<Serializable, Object> eXoCache;
+ try
+ {
+ final Configuration conf;
+ if (customConfig != null)
+ {
+ // A custom configuration has been set
+ if (LOG.isInfoEnabled())
+ LOG.info("A custom configuration has been set for the cache '" + region + "'.");
+ DefaultCacheManager cacheManager =
+ new DefaultCacheManager(configManager.getInputStream(customConfig), false);
+ conf = cacheManager.getDefaultConfiguration().clone();
+ }
+ else
+ {
+ // 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 the cache '" + region + "'.");
+ conf = cacheManager.getDefaultConfiguration().clone();
+ if (!config.isDistributed() && !config.isRepicated())
+ {
+ // The cache is local
+ conf.setCacheMode(CacheMode.LOCAL);
+ }
+ }
+ // Reset the configuration to avoid conflicts
+ resetConfiguration(conf);
+ final ExoCacheCreator creator = getExoCacheCreator(config);
+ // Create the cache
+ eXoCache = creator.create(config, conf, new Callable<Cache<Serializable, Object>>()
+ {
+ @Override
+ public Cache<Serializable, Object> call() throws Exception
+ {
+ // Define the configuration
+ cacheManager.defineConfiguration(region, conf);
+ // create and start the cache
+ return cacheManager.getCache(region);
+ }
+ });
+ }
+ catch (Exception e)
+ {
+ 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<ExoCacheCreator> creators = plugin.getCreators();
+ for (ExoCacheCreator creator : creators)
+ {
+ mappingConfigTypeCreators.put(creator.getExpectedConfigType(), creator);
+ Set<String> implementations = creator.getExpectedImplementations();
+ if (implementations == null)
+ {
+ throw new NullPointerException("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<String, String> configs = plugin.getConfigs();
+ mappingCacheNameConfig.putAll(configs);
+ }
+
+ /**
+ * 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 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(Configuration config)
+ {
+ config.setInvocationBatchingEnabled(true);
+ config.setEvictionStrategy(EvictionStrategy.NONE);
+ config.setEvictionMaxEntries(-1);
+ config.setExpirationLifespan(-1);
+ config.setExpirationMaxIdle(-1);
+ config.setEvictionWakeUpInterval(5000);
+ }
+}
Added: kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheConfig.java
===================================================================
--- kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheConfig.java (rev 0)
+++ kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheConfig.java 2010-07-13 16:53:30 UTC (rev 2780)
@@ -0,0 +1,123 @@
+/*
+ * 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 <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ *
+ */
+public class GenericExoCacheConfig extends ExoCacheConfig
+{
+
+ private String strategy;
+
+ private int maxEntries;
+
+ private long lifespan;
+
+ 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 maxEntries
+ */
+ public int getMaxEntries()
+ {
+ return maxEntries;
+ }
+
+ /**
+ * @param maxEntries the maxEntries to set
+ */
+ public void setMaxEntries(int maxEntries)
+ {
+ this.maxEntries = maxEntries;
+ }
+
+ /**
+ * @return the lifespan
+ */
+ public long getLifespan()
+ {
+ return lifespan;
+ }
+
+ /**
+ * @param lifespan the lifespan to set
+ */
+ public void setLifespan(long lifespan)
+ {
+ this.lifespan = lifespan;
+ }
+
+ /**
+ * @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
Added: kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java
===================================================================
--- kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java (rev 0)
+++ kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java 2010-07-13 16:53:30 UTC (rev 2780)
@@ -0,0 +1,191 @@
+/*
+ * 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.config.Configuration;
+
+import java.io.Serializable;
+import java.util.Set;
+import java.util.concurrent.Callable;
+
+/**
+ * The generic {@link ExoCacheCreator} for all the expiration available in infinispan.
+ *
+ * @author <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas Filotto</a>
+ * @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<String> implementations;
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<String> getExpectedImplementations()
+ {
+ return implementations;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Class<? extends ExoCacheConfig> getExpectedConfigType()
+ {
+ return GenericExoCacheConfig.class;
+ }
+
+ /**
+ * @see org.exoplatform.services.cache.impl.infinispan.ExoCacheCreator#create(org.exoplatform.services.cache.ExoCacheConfig, java.util.concurrent.Callable)
+ */
+ public ExoCache<Serializable, Object> create(ExoCacheConfig config, Configuration cacheConfig,
+ Callable<Cache<Serializable, Object>> cacheGetter) throws ExoCacheInitException
+ {
+ if (config instanceof GenericExoCacheConfig)
+ {
+ final GenericExoCacheConfig gConfig = (GenericExoCacheConfig)config;
+ return create(config, cacheConfig, cacheGetter, gConfig.getStrategy(), gConfig.getMaxEntries(), gConfig
+ .getLifespan(), gConfig.getMaxIdle() == 0 ? defaultMaxIdle : gConfig.getMaxIdle(), gConfig
+ .getWakeUpInterval() == 0 ? defaultWakeUpInterval : gConfig.getWakeUpInterval());
+ }
+ else
+ {
+ final long period = config.getLiveTime();
+ return create(config, cacheConfig, 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<Serializable, Object> create(ExoCacheConfig config, Configuration cacheConfig,
+ Callable<Cache<Serializable, Object>> cacheGetter, String strategy, int maxEntries, long lifespan, long maxIdle,
+ long wakeUpInterval) throws ExoCacheInitException
+ {
+ cacheConfig.setEvictionStrategy(strategy);
+ cacheConfig.setEvictionMaxEntries(maxEntries);
+ cacheConfig.setExpirationLifespan(lifespan);
+ cacheConfig.setExpirationMaxIdle(maxIdle);
+ cacheConfig.setEvictionWakeUpInterval(wakeUpInterval);
+ try
+ {
+ return new GenericExoCache(cacheConfig, config, cacheGetter.call());
+ }
+ catch (Exception e)
+ {
+ throw new ExoCacheInitException("Cannot create the cache '" + config.getName() + "'", e);
+ }
+ }
+
+ /**
+ * The Generic implementation of an ExoCache
+ */
+ public static class GenericExoCache extends AbstractExoCache<Serializable, Object>
+ {
+
+ private final Configuration cacheConfig;
+
+ public GenericExoCache(Configuration cacheConfig, ExoCacheConfig config, Cache<Serializable, Object> cache)
+ {
+ super(config, cache);
+ this.cacheConfig = cacheConfig;
+ }
+
+ public void setMaxSize(int max)
+ {
+ cacheConfig.setEvictionMaxEntries(max);
+ }
+
+ public void setLiveTime(long period)
+ {
+ cacheConfig.setExpirationLifespan(period);
+ }
+
+ public void setMaxIdle(long maxIdle)
+ {
+ cacheConfig.setExpirationMaxIdle(maxIdle);
+ }
+
+ public void setWakeUpInterval(long wakeUpInterval)
+ {
+ cacheConfig.setEvictionWakeUpInterval(wakeUpInterval);
+ }
+
+ @ManagedName("MaxEntries")
+ @ManagedDescription("Maximum number of entries in a cache instance. -1 means no limit.")
+ public int getMaxSize()
+ {
+ return cacheConfig.getEvictionMaxEntries();
+ }
+
+ @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 cacheConfig.getExpirationLifespan();
+ }
+
+ @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 cacheConfig.getExpirationMaxIdle();
+ }
+
+ @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 cacheConfig.getEvictionWakeUpInterval();
+ }
+ }
+}
\ No newline at end of file
Added: kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/resources/conf/portal/cache-configuration-template.xml
===================================================================
--- kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/resources/conf/portal/cache-configuration-template.xml (rev 0)
+++ kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/resources/conf/portal/cache-configuration-template.xml 2010-07-13 16:53:30 UTC (rev 2780)
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:infinispan:config:4.0 http://www.infinispan.org/schemas/infinispan-config-4.0.xsd"
+ xmlns="urn:infinispan:config:4.0">
+ <global>
+ <asyncListenerExecutor factory="org.infinispan.executors.DefaultExecutorFactory">
+ <properties>
+ <property name="maxThreads" value="1"/>
+ <property name="queueSize" value="100000"/>
+ <property name="threadNamePrefix" value="AsyncListenerThread"/>
+ </properties>
+ </asyncListenerExecutor>
+ <asyncTransportExecutor factory="org.infinispan.executors.DefaultExecutorFactory">
+ <properties>
+ <property name="threadNamePrefix" value="AsyncSerializationThread"/>
+ </properties>
+ </asyncTransportExecutor>
+ <evictionScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory">
+ <properties>
+ <property name="threadNamePrefix" value="EvictionThread"/>
+ </properties>
+ </evictionScheduledExecutor>
+ <replicationQueueScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory">
+ <properties>
+ <property name="threadNamePrefix" value="ReplicationQueueThread"/>
+ </properties>
+ </replicationQueueScheduledExecutor>
+ <globalJmxStatistics jmxDomain="infinispan" enabled="true"/>
+ <transport transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport" clusterName="Infinispan-cluster" distributedSyncTimeout="20000">
+ <properties>
+ <property name="configurationFile" value="flush-udp.xml"/>
+ </properties>
+ </transport>
+ <shutdown hookBehavior="DEFAULT"/>
+ </global>
+ <default>
+ <locking isolationLevel="READ_COMMITTED" lockAcquisitionTimeout="10000" writeSkewCheck="false" concurrencyLevel="500"/>
+ <transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup" syncRollbackPhase="false" syncCommitPhase="false"/>
+ <jmxStatistics enabled="true"/>
+ <invocationBatching enabled="true"/>
+ <clustering mode="replication">
+ <stateRetrieval timeout="20000" fetchInMemoryState="false"/>
+ <sync replTimeout="20000"/>
+ </clustering>
+ </default>
+</infinispan>
\ No newline at end of file
Added: kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/resources/conf/portal/configuration.xml
===================================================================
--- kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/resources/conf/portal/configuration.xml (rev 0)
+++ kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/resources/conf/portal/configuration.xml 2010-07-13 16:53:30 UTC (rev 2780)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ Copyright (C) 2009 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.
+
+-->
+<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+ xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+ <component>
+ <key>org.exoplatform.services.cache.ExoCacheFactory</key>
+ <type>org.exoplatform.services.cache.impl.infinispan.ExoCacheFactoryImpl</type>
+ <init-params>
+ <value-param>
+ <name>cache.config.template</name>
+ <value>jar:/conf/portal/cache-configuration-template.xml</value>
+ </value-param>
+ </init-params>
+ </component>
+</configuration>
Added: kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestAbstractExoCache.java
===================================================================
--- kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestAbstractExoCache.java (rev 0)
+++ kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestAbstractExoCache.java 2010-07-13 16:53:30 UTC (rev 2780)
@@ -0,0 +1,731 @@
+/*
+ * 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.PortalContainer;
+import org.exoplatform.container.configuration.ConfigurationManager;
+import org.exoplatform.services.cache.CacheListener;
+import org.exoplatform.services.cache.CacheListenerContext;
+import org.exoplatform.services.cache.CacheService;
+import org.exoplatform.services.cache.CachedObjectSelector;
+import org.exoplatform.services.cache.ExoCache;
+import org.exoplatform.services.cache.ExoCacheConfig;
+import org.exoplatform.services.cache.ExoCacheFactory;
+import org.exoplatform.services.cache.ExoCacheInitException;
+import org.exoplatform.services.cache.ObjectCacheInfo;
+import org.exoplatform.test.BasicTestCase;
+
+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.Set;
+import java.util.Map.Entry;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * @author <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ *
+ */
+public class TestAbstractExoCache extends BasicTestCase
+{
+
+ CacheService service;
+
+ AbstractExoCache<Serializable, Object> cache;
+
+ public TestAbstractExoCache(String name)
+ {
+ super(name);
+ }
+
+ public void setUp() throws Exception
+ {
+ this.service = (CacheService)PortalContainer.getInstance().getComponentInstanceOfType(CacheService.class);
+ this.cache = (AbstractExoCache<Serializable, Object>)service.getCacheInstance("myCache");
+ }
+
+ protected void tearDown() throws Exception
+ {
+ cache.clearCache();
+ }
+
+ public void testPut() throws Exception
+ {
+ cache.put(new MyKey("a"), "a");
+ cache.put(new MyKey("b"), "b");
+ cache.put(new MyKey("c"), "c");
+ assertEquals(3, cache.getCacheSize());
+ cache.put(new MyKey("a"), "c");
+ assertEquals(3, cache.getCacheSize());
+ cache.put(new MyKey("d"), "c");
+ assertEquals(4, cache.getCacheSize());
+ }
+
+ public void testClearCache() throws Exception
+ {
+ cache.put(new MyKey("a"), "a");
+ cache.put(new MyKey("b"), "b");
+ cache.put(new MyKey("c"), "c");
+ assertTrue(cache.getCacheSize() > 0);
+ cache.clearCache();
+ assertTrue(cache.getCacheSize() == 0);
+ }
+
+ public void testGet() throws Exception
+ {
+ cache.put(new MyKey("a"), "a");
+ assertEquals("a", cache.get(new MyKey("a")));
+ cache.put(new MyKey("a"), "c");
+ assertEquals("c", cache.get(new MyKey("a")));
+ cache.remove(new MyKey("a"));
+ assertEquals(null, cache.get(new MyKey("a")));
+ assertEquals(null, cache.get(new MyKey("x")));
+ }
+
+ public void testRemove() throws Exception
+ {
+ cache.put(new MyKey("a"), 1);
+ cache.put(new MyKey("b"), 2);
+ cache.put(new MyKey("c"), 3);
+ assertEquals(3, cache.getCacheSize());
+ assertEquals(1, cache.remove(new MyKey("a")));
+ assertEquals(2, cache.getCacheSize());
+ assertEquals(2, cache.remove(new MyKey("b")));
+ assertEquals(1, cache.getCacheSize());
+ assertEquals(null, cache.remove(new MyKey("x")));
+ assertEquals(1, cache.getCacheSize());
+ }
+
+ public void testPutMap() throws Exception
+ {
+ Map<Serializable, Object> values = new HashMap<Serializable, Object>();
+ 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<Serializable, Object>()
+ {
+ private static final long serialVersionUID = 1L;
+
+ public Set<Entry<Serializable, Object>> entrySet()
+ {
+ Set<Entry<Serializable, Object>> set = new LinkedHashSet<Entry<Serializable, Object>>(super.entrySet());
+ set.add(new Entry<Serializable, Object>()
+ {
+
+ public Object setValue(Object paramV)
+ {
+ return null;
+ }
+
+ public Object getValue()
+ {
+ throw new RuntimeException("An exception");
+ }
+
+ public Serializable getKey()
+ {
+ return "c";
+ }
+ });
+ return set;
+ }
+ };
+ values.put(new MyKey("e"), "e");
+ values.put(new MyKey("d"), "d");
+ cache.putMap(values);
+ assertEquals(2, cache.getCacheSize());
+ }
+
+ public void testGetCachedObjects() throws Exception
+ {
+ cache.put(new MyKey("a"), "a");
+ cache.put(new MyKey("b"), "b");
+ cache.put(new MyKey("c"), "c");
+ cache.put(new MyKey("d"), null);
+ assertEquals(3, cache.getCacheSize());
+ List<Object> values = cache.getCachedObjects();
+ assertEquals(3, values.size());
+ assertTrue(values.contains("a"));
+ assertTrue(values.contains("b"));
+ assertTrue(values.contains("c"));
+ }
+
+ public void testRemoveCachedObjects() throws Exception
+ {
+ cache.put(new MyKey("a"), "a");
+ cache.put(new MyKey("b"), "b");
+ cache.put(new MyKey("c"), "c");
+ cache.put(new MyKey("d"), null);
+ assertEquals(3, cache.getCacheSize());
+ List<Object> values = cache.removeCachedObjects();
+ assertEquals(3, values.size());
+ assertTrue(values.contains("a"));
+ assertTrue(values.contains("b"));
+ assertTrue(values.contains("c"));
+ assertEquals(0, cache.getCacheSize());
+ }
+
+ public void testSelect() throws Exception
+ {
+ cache.put(new MyKey("a"), 1);
+ cache.put(new MyKey("b"), 2);
+ cache.put(new MyKey("c"), 3);
+ final AtomicInteger count = new AtomicInteger();
+ CachedObjectSelector<Serializable, Object> selector = new CachedObjectSelector<Serializable, Object>()
+ {
+
+ public void onSelect(ExoCache<? extends Serializable, ? extends Object> cache, Serializable key,
+ ObjectCacheInfo<? extends Object> ocinfo) throws Exception
+ {
+ assertTrue(key.equals(new MyKey("a")) || key.equals(new MyKey("b")) || key.equals(new MyKey("c")));
+ assertTrue(ocinfo.get().equals(1) || ocinfo.get().equals(2) || ocinfo.get().equals(3));
+ count.incrementAndGet();
+ }
+
+ public boolean select(Serializable key, ObjectCacheInfo<? extends Object> ocinfo)
+ {
+ return true;
+ }
+ };
+ cache.select(selector);
+ assertEquals(3, count.intValue());
+ }
+
+ public void testGetHitsNMisses() throws Exception
+ {
+ int hits = cache.getCacheHit();
+ int misses = cache.getCacheMiss();
+ cache.put(new MyKey("a"), "a");
+ cache.get(new MyKey("a"));
+ cache.remove(new MyKey("a"));
+ cache.get(new MyKey("a"));
+ cache.get(new MyKey("z"));
+ assertEquals(1, cache.getCacheHit() - hits);
+ assertEquals(2, cache.getCacheMiss() - misses);
+ }
+
+ private ExoCacheFactory getExoCacheFactoryInstance() throws ExoCacheInitException
+ {
+ PortalContainer pc = PortalContainer.getInstance();
+ return new ExoCacheFactoryImpl((ExoContainerContext)pc.getComponentInstanceOfType(ExoContainerContext.class),
+ "jar:/conf/portal/cache-configuration-template.xml", (ConfigurationManager)pc
+ .getComponentInstanceOfType(ConfigurationManager.class));
+ }
+
+ public void testMultiThreading() throws Exception
+ {
+ long time = System.currentTimeMillis();
+ final ExoCache<Serializable, Object> cache = service.getCacheInstance("test-multi-threading");
+ final int totalElement = 100;
+ final int totalTimes = 20;
+ int reader = 20;
+ int writer = 10;
+ int remover = 5;
+ int cleaner = 1;
+ final CountDownLatch startSignalWriter = new CountDownLatch(1);
+ final CountDownLatch startSignalOthers = new CountDownLatch(1);
+ final CountDownLatch doneSignal = new CountDownLatch(reader + writer + remover);
+ final List<Exception> errors = Collections.synchronizedList(new ArrayList<Exception>());
+ for (int i = 0; i < writer; i++)
+ {
+ final int index = i;
+ Thread thread = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ startSignalWriter.await();
+ for (int j = 0; j < totalTimes; j++)
+ {
+ for (int i = 0; i < totalElement; i++)
+ {
+ cache.put(new MyKey("key" + i), "value" + i);
+ }
+ if (index == 0 && j == 0)
+ {
+ // The cache is full, we can launch the others
+ startSignalOthers.countDown();
+ }
+ sleep(50);
+ }
+ }
+ catch (Exception e)
+ {
+ errors.add(e);
+ }
+ finally
+ {
+ doneSignal.countDown();
+ }
+ }
+ };
+ thread.start();
+ }
+ startSignalWriter.countDown();
+ for (int i = 0; i < reader; i++)
+ {
+ Thread thread = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ startSignalOthers.await();
+ for (int j = 0; j < totalTimes; j++)
+ {
+ for (int i = 0; i < totalElement; i++)
+ {
+ cache.get(new MyKey("key" + i));
+ }
+ sleep(50);
+ }
+ }
+ catch (Exception e)
+ {
+ errors.add(e);
+ }
+ finally
+ {
+ doneSignal.countDown();
+ }
+ }
+ };
+ thread.start();
+ }
+ for (int i = 0; i < remover; i++)
+ {
+ Thread thread = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ startSignalOthers.await();
+ for (int j = 0; j < totalTimes; j++)
+ {
+ for (int i = 0; i < totalElement; i++)
+ {
+ cache.remove(new MyKey("key" + i));
+ }
+ sleep(50);
+ }
+ }
+ catch (Exception e)
+ {
+ errors.add(e);
+ }
+ finally
+ {
+ doneSignal.countDown();
+ }
+ }
+ };
+ thread.start();
+ }
+ doneSignal.await();
+ for (int i = 0; i < totalElement; i++)
+ {
+ cache.put(new MyKey("key" + i), "value" + i);
+ }
+ assertEquals(totalElement, cache.getCacheSize());
+ final CountDownLatch startSignal = new CountDownLatch(1);
+ final CountDownLatch doneSignal2 = new CountDownLatch(writer + cleaner);
+ for (int i = 0; i < writer; i++)
+ {
+ Thread thread = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ startSignal.await();
+ for (int j = 0; j < totalTimes; j++)
+ {
+ for (int i = 0; i < totalElement; i++)
+ {
+ cache.put(new MyKey("key" + i), "value" + i);
+ }
+ sleep(50);
+ }
+ }
+ catch (Exception e)
+ {
+ errors.add(e);
+ }
+ finally
+ {
+ doneSignal2.countDown();
+ }
+ }
+ };
+ thread.start();
+ }
+ for (int i = 0; i < cleaner; i++)
+ {
+ Thread thread = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ startSignal.await();
+ for (int j = 0; j < totalTimes; j++)
+ {
+ sleep(150);
+ cache.clearCache();
+ }
+ }
+ catch (Exception e)
+ {
+ errors.add(e);
+ }
+ finally
+ {
+ doneSignal2.countDown();
+ }
+ }
+ };
+ thread.start();
+ }
+ cache.clearCache();
+ assertEquals(0, cache.getCacheSize());
+ if (!errors.isEmpty())
+ {
+ for (Exception e : errors)
+ {
+ e.printStackTrace();
+ }
+ throw errors.get(0);
+ }
+ System.out.println("Total Time = " + (System.currentTimeMillis() - time));
+ }
+
+ public static class MyCacheListener implements CacheListener<Serializable, Object>
+ {
+
+ public int clearCache;
+
+ public int expire;
+
+ public int get;
+
+ public int put;
+
+ public int remove;
+
+ public void onClearCache(ExoCache<Serializable, Object> cache) throws Exception
+ {
+ clearCache++;
+ }
+
+ public void onExpire(ExoCache<Serializable, Object> cache, Serializable key, Object obj) throws Exception
+ {
+ expire++;
+ }
+
+ public void onGet(ExoCache<Serializable, Object> cache, Serializable key, Object obj) throws Exception
+ {
+ get++;
+ }
+
+ public void onPut(ExoCache<Serializable, Object> cache, Serializable key, Object obj) throws Exception
+ {
+ put++;
+ }
+
+ public void onRemove(ExoCache<Serializable, Object> cache, Serializable key, Object obj) throws Exception
+ {
+ remove++;
+ }
+
+ public void onClearCache(CacheListenerContext context) throws Exception
+ {
+ clearCache++;
+ }
+
+ public void onExpire(CacheListenerContext context, Serializable key, Object obj) throws Exception
+ {
+ expire++;
+ }
+
+ public void onGet(CacheListenerContext context, Serializable key, Object obj) throws Exception
+ {
+ get++;
+ }
+
+ public void onPut(CacheListenerContext context, Serializable key, Object obj) throws Exception
+ {
+ put++;
+ }
+
+ public void onRemove(CacheListenerContext context, Serializable key, Object obj) throws Exception
+ {
+ remove++;
+ }
+ }
+
+ public static class MyKey implements Serializable
+ {
+ private static final long serialVersionUID = 1L;
+
+ public String value;
+
+ public MyKey(String value)
+ {
+ this.value = value;
+ }
+
+ @Override
+ public boolean equals(Object paramObject)
+ {
+ return paramObject instanceof MyKey && ((MyKey)paramObject).value.endsWith(value);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return value.hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return value;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testDistributedCache() throws Exception
+ {
+ // If the cache is still alive this test fails due to a TimeoutException.
+ cache.cache.getCacheManager().stop();
+
+ System.out
+ .println("WARNING: For Linux distributions the following JVM parameter must be set to true, java.net.preferIPv4Stack = "
+ + System.getProperty("java.net.preferIPv4Stack"));
+ ExoCacheConfig config = new ExoCacheConfig();
+ config.setName("MyCacheDistributed");
+ config.setMaxSize(5);
+ config.setLiveTime(1);
+ config.setImplementation("LRU");
+ config.setDistributed(true);
+ ExoCacheConfig config2 = new ExoCacheConfig();
+ config2.setName("MyCacheDistributed2");
+ config2.setMaxSize(5);
+ config2.setLiveTime(1);
+ config2.setImplementation("LRU");
+ config2.setDistributed(true);
+ AbstractExoCache<Serializable, Object> cache1 =
+ (AbstractExoCache<Serializable, Object>)getExoCacheFactoryInstance().createCache(config);
+ MyCacheListener listener1 = new MyCacheListener();
+ cache1.addCacheListener(listener1);
+ AbstractExoCache<Serializable, Object> cache2 =
+ (AbstractExoCache<Serializable, Object>)getExoCacheFactoryInstance().createCache(config);
+ MyCacheListener listener2 = new MyCacheListener();
+ cache2.addCacheListener(listener2);
+// Cache 3 creates a conflict with cache 1 and 2
+// AbstractExoCache<Serializable, Object> cache3 =
+// (AbstractExoCache<Serializable, Object>)getExoCacheFactoryInstance().createCache(config2);
+// MyCacheListener listener3 = new MyCacheListener();
+// cache3.addCacheListener(listener3);
+ try
+ {
+ cache1.put(new MyKey("a"), "b");
+ assertEquals(1, cache1.getCacheSize());
+ assertEquals("b", cache2.get(new MyKey("a")));
+ assertEquals(1, cache2.getCacheSize());
+// assertEquals(0, cache3.getCacheSize());
+ assertEquals(1, listener1.put);
+ assertEquals(1, listener2.put);
+// assertEquals(0, listener3.put);
+ assertEquals(0, listener1.get);
+ assertEquals(1, listener2.get);
+// assertEquals(0, listener3.get);
+ cache2.put(new MyKey("b"), "c");
+ assertEquals(2, cache1.getCacheSize());
+ assertEquals(2, cache2.getCacheSize());
+ assertEquals("c", cache1.get(new MyKey("b")));
+// assertEquals(0, cache3.getCacheSize());
+ assertEquals(2, listener1.put);
+ assertEquals(2, listener2.put);
+// assertEquals(0, listener3.put);
+ assertEquals(1, listener1.get);
+ assertEquals(1, listener2.get);
+// assertEquals(0, listener3.get);
+// cache3.put(new MyKey("c"), "d");
+ assertEquals(2, cache1.getCacheSize());
+ assertEquals(2, cache2.getCacheSize());
+// assertEquals(1, cache3.getCacheSize());
+// assertEquals("d", cache3.get(new MyKey("c")));
+ assertEquals(2, listener1.put);
+ assertEquals(2, listener2.put);
+// assertEquals(1, listener3.put);
+ assertEquals(1, listener1.get);
+ assertEquals(1, listener2.get);
+// assertEquals(1, listener3.get);
+ cache2.put(new MyKey("a"), "a");
+ assertEquals(2, cache1.getCacheSize());
+ assertEquals(2, cache2.getCacheSize());
+ assertEquals("a", cache1.get(new MyKey("a")));
+ assertEquals(3, listener1.put);
+ assertEquals(3, listener2.put);
+// assertEquals(1, listener3.put);
+ assertEquals(2, listener1.get);
+ assertEquals(1, listener2.get);
+// assertEquals(1, listener3.get);
+ cache2.remove(new MyKey("a"));
+ assertEquals(1, cache1.getCacheSize());
+ assertEquals(1, cache2.getCacheSize());
+ assertEquals(3, listener1.put);
+ assertEquals(3, listener2.put);
+// assertEquals(1, listener3.put);
+ assertEquals(2, listener1.get);
+ assertEquals(1, listener2.get);
+// assertEquals(1, listener3.get);
+ assertEquals(1, listener1.remove);
+ assertEquals(1, listener2.remove);
+// assertEquals(0, listener3.remove);
+ cache1.put(new MyKey("c"), "c");
+ cache1.clearCache();
+ assertEquals(0, cache1.getCacheSize());
+ assertEquals(null, cache1.get(new MyKey("b")));
+ assertEquals("c", cache2.get(new MyKey("b")));
+ assertEquals("c", cache2.get(new MyKey("c")));
+ assertEquals(2, cache2.getCacheSize());
+ assertEquals(4, listener1.put);
+ assertEquals(4, listener2.put);
+// assertEquals(1, listener3.put);
+ assertEquals(3, listener1.get);
+ assertEquals(3, listener2.get);
+// assertEquals(1, listener3.get);
+ assertEquals(1, listener1.remove);
+ assertEquals(1, listener2.remove);
+// assertEquals(0, listener3.remove);
+ assertEquals(1, listener1.clearCache);
+ assertEquals(0, listener2.clearCache);
+// assertEquals(0, listener3.clearCache);
+ Map<Serializable, Object> values = new HashMap<Serializable, Object>();
+ values.put(new MyKey("a"), "a");
+ values.put(new MyKey("b"), "b");
+ cache1.putMap(values);
+ assertEquals(2, cache1.getCacheSize());
+ Thread.sleep(40);
+ assertEquals("a", cache2.get(new MyKey("a")));
+ assertEquals("b", cache2.get(new MyKey("b")));
+ assertEquals(3, cache2.getCacheSize());
+ assertEquals(6, listener1.put);
+ assertEquals(6, listener2.put);
+// assertEquals(1, listener3.put);
+ assertEquals(3, listener1.get);
+ assertEquals(5, listener2.get);
+// assertEquals(1, listener3.get);
+ assertEquals(1, listener1.remove);
+ assertEquals(1, listener2.remove);
+// assertEquals(0, listener3.remove);
+ assertEquals(1, listener1.clearCache);
+ assertEquals(0, listener2.clearCache);
+// assertEquals(0, listener3.clearCache);
+ values = new HashMap<Serializable, Object>()
+ {
+ private static final long serialVersionUID = 1L;
+
+ public Set<Entry<Serializable, Object>> entrySet()
+ {
+ Set<Entry<Serializable, Object>> set = new LinkedHashSet<Entry<Serializable, Object>>(super.entrySet());
+ set.add(new Entry<Serializable, Object>()
+ {
+
+ public Object setValue(Object paramV)
+ {
+ return null;
+ }
+
+ public Object getValue()
+ {
+ throw new RuntimeException("An exception");
+ }
+
+ public Serializable getKey()
+ {
+ return "c";
+ }
+ });
+ return set;
+ }
+ };
+ values.put(new MyKey("e"), "e");
+ values.put(new MyKey("d"), "d");
+ cache1.putMap(values);
+ assertEquals(2, cache1.getCacheSize());
+ assertEquals(3, cache2.getCacheSize());
+// assertEquals(1, cache3.getCacheSize());
+ assertEquals(6, listener1.put);
+ assertEquals(6, listener2.put);
+// assertEquals(1, listener3.put);
+ assertEquals(3, listener1.get);
+ assertEquals(5, listener2.get);
+// assertEquals(1, listener3.get);
+ assertEquals(1, listener1.remove);
+ assertEquals(1, listener2.remove);
+// assertEquals(0, listener3.remove);
+ assertEquals(1, listener1.clearCache);
+ assertEquals(0, listener2.clearCache);
+// assertEquals(0, listener3.clearCache);
+ assertEquals(0, listener1.expire);
+ assertEquals(0, listener2.expire);
+// assertEquals(0, listener3.expire);
+ Thread.sleep(5600);
+ assertEquals(0, cache1.getCacheSize());
+ assertEquals(0, cache2.getCacheSize());
+// assertEquals(0, cache3.getCacheSize());
+ assertEquals(6, listener1.put);
+ assertEquals(6, listener2.put);
+// assertEquals(1, listener3.put);
+ assertEquals(3, listener1.get);
+ assertEquals(5, listener2.get);
+// assertEquals(1, listener3.get);
+ assertEquals(1, listener1.remove);
+ assertEquals(1, listener2.remove);
+// assertEquals(0, listener3.remove);
+ assertEquals(1, listener1.clearCache);
+ assertEquals(0, listener2.clearCache);
+// assertEquals(0, listener3.clearCache);
+// Expiration events are not triggered in infinispan
+// assertEquals(2, listener1.expire);
+// assertEquals(3, listener2.expire);
+// assertEquals(1, listener3.expire);
+ }
+ finally
+ {
+ cache1.cache.getCacheManager().stop();
+ cache2.cache.getCacheManager().stop();
+// cache3.cache.getCacheManager().stop();
+ }
+ }
+}
Added: kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheConfig.java
===================================================================
--- kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheConfig.java (rev 0)
+++ kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheConfig.java 2010-07-13 16:53:30 UTC (rev 2780)
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.cache.impl.infinispan;
+
+import org.exoplatform.services.cache.ExoCacheConfig;
+
+/**
+ * @author <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ *
+ */
+public class TestExoCacheConfig extends ExoCacheConfig
+{
+
+}
Added: kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheCreator.java
===================================================================
--- kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheCreator.java (rev 0)
+++ kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheCreator.java 2010-07-13 16:53:30 UTC (rev 2780)
@@ -0,0 +1,225 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.cache.impl.infinispan;
+
+import org.exoplatform.services.cache.CacheListener;
+import org.exoplatform.services.cache.CachedObjectSelector;
+import org.exoplatform.services.cache.ExoCache;
+import org.exoplatform.services.cache.ExoCacheConfig;
+import org.exoplatform.services.cache.ExoCacheInitException;
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Callable;
+
+/**
+ * @author <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ *
+ */
+public class TestExoCacheCreator implements ExoCacheCreator
+{
+
+ /**
+ * @see org.exoplatform.services.cache.impl.infinispan.ExoCacheCreator#create(org.exoplatform.services.cache.ExoCacheConfig, org.infinispan.config.Configuration, java.util.concurrent.Callable)
+ */
+ @Override
+ public ExoCache<Serializable, Object> create(ExoCacheConfig config, Configuration cacheConfig,
+ Callable<Cache<Serializable, Object>> cacheGetter) throws ExoCacheInitException
+ {
+ return new TestExoCache();
+ }
+
+ public Class<? extends ExoCacheConfig> getExpectedConfigType()
+ {
+ return TestExoCacheConfig.class;
+ }
+
+ public Set<String> getExpectedImplementations()
+ {
+ return Collections.singleton("TEST");
+ }
+
+ public static class TestExoCache implements ExoCache<Serializable, Object>
+ {
+
+ public void addCacheListener(CacheListener listener)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ public int getCacheHit()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int getCacheMiss()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int getCacheSize()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public List getCachedObjects()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getLabel()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public long getLiveTime()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int getMaxSize()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public String getName()
+ {
+ return "name";
+ }
+
+ public boolean isDistributed()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isLogEnabled()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isReplicated()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+
+ public void select(CachedObjectSelector selector) throws Exception
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setDistributed(boolean b)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setLabel(String s)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setLiveTime(long period)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setLogEnabled(boolean b)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setMaxSize(int max)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setName(String name)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setReplicated(boolean b)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void clearCache()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Object get(Serializable key)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void put(Serializable key, Object value) throws NullPointerException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void putMap(Map objs) throws NullPointerException, IllegalArgumentException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Object remove(Serializable key) throws NullPointerException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List removeCachedObjects()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ }
+}
Added: kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java
===================================================================
--- kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java (rev 0)
+++ kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java 2010-07-13 16:53:30 UTC (rev 2780)
@@ -0,0 +1,78 @@
+/*
+ * 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.PortalContainer;
+import org.exoplatform.services.cache.CacheService;
+import org.exoplatform.services.cache.ExoCache;
+import org.exoplatform.services.cache.impl.infinispan.TestExoCacheCreator.TestExoCache;
+import org.exoplatform.test.BasicTestCase;
+import org.infinispan.config.Configuration.CacheMode;
+
+/**
+ * @author <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ *
+ */
+public class TestExoCacheFactoryImpl extends BasicTestCase
+{
+
+ CacheService service_;
+
+ public TestExoCacheFactoryImpl(String name)
+ {
+ super(name);
+ }
+
+ public void setUp() throws Exception
+ {
+ service_ = (CacheService)PortalContainer.getInstance().getComponentInstanceOfType(CacheService.class);
+ }
+
+ public void testCacheFactory()
+ {
+ ExoCache cache = service_.getCacheInstance("myCache");
+ assertTrue("expect an instance of AbstractExoCache", cache instanceof AbstractExoCache);
+ AbstractExoCache aCache = (AbstractExoCache)cache;
+ assertTrue("expect a local cache", aCache.cache.getConfiguration().getCacheMode() == CacheMode.LOCAL);
+ aCache.cache.stop();
+ cache = service_.getCacheInstance("cacheDistributed");
+ assertTrue("expect an instance of AbstractExoCache", cache instanceof AbstractExoCache);
+ aCache = (AbstractExoCache)cache;
+ assertTrue("expect a distributed cache", aCache.cache.getConfiguration().getCacheMode() == CacheMode.REPL_SYNC);
+ aCache.cache.stop();
+ cache = service_.getCacheInstance("myCustomCache");
+ assertTrue("expect an instance of AbstractExoCache", cache instanceof AbstractExoCache);
+ aCache = (AbstractExoCache)cache;
+ assertTrue("expect a distributed cache", aCache.cache.getConfiguration().getCacheMode() == CacheMode.REPL_SYNC);
+ aCache.cache.stop();
+ }
+
+ public void testExoCacheCreator()
+ {
+ ExoCache cache = service_.getCacheInstance("test-default-impl");
+ assertTrue("expect an instance of AbstractExoCache", cache instanceof AbstractExoCache);
+ AbstractExoCache aCache = (AbstractExoCache)cache;
+ aCache.cache.stop();
+ cache = service_.getCacheInstance("test-custom-impl-with-old-config");
+ assertTrue("expect an instance of TestExoCache", cache instanceof TestExoCache);
+ cache = service_.getCacheInstance("test-custom-impl-with-new-config");
+ assertTrue("expect an instance of TestExoCache", cache instanceof TestExoCache);
+ }
+}
Added: kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/cache-configuration-template.xml
===================================================================
--- kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/cache-configuration-template.xml (rev 0)
+++ kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/cache-configuration-template.xml 2010-07-13 16:53:30 UTC (rev 2780)
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:infinispan:config:4.0 http://www.infinispan.org/schemas/infinispan-config-4.0.xsd"
+ xmlns="urn:infinispan:config:4.0">
+ <global>
+ <asyncListenerExecutor factory="org.infinispan.executors.DefaultExecutorFactory">
+ <properties>
+ <property name="maxThreads" value="1"/>
+ <property name="queueSize" value="100000"/>
+ <property name="threadNamePrefix" value="AsyncListenerThread"/>
+ </properties>
+ </asyncListenerExecutor>
+ <asyncTransportExecutor factory="org.infinispan.executors.DefaultExecutorFactory">
+ <properties>
+ <property name="threadNamePrefix" value="AsyncSerializationThread"/>
+ </properties>
+ </asyncTransportExecutor>
+ <evictionScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory">
+ <properties>
+ <property name="threadNamePrefix" value="EvictionThread"/>
+ </properties>
+ </evictionScheduledExecutor>
+ <replicationQueueScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory">
+ <properties>
+ <property name="threadNamePrefix" value="ReplicationQueueThread"/>
+ </properties>
+ </replicationQueueScheduledExecutor>
+ <globalJmxStatistics jmxDomain="infinispan" enabled="false"/>
+ <transport transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport" clusterName="Infinispan-cluster" distributedSyncTimeout="20000">
+ <properties>
+ <property name="configurationFile" value="flush-udp.xml"/>
+ </properties>
+ </transport>
+ <shutdown hookBehavior="DEFAULT"/>
+ </global>
+ <default>
+ <locking isolationLevel="READ_COMMITTED" lockAcquisitionTimeout="10000" writeSkewCheck="false" concurrencyLevel="500"/>
+ <transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup" syncRollbackPhase="false" syncCommitPhase="false"/>
+ <jmxStatistics enabled="false"/>
+ <clustering mode="replication">
+ <stateRetrieval timeout="20000" fetchInMemoryState="false"/>
+ <sync replTimeout="20000"/>
+ </clustering>
+ </default>
+</infinispan>
\ No newline at end of file
Added: kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/distributed-cache-configuration-template.xml
===================================================================
--- kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/distributed-cache-configuration-template.xml (rev 0)
+++ kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/distributed-cache-configuration-template.xml 2010-07-13 16:53:30 UTC (rev 2780)
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:infinispan:config:4.0 http://www.infinispan.org/schemas/infinispan-config-4.0.xsd"
+ xmlns="urn:infinispan:config:4.0">
+ <global>
+ <asyncListenerExecutor factory="org.infinispan.executors.DefaultExecutorFactory">
+ <properties>
+ <property name="maxThreads" value="1"/>
+ <property name="queueSize" value="100000"/>
+ <property name="threadNamePrefix" value="AsyncListenerThread"/>
+ </properties>
+ </asyncListenerExecutor>
+ <asyncTransportExecutor factory="org.infinispan.executors.DefaultExecutorFactory">
+ <properties>
+ <property name="threadNamePrefix" value="AsyncSerializationThread"/>
+ </properties>
+ </asyncTransportExecutor>
+ <evictionScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory">
+ <properties>
+ <property name="threadNamePrefix" value="EvictionThread"/>
+ </properties>
+ </evictionScheduledExecutor>
+ <replicationQueueScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory">
+ <properties>
+ <property name="threadNamePrefix" value="ReplicationQueueThread"/>
+ </properties>
+ </replicationQueueScheduledExecutor>
+ <globalJmxStatistics jmxDomain="infinispan" enabled="true"/>
+ <transport transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport" clusterName="Infinispan-cluster" distributedSyncTimeout="20000">
+ <properties>
+ <property name="configurationFile" value="flush-udp.xml"/>
+ </properties>
+ </transport>
+ <shutdown hookBehavior="DEFAULT"/>
+ </global>
+ <default>
+ <locking isolationLevel="READ_COMMITTED" lockAcquisitionTimeout="20000" writeSkewCheck="false" concurrencyLevel="500"/>
+ <transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup" syncRollbackPhase="false" syncCommitPhase="false"/>
+ <jmxStatistics enabled="true"/>
+ <clustering mode="replication">
+ <stateRetrieval timeout="20000" fetchInMemoryState="false"/>
+ <sync replTimeout="20000"/>
+ </clustering>
+ </default>
+</infinispan>
\ No newline at end of file
Added: kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/test-configuration.xml
===================================================================
--- kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/test-configuration.xml (rev 0)
+++ kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/test-configuration.xml 2010-07-13 16:53:30 UTC (rev 2780)
@@ -0,0 +1,219 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ Copyright (C) 2009 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.
+
+-->
+<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+ xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+
+ <component>
+ <key>org.exoplatform.services.cache.CacheService</key>
+ <type>org.exoplatform.services.cache.impl.CacheServiceImpl</type>
+
+ <init-params>
+ <object-param>
+ <name>cache.config.default</name>
+ <description>The default cache configuration</description>
+ <object type="org.exoplatform.services.cache.ExoCacheConfig">
+ <field name="name"><string>default</string></field>
+ <field name="maxSize"><int>5</int></field>
+ <field name="liveTime"><long>2</long></field>
+ </object>
+ </object-param>
+ <object-param>
+ <name>test-multi-threading</name>
+ <description>The default cache configuration</description>
+ <object type="org.exoplatform.services.cache.impl.infinispan.generic.GenericExoCacheConfig">
+ <field name="name"><string>test-multi-threading</string></field>
+ <field name="strategy"><string>NONE</string></field>
+ <field name="maxEntries"><int>-1</int></field>
+ <field name="lifespan"><long>-1</long></field>
+ </object>
+ </object-param>
+ <object-param>
+ <name>cacheDistributed</name>
+ <description>The default cache configuration</description>
+ <object type="org.exoplatform.services.cache.ExoCacheConfig">
+ <field name="name"><string>cacheDistributed</string></field>
+ <field name="maxSize"><int>5</int></field>
+ <field name="liveTime"><long>2</long></field>
+ <field name="distributed"><boolean>true</boolean></field>
+ </object>
+ </object-param>
+ <object-param>
+ <name>test-default-impl</name>
+ <description>The default cache configuration</description>
+ <object type="org.exoplatform.services.cache.ExoCacheConfig">
+ <field name="name"><string>test-default-impl</string></field>
+ <field name="maxSize"><int>5</int></field>
+ <field name="liveTime"><long>2</long></field>
+ </object>
+ </object-param>
+ <object-param>
+ <name>test-custom-impl-with-old-config</name>
+ <description>The default cache configuration</description>
+ <object type="org.exoplatform.services.cache.ExoCacheConfig">
+ <field name="name"><string>test-custom-impl-with-old-config</string></field>
+ <field name="maxSize"><int>5</int></field>
+ <field name="liveTime"><long>2</long></field>
+ <field name="implementation"><string>TEST</string></field>
+ </object>
+ </object-param>
+ <object-param>
+ <name>test-custom-impl-with-new-config</name>
+ <description>The default cache configuration</description>
+ <object type="org.exoplatform.services.cache.impl.infinispan.TestExoCacheConfig">
+ <field name="name"><string>test-custom-impl-with-new-config</string></field>
+ <field name="maxSize"><int>5</int></field>
+ <field name="liveTime"><long>2</long></field>
+ </object>
+ </object-param>
+<!-- <object-param>-->
+<!-- <name>test-fifo-with-old-config</name>-->
+<!-- <description>The default cache configuration</description>-->
+<!-- <object type="org.exoplatform.services.cache.ExoCacheConfig">-->
+<!-- <field name="name"><string>test-fifo-with-old-config</string></field>-->
+<!-- <field name="maxSize"><int>5</int></field>-->
+<!-- <field name="liveTime"><long>1</long></field>-->
+<!-- <field name="implementation"><string>FIFO</string></field>-->
+<!-- </object>-->
+<!-- </object-param> -->
+<!-- <object-param>-->
+<!-- <name>test-fifo</name>-->
+<!-- <description>The default cache configuration</description>-->
+<!-- <object type="org.exoplatform.services.cache.impl.infinispan.generic.GenericExoCacheConfig">-->
+<!-- <field name="name"><string>test-fifo</string></field>-->
+<!-- <field name="strategy"><string>FIFO</string></field>-->
+<!-- <field name="maxEntries"><int>5</int></field>-->
+<!-- <field name="lifespan"><long>1000</long></field>-->
+<!-- </object>-->
+<!-- </object-param> -->
+<!-- <object-param>-->
+<!-- <name>test-lru-with-old-config</name>-->
+<!-- <description>The default cache configuration</description>-->
+<!-- <object type="org.exoplatform.services.cache.ExoCacheConfig">-->
+<!-- <field name="name"><string>test-lru-with-old-config</string></field>-->
+<!-- <field name="maxSize"><int>4</int></field>-->
+<!-- <field name="liveTime"><long>1</long></field>-->
+<!-- <field name="implementation"><string>LRU</string></field>-->
+<!-- </object>-->
+<!-- </object-param> -->
+<!-- <object-param>-->
+<!-- <name>test-lru</name>-->
+<!-- <description>The default cache configuration</description>-->
+<!-- <object type="org.exoplatform.services.cache.impl.infinispan.generic.GenericExoCacheConfig">-->
+<!-- <field name="name"><string>test-lru</string></field>-->
+<!-- <field name="strategy"><string>LRU</string></field>-->
+<!-- <field name="maxEntries"><int>4</int></field>-->
+<!-- <field name="lifespan"><long>1000</long></field>-->
+<!-- <field name="maxIdle"><long>-1</long></field>-->
+<!-- </object>-->
+<!-- </object-param> -->
+<!-- <object-param>-->
+<!-- <name>test-ea-with-old-config</name>-->
+<!-- <description>The default cache configuration</description>-->
+<!-- <object type="org.exoplatform.services.cache.ExoCacheConfig">-->
+<!-- <field name="name"><string>test-ea-with-old-config</string></field>-->
+<!-- <field name="maxSize"><int>5</int></field>-->
+<!-- <field name="liveTime"><long>1</long></field>-->
+<!-- <field name="implementation"><string>NONE</string></field>-->
+<!-- </object>-->
+<!-- </object-param> -->
+<!-- <object-param>-->
+<!-- <name>test-ea</name>-->
+<!-- <description>The default cache configuration</description>-->
+<!-- <object type="org.exoplatform.services.cache.impl.infinispan.generic.GenericExoCacheConfig">-->
+<!-- <field name="name"><string>test-ea</string></field>-->
+<!-- <field name="strategy"><string>NONE</string></field>-->
+<!-- <field name="maxEntries"><int>5</int></field>-->
+<!-- <field name="maxIdle"><long>1000</long></field>-->
+<!-- <field name="lifespan"><long>2000</long></field>-->
+<!-- </object>-->
+<!-- </object-param> -->
+ </init-params>
+ </component>
+
+ <component>
+ <key>org.exoplatform.services.cache.ExoCacheFactory</key>
+ <type>org.exoplatform.services.cache.impl.infinispan.ExoCacheFactoryImpl</type>
+ <init-params>
+ <value-param>
+ <name>cache.config.template</name>
+ <value>jar:/conf/portal/cache-configuration-template.xml</value>
+ </value-param>
+ </init-params>
+ </component>
+
+ <external-component-plugins>
+ <target-component>org.exoplatform.services.cache.ExoCacheFactory</target-component>
+ <component-plugin>
+ <name>addConfig</name>
+ <set-method>addConfig</set-method>
+ <type>org.exoplatform.services.cache.impl.infinispan.ExoCacheFactoryConfigPlugin</type>
+ <description>add Custom Configurations</description>
+ <init-params>
+ <value-param>
+ <name>myCustomCache</name>
+ <value>jar:/conf/portal/distributed-cache-configuration-template.xml</value>
+ </value-param>
+ </init-params>
+ </component-plugin>
+ <component-plugin>
+ <name>addCreator</name>
+ <set-method>addCreator</set-method>
+ <type>org.exoplatform.services.cache.impl.infinispan.ExoCacheCreatorPlugin</type>
+ <description>add Exo Cache Creator</description>
+ <init-params>
+ <object-param>
+ <name>Test</name>
+ <description>The cache creator for testing purpose</description>
+ <object type="org.exoplatform.services.cache.impl.infinispan.TestExoCacheCreator"></object>
+ </object-param>
+ <object-param>
+ <name>GENERIC</name>
+ <description>The generic cache creator</description>
+ <object type="org.exoplatform.services.cache.impl.infinispan.generic.GenericExoCacheCreator">
+ <field name="implementations">
+ <collection type="java.util.HashSet">
+ <value>
+ <string>NONE</string>
+ </value>
+ <value>
+ <string>FIFO</string>
+ </value>
+ <value>
+ <string>LRU</string>
+ </value>
+ <value>
+ <string>UNORDERED</string>
+ </value>
+ <value>
+ <string>LIRS</string>
+ </value>
+ </collection>
+ </field>
+ <field name="defaultStrategy"><string>LRU</string></field>
+ <field name="defaultMaxIdle"><long>-1</long></field>
+ <field name="defaultWakeUpInterval"><long>500</long></field>
+ </object>
+ </object-param>
+ </init-params>
+ </component-plugin>
+ </external-component-plugins>
+</configuration>
Modified: kernel/branches/2.3-ISPN/pom.xml
===================================================================
--- kernel/branches/2.3-ISPN/pom.xml 2010-07-13 13:15:23 UTC (rev 2779)
+++ kernel/branches/2.3-ISPN/pom.xml 2010-07-13 16:53:30 UTC (rev 2780)
@@ -54,7 +54,8 @@
<module>exo.kernel.commons.test</module>
<module>exo.kernel.component.common</module>
<module>exo.kernel.component.cache</module>
- <module>exo.kernel.component.ext.cache.impl.jboss.v3</module>
+ <module>exo.kernel.component.ext.cache.impl.jboss.v3</module>
+ <module>exo.kernel.component.ext.cache.impl.infinispan.v4</module>
<module>exo.kernel.component.command</module>
<module>exo.kernel.mc-integration</module>
<module>packaging/module</module>
@@ -177,15 +178,20 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>jgroups</groupId>
+ <groupId>org.jgroups</groupId>
<artifactId>jgroups</artifactId>
- <version>2.6.13.GA</version>
+ <version>2.10.0.CR1</version>
</dependency>
<dependency>
<groupId>org.jboss.cache</groupId>
<artifactId>jbosscache-core</artifactId>
<version>3.2.4.GA</version>
- </dependency>
+ </dependency>
+ <dependency>
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-core</artifactId>
+ <version>4.1.0.CR1</version>
+ </dependency>
<dependency>
<groupId>org.jibx</groupId>
<artifactId>jibx-bind</artifactId>
13 years, 11 months
exo-jcr SVN: r2779 - ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-07-13 09:15:23 -0400 (Tue, 13 Jul 2010)
New Revision: 2779
Modified:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java
Log:
EXOJCR-482 : cleanup
Modified: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java 2010-07-13 12:47:25 UTC (rev 2778)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java 2010-07-13 13:15:23 UTC (rev 2779)
@@ -110,7 +110,6 @@
URL resource = null;
synchronized (filename)
{
- System.out.println(">>>>>>>> "+resources.size());
resource = resources.get(filename);
boolean inCache = resource != null;
for (URL root : roots)
13 years, 11 months
exo-jcr SVN: r2778 - jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-07-13 08:47:25 -0400 (Tue, 13 Jul 2010)
New Revision: 2778
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScriptAddRepoPlugin.java
Log:
EXOJCR-482
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScriptAddRepoPlugin.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScriptAddRepoPlugin.java 2010-07-13 12:06:50 UTC (rev 2777)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScriptAddRepoPlugin.java 2010-07-13 12:47:25 UTC (rev 2778)
@@ -23,6 +23,8 @@
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.PropertiesParam;
import org.exoplatform.services.jcr.ext.resource.UnifiedNodeReference;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
import java.net.MalformedURLException;
import java.net.URL;
@@ -39,6 +41,9 @@
public class GroovyScriptAddRepoPlugin extends BaseComponentPlugin
{
+ /** Logger. */
+ private static final Log LOG = ExoLogger.getLogger(GroovyScriptAddRepoPlugin.class);
+
private final InitParams params;
public GroovyScriptAddRepoPlugin(InitParams params)
@@ -46,6 +51,7 @@
this.params = params;
}
+ @SuppressWarnings("unchecked")
public Collection<URL> getRepositories()
{
if (params == null)
@@ -65,8 +71,7 @@
}
catch (MalformedURLException e)
{
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("Failed add groovy script repository. " + e.getMessage());
}
}
return repos;
13 years, 11 months
exo-jcr SVN: r2777 - ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-07-13 08:06:50 -0400 (Tue, 13 Jul 2010)
New Revision: 2777
Modified:
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ResourceBinder.java
Log:
EXOJCR-824 :
Modified: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java 2010-07-13 11:48:53 UTC (rev 2776)
+++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java 2010-07-13 12:06:50 UTC (rev 2777)
@@ -329,8 +329,6 @@
*/
public void stop()
{
- // TODO improve
- ResourceBinder.cleanerStop = true;
}
//
Modified: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ResourceBinder.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ResourceBinder.java 2010-07-13 11:48:53 UTC (rev 2776)
+++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ResourceBinder.java 2010-07-13 12:06:50 UTC (rev 2777)
@@ -39,6 +39,7 @@
import org.exoplatform.services.rest.resource.ResourceContainer;
import org.exoplatform.services.rest.resource.ResourceDescriptorVisitor;
import org.exoplatform.services.rest.uri.UriPattern;
+import org.picocontainer.Startable;
import java.util.ArrayList;
import java.util.Collections;
@@ -65,7 +66,7 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public class ResourceBinder
+public class ResourceBinder implements Startable
{
/**
@@ -99,7 +100,7 @@
}
};
- static boolean cleanerStop = false;
+ protected boolean cleanerStop = false;
protected class ResourceCleaner implements Runnable
{
@@ -190,6 +191,8 @@
/** Resource listeners. */
protected final List<ResourceListener> resourceListeners = new ArrayList<ResourceListener>();
+ protected final ExoContainer container;
+
public ResourceBinder(ExoContainerContext containerContext) throws Exception
{
this(containerContext, null);
@@ -203,54 +206,13 @@
*/
public ResourceBinder(ExoContainerContext containerContext, MethodInvokerFactory invokerFactory) throws Exception
{
- this(containerContext, null, invokerFactory);
- }
-
- @SuppressWarnings("unchecked")
- protected ResourceBinder(ExoContainerContext containerContext, ResourceCleaner cleaner,
- MethodInvokerFactory invokerFactory) throws Exception
- {
this.invokerFactory = invokerFactory;
-
// Initialize RuntimeDelegate instance
// This is first component in life cycle what needs.
// TODO better solution to initialize RuntimeDelegate
RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
rd = RuntimeDelegate.getInstance();
-
- ExoContainer container = containerContext.getContainer();
-
- // Lookup Applications
- List<Application> al = container.getComponentInstancesOfType(Application.class);
- for (Application a : al)
- {
- try
- {
- addApplication(a);
- }
- catch (Exception e)
- {
- LOG.error("Failed add JAX-RS application " + a.getClass().getName(), e);
- }
- }
-
- // Lookup all object which implements ResourceContainer interface and
- // process them to be add as root resources.
- for (Object resource : container.getComponentInstancesOfType(ResourceContainer.class))
- {
- try
- {
- addResource(resource, null);
- }
- catch (Exception e)
- {
- LOG.error("Failed add JAX-RS resource " + resource.getClass().getName(), e);
- }
- }
-
- Thread thread = new Thread(cleaner == null ? new ResourceCleaner(60) : cleaner);
- thread.setDaemon(true);
- thread.start();
+ container = containerContext.getContainer();
}
/**
@@ -716,4 +678,71 @@
return null != removeResource(path);
}
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ public void start()
+ {
+ // Lookup Applications
+ List<Application> al = container.getComponentInstancesOfType(Application.class);
+ for (Application a : al)
+ {
+ try
+ {
+ addApplication(a);
+ }
+ catch (Exception e)
+ {
+ LOG.error("Failed add JAX-RS application " + a.getClass().getName(), e);
+ }
+ }
+
+ // Lookup all object which implements ResourceContainer interface and
+ // process them to be add as root resources.
+ for (Object resource : container.getComponentInstancesOfType(ResourceContainer.class))
+ {
+ try
+ {
+ addResource(resource, null);
+ }
+ catch (Exception e)
+ {
+ LOG.error("Failed add JAX-RS resource " + resource.getClass().getName(), e);
+ }
+ }
+
+ startResourceCleaner();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void stop()
+ {
+ cleanerStop = true;
+ }
+
+ /**
+ * Start resource cleaner which periodically check all available resources
+ * and remove expired. Expired date may be specified by adding special
+ * property (see {@link #RESOURCE_EXPIRED}) when resource added. In example
+ * below resource will be expired in one minute. By default resources check
+ * one time per minute so live time less than one minute is not guaranteed.
+ *
+ * <pre>
+ * ResourceBinder binder = ...
+ * Class<?> resource = ...
+ * MultivaluedMap<String, String> properties = new MultivaluedMapImpl();
+ * properties.putSingle("resource.expiration.date",
+ * Long.toString(System.currentTimeMillis() + 60000L));
+ * binder.addResource(resource, properties);
+ * </pre>
+ */
+ protected void startResourceCleaner()
+ {
+ Thread thread = new Thread(new ResourceCleaner(60));
+ thread.setDaemon(true);
+ thread.start();
+ }
}
13 years, 11 months