Author: chris.laprun(a)jboss.com
Date: 2009-02-01 10:16:39 -0500 (Sun, 01 Feb 2009)
New Revision: 12762
Modified:
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectTestCase.java
Log:
- JBPORTAL-2281: Ported performance improvements to 2.6 branch
Modified:
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2009-02-01
03:56:00 UTC (rev 12761)
+++
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2009-02-01
15:16:39 UTC (rev 12762)
@@ -1,6 +1,6 @@
/******************************************************************************
* JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * Copyright 2009, Red Hat Middleware, LLC, and individual *
* contributors as indicated by the @authors tag. See the *
* copyright.txt in the distribution for a full listing of *
* individual contributors. *
@@ -20,8 +20,17 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
* 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
******************************************************************************/
+
package org.jboss.portal.core.impl.model.portal;
+import org.apache.log4j.Logger;
+import org.jboss.portal.common.NotYetImplemented;
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portal.core.model.portal.DuplicatePortalObjectException;
+import org.jboss.portal.core.model.portal.NoSuchPortalObjectException;
+import org.jboss.portal.core.model.portal.PortalObject;
+import org.jboss.portal.core.model.portal.PortalObjectId;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -31,18 +40,11 @@
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
+import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
-import org.apache.log4j.Logger;
-import org.jboss.portal.common.NotYetImplemented;
-import org.jboss.portal.common.i18n.LocalizedString;
-import org.jboss.portal.core.model.portal.DuplicatePortalObjectException;
-import org.jboss.portal.core.model.portal.NoSuchPortalObjectException;
-import org.jboss.portal.core.model.portal.PortalObject;
-import org.jboss.portal.core.model.portal.PortalObjectId;
-
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision$
@@ -74,8 +76,6 @@
private ObjectNode objectNode;
// Runtime fields
-
- private Map childrenMap;
private Map properties;
private Map unmodifiableProperties;
private SortedSet accessedChildren;
@@ -91,7 +91,6 @@
this.listener = null;
//
- this.childrenMap = null;
this.properties = null;
this.unmodifiableProperties = null;
this.accessedChildren = null;
@@ -117,8 +116,6 @@
this.objectNode = objectNode;
}
- //
-
public PortalObjectId getId()
{
return objectNode.getPath();
@@ -140,13 +137,12 @@
{
return objectNode.getName();
}
-
+
public void setDisplayNames(Map displayNames)
{
this.displayNames = displayNames;
}
-
-
+
public Map getDisplayNames()
{
return displayNames;
@@ -160,7 +156,7 @@
}
displayNames = new HashMap();
-
+
Map map = displayName.getValues();
Iterator it = map.values().iterator();
while (it.hasNext())
@@ -169,7 +165,7 @@
displayNames.put(value.getLocale(), value.getString());
}
}
-
+
public LocalizedString getDisplayName()
{
if (displayNames != null)
@@ -202,13 +198,14 @@
private class ChildrenCollection implements Collection
{
-
/** . */
private final int mask;
+ private final SortedMap children;
- public ChildrenCollection(int mask)
+ public ChildrenCollection(int mask, Map children)
{
this.mask = mask;
+ this.children = new TreeMap(children);
}
public void clear()
@@ -253,30 +250,36 @@
public boolean isEmpty()
{
- return objectNode.getChildren().isEmpty();
+ return children.isEmpty();
}
public int size()
{
- if (mask == ALL_TYPES_MASK)
+ if (mask != ALL_TYPES_MASK)
{
- return objectNode.getChildren().size();
- }
- else
- {
int count = 0;
- for (Iterator i = iterator(); i.hasNext();)
+
+ for (Object object : children.values())
{
- i.next();
- count++;
+ ObjectNode childNode = (ObjectNode)object;
+ PortalObjectImpl childObject = childNode.getObject();
+ if (isMatchingMask(childObject, mask))
+ {
+ count++;
+ }
}
+
return count;
}
+ else
+ {
+ return children.size();
+ }
}
public Object[] toArray()
{
- return toArray(new Object[0]);
+ return toArray(new Object[size()]);
}
public Iterator iterator()
@@ -286,40 +289,39 @@
public Object[] toArray(Object a[])
{
- ArrayList tmp = new ArrayList(objectNode.getChildren().size());
-
- //
- Set accessedChildren = getAccessedChildren();
-
- //
- for (Iterator i = iterator(); i.hasNext();)
+ ArrayList tmp = new ArrayList(children.size());
+ for (Object child : this)
{
- PortalObject childObject = (PortalObject)i.next();
+ // no need to add to accessedChildren here as it's already done by
ChildrenIterator.next()...
+ tmp.add(child);
+ }
- //
- accessedChildren.add(childObject);
+ return tmp.toArray(a);
+ }
- //
- tmp.add(childObject);
+ @Override
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder(512);
+ sb.append("[");
+ for (Object o : this)
+ {
+ sb.append(" ").append(o);
}
- return tmp.toArray(a);
+ sb.append(" ]");
+ return sb.toString();
}
private class ChildrenIterator implements Iterator
{
-
- /** . */
private final Iterator iterator;
- /** . */
private PortalObject nextChild = null;
public ChildrenIterator()
{
// Make sure the children are sorted for consistent ordering downstream
- Map childrenMap = new TreeMap(objectNode.getChildren());
- Collection children = childrenMap.values();
- iterator = children.iterator();
+ iterator = children.values().iterator();
}
public void remove()
@@ -335,7 +337,7 @@
{
ObjectNode childNode = (ObjectNode)iterator.next();
PortalObjectImpl childObject = childNode.getObject();
- if (mask == ALL_TYPES_MASK || (childObject.getMask() & mask) != 0)
+ if (isMatchingMask(childObject, mask))
{
nextChild = childObject;
}
@@ -368,32 +370,17 @@
}
}
+ private boolean isMatchingMask(PortalObjectImpl object, int mask)
+ {
+ return (mask == ALL_TYPES_MASK || (object.getMask() & mask) != 0);
+ }
+
public Collection getChildren(int wantedMask)
{
- /// Correct eventually the mask
+ // Correct eventually the mask
final int mask = wantedMask & ALL_TYPES_MASK;
- // Compute the lookup cache key
- Integer key = new Integer(mask);
-
- //
- Collection children = null;
- if (childrenMap == null)
- {
- childrenMap = new HashMap();
- }
- else
- {
- children = (Collection)childrenMap.get(key);
- }
-
- //
- if (children == null)
- {
- children = new ChildrenCollection(mask);
- childrenMap.put(key, children);
- }
- return children;
+ return new ChildrenCollection(mask, objectNode.getChildren());
}
public String getListener()
Modified:
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java 2009-02-01
03:56:00 UTC (rev 12761)
+++
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java 2009-02-01
15:16:39 UTC (rev 12762)
@@ -1,6 +1,6 @@
/******************************************************************************
* JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * Copyright 2009, Red Hat Middleware, LLC, and individual *
* contributors as indicated by the @authors tag. See the *
* copyright.txt in the distribution for a full listing of *
* individual contributors. *
@@ -20,6 +20,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
* 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
******************************************************************************/
+
package org.jboss.portal.test.core.model.portal;
import junit.framework.TestSuite;
@@ -130,7 +131,7 @@
duplicate = true;
}
assertTrue(duplicate);
-
+
TransactionAssert.commitTransaction();
}
@@ -144,9 +145,9 @@
n1.createPage("default");
TransactionAssert.commitTransaction();
-
+
boolean rollback = false;
-
+
TransactionAssert.beginTransaction();
try
{
@@ -361,11 +362,6 @@
TransactionAssert.commitTransaction();
}
- public void testPortalNode() throws Exception
- {
-
- }
-
public void testRecreate() throws Exception
{
PortalObjectId defaultId = PortalObjectId.parse("/default",
PortalObjectPath.CANONICAL_FORMAT);
@@ -443,16 +439,6 @@
TransactionAssert.commitTransaction();
}
-// private void constructPortalObjects() throws Exception
-// {
-// Context root = container.getContext();
-// assertNotNull(root);
-// Portal portal = root.createPortal("default");
-// assertNotNull(portal);
-// Page page = portal.createPage("default");
-// assertNotNull(page);
-// }
-
private static class PortalObjectComparator implements Comparator
{
public int compare(Object o1, Object o2)
Modified:
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectTestCase.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectTestCase.java 2009-02-01
03:56:00 UTC (rev 12761)
+++
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectTestCase.java 2009-02-01
15:16:39 UTC (rev 12762)
@@ -147,7 +147,10 @@
}
}
- /*public void testPerformanceGetChildren() throws DuplicatePortalObjectException,
NoSuchPortalObjectException
+ /*
+ // This is commented out because this test is meant to test performance and takes a
long time
+ // TODO: Should be moved to a performance test suite
+ public void testPerformanceToArray() throws NoSuchPortalObjectException,
DuplicatePortalObjectException
{
Portal portal;
Page page;
@@ -155,6 +158,41 @@
long time = System.currentTimeMillis();
TransactionAssert.beginTransaction();
root.destroyChild(p_1.getName());
+ portal = root.createPortal("portal");
+ page = portal.createPage("page");
+ int nbPages = 200;
+ int nbWindows = 100;
+ for(int j = 0; j < nbPages; j++)
+ {
+ page.createPage("page" + j);
+ }
+ for (int k = 0; k < nbWindows; k++)
+ {
+ page.createWindow("window" + k, ContentType.PORTLET, "foo" +
k);
+ }
+ TransactionAssert.commitTransaction();
+ System.out.println("Creation time = " + (System.currentTimeMillis() -
time));
+
+ time = System.currentTimeMillis();
+ for (int i = 0; i < 100000; i++)
+ {
+ assertEquals(nbWindows,
page.getChildren(PortalObject.WINDOW_MASK).toArray().length);
+ assertEquals(nbPages,
page.getChildren(PortalObject.PAGE_MASK).toArray().length);
+ }
+ System.out.println("Tests time = " + (System.currentTimeMillis() -
time));
+ }*/
+
+ /*
+ // This is commented out because this test is meant to test performance and takes a
long time
+ // TODO: Should be moved to a performance test suite
+ public void testPerformanceGetChildren() throws DuplicatePortalObjectException,
NoSuchPortalObjectException
+ {
+ Portal portal;
+ Page page;
+
+ long time = System.currentTimeMillis();
+ TransactionAssert.beginTransaction();
+ root.destroyChild(p_1.getName());
int nbPortals = 5;
int nbPages = 20;
int nbWindows = 20;
@@ -199,4 +237,4 @@
}
System.out.println("Tests time = " + (System.currentTimeMillis() -
time));
}*/
-}
+}
\ No newline at end of file