Author: julien_viet
Date: 2011-08-23 06:00:39 -0400 (Tue, 23 Aug 2011)
New Revision: 7198
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/commons/scope/
portal/trunk/component/common/src/main/java/org/exoplatform/commons/scope/AbstractScopedKey.java
portal/trunk/component/common/src/main/java/org/exoplatform/commons/scope/ScopeManager.java
portal/trunk/component/common/src/main/java/org/exoplatform/commons/scope/ScopedKey.java
portal/trunk/component/common/src/test/java/org/exoplatform/commons/scope/
portal/trunk/component/common/src/test/java/org/exoplatform/commons/scope/ScopeTestCase.java
portal/trunk/component/common/src/test/resources/org/
portal/trunk/component/common/src/test/resources/org/exoplatform/
portal/trunk/component/common/src/test/resources/org/exoplatform/commons/
portal/trunk/component/common/src/test/resources/org/exoplatform/commons/chromattic/
portal/trunk/component/common/src/test/resources/org/exoplatform/commons/chromattic/configuration.xml
portal/trunk/component/common/src/test/resources/org/exoplatform/commons/scope/
portal/trunk/component/common/src/test/resources/org/exoplatform/commons/scope/configuration.xml
Removed:
portal/trunk/component/common/src/test/resources/conf/
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/GlobalKey.java
Modified:
portal/trunk/component/common/src/test/java/org/exoplatform/commons/chromattic/ChromatticIntegrationTestCase.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/description/CacheKey.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/description/DescriptionServiceImpl.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/description/ExoDataCache.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/ExoDataCache.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSessionManager.java
portal/trunk/component/portal/src/test/resources/conf/exo.portal.component.portal-configuration.xml
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/common/common-configuration.xml
Log:
GTNPORTAL-2042 : ScopeManager to take care of repository scoping life cycle
GTNPORTAL-2043 : DescriptionService cache not properly configured
GTNPORTAL-2044 : NavigationService and DescriptionService scope aware
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/commons/scope/AbstractScopedKey.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/commons/scope/AbstractScopedKey.java
(rev 0)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/commons/scope/AbstractScopedKey.java 2011-08-23
10:00:39 UTC (rev 7198)
@@ -0,0 +1,100 @@
+/*
+ * 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.
+ */
+
+package org.exoplatform.commons.scope;
+
+import java.io.Serializable;
+
+/**
+ * The abstract scoped key should be subclasses to create scoped key.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public abstract class AbstractScopedKey implements Serializable
+{
+
+ /** . */
+ private final String scope;
+
+ protected AbstractScopedKey()
+ {
+ String scope = ScopeManager.getCurrentScope();
+ if (scope == null)
+ {
+ scope = "";
+ }
+
+ //
+ this.scope = scope;
+ }
+
+ protected AbstractScopedKey(String scope) throws NullPointerException
+ {
+ if (scope == null)
+ {
+ throw new NullPointerException();
+ }
+
+ //
+ this.scope = scope;
+ }
+
+ public final String getScope()
+ {
+ return scope;
+ }
+
+ /**
+ * Returns the scope value hashCode.
+ *
+ * @return the hash code
+ */
+ @Override
+ public int hashCode()
+ {
+ return scope.hashCode();
+ }
+
+ /**
+ * Returns true when:
+ * <ul>
+ * <li>the obj argument has the same reference than this object</li>
+ * <li>or the obj has class equality
(<code>getClass().equals(obj.getClass())</code>) and scope
equality</li>
+ * </ul>
+ *
+ * Subclasses should override this method and call the super method to ensure that the
objects are of the same
+ * class and have the same scope. When this method returns true, the obj argument can
be safely casted to
+ * the same sub class for performing more state equality checks.
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj instanceof AbstractScopedKey)
+ {
+ AbstractScopedKey that = (AbstractScopedKey)obj;
+ return getClass().equals(that.getClass()) && scope.equals(that.scope);
+ }
+ return false;
+ }
+}
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/commons/scope/ScopeManager.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/commons/scope/ScopeManager.java
(rev 0)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/commons/scope/ScopeManager.java 2011-08-23
10:00:39 UTC (rev 7198)
@@ -0,0 +1,107 @@
+/**
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.commons.scope;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.component.ComponentRequestLifecycle;
+import org.exoplatform.services.jcr.RepositoryService;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * <p></p>The scope manager manages the life cycle of a scope value (which
means a mere string) associated with the current
+ * thread aimed to scope state. The scope manager takes it values from the current
repository service name when
+ * it is associated with a request on a container containing the repository
service.</p>
+ *
+ * <p>The manager implements the {@link ComponentRequestLifecycle}</p>
interface to be aware of the request life cycle.</p>
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ */
+public class ScopeManager implements ComponentRequestLifecycle
+{
+
+ /** The scope thread local. */
+ private static final ThreadLocal<String> currentScope = new
ThreadLocal<String>();
+
+ /** . */
+ private static final Logger log = LoggerFactory.getLogger(ScopeManager.class);
+
+ /**
+ * Returns the current scope value or null if no value is associated with the current
thread.
+ *
+ * @return the current scope
+ */
+ public static String getCurrentScope()
+ {
+ return currentScope.get();
+ }
+
+ public void startRequest(ExoContainer container)
+ {
+ if (currentScope.get() != null)
+ {
+ throw new IllegalStateException("Detected scope reentrancy " +
currentScope.get());
+ }
+
+ //
+ RepositoryService repositoryService =
(RepositoryService)container.getComponentInstanceOfType(RepositoryService.class);
+
+ //
+ String scope = null;
+ if (repositoryService != null)
+ {
+ try
+ {
+ ManageableRepository currentRepository =
repositoryService.getCurrentRepository();
+ if (currentRepository != null)
+ {
+ scope = currentRepository.getConfiguration().getName();
+ }
+ }
+ catch (RepositoryException e)
+ {
+ log.error("Could not obtain scope value from repository", e);
+ }
+ }
+
+ //
+ if (scope == null)
+ {
+ scope = "";
+ }
+
+ //
+ currentScope.set(scope);
+ log.debug("Starting scope request \"" + scope +
"\"");
+ }
+
+ public void endRequest(ExoContainer container)
+ {
+ if (currentScope.get() == null)
+ {
+ throw new IllegalStateException("Detected unscoped unscoping ");
+ }
+
+ //
+ currentScope.set(null);
+ }
+}
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/commons/scope/ScopedKey.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/commons/scope/ScopedKey.java
(rev 0)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/commons/scope/ScopedKey.java 2011-08-23
10:00:39 UTC (rev 7198)
@@ -0,0 +1,110 @@
+/*
+ * 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.
+ */
+
+package org.exoplatform.commons.scope;
+
+import java.io.Serializable;
+
+/**
+ * A scoped key wrapping a key including the a scope. The scoped key implements the
{@link #hashCode()} and
+ * {@link #equals(Object)} method based on the scope and the current value.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class ScopedKey<S extends Serializable> extends AbstractScopedKey
+{
+
+ /**
+ * Create a scoped key from a key, the scope value is obtained from the {@link
ScopeManager#getCurrentScope()} method.
+ *
+ * @param key the local key
+ * @param <S> the key generic serializable type
+ * @return the scoped key
+ * @throws NullPointerException if the key argument is null
+ */
+ public static <S extends Serializable> ScopedKey<S> create(S key) throws
NullPointerException
+ {
+ return new ScopedKey<S>(key);
+ }
+
+ /**
+ * Creates a new scoped key with an explicit scope value.
+ *
+ * @param scope the scope value
+ * @param key the key
+ * @param <S> the key generic serializable type
+ * @return the scoped key
+ * @throws NullPointerException if any argument is null
+ */
+ public static <S extends Serializable> ScopedKey<S> create(String scope, S
key) throws NullPointerException
+ {
+ return new ScopedKey<S>(scope, key);
+ }
+
+ /** . */
+ private final S key;
+
+ public ScopedKey(S key) throws NullPointerException
+ {
+ if (key == null)
+ {
+ throw new NullPointerException();
+ }
+
+ //
+ this.key = key;
+ }
+
+ public ScopedKey(String scope, S key) throws NullPointerException
+ {
+ super(scope);
+
+ if (key == null)
+ {
+ throw new NullPointerException();
+ }
+
+ //
+ this.key = key;
+ }
+
+ public S getKey()
+ {
+ return key;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return super.hashCode() ^ key.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return super.equals(obj) && ((ScopedKey)obj).key.equals(key);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ScopedKey[scope=" + getScope() + ",key=" + key +
"]";
+ }
+}
Modified:
portal/trunk/component/common/src/test/java/org/exoplatform/commons/chromattic/ChromatticIntegrationTestCase.java
===================================================================
---
portal/trunk/component/common/src/test/java/org/exoplatform/commons/chromattic/ChromatticIntegrationTestCase.java 2011-08-23
05:28:05 UTC (rev 7197)
+++
portal/trunk/component/common/src/test/java/org/exoplatform/commons/chromattic/ChromatticIntegrationTestCase.java 2011-08-23
10:00:39 UTC (rev 7198)
@@ -32,7 +32,7 @@
*/
@ConfiguredBy({
@ConfigurationUnit(scope = ContainerScope.PORTAL, path =
"conf/exo.portal.component.test.jcr-configuration.xml"),
- @ConfigurationUnit(scope = ContainerScope.PORTAL, path =
"conf/exo.portal.component.common-configuration.xml")
+ @ConfigurationUnit(scope = ContainerScope.PORTAL, path =
"org/exoplatform/commons/chromattic/configuration.xml")
})
public class ChromatticIntegrationTestCase extends AbstractKernelTest
{
Added:
portal/trunk/component/common/src/test/java/org/exoplatform/commons/scope/ScopeTestCase.java
===================================================================
---
portal/trunk/component/common/src/test/java/org/exoplatform/commons/scope/ScopeTestCase.java
(rev 0)
+++
portal/trunk/component/common/src/test/java/org/exoplatform/commons/scope/ScopeTestCase.java 2011-08-23
10:00:39 UTC (rev 7198)
@@ -0,0 +1,78 @@
+package org.exoplatform.commons.scope;
+
+import org.exoplatform.component.test.AbstractKernelTest;
+import org.exoplatform.component.test.ConfigurationUnit;
+import org.exoplatform.component.test.ConfiguredBy;
+import org.exoplatform.component.test.ContainerScope;
+
+/** @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a> */
+@ConfiguredBy({
+ @ConfigurationUnit(scope = ContainerScope.PORTAL, path =
"conf/exo.portal.component.test.jcr-configuration.xml"),
+ @ConfigurationUnit(scope = ContainerScope.PORTAL, path =
"org/exoplatform/commons/scope/configuration.xml")
+})
+public class ScopeTestCase extends AbstractKernelTest
+{
+
+ public void testKey()
+ {
+ ScopedKey<String> k1 = ScopedKey.create("foo", "bar");
+ assertEquals("foo", k1.getScope());
+ assertEquals("bar", k1.getKey());
+
+ //
+ ScopedKey<String> k2 = ScopedKey.create("foo", "bar");
+ assertEquals("foo", k1.getScope());
+ assertEquals("bar", k1.getKey());
+
+ //
+ ScopedKey<String> k3 = ScopedKey.create("juu", "bar");
+ assertEquals("juu", k3.getScope());
+ assertEquals("bar", k3.getKey());
+
+ //
+ ScopedKey<String> k4 = ScopedKey.create("juu", "daa");
+ assertEquals("juu", k4.getScope());
+ assertEquals("daa", k4.getKey());
+
+ //
+ assertTrue(k1.equals(k2));
+ assertTrue(k2.equals(k1));
+ assertEquals(k1.hashCode(), k2.hashCode());
+ assertFalse(k1.equals(k3));
+ assertFalse(k3.equals(k1));
+ assertFalse(k3.equals(k4));
+ assertFalse(k4.equals(k3));
+ }
+
+ public void testLifeCycle()
+ {
+ assertNull(ScopeManager.getCurrentScope());
+ ScopedKey<String> key = ScopedKey.create("foo");
+ assertEquals("", key.getScope());
+ assertEquals("foo", key.getKey());
+
+ //
+ assertNull(ScopeManager.getCurrentScope());
+ key = ScopedKey.create("foo");
+ assertEquals("", key.getScope());
+ assertEquals("foo", key.getKey());
+
+ //
+ begin();
+
+ //
+ assertEquals("repository", ScopeManager.getCurrentScope());
+ key = ScopedKey.create("foo");
+ assertEquals("repository", key.getScope());
+ assertEquals("foo", key.getKey());
+
+ //
+ end();
+
+ //
+ assertNull(ScopeManager.getCurrentScope());
+ key = ScopedKey.create("foo");
+ assertEquals("", key.getScope());
+ assertEquals("foo", key.getKey());
+ }
+}
Added:
portal/trunk/component/common/src/test/resources/org/exoplatform/commons/chromattic/configuration.xml
===================================================================
---
portal/trunk/component/common/src/test/resources/org/exoplatform/commons/chromattic/configuration.xml
(rev 0)
+++
portal/trunk/component/common/src/test/resources/org/exoplatform/commons/chromattic/configuration.xml 2011-08-23
10:00:39 UTC (rev 7198)
@@ -0,0 +1,72 @@
+<?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.commons.chromattic.ChromatticManager</key>
+ <type>org.exoplatform.commons.chromattic.ChromatticManager</type>
+ </component>
+
+ <external-component-plugins>
+
<target-component>org.exoplatform.commons.chromattic.ChromatticManager</target-component>
+ <component-plugin>
+ <name>chromattic</name>
+ <set-method>addLifeCycle</set-method>
+ <type>org.exoplatform.commons.chromattic.ChromatticLifeCycle</type>
+ <init-params>
+ <value-param>
+ <name>domain-name</name>
+ <value>test1</value>
+ </value-param>
+ <value-param>
+ <name>workspace-name</name>
+ <value>portal-test</value>
+ </value-param>
+ <values-param>
+ <name>entities</name>
+ <value>org.exoplatform.commons.chromattic.FooEntity</value>
+ </values-param>
+ </init-params>
+ </component-plugin>
+ <component-plugin>
+ <name>chromattic</name>
+ <set-method>addLifeCycle</set-method>
+ <type>org.exoplatform.commons.chromattic.ChromatticLifeCycle</type>
+ <init-params>
+ <value-param>
+ <name>domain-name</name>
+ <value>test2</value>
+ </value-param>
+ <value-param>
+ <name>workspace-name</name>
+ <value>portal-test</value>
+ </value-param>
+ <values-param>
+ <name>entities</name>
+ </values-param>
+ </init-params>
+ </component-plugin>
+ </external-component-plugins>
+
+</configuration>
Added:
portal/trunk/component/common/src/test/resources/org/exoplatform/commons/scope/configuration.xml
===================================================================
---
portal/trunk/component/common/src/test/resources/org/exoplatform/commons/scope/configuration.xml
(rev 0)
+++
portal/trunk/component/common/src/test/resources/org/exoplatform/commons/scope/configuration.xml 2011-08-23
10:00:39 UTC (rev 7198)
@@ -0,0 +1,30 @@
+<?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.commons.scope.ScopeManager</key>
+ <type>org.exoplatform.commons.scope.ScopeManager</type>
+ </component>
+</configuration>
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/description/CacheKey.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/description/CacheKey.java 2011-08-23
05:28:05 UTC (rev 7197)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/description/CacheKey.java 2011-08-23
10:00:39 UTC (rev 7198)
@@ -19,13 +19,15 @@
package org.exoplatform.portal.mop.description;
+import org.exoplatform.commons.scope.AbstractScopedKey;
+
import java.io.Serializable;
import java.util.Locale;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
*/
-public final class CacheKey implements Serializable
+public final class CacheKey extends AbstractScopedKey implements Serializable
{
/** . */
@@ -53,12 +55,8 @@
@Override
public boolean equals(Object obj)
{
- if (obj == this)
+ if (super.equals(obj))
{
- return true;
- }
- if (obj instanceof CacheKey)
- {
CacheKey that = (CacheKey)obj;
return locale.equals(that.locale) && id.equals(that.id);
}
@@ -68,6 +66,6 @@
@Override
public int hashCode()
{
- return locale.hashCode() ^ id.hashCode();
+ return super.hashCode() ^ locale.hashCode() ^ id.hashCode();
}
}
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/description/DescriptionServiceImpl.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/description/DescriptionServiceImpl.java 2011-08-23
05:28:05 UTC (rev 7197)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/description/DescriptionServiceImpl.java 2011-08-23
10:00:39 UTC (rev 7198)
@@ -23,6 +23,7 @@
import org.exoplatform.portal.mop.i18n.I18NAdapter;
import org.exoplatform.portal.pom.config.POMSession;
import org.exoplatform.portal.pom.config.POMSessionManager;
+import org.exoplatform.services.cache.CacheService;
import org.gatein.mop.api.workspace.WorkspaceObject;
import java.util.Collection;
@@ -53,6 +54,11 @@
this.cache = cache;
}
+ public DescriptionServiceImpl(POMSessionManager manager, CacheService cacheService)
+ {
+ this(manager, new ExoDataCache(cacheService));
+ }
+
public Described.State resolveDescription(String id, Locale locale) throws
NullPointerException
{
return resolveDescription(id, null, locale);
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/description/ExoDataCache.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/description/ExoDataCache.java 2011-08-23
05:28:05 UTC (rev 7197)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/description/ExoDataCache.java 2011-08-23
10:00:39 UTC (rev 7198)
@@ -49,7 +49,7 @@
public ExoDataCache(CacheService cacheService)
{
- this.cache = cacheService.getCacheInstance("NavigationService");
+ this.cache =
cacheService.getCacheInstance(DescriptionService.class.getSimpleName());
this.values = new FutureExoCache<CacheKey, CacheValue,
POMSession>(valueLoader, cache)
{
@Override
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/ExoDataCache.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/ExoDataCache.java 2011-08-23
05:28:05 UTC (rev 7197)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/ExoDataCache.java 2011-08-23
10:00:39 UTC (rev 7198)
@@ -21,6 +21,7 @@
import org.exoplatform.commons.cache.future.FutureExoCache;
import org.exoplatform.commons.cache.future.Loader;
+import org.exoplatform.commons.scope.ScopedKey;
import org.exoplatform.portal.mop.SiteKey;
import org.exoplatform.portal.pom.config.POMSession;
import org.exoplatform.services.cache.CacheService;
@@ -38,16 +39,17 @@
{
/** . */
- protected ExoCache<Serializable, Serializable> cache;
+ protected ExoCache<ScopedKey<?>, Serializable> cache;
/** . */
- protected FutureExoCache<Serializable, Serializable, POMSession> objects;
+ protected FutureExoCache<ScopedKey<?>, Serializable, POMSession> objects;
/** . */
- private Loader<Serializable, Serializable, POMSession> navigationLoader = new
Loader<Serializable, Serializable, POMSession>()
+ private Loader<ScopedKey<?>, Serializable, POMSession> navigationLoader =
new Loader<ScopedKey<?>, Serializable, POMSession>()
{
- public Serializable retrieve(POMSession session, Serializable key) throws
Exception
+ public Serializable retrieve(POMSession session, ScopedKey<?> scopedKey)
throws Exception
{
+ Object key = scopedKey.getKey();
if (key instanceof SiteKey)
{
return loadNavigation(session, (SiteKey)key);
@@ -61,8 +63,8 @@
public ExoDataCache(CacheService cacheService)
{
- this.cache = cacheService.getCacheInstance("NavigationService");
- this.objects = new FutureExoCache<Serializable, Serializable,
POMSession>(navigationLoader, cache);
+ this.cache =
cacheService.getCacheInstance(NavigationService.class.getSimpleName());
+ this.objects = new FutureExoCache<ScopedKey<?>, Serializable,
POMSession>(navigationLoader, cache);
}
@Override
@@ -70,26 +72,26 @@
{
for (String key : keys)
{
- cache.remove(key);
+ cache.remove(ScopedKey.create(key));
}
}
@Override
protected NodeData getNode(POMSession session, String key)
{
- return (NodeData)objects.get(session, key);
+ return (NodeData)objects.get(session, ScopedKey.create(key));
}
@Override
protected void removeNavigation(SiteKey key)
{
- cache.remove(key);
+ cache.remove(ScopedKey.create(key));
}
@Override
protected NavigationData getNavigation(POMSession session, SiteKey key)
{
- return (NavigationData)objects.get(session, key);
+ return (NavigationData)objects.get(session, ScopedKey.create(key));
}
@Override
Deleted:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/GlobalKey.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/GlobalKey.java 2011-08-23
05:28:05 UTC (rev 7197)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/GlobalKey.java 2011-08-23
10:00:39 UTC (rev 7198)
@@ -1,94 +0,0 @@
-/*
- * 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.
- */
-
-package org.exoplatform.portal.pom.config;
-
-import java.io.Serializable;
-
-/**
- * A global key wrapping a local key including the current repository id.
- *
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
- * @version $Revision$
- */
-public class GlobalKey implements Serializable
-{
-
- public static GlobalKey wrap(String repositoryName, Serializable localKey)
- {
- return new GlobalKey(repositoryName, localKey);
- }
-
- /** . */
- private final String repositoryId;
-
- /** . */
- private final Serializable localKey;
-
- public GlobalKey(String repositoryId, Serializable localKey)
- {
- if (repositoryId == null)
- {
- throw new NullPointerException();
- }
- if (localKey == null)
- {
- throw new NullPointerException();
- }
- this.repositoryId = repositoryId;
- this.localKey = localKey;
- }
-
- public String getRepositoryId()
- {
- return repositoryId;
- }
-
- public Serializable getLocalKey()
- {
- return localKey;
- }
-
- @Override
- public int hashCode()
- {
- return repositoryId.hashCode() ^ localKey.hashCode();
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj == this)
- {
- return true;
- }
- if (obj instanceof GlobalKey)
- {
- GlobalKey that = (GlobalKey)obj;
- return repositoryId.equals(that.repositoryId) &&
localKey.equals(that.localKey);
- }
- return false;
- }
-
- @Override
- public String toString()
- {
- return "GlobalKey[repositoryId=" + repositoryId + ",localKey="
+ localKey + "]";
- }
-}
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSessionManager.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSessionManager.java 2011-08-23
05:28:05 UTC (rev 7197)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSessionManager.java 2011-08-23
10:00:39 UTC (rev 7198)
@@ -22,6 +22,7 @@
import org.exoplatform.commons.chromattic.ChromatticLifeCycle;
import org.exoplatform.commons.chromattic.ChromatticManager;
import org.exoplatform.commons.chromattic.SessionContext;
+import org.exoplatform.commons.scope.ScopedKey;
import org.exoplatform.portal.pom.config.cache.DataCache;
import org.exoplatform.portal.pom.config.cache.PortalNamesCache;
import org.exoplatform.portal.pom.data.OwnerKey;
@@ -53,7 +54,7 @@
private MOPService pomService;
/** . */
- private final ExoCache<GlobalKey, Object> cache;
+ private final ExoCache<ScopedKey<?>, Object> cache;
/** . */
final ChromatticManager manager;
@@ -84,7 +85,7 @@
public void cachePut(Serializable key, Object value)
{
- GlobalKey globalKey = GlobalKey.wrap(configurator.getRepositoryName(), key);
+ ScopedKey<?> globalKey = ScopedKey.create(key);
//
if (log.isTraceEnabled())
@@ -98,7 +99,7 @@
public Object cacheGet(Serializable key)
{
- GlobalKey globalKey = GlobalKey.wrap(configurator.getRepositoryName(), key);
+ ScopedKey globalKey = ScopedKey.create(key);
//
Object value = cache.get(globalKey);
@@ -115,7 +116,7 @@
public void cacheRemove(Serializable key)
{
- final GlobalKey globalKey = GlobalKey.wrap(configurator.getRepositoryName(), key);
+ final ScopedKey<?> globalKey = ScopedKey.create(key);
//
if (log.isTraceEnabled())
@@ -132,13 +133,13 @@
final PortalKey portalKey = (PortalKey)key;
try
{
- cache.select(new CachedObjectSelector<GlobalKey, Object>()
+ cache.select(new CachedObjectSelector<ScopedKey<?>, Object>()
{
- public boolean select(GlobalKey selectedGlobalKey,
ObjectCacheInfo<?> ocinfo)
+ public boolean select(ScopedKey<?> selectedGlobalKey,
ObjectCacheInfo<?> ocinfo)
{
- if
(globalKey.getRepositoryId().equals(selectedGlobalKey.getRepositoryId()))
+ if (globalKey.getScope().equals(selectedGlobalKey.getScope()))
{
- Serializable selectedLocalKey = selectedGlobalKey.getLocalKey();
+ Serializable selectedLocalKey = selectedGlobalKey.getKey();
if (selectedLocalKey instanceof OwnerKey)
{
OwnerKey selectedOwnerKey = (OwnerKey)selectedLocalKey;
@@ -150,7 +151,8 @@
}
return false;
}
- public void onSelect(ExoCache<? extends GlobalKey, ?> exoCache,
GlobalKey key, ObjectCacheInfo<?> ocinfo) throws Exception
+
+ public void onSelect(ExoCache<? extends ScopedKey<?>, ?>
exoCache, ScopedKey<?> key, ObjectCacheInfo<?> ocinfo) throws Exception
{
cache.remove(key);
}
Modified:
portal/trunk/component/portal/src/test/resources/conf/exo.portal.component.portal-configuration.xml
===================================================================
---
portal/trunk/component/portal/src/test/resources/conf/exo.portal.component.portal-configuration.xml 2011-08-23
05:28:05 UTC (rev 7197)
+++
portal/trunk/component/portal/src/test/resources/conf/exo.portal.component.portal-configuration.xml 2011-08-23
10:00:39 UTC (rev 7198)
@@ -25,6 +25,11 @@
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
<component>
+ <key>org.exoplatform.commons.scope.ScopeManager</key>
+ <type>org.exoplatform.commons.scope.ScopeManager</type>
+ </component>
+
+ <component>
<key>org.exoplatform.services.cache.CacheService</key>
<jmx-name>cache:type=CacheService</jmx-name>
<type>org.exoplatform.services.cache.impl.CacheServiceImpl</type>
Modified:
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/common/common-configuration.xml
===================================================================
---
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/common/common-configuration.xml 2011-08-23
05:28:05 UTC (rev 7197)
+++
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/common/common-configuration.xml 2011-08-23
10:00:39 UTC (rev 7198)
@@ -103,6 +103,11 @@
</component>
<component>
+ <key>org.exoplatform.commons.scope.ScopeManager</key>
+ <type>org.exoplatform.commons.scope.ScopeManager</type>
+ </component>
+
+ <component>
<key>org.exoplatform.services.cache.CacheService</key>
<jmx-name>cache:type=CacheService</jmx-name>
<type>org.exoplatform.services.cache.impl.CacheServiceImpl</type>