[gatein-commits] gatein SVN: r416 - in portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal: pom/config and 3 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Sat Oct 24 06:48:26 EDT 2009


Author: julien_viet
Date: 2009-10-24 06:48:25 -0400 (Sat, 24 Oct 2009)
New Revision: 416

Added:
   portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/ExecutorDispatcher.java
   portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/TaskExecutor.java
   portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/
   portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/CacheableDataTask.java
   portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/DataAccessMode.java
   portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/DataCache.java
Modified:
   portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java
   portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java
   portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/PageNavigationTask.java
   portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/PageTask.java
   portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/PortalConfigTask.java
   portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/data/ModelDataStorage.java
Log:
first bits of proper caching


Modified: portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java
===================================================================
--- portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java	2009-10-24 08:35:40 UTC (rev 415)
+++ portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java	2009-10-24 10:48:25 UTC (rev 416)
@@ -37,7 +37,6 @@
 import org.exoplatform.portal.pom.data.PageKey;
 import org.exoplatform.portal.pom.data.PortalData;
 import org.exoplatform.portal.pom.data.PortalKey;
-import org.exoplatform.portal.pom.config.tasks.DashboardTask;
 
 import java.lang.reflect.Array;
 import java.util.Comparator;
@@ -261,13 +260,13 @@
 
    public Dashboard loadDashboard(String dashboardId) throws Exception
    {
-      DashboardData data = delegate.execute(new DashboardTask.Load(dashboardId)).getDashboard();
+      DashboardData data = delegate.loadDashboard(dashboardId);
       return data != null ? new Dashboard(data) : null;
    }
 
    public void saveDashboard(Dashboard dashboard) throws Exception
    {
-      delegate.execute(new DashboardTask.Save(dashboard.build()));
+      delegate.saveDashboard(dashboard.build());
    }
 
    public void begin()

Added: portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/ExecutorDispatcher.java
===================================================================
--- portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/ExecutorDispatcher.java	                        (rev 0)
+++ portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/ExecutorDispatcher.java	2009-10-24 10:48:25 UTC (rev 416)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.portal.pom.config;
+
+import org.exoplatform.portal.pom.config.TaskExecutor;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class ExecutorDispatcher implements TaskExecutor
+{
+
+   /** . */
+   private final POMSessionManager pomMgr;
+
+   /** . */
+   private final Log log = ExoLogger.getLogger(getClass());
+
+   /** . */
+   private static final String[] padding = {"    ", "   ", "  ", " "};
+
+   public ExecutorDispatcher(POMSessionManager pomMgr)
+   {
+      this.pomMgr = pomMgr;
+   }
+
+   public <T extends POMTask> T execute(T task) throws Exception
+   {
+      String s = task.toString();
+      long t0 = System.currentTimeMillis();
+      pomMgr.execute(task);
+      long t1 = System.currentTimeMillis();
+      String t = "" + (t1 - t0);
+      if (t.length() < 4)
+      {
+         t = padding[t.length()] + t;
+         log.info("Executed [" + t + "] " + s + "");
+      }
+      else
+      {
+         log.info("Executed in " + t + " " + s + "");
+      }
+      return task;
+   }
+}

Modified: portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java
===================================================================
--- portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java	2009-10-24 08:35:40 UTC (rev 415)
+++ portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java	2009-10-24 10:48:25 UTC (rev 416)
@@ -29,6 +29,10 @@
 import org.exoplatform.portal.config.model.Container;
 import org.exoplatform.portal.config.model.ModelChange;
 import org.exoplatform.portal.config.model.ModelObject;
+import org.exoplatform.portal.pom.config.cache.DataCache;
+import org.exoplatform.portal.pom.config.TaskExecutor;
+import org.exoplatform.portal.pom.config.tasks.DashboardTask;
+import org.exoplatform.portal.pom.data.DashboardData;
 import org.exoplatform.portal.pom.data.ModelDataStorage;
 import org.exoplatform.portal.pom.data.NavigationData;
 import org.exoplatform.portal.pom.data.NavigationKey;
@@ -44,6 +48,7 @@
 import org.exoplatform.portal.pom.config.tasks.PortletPreferencesTask;
 import org.exoplatform.portal.pom.config.tasks.PreferencesTask;
 import org.exoplatform.portal.pom.config.tasks.SearchTask;
+import org.exoplatform.services.cache.CacheService;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
 import org.jibx.runtime.BindingDirectory;
@@ -70,34 +75,17 @@
 
    /** . */
    private final Log log = ExoLogger.getLogger(getClass());
+   
+   /** . */
+   private final TaskExecutor executor;
 
-   public POMDataStorage(POMSessionManager pomMgr, ConfigurationManager confManager)
+   public POMDataStorage(CacheService cacheService, POMSessionManager pomMgr, ConfigurationManager confManager)
    {
       this.pomMgr = pomMgr;
-      confManager_ = confManager;
+      this.confManager_ = confManager;
+      this.executor = new DataCache(cacheService, new ExecutorDispatcher(pomMgr));
    }
 
-   private static final String[] padding = {"    ", "   ", "  ", " "};
-
-   public <T extends POMTask> T execute(T task) throws Exception
-   {
-      String s = task.toString();
-      long t0 = System.currentTimeMillis();
-      pomMgr.execute(task);
-      long t1 = System.currentTimeMillis();
-      String t = "" + (t1 - t0);
-      if (t.length() < 4)
-      {
-         t = padding[t.length()] + t;
-         log.info("Executed [" + t + "] " + s + "");
-      }
-      else
-      {
-         log.info("Executed in " + t + " " + s + "");
-      }
-      return task;
-   }
-
    public POMSessionManager getPOMSessionManager()
    {
       return pomMgr;
@@ -105,73 +93,73 @@
 
    public PortalData getPortalConfig(PortalKey key) throws Exception
    {
-      return execute(new PortalConfigTask.Load(key)).getConfig();
+      return executor.execute(new PortalConfigTask.Load(key)).getConfig();
    }
 
    public void create(PortalData config) throws Exception
    {
-      execute(new PortalConfigTask.Save(config, true));
+      executor.execute(new PortalConfigTask.Save(config, true));
    }
 
    public void save(PortalData config) throws Exception
    {
-      execute(new PortalConfigTask.Save(config, true));
+      executor.execute(new PortalConfigTask.Save(config, true));
    }
 
    public void remove(PortalData config) throws Exception
    {
-      execute(new PortalConfigTask.Remove(config.getKey()));
+      executor.execute(new PortalConfigTask.Remove(config.getKey()));
    }
 
    public PageData getPage(PageKey key) throws Exception
    {
-      return execute(new PageTask.Load(key)).getPage();
+      return executor.execute(new PageTask.Load(key)).getPage();
    }
 
    public PageData clonePage(PageKey key, PageKey cloneKey)
       throws Exception
    {
-      return execute(new PageTask.Clone(key, cloneKey, true)).getPage();
+      return executor.execute(new PageTask.Clone(key, cloneKey, true)).getPage();
    }
 
    public void remove(PageData page) throws Exception
    {
-      execute(new PageTask.Remove(page));
+      executor.execute(new PageTask.Remove(page));
    }
 
    public void create(PageData page) throws Exception
    {
-      execute(new PageTask.Save(page));
+      executor.execute(new PageTask.Save(page));
    }
 
    public List<ModelChange> save(PageData page) throws Exception
    {
-      return execute(new PageTask.Save(page)).getChanges();
+      return executor.execute(new PageTask.Save(page)).getChanges();
    }
 
    public NavigationData getPageNavigation(NavigationKey key) throws Exception
    {
-      return execute(new PageNavigationTask.Load(key)).getPageNavigation();
+      return executor.execute(new PageNavigationTask.Load(key)).getPageNavigation();
    }
 
    public void save(NavigationData navigation) throws Exception
    {
-      execute(new PageNavigationTask.Save(navigation, true));
+      executor.execute(new PageNavigationTask.Save(navigation, true));
    }
 
    public void create(NavigationData navigation) throws Exception
    {
-      execute(new PageNavigationTask.Save(navigation, false));
+      executor.execute(new PageNavigationTask.Save(navigation, false));
    }
 
    public void remove(NavigationData navigation) throws Exception
    {
-      execute(new PageNavigationTask.Remove(navigation));
+      executor.execute(new PageNavigationTask.Remove(navigation));
    }
 
    public void save(PortletPreferences portletPreferences) throws Exception
    {
-      execute(new PortletPreferencesTask.Save(portletPreferences));
+      executor.execute(new PortletPreferencesTask.Save(portletPreferences));
    }
 
    public <S> S load(ApplicationState<S> state) throws Exception
@@ -185,7 +173,7 @@
       else
       {
          PreferencesTask.Load<S> load = new PreferencesTask.Load<S>((PersistentApplicationState<S>)state);
-         execute(load);
+         executor.execute(load);
          return load.getState();
       }
    }
@@ -199,14 +187,14 @@
       else
       {
          PreferencesTask.Save<S> save = new PreferencesTask.Save<S>((PersistentApplicationState<S>)state, preferences);
-         execute(save);
+         executor.execute(save);
          return state;
       }
    }
 
    public PortletPreferences getPortletPreferences(String windowID) throws Exception
    {
-      return execute(new PortletPreferencesTask.Load(windowID)).getPreferences();
+      return executor.execute(new PortletPreferencesTask.Load(windowID)).getPreferences();
    }
 
    public <T> LazyPageList<T> find(Query<T> q) throws Exception
@@ -219,23 +207,23 @@
       Class<T> type = q.getClassType();
       if (PageData.class.equals(type))
       {
-         return (LazyPageList<T>)execute(new SearchTask.FindPage((Query<PageData>)q)).getResult();
+         return (LazyPageList<T>)executor.execute(new SearchTask.FindPage((Query<PageData>)q)).getResult();
       }
       else if (NavigationData.class.equals(type))
       {
-         return (LazyPageList<T>)execute(new SearchTask.FindNavigation((Query<NavigationData>)q)).getResult();
+         return (LazyPageList<T>)executor.execute(new SearchTask.FindNavigation((Query<NavigationData>)q)).getResult();
       }
       else if (PortletPreferences.class.equals(type))
       {
-         return (LazyPageList<T>)execute(new SearchTask.FindPortletPreferences((Query<PortletPreferences>)q)).getResult();
+         return (LazyPageList<T>)executor.execute(new SearchTask.FindPortletPreferences((Query<PortletPreferences>)q)).getResult();
       }
       else if (PortalData.class.equals(type) && "portal".equals(q.getOwnerType()))
       {
-         return (LazyPageList<T>)execute(new SearchTask.FindSite((Query<PortalData>)q)).getResult();
+         return (LazyPageList<T>)executor.execute(new SearchTask.FindSite((Query<PortalData>)q)).getResult();
       }
       else if (PortalKey.class.equals(type) && "portal".equals(q.getOwnerType()))
       {
-         return (LazyPageList<T>)execute(new SearchTask.FindSiteKey((Query<PortalKey>)q)).getResult();
+         return (LazyPageList<T>)executor.execute(new SearchTask.FindSiteKey((Query<PortalKey>)q)).getResult();
       }
       else
       {
@@ -262,6 +250,16 @@
       }
    }
 
+   public DashboardData loadDashboard(String dashboardId) throws Exception
+   {
+      return executor.execute(new DashboardTask.Load(dashboardId)).getDashboard();
+   }
+
+   public void saveDashboard(DashboardData dashboard) throws Exception
+   {
+      executor.execute(new DashboardTask.Save(dashboard));
+   }
+
    public Container getSharedLayout() throws Exception
    {
       String path = "war:/conf/portal/portal/sharedlayout.xml";

Added: portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/TaskExecutor.java
===================================================================
--- portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/TaskExecutor.java	                        (rev 0)
+++ portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/TaskExecutor.java	2009-10-24 10:48:25 UTC (rev 416)
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.portal.pom.config;
+
+import org.exoplatform.portal.pom.config.POMTask;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public interface TaskExecutor
+{
+
+   <T extends POMTask> T execute(T task) throws Exception;
+
+}

Added: portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/CacheableDataTask.java
===================================================================
--- portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/CacheableDataTask.java	                        (rev 0)
+++ portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/CacheableDataTask.java	2009-10-24 10:48:25 UTC (rev 416)
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.portal.pom.config.cache;
+
+import org.exoplatform.portal.pom.config.POMTask;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public interface CacheableDataTask<K extends Serializable, V> extends POMTask
+{
+
+   DataAccessMode getAccessMode();
+
+   K getKey();
+
+   V getValue();
+
+   void setValue(V value);
+
+   Class<V> getValueType();
+
+}

Added: portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/DataAccessMode.java
===================================================================
--- portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/DataAccessMode.java	                        (rev 0)
+++ portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/DataAccessMode.java	2009-10-24 10:48:25 UTC (rev 416)
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.portal.pom.config.cache;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public enum DataAccessMode
+{
+
+   CREATE, READ, WRITE, DESTROY
+
+}

Added: portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/DataCache.java
===================================================================
--- portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/DataCache.java	                        (rev 0)
+++ portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/DataCache.java	2009-10-24 10:48:25 UTC (rev 416)
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.portal.pom.config.cache;
+
+import org.exoplatform.portal.pom.config.POMTask;
+import org.exoplatform.portal.pom.config.TaskExecutor;
+import org.exoplatform.services.cache.CacheService;
+import org.exoplatform.services.cache.ExoCache;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class DataCache implements TaskExecutor
+{
+
+   /** . */
+   private TaskExecutor next;
+
+   /** . */
+   private ExoCache<Serializable, Object> cache;
+
+   public DataCache(CacheService cacheService, TaskExecutor next)
+   {
+      this.next = next;
+      this.cache = cacheService.getCacheInstance(DataCache.class.getSimpleName());
+   }
+
+   public <T extends POMTask> T execute(T task) throws Exception
+   {
+      if (task instanceof CacheableDataTask)
+      {
+         CacheableDataTask<?, ?> loadTask = (CacheableDataTask<?,?>)task;
+         switch (loadTask.getAccessMode())
+         {
+            case READ:
+               return (T)read(loadTask);
+            case CREATE:
+               return (T)create(loadTask);
+            case WRITE:
+               return (T)write(loadTask);
+            case DESTROY:
+               return (T)remove(loadTask);
+            default:
+               throw new UnsupportedOperationException();
+
+         }
+      }
+      else
+      {
+         return next.execute(task);
+      }
+   }
+
+   private <K extends Serializable, V, T extends CacheableDataTask<K, V>> T remove(T task) throws Exception
+   {
+      K key = task.getKey();
+      cache.remove(key);
+      return next.execute(task);
+   }
+
+   private <K extends Serializable, V, T extends CacheableDataTask<K, V>> T write(T task) throws Exception
+   {
+      K key = task.getKey();
+      cache.remove(key);
+      return next.execute(task);
+   }
+
+   private <K extends Serializable, V, T extends CacheableDataTask<K, V>> T create(T task) throws Exception
+   {
+      // Nothing to do for now
+      return next.execute(task);
+   }
+
+   private <K extends Serializable, V, T extends CacheableDataTask<K, V>> T read(T task) throws Exception
+   {
+      K key = task.getKey();
+      Object o = cache.get(key);
+      V v = null;
+      if (o != null)
+      {
+         Class<V> type = task.getValueType();
+         if (type.isInstance(o))
+         {
+            v = type.cast(o);
+         }
+      }
+
+      //
+      if (v != null)
+      {
+         task.setValue(v);
+      }
+      else
+      {
+         //
+         next.execute(task);
+
+         //
+         v = task.getValue();
+         if (v != null)
+         {
+            cache.put(key, v);
+         }
+      }
+
+      //
+      return task;
+   }
+}

Modified: portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/PageNavigationTask.java
===================================================================
--- portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/PageNavigationTask.java	2009-10-24 08:35:40 UTC (rev 415)
+++ portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/PageNavigationTask.java	2009-10-24 10:48:25 UTC (rev 416)
@@ -19,6 +19,8 @@
 
 package org.exoplatform.portal.pom.config.tasks;
 
+import org.exoplatform.portal.pom.config.cache.DataAccessMode;
+import org.exoplatform.portal.pom.config.cache.CacheableDataTask;
 import org.exoplatform.portal.pom.data.Mapper;
 
 import org.exoplatform.portal.pom.config.AbstractPOMTask;
@@ -38,22 +40,18 @@
 {
 
    /** . */
-   protected final String ownerType;
+   protected final ObjectType<? extends Site> siteType;
 
    /** . */
-   protected final String ownerId;
+   protected final NavigationKey key;
 
-   /** . */
-   protected final ObjectType<? extends Site> siteType;
-
    protected PageNavigationTask(NavigationKey key)
    {
-      this.ownerType = key.getOwnerType();
-      this.ownerId = key.getOwnerId();
-      this.siteType = Mapper.parseSiteType(ownerType);
+      this.key = key;
+      this.siteType = Mapper.parseSiteType(key.getOwnerType());
    }
 
-   public static class Load extends PageNavigationTask
+   public static class Load extends PageNavigationTask implements CacheableDataTask<NavigationKey, NavigationData>
    {
 
       /** . */
@@ -69,10 +67,35 @@
          return pageNav;
       }
 
+      public DataAccessMode getAccessMode()
+      {
+         return DataAccessMode.READ;
+      }
+
+      public NavigationKey getKey()
+      {
+         return key;
+      }
+
+      public NavigationData getValue()
+      {
+         return pageNav;
+      }
+
+      public void setValue(NavigationData value)
+      {
+         this.pageNav = value;
+      }
+
+      public Class<NavigationData> getValueType()
+      {
+         return NavigationData.class;
+      }
+
       public void run(POMSession session) throws Exception
       {
          Workspace workspace = session.getWorkspace();
-         Site site = workspace.getSite(siteType, ownerId);
+         Site site = workspace.getSite(siteType, key.getOwnerId());
          if (site != null)
          {
             Navigation nav = site.getRootNavigation();
@@ -84,7 +107,7 @@
          }
          else
          {
-            System.out.println("Cannot load page navigation as the corresponding portal " + ownerId
+            System.out.println("Cannot load page navigation as the corresponding portal " + key.getOwnerId()
                + " with type " + siteType + " does not exist");
          }
       }
@@ -92,11 +115,11 @@
       @Override
       public String toString()
       {
-         return "PageNavigation.Load[ownerType=" + ownerType + ",ownerId=" + ownerId + "]";
+         return "PageNavigation.Load[ownerType=" + key.getOwnerType() + ",ownerId=" + key.getOwnerId() + "]";
       }
    }
 
-   public static class Save extends PageNavigationTask
+   public static class Save extends PageNavigationTask implements CacheableDataTask<NavigationKey, NavigationData>
    {
 
       /** . */
@@ -114,14 +137,39 @@
          this.overwrite = overwrite;
       }
 
+      public DataAccessMode getAccessMode()
+      {
+         return pageNav.getStorageId() != null ? DataAccessMode.WRITE : DataAccessMode.CREATE;
+      }
+
+      public void setValue(NavigationData value)
+      {
+         throw new UnsupportedOperationException();
+      }
+
+      public Class<NavigationData> getValueType()
+      {
+         return NavigationData.class;
+      }
+
+      public NavigationData getValue()
+      {
+         return pageNav;
+      }
+
+      public NavigationKey getKey()
+      {
+         return key;
+      }
+
       public void run(POMSession session) throws Exception
       {
          Workspace workspace = session.getWorkspace();
-         Site site = workspace.getSite(siteType, ownerId);
+         Site site = workspace.getSite(siteType, key.getOwnerId());
          if (site == null)
          {
             throw new IllegalArgumentException("Cannot insert page navigation "
-               + " as the corresponding portal " + ownerId + " with type " + siteType + " does not exist");
+               + " as the corresponding portal " + key.getOwnerId() + " with type " + siteType + " does not exist");
          }
 
          // Delete node descendants first
@@ -141,11 +189,11 @@
       @Override
       public String toString()
       {
-         return "PageNavigation.Save[ownerType=" + ownerType + ",ownerId=" + ownerId + "]";
+         return "PageNavigation.Save[ownerType=" + key.getOwnerType() + ",ownerId=" + key.getOwnerId() + "]";
       }
    }
 
-   public static class Remove extends PageNavigationTask
+   public static class Remove extends PageNavigationTask implements CacheableDataTask<NavigationKey, NavigationData>
    {
 
       public Remove(NavigationData pageNav)
@@ -153,14 +201,39 @@
          super(pageNav.getKey());
       }
 
+      public DataAccessMode getAccessMode()
+      {
+         return DataAccessMode.DESTROY;
+      }
+
+      public void setValue(NavigationData value)
+      {
+         throw new UnsupportedOperationException();
+      }
+
+      public Class<NavigationData> getValueType()
+      {
+         return NavigationData.class;
+      }
+
+      public NavigationData getValue()
+      {
+         return null;
+      }
+
+      public NavigationKey getKey()
+      {
+         return key;
+      }
+
       public void run(POMSession session) throws Exception
       {
          Workspace workspace = session.getWorkspace();
-         Site site = workspace.getSite(siteType, ownerId);
+         Site site = workspace.getSite(siteType, key.getOwnerId());
          if (site == null)
          {
             throw new IllegalArgumentException("Cannot insert page navigation "
-               + " as the corresponding portal " + ownerId + " with type " + siteType + " does not exist");
+               + " as the corresponding portal " + key.getOwnerId() + " with type " + siteType + " does not exist");
          }
 
          // Delete descendants
@@ -177,7 +250,7 @@
       @Override
       public String toString()
       {
-         return "PageNavigation.Remove[ownerType=" + ownerType + ",ownerId=" + ownerId + "]";
+         return "PageNavigation.Remove[ownerType=" + key.getOwnerType() + ",ownerId=" + key.getOwnerId() + "]";
       }
    }
 }
\ No newline at end of file

Modified: portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/PageTask.java
===================================================================
--- portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/PageTask.java	2009-10-24 08:35:40 UTC (rev 415)
+++ portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/PageTask.java	2009-10-24 10:48:25 UTC (rev 416)
@@ -19,6 +19,8 @@
 
 package org.exoplatform.portal.pom.config.tasks;
 
+import org.exoplatform.portal.pom.config.cache.DataAccessMode;
+import org.exoplatform.portal.pom.config.cache.CacheableDataTask;
 import org.exoplatform.portal.pom.data.Mapper;
 import org.exoplatform.portal.pom.data.PageData;
 
@@ -56,10 +58,14 @@
    protected final String name;
 
    /** . */
+   protected final PageKey key;
+
+   /** . */
    protected final ObjectType<? extends Site> siteType;
 
    protected PageTask(PageKey key)
    {
+      this.key = key;
       this.ownerType = key.getOwnerType();
       this.ownerId = key.getOwnerId();
       this.name = key.getName();
@@ -230,7 +236,7 @@
       }
    }
 
-   public static class Remove extends PageTask
+   public static class Remove extends PageTask implements CacheableDataTask<PageKey, PageData>
    {
 
       public Remove(PageData page)
@@ -238,6 +244,31 @@
          super(page.getKey());
       }
 
+      public DataAccessMode getAccessMode()
+      {
+         return DataAccessMode.DESTROY;
+      }
+
+      public void setValue(PageData value)
+      {
+         throw new UnsupportedOperationException();
+      }
+
+      public Class<PageData> getValueType()
+      {
+         return PageData.class;
+      }
+
+      public PageData getValue()
+      {
+         return null;
+      }
+
+      public PageKey getKey()
+      {
+         return key;
+      }
+
       public void run(POMSession session)
       {
          Workspace workspace = session.getWorkspace();
@@ -268,7 +299,7 @@
       }
    }
 
-   public static class Save extends PageTask
+   public static class Save extends PageTask implements CacheableDataTask<PageKey, PageData>
    {
 
       /** . */
@@ -285,6 +316,31 @@
          this.page = page;
       }
 
+      public DataAccessMode getAccessMode()
+      {
+         return page.getStorageId() != null ? DataAccessMode.WRITE : DataAccessMode.CREATE;
+      }
+
+      public void setValue(PageData value)
+      {
+         throw new UnsupportedOperationException();
+      }
+
+      public Class<PageData> getValueType()
+      {
+         return PageData.class;
+      }
+
+      public PageData getValue()
+      {
+         return page;
+      }
+
+      public PageKey getKey()
+      {
+         return key;
+      }
+
       public void run(POMSession session) throws Exception
       {
          Workspace workspace = session.getWorkspace();
@@ -312,7 +368,7 @@
       }
    }
 
-   public static class Load extends PageTask
+   public static class Load extends PageTask implements CacheableDataTask<PageKey, PageData>
    {
 
       /** . */
@@ -328,6 +384,31 @@
          return page;
       }
 
+      public DataAccessMode getAccessMode()
+      {
+         return DataAccessMode.READ;
+      }
+
+      public PageKey getKey()
+      {
+         return key;
+      }
+
+      public Class<PageData> getValueType()
+      {
+         return PageData.class;
+      }
+
+      public void setValue(PageData value)
+      {
+         page = value;
+      }
+
+      public PageData getValue()
+      {
+         return page;
+      }
+
       public void run(POMSession session)
       {
          Workspace workspace = session.getWorkspace();

Modified: portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/PortalConfigTask.java
===================================================================
--- portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/PortalConfigTask.java	2009-10-24 08:35:40 UTC (rev 415)
+++ portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/PortalConfigTask.java	2009-10-24 10:48:25 UTC (rev 416)
@@ -20,6 +20,8 @@
 package org.exoplatform.portal.pom.config.tasks;
 
 import org.exoplatform.portal.application.PortletPreferences;
+import org.exoplatform.portal.pom.config.cache.DataAccessMode;
+import org.exoplatform.portal.pom.config.cache.CacheableDataTask;
 import org.exoplatform.portal.pom.data.Mapper;
 import org.exoplatform.portal.pom.data.PortalData;
 import org.exoplatform.portal.pom.config.AbstractPOMTask;
@@ -38,22 +40,18 @@
 {
 
    /** . */
-   protected final String name;
+   protected final PortalKey key;
 
    /** . */
    protected final ObjectType<? extends Site> type;
 
-   /** . */
-   protected final String ownerType;
-
    protected PortalConfigTask(PortalKey key)
    {
-      this.name = key.getOwnerId();
-      this.ownerType = key.getOwnerType();
+      this.key = key;
       this.type = Mapper.parseSiteType(key.getOwnerType());
    }
 
-   public static class Remove extends PortalConfigTask
+   public static class Remove extends PortalConfigTask implements CacheableDataTask<PortalKey, PortalData>
    {
 
       public Remove(PortalKey key)
@@ -61,13 +59,38 @@
          super(key);
       }
 
+      public DataAccessMode getAccessMode()
+      {
+         return DataAccessMode.DESTROY;
+      }
+
+      public Class<PortalData> getValueType()
+      {
+         return PortalData.class;
+      }
+
+      public PortalKey getKey()
+      {
+         return key;
+      }
+
+      public void setValue(PortalData value)
+      {
+         throw new UnsupportedOperationException();
+      }
+
+      public PortalData getValue()
+      {
+         return null;
+      }
+
       public void run(POMSession session)
       {
          Workspace workspace = session.getWorkspace();
-         Site site = workspace.getSite(type, name);
+         Site site = workspace.getSite(type, key.getOwnerId());
          if (site == null)
          {
-            throw new NullPointerException("Could not remove non existing portal " + name);
+            throw new NullPointerException("Could not remove non existing portal " + key.getOwnerId());
          }
          else
          {
@@ -78,11 +101,11 @@
       @Override
       public String toString()
       {
-         return "PortalConfig.Remove[ownerType=" + ownerType + ",ownerId=" + name + "]";
+         return "PortalConfig.Remove[ownerType=" + key.getOwnerType() + ",ownerId=" + key.getOwnerId() + "]";
       }
    }
 
-   public static class Save extends PortalConfigTask
+   public static class Save extends PortalConfigTask implements CacheableDataTask<PortalKey, PortalData>
    {
 
       /** . */
@@ -100,10 +123,35 @@
          this.overwrite = overwrite;
       }
 
+      public DataAccessMode getAccessMode()
+      {
+         return config.getStorageId() != null ? DataAccessMode.WRITE : DataAccessMode.CREATE;
+      }
+
+      public void setValue(PortalData value)
+      {
+         throw new UnsupportedOperationException();
+      }
+
+      public Class<PortalData> getValueType()
+      {
+         return PortalData.class;
+      }
+
+      public PortalData getValue()
+      {
+         return config;
+      }
+
+      public PortalKey getKey()
+      {
+         return key;
+      }
+
       public void run(POMSession session) throws Exception
       {
          Workspace workspace = session.getWorkspace();
-         Site site = workspace.getSite(type, name);
+         Site site = workspace.getSite(type, key.getOwnerId());
          if (site != null)
          {
             if (!overwrite)
@@ -130,11 +178,11 @@
       @Override
       public String toString()
       {
-         return "PortalConfig.Save[ownerType=" + ownerType + ",ownerId=" + name + "]";
+         return "PortalConfig.Save[ownerType=" + key.getOwnerType() + ",ownerId=" + key.getOwnerId() + "]";
       }
    }
 
-   public static class Load extends PortalConfigTask
+   public static class Load extends PortalConfigTask implements CacheableDataTask<PortalKey, PortalData>
    {
 
       /** . */
@@ -145,6 +193,31 @@
          super(key);
       }
 
+      public DataAccessMode getAccessMode()
+      {
+         return DataAccessMode.READ;
+      }
+
+      public PortalKey getKey()
+      {
+         return key;
+      }
+
+      public void setValue(PortalData value)
+      {
+         config = value;
+      }
+
+      public Class<PortalData> getValueType()
+      {
+         return PortalData.class;
+      }
+
+      public PortalData getValue()
+      {
+         return config;
+      }
+
       public PortalData getConfig()
       {
          return config;
@@ -153,7 +226,7 @@
       public void run(POMSession session)
       {
          Workspace workspace = session.getWorkspace();
-         Site site = workspace.getSite(type, name);
+         Site site = workspace.getSite(type, key.getOwnerId());
          if (site != null)
          {
             this.config = new Mapper(session).load(site);
@@ -163,7 +236,7 @@
       @Override
       public String toString()
       {
-         return "PortalConfig.Load[ownerType=" + ownerType + ",ownerId=" + name + "]";
+         return "PortalConfig.Load[ownerType=" + key.getOwnerType() + ",ownerId=" + key.getOwnerId() + "]";
       }
    }
 }

Modified: portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/data/ModelDataStorage.java
===================================================================
--- portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/data/ModelDataStorage.java	2009-10-24 08:35:40 UTC (rev 415)
+++ portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/pom/data/ModelDataStorage.java	2009-10-24 10:48:25 UTC (rev 416)
@@ -24,6 +24,7 @@
 import org.exoplatform.portal.config.Query;
 import org.exoplatform.portal.config.model.ApplicationState;
 import org.exoplatform.portal.config.model.Container;
+import org.exoplatform.portal.config.model.Dashboard;
 import org.exoplatform.portal.config.model.ModelChange;
 import org.exoplatform.portal.pom.data.PageData;
 import org.exoplatform.portal.pom.data.PortalData;
@@ -42,8 +43,6 @@
 public interface ModelDataStorage
 {
 
-   public <T extends POMTask> T execute(T task) throws Exception;
-
    public void create(PortalData config) throws Exception;
 
    public void save(PortalData config) throws Exception;
@@ -103,4 +102,8 @@
    public <T> LazyPageList<T> find(Query<T> q, Comparator<T> sortComparator) throws Exception;
 
    public Container getSharedLayout() throws Exception;
+
+   public DashboardData loadDashboard(String dashboardId) throws Exception;
+
+   public void saveDashboard(DashboardData dashboard) throws Exception;
 }
\ No newline at end of file



More information about the gatein-commits mailing list