[gatein-commits] gatein SVN: r5238 - in epp/portal/branches/EPP_5_1_Branch/component/portal/src: main/java/org/exoplatform/portal/pom/config and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Nov 23 16:31:21 EST 2010


Author: thomas.heute at jboss.com
Date: 2010-11-23 16:31:21 -0500 (Tue, 23 Nov 2010)
New Revision: 5238

Added:
   epp/portal/branches/EPP_5_1_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/PortalNamesCache.java
Modified:
   epp/portal/branches/EPP_5_1_Branch/component/portal/src/main/java/org/exoplatform/portal/config/model/PortalConfig.java
   epp/portal/branches/EPP_5_1_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSessionManager.java
   epp/portal/branches/EPP_5_1_Branch/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java
Log:
JBEPP-658: getAllPortalNames bottleneck


Modified: epp/portal/branches/EPP_5_1_Branch/component/portal/src/main/java/org/exoplatform/portal/config/model/PortalConfig.java
===================================================================
--- epp/portal/branches/EPP_5_1_Branch/component/portal/src/main/java/org/exoplatform/portal/config/model/PortalConfig.java	2010-11-23 21:28:31 UTC (rev 5237)
+++ epp/portal/branches/EPP_5_1_Branch/component/portal/src/main/java/org/exoplatform/portal/config/model/PortalConfig.java	2010-11-23 21:31:21 UTC (rev 5238)
@@ -67,6 +67,16 @@
       this(PORTAL_TYPE);
    }
 
+   public PortalConfig(String type)
+   {
+      this(type, null);
+   }
+
+   public PortalConfig(String type, String ownerId)
+   {
+      this(type, ownerId, null);
+   }
+
    public PortalConfig(String type, String ownerId, String storageId)
    {
       super(storageId);
@@ -74,16 +84,9 @@
       //
       this.type = type;
       this.name = ownerId;
+      this.portalLayout = new Container();
    }
 
-   public PortalConfig(String type)
-   {
-      this.type = type;
-
-      //
-      setPortalLayout(new Container());
-   }
-
    public PortalConfig(PortalData data)
    {
       super(data.getStorageId());
@@ -99,14 +102,6 @@
       this.portalLayout = new Container(data.getPortalLayout());
    }
 
-   PortalConfig(String storageId, String type)
-   {
-      super(storageId);
-
-      //
-      this.type = type;
-   }
-
    public String getType()
    {
       return type;

Modified: epp/portal/branches/EPP_5_1_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSessionManager.java
===================================================================
--- epp/portal/branches/EPP_5_1_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSessionManager.java	2010-11-23 21:28:31 UTC (rev 5237)
+++ epp/portal/branches/EPP_5_1_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSessionManager.java	2010-11-23 21:31:21 UTC (rev 5238)
@@ -23,6 +23,7 @@
 import org.exoplatform.commons.chromattic.ChromatticManager;
 import org.exoplatform.commons.chromattic.SessionContext;
 import org.exoplatform.portal.pom.config.cache.DataCache;
+import org.exoplatform.portal.pom.config.cache.PortalNamesCache;
 import org.exoplatform.services.cache.CacheService;
 import org.exoplatform.services.cache.ExoCache;
 import org.exoplatform.services.jcr.RepositoryService;
@@ -69,7 +70,7 @@
       this.manager = manager;
       this.cache = cacheService.getCacheInstance("MOPSessionManager");
       this.pomService = null;
-      this.executor = new DataCache(new ExecutorDispatcher());
+      this.executor = new PortalNamesCache(new DataCache(new ExecutorDispatcher()));
    }
 
    public void cachePut(Serializable key, Object value)

Copied: epp/portal/branches/EPP_5_1_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/PortalNamesCache.java (from rev 5237, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/PortalNamesCache.java)
===================================================================
--- epp/portal/branches/EPP_5_1_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/PortalNamesCache.java	                        (rev 0)
+++ epp/portal/branches/EPP_5_1_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/PortalNamesCache.java	2010-11-23 21:31:21 UTC (rev 5238)
@@ -0,0 +1,79 @@
+/*
+ * 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.portal.pom.config.cache;
+
+import org.exoplatform.commons.utils.LazyPageList;
+import org.exoplatform.commons.utils.ListAccessImpl;
+import org.exoplatform.portal.pom.config.POMSession;
+import org.exoplatform.portal.pom.config.POMTask;
+import org.exoplatform.portal.pom.config.TaskExecutionDecorator;
+import org.exoplatform.portal.pom.config.TaskExecutor;
+import org.exoplatform.portal.pom.config.tasks.PortalConfigTask;
+import org.exoplatform.portal.pom.config.tasks.SearchTask;
+import org.exoplatform.portal.pom.data.PortalKey;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class PortalNamesCache extends TaskExecutionDecorator
+{
+
+   public PortalNamesCache(TaskExecutor next)
+   {
+      super(next);
+   }
+
+   @Override
+   public <V> V execute(POMSession session, POMTask<V> task) throws Exception
+   {
+      if (!session.isModified())
+      {
+         if (task instanceof SearchTask.FindSiteKey)
+         {
+            List<PortalKey> data = (List<PortalKey>)session.getFromCache(SearchTask.FindSiteKey.class);
+            if (data == null)
+            {
+               V result = super.execute(session, task);
+               LazyPageList<PortalKey> list = (LazyPageList<PortalKey>)result;
+               session.putInCache(SearchTask.FindSiteKey.class, Collections.unmodifiableList(new ArrayList<PortalKey>(list.getAll())));
+               return result;
+            }
+            else
+            {
+               return (V)new LazyPageList<PortalKey>(new ListAccessImpl<PortalKey>(PortalKey.class, data), 10);
+            }
+         }
+         else if (task instanceof PortalConfigTask.Save || task instanceof PortalConfigTask.Remove)
+         {
+            V result = super.execute(session, task);
+            session.scheduleForEviction(SearchTask.FindSiteKey.class);
+            return result;
+         }
+      }
+
+      //
+      return super.execute(session, task);
+   }
+}

Modified: epp/portal/branches/EPP_5_1_Branch/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java
===================================================================
--- epp/portal/branches/EPP_5_1_Branch/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java	2010-11-23 21:28:31 UTC (rev 5237)
+++ epp/portal/branches/EPP_5_1_Branch/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java	2010-11-23 21:31:21 UTC (rev 5238)
@@ -21,11 +21,21 @@
 
 import static org.exoplatform.portal.pom.config.Utils.split;
 
+import junit.framework.AssertionFailedError;
 import org.exoplatform.container.PortalContainer;
 import org.exoplatform.portal.application.PortletPreferences;
 import org.exoplatform.portal.application.Preference;
-import org.exoplatform.portal.config.model.*;
-import org.exoplatform.portal.pom.config.POMSession;
+import org.exoplatform.portal.config.model.Application;
+import org.exoplatform.portal.config.model.ApplicationState;
+import org.exoplatform.portal.config.model.ApplicationType;
+import org.exoplatform.portal.config.model.Container;
+import org.exoplatform.portal.config.model.Dashboard;
+import org.exoplatform.portal.config.model.ModelObject;
+import org.exoplatform.portal.config.model.Page;
+import org.exoplatform.portal.config.model.PageNavigation;
+import org.exoplatform.portal.config.model.PageNode;
+import org.exoplatform.portal.config.model.PortalConfig;
+import org.exoplatform.portal.config.model.TransientApplicationState;
 import org.exoplatform.portal.pom.config.POMSessionManager;
 import org.exoplatform.portal.pom.data.ModelChange;
 import org.exoplatform.portal.pom.spi.gadget.Gadget;
@@ -35,7 +45,14 @@
 import org.exoplatform.services.listener.Listener;
 import org.exoplatform.services.listener.ListenerService;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicReference;
 
 /**
  * Created by The eXo Platform SARL Author : Tung Pham thanhtungty at gmail.com Nov
@@ -56,9 +73,6 @@
    /** . */
    private POMSessionManager mgr;
 
-   /** . */
-   private POMSession session;
-
    private LinkedList<Event> events;
 
    private ListenerService listenerService;
@@ -78,17 +92,16 @@
             events.add(event);
          }
       };
-      
+
+      //
       super.setUp();
-      begin();
       PortalContainer container = PortalContainer.getInstance();
       storage_ = (DataStorage)container.getComponentInstanceOfType(DataStorage.class);
       mgr = (POMSessionManager)container.getComponentInstanceOfType(POMSessionManager.class);
-      session = mgr.openSession();
-      
       events = new LinkedList<Event>();
       listenerService = (ListenerService)container.getComponentInstanceOfType(ListenerService.class);
-      
+
+      //
       listenerService.addListener(DataStorage.PAGE_CREATED, listener);
       listenerService.addListener(DataStorage.PAGE_REMOVED, listener);
       listenerService.addListener(DataStorage.PAGE_UPDATED, listener);
@@ -98,11 +111,13 @@
       listenerService.addListener(DataStorage.PORTAL_CONFIG_CREATED, listener);
       listenerService.addListener(DataStorage.PORTAL_CONFIG_UPDATED, listener);
       listenerService.addListener(DataStorage.PORTAL_CONFIG_REMOVED, listener);
+
+      //
+      begin();
    }
 
    protected void tearDown() throws Exception
    {
-      session.close();
       end();
       super.tearDown();
    }
@@ -869,6 +884,117 @@
       assertEquals("foo", storage_.getId(gadgetApp.getState()));
    }
 
+   public void testGetAllPortalNames() throws Exception
+   {
+      final List<String> names = storage_.getAllPortalNames();
+
+      // Create new portal
+      storage_.create(new PortalConfig("portal", "testGetAllPortalNames"));
+
+      // Test during tx we see the good names
+      List<String> transientNames = storage_.getAllPortalNames();
+      assertTrue(transientNames.containsAll(names));
+      transientNames.removeAll(names);
+      assertEquals(Collections.singletonList("testGetAllPortalNames"), transientNames);
+
+      // Test we have not seen anything yet outside of tx
+      final CountDownLatch addSync = new CountDownLatch(1);
+      final AtomicReference<Throwable> error = new AtomicReference<Throwable>();
+      new Thread()
+      {
+         @Override
+         public void run()
+         {
+            begin();
+            try
+            {
+               List<String> isolatedNames = storage_.getAllPortalNames();
+               assertEquals(new HashSet<String>(names), new HashSet<String>(isolatedNames));
+            }
+            catch (Throwable t)
+            {
+               error.set(t);
+            }
+            finally
+            {
+               addSync.countDown();
+               end();
+            }
+         }
+      }.start();
+
+      //
+      addSync.await();
+      if (error.get() != null)
+      {
+         AssertionFailedError afe = new AssertionFailedError();
+         afe.initCause(error.get());
+         throw afe;
+      }
+
+      // Now commit tx
+      end(true);
+
+      // We test we observe the change
+      begin();
+      List<String> afterNames = storage_.getAllPortalNames();
+      assertTrue(afterNames.containsAll(names));
+      afterNames.removeAll(names);
+      assertEquals(Collections.singletonList("testGetAllPortalNames"), afterNames);
+
+      // Then we remove the newly created portal
+      storage_.remove(new PortalConfig("portal", "testGetAllPortalNames"));
+
+      // Test we are syeing the transient change
+      transientNames.clear();
+      transientNames = storage_.getAllPortalNames();
+      assertEquals(names, transientNames);
+
+      // Test we have not seen anything yet outside of tx
+      error.set(null);
+      final CountDownLatch removeSync = new CountDownLatch(1);
+      new Thread()
+      {
+         public void run()
+         {
+            begin();
+            try
+            {
+               List<String> isolatedNames = storage_.getAllPortalNames();
+               assertTrue(isolatedNames.containsAll(names));
+               isolatedNames.removeAll(names);
+               assertEquals(Collections.singletonList("testGetAllPortalNames"), isolatedNames);
+            }
+            catch (Throwable t)
+            {
+               error.set(t);
+            }
+            finally
+            {
+               removeSync.countDown();
+               end();
+            }
+         }
+      }.start();
+
+      //
+      removeSync.await();
+      if (error.get() != null)
+      {
+         AssertionFailedError afe = new AssertionFailedError();
+         afe.initCause(error.get());
+         throw afe;
+      }
+
+      //
+      end(true);
+
+      // Now test it is still removed
+      begin();
+      afterNames = storage_.getAllPortalNames();
+      assertEquals(new HashSet<String>(names), new HashSet<String>(afterNames));
+   }
+
    private Application<Portlet> create(String instanceId)
    {
       int i0 = instanceId.indexOf("#");



More information about the gatein-commits mailing list