Author: theute
Date: 2011-10-03 17:16:27 -0400 (Mon, 03 Oct 2011)
New Revision: 7626
Added:
epp/portal/branches/EPP_5_2_Branch/component/common/src/main/java/org/exoplatform/commons/serialization/MarshalledObject.java
epp/portal/branches/EPP_5_2_Branch/component/common/src/test/java/org/exoplatform/commons/utils/TestMarshalledObject.java
Modified:
epp/portal/branches/EPP_5_2_Branch/component/
epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/
epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationData.java
epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/SimpleDataCache.java
Log:
JBEPP-1248: Proper navigation for navigation cache
Property changes on: epp/portal/branches/EPP_5_2_Branch/component
___________________________________________________________________
Modified: svn:mergeinfo
- /epp/portal/branches/EPP_5_1_0_GA_JBEPP-795/component:5868
/portal/branches/branch-GTNPORTAL-1592/component:4894
/portal/branches/branch-GTNPORTAL-1643/component:5002,5063,5167
/portal/branches/branch-GTNPORTAL-1700/component:5348,5363,5402,5445
/portal/branches/branch-GTNPORTAL-1731/component:5622,5644,5668
/portal/branches/branch-GTNPORTAL-1745/component:5765
/portal/branches/branch-GTNPORTAL-1790/component:5871
/portal/branches/branch-GTNPORTAL-1822/component:5943,5952
/portal/branches/branch-GTNPORTAL-1832/component:6030,6063
/portal/branches/branch-GTNPORTAL-1872/component:6400,6551
/portal/branches/branch-GTNPORTAL-1921/component:6603,6771-6772,6774
/portal/branches/branch-GTNPORTAL-1963/component:6904,6915-6916
/portal/trunk/component:4876,4891,5269,5744,5822,5943,6031,6033,6168,6196,6201-6203,6205-6206,6223,6292,6323,6437,6440,6449,6452,6573,6783-6784,6912-6913,6960,7042,7061,7095,7117,7120,7125,7132-7134,7186,7239,7262,7308,7326,7331,7334,7359,7367,7433,7450-7452,7454,7478,7497,7500,7552,7554-7555,7598
+ /epp/portal/branches/EPP_5_1_0_GA_JBEPP-795/component:5868
/portal/branches/branch-GTNPORTAL-1592/component:4894
/portal/branches/branch-GTNPORTAL-1643/component:5002,5063,5167
/portal/branches/branch-GTNPORTAL-1700/component:5348,5363,5402,5445
/portal/branches/branch-GTNPORTAL-1731/component:5622,5644,5668
/portal/branches/branch-GTNPORTAL-1745/component:5765
/portal/branches/branch-GTNPORTAL-1790/component:5871
/portal/branches/branch-GTNPORTAL-1822/component:5943,5952
/portal/branches/branch-GTNPORTAL-1832/component:6030,6063
/portal/branches/branch-GTNPORTAL-1872/component:6400,6551
/portal/branches/branch-GTNPORTAL-1921/component:6603,6771-6772,6774
/portal/branches/branch-GTNPORTAL-1963/component:6904,6915-6916
/portal/trunk/component:4876,4891,5269,5744,5822,5943,6031,6033,6168,6196,6201-6203,6205-6206,6223,6292,6323,6437,6440,6449,6452,6573,6783-6784,6912-6913,6960,7042,7061,7095,7117,7120,7125,7132-7134,7186,7239,7262,7308,7326,7331-7334,7359,7367,7433,7450-7452,7454,7478,7497,7500,7552,7554-7555,7598
Copied:
epp/portal/branches/EPP_5_2_Branch/component/common/src/main/java/org/exoplatform/commons/serialization/MarshalledObject.java
(from rev 7332,
portal/trunk/component/common/src/main/java/org/exoplatform/commons/serialization/MarshalledObject.java)
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/component/common/src/main/java/org/exoplatform/commons/serialization/MarshalledObject.java
(rev 0)
+++
epp/portal/branches/EPP_5_2_Branch/component/common/src/main/java/org/exoplatform/commons/serialization/MarshalledObject.java 2011-10-03
21:16:27 UTC (rev 7626)
@@ -0,0 +1,102 @@
+/*
+ * 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.serialization;
+
+import org.gatein.common.io.IOTools;
+import org.gatein.common.io.UndeclaredIOException;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.util.Arrays;
+
+/**
+ * A simple marshalled object that retain the state of an object as a bytes.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ */
+public class MarshalledObject<S extends Serializable>
+{
+
+ public static <S extends Serializable> MarshalledObject<S> marshall(S
serializable) throws NullPointerException
+ {
+ if (serializable == null)
+ {
+ throw new NullPointerException("Cannot marshall null");
+ }
+ try
+ {
+ byte[] bytes = IOTools.serialize(serializable);
+ return new MarshalledObject<S>(serializable.getClass().getClassLoader(),
bytes);
+ }
+ catch (IOException e)
+ {
+ throw new UndeclaredIOException(e);
+ }
+ }
+
+ /** . */
+ private final ClassLoader loader;
+
+ /** . */
+ private final byte[] state;
+
+ private MarshalledObject(ClassLoader loader, byte[] state)
+ {
+ this.loader = loader;
+ this.state = state;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj instanceof MarshalledObject)
+ {
+ MarshalledObject<?> that = (MarshalledObject<?>)obj;
+ return Arrays.equals(state, that.state);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Arrays.hashCode(state);
+ }
+
+ public S unmarshall() throws UndeclaredThrowableException
+ {
+ try
+ {
+ return (S)IOTools.unserialize(state, loader);
+ }
+ catch (IOException e)
+ {
+ throw new UndeclaredIOException(e);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new UndeclaredThrowableException(e);
+ }
+ }
+}
Copied:
epp/portal/branches/EPP_5_2_Branch/component/common/src/test/java/org/exoplatform/commons/utils/TestMarshalledObject.java
(from rev 7332,
portal/trunk/component/common/src/test/java/org/exoplatform/commons/utils/TestMarshalledObject.java)
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/component/common/src/test/java/org/exoplatform/commons/utils/TestMarshalledObject.java
(rev 0)
+++
epp/portal/branches/EPP_5_2_Branch/component/common/src/test/java/org/exoplatform/commons/utils/TestMarshalledObject.java 2011-10-03
21:16:27 UTC (rev 7626)
@@ -0,0 +1,72 @@
+/**
+ * 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.utils;
+
+import org.exoplatform.commons.serialization.MarshalledObject;
+import org.exoplatform.component.test.AbstractGateInTest;
+
+/** @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a> */
+public class TestMarshalledObject extends AbstractGateInTest
+{
+
+ public void testSerialization()
+ {
+ String from = "foo";
+ MarshalledObject<String> marshalled = MarshalledObject.marshall(from);
+ String to = marshalled.unmarshall();
+ assertEquals(to, from);
+ }
+
+ public void testNPE()
+ {
+ try
+ {
+ MarshalledObject.marshall(null);
+ fail();
+ }
+ catch (NullPointerException e)
+ {
+ }
+ }
+
+ public void testHashCode()
+ {
+ MarshalledObject<String> marshalled1 =
MarshalledObject.marshall("foo");
+ assertEquals(marshalled1.hashCode(), marshalled1.hashCode());
+ MarshalledObject<String> marshalled2 =
MarshalledObject.marshall("foo");
+ assertEquals(marshalled1.hashCode(), marshalled2.hashCode());
+ assertEquals(marshalled2.hashCode(), marshalled1.hashCode());
+ MarshalledObject<String> marshalled3 =
MarshalledObject.marshall("bar");
+ assertNotSame(marshalled1.hashCode(), marshalled3.hashCode());
+ assertNotSame(marshalled3.hashCode(), marshalled1.hashCode());
+ }
+
+ public void testEquals()
+ {
+ MarshalledObject<String> marshalled1 =
MarshalledObject.marshall("foo");
+ assertTrue(marshalled1.equals(marshalled1));
+ MarshalledObject<String> marshalled2 =
MarshalledObject.marshall("foo");
+ assertTrue(marshalled1.equals(marshalled2));
+ assertTrue(marshalled2.equals(marshalled1));
+ MarshalledObject<String> marshalled3 =
MarshalledObject.marshall("bar");
+ assertFalse(marshalled1.equals(marshalled3));
+ assertFalse(marshalled3.equals(marshalled1));
+ }
+}
Property changes on:
epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org
___________________________________________________________________
Modified: svn:mergeinfo
- /epp/portal/branches/EPP_5_1_0_GA_JBEPP-795/component/portal/src/main/java/org:5868
/portal/branches/branch-GTNPORTAL-1592/component/portal/src/main/java/org:4894
/portal/branches/branch-GTNPORTAL-1643/component/portal/src/main/java/org:5002,5063,5167
/portal/branches/branch-GTNPORTAL-1700/component/portal/src/main/java/org:5348,5363,5402,5445
/portal/branches/branch-GTNPORTAL-1731/component/portal/src/main/java/org:5622,5644,5668
/portal/branches/branch-GTNPORTAL-1745/component/portal/src/main/java/org:5765
/portal/branches/branch-GTNPORTAL-1790/component/portal/src/main/java/org:5871
/portal/branches/branch-GTNPORTAL-1822/component/portal/src/main/java/org:5943,5952
/portal/branches/branch-GTNPORTAL-1832/component/portal/src/main/java/org:6030,6063
/portal/branches/branch-GTNPORTAL-1872/component/portal/src/main/java/org:6400,6551
/portal/branches/branch-GTNPORTAL-1921/component/portal/src/main/java/org:6603,6771-6772,6774
/portal/branches/branch-GTNPORTAL-1963/component/portal/src/main/java/org:6904,6915-6916
/portal/trunk/component/portal/src/main/java/org:4876,4891,5269,5744,5822,5943,6031,6033,6168,6196,6201-6203,6205-6206,6223,6292,6323,6437,6440,6449,6452,6573,6741,6783-6784,6912-6913,6960,7042,7061,7095,7117,7120,7125,7132-7134,7186,7198,7239,7262,7308,7326,7331,7334,7359,7367,7433,7452,7454,7478,7497,7552,7554-7555,7598
+ /epp/portal/branches/EPP_5_1_0_GA_JBEPP-795/component/portal/src/main/java/org:5868
/portal/branches/branch-GTNPORTAL-1592/component/portal/src/main/java/org:4894
/portal/branches/branch-GTNPORTAL-1643/component/portal/src/main/java/org:5002,5063,5167
/portal/branches/branch-GTNPORTAL-1700/component/portal/src/main/java/org:5348,5363,5402,5445
/portal/branches/branch-GTNPORTAL-1731/component/portal/src/main/java/org:5622,5644,5668
/portal/branches/branch-GTNPORTAL-1745/component/portal/src/main/java/org:5765
/portal/branches/branch-GTNPORTAL-1790/component/portal/src/main/java/org:5871
/portal/branches/branch-GTNPORTAL-1822/component/portal/src/main/java/org:5943,5952
/portal/branches/branch-GTNPORTAL-1832/component/portal/src/main/java/org:6030,6063
/portal/branches/branch-GTNPORTAL-1872/component/portal/src/main/java/org:6400,6551
/portal/branches/branch-GTNPORTAL-1921/component/portal/src/main/java/org:6603,6771-6772,6774
/portal/branches/branch-GTNPORTAL-1963/component/portal/src/main/java/org:6904,6915-6916
/portal/trunk/component/portal/src/main/java/org:4876,4891,5269,5744,5822,5943,6031,6033,6168,6196,6201-6203,6205-6206,6223,6292,6323,6437,6440,6449,6452,6573,6741,6783-6784,6912-6913,6960,7042,7061,7095,7117,7120,7125,7132-7134,7186,7198,7239,7262,7308,7326,7331-7334,7359,7367,7433,7452,7454,7478,7497,7552,7554-7555,7598
Modified:
epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationData.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationData.java 2011-10-03
21:14:16 UTC (rev 7625)
+++
epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationData.java 2011-10-03
21:16:27 UTC (rev 7626)
@@ -69,4 +69,16 @@
this.state = state;
this.rootId = rootId;
}
+
+ protected Object readResolve()
+ {
+ if (key == null && state == null && rootId == null)
+ {
+ return EMPTY;
+ }
+ else
+ {
+ return this;
+ }
+ }
}
Modified:
epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/SimpleDataCache.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/SimpleDataCache.java 2011-10-03
21:14:16 UTC (rev 7625)
+++
epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/SimpleDataCache.java 2011-10-03
21:16:27 UTC (rev 7626)
@@ -19,6 +19,7 @@
package org.exoplatform.portal.mop.navigation;
+import org.exoplatform.commons.serialization.MarshalledObject;
import org.exoplatform.portal.mop.SiteKey;
import org.exoplatform.portal.pom.config.POMSession;
@@ -35,57 +36,78 @@
{
/** . */
- protected Map<SiteKey, NavigationData> navigations;
+ protected Map<MarshalledObject<SiteKey>,
MarshalledObject<NavigationData>> navigations;
/** . */
- protected Map<String, NodeData> nodes;
+ protected Map<MarshalledObject<String>, MarshalledObject<NodeData>>
nodes;
public SimpleDataCache()
{
- this.navigations = new ConcurrentHashMap<SiteKey, NavigationData>();
- this.nodes = new ConcurrentHashMap<String, NodeData>();
+ this.navigations = new ConcurrentHashMap<MarshalledObject<SiteKey>,
MarshalledObject<NavigationData>>();
+ this.nodes = new ConcurrentHashMap<MarshalledObject<String>,
MarshalledObject<NodeData>>();
}
@Override
protected void removeNodes(Collection<String> keys)
{
- nodes.keySet().removeAll(keys);
+ for (String key : keys)
+ {
+ nodes.remove(MarshalledObject.marshall(key));
+ }
}
@Override
protected NodeData getNode(POMSession session, String key)
{
- NodeData node = nodes.get(key);
- if (node == null)
+ MarshalledObject<String> marshalledKey = MarshalledObject.marshall(key);
+ MarshalledObject<NodeData> marshalledNode = nodes.get(marshalledKey);
+ if (marshalledNode == null)
{
- node = loadNode(session, key);
+ NodeData node = loadNode(session, key);
if (node != null)
{
- nodes.put(key, node);
+ nodes.put(marshalledKey, MarshalledObject.marshall(node));
+ return node;
}
+ else
+ {
+ return null;
+ }
}
- return node;
+ else
+ {
+ return marshalledNode.unmarshall();
+ }
}
@Override
protected void removeNavigation(SiteKey key)
{
- navigations.remove(key);
+ navigations.remove(MarshalledObject.marshall(key));
}
@Override
protected NavigationData getNavigation(POMSession session, SiteKey key)
{
- NavigationData navigation = navigations.get(key);
- if (navigation == null)
+ MarshalledObject<SiteKey> marshalledKey = MarshalledObject.marshall(key);
+ MarshalledObject<NavigationData> marshalledNavigation =
navigations.get(marshalledKey);
+ if (marshalledNavigation == null)
{
- navigation = loadNavigation(session, key);
+ NavigationData navigation = loadNavigation(session, key);
if (navigation != null)
{
- navigations.put(key, navigation);
+ navigations.put(marshalledKey, MarshalledObject.marshall(navigation));
+ return navigation;
}
+ else
+ {
+ return null;
+ }
}
- return navigations.get(key);
+ else
+ {
+ return marshalledNavigation.unmarshall();
+ }
}
@Override