Author: julien_viet
Date: 2009-11-03 10:40:51 -0500 (Tue, 03 Nov 2009)
New Revision: 480
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/ExecutorDispatcher.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSession.java
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/TaskExecutor.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/DataCache.java
Log:
- use the cache only when underlying session is not modified (i.e we don't put in the
shared cache data that is still transient and we don't read in the cache data that may
be transiently stale)
- debug level instead of log level for the task execution logging
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/ExecutorDispatcher.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/ExecutorDispatcher.java 2009-11-03
12:58:47 UTC (rev 479)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/ExecutorDispatcher.java 2009-11-03
15:40:51 UTC (rev 480)
@@ -29,35 +29,26 @@
{
/** . */
- private final POMSessionManager pomMgr;
-
- /** . */
private final Log log = ExoLogger.getLogger(getClass());
/** . */
private static final String[] padding = {" ", " ", "
", " "};
- public ExecutorDispatcher(POMSessionManager pomMgr)
+ public void execute(POMSession session, POMTask task) throws Exception
{
- this.pomMgr = pomMgr;
- }
-
- public <T extends POMTask> T execute(T task) throws Exception
- {
String s = task.toString();
long t0 = System.currentTimeMillis();
- pomMgr.execute(task);
+ session.execute(task);
long t1 = System.currentTimeMillis();
String t = "" + (t1 - t0);
if (t.length() < 4)
{
t = padding[t.length()] + t;
- log.info("Executed [" + t + "] " + s + "");
+ log.debug("Executed [" + t + "] " + s + "");
}
else
{
- log.info("Executed in " + t + " " + s + "");
+ log.debug("Executed in " + t + " " + s + "");
}
- return task;
}
}
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java 2009-11-03
12:58:47 UTC (rev 479)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java 2009-11-03
15:40:51 UTC (rev 480)
@@ -30,7 +30,6 @@
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;
@@ -83,83 +82,114 @@
{
this.pomMgr = pomMgr;
this.confManager_ = confManager;
- this.executor = new DataCache(cacheService, new ExecutorDispatcher(pomMgr));
+ this.executor = new DataCache(cacheService, new ExecutorDispatcher());
}
public POMSessionManager getPOMSessionManager()
{
return pomMgr;
}
+
+ /**
+ * <p>Execute the task with a session. The method attempts first to get a
current session and if no such session
+ * is found then a session will be created for the scope of the method.</p>
+ *
+ * @param task the task to execute
+ * @throws Exception any exception thrown by the task
+ */
+ private <T extends POMTask> T execute(T task) throws Exception
+ {
+ POMSession session = POMSessionManager.getSession();
+ if (session == null)
+ {
+ session = pomMgr.openSession();
+ try
+ {
+ executor.execute(session, task);
+ }
+ finally
+ {
+ pomMgr.closeSession(true);
+ }
+ }
+ else
+ {
+ session.execute(task);
+ }
+ //
+ return task;
+ }
+
public PortalData getPortalConfig(PortalKey key) throws Exception
{
- return executor.execute(new PortalConfigTask.Load(key)).getConfig();
+ return execute(new PortalConfigTask.Load(key)).getConfig();
}
public void create(PortalData config) throws Exception
{
- executor.execute(new PortalConfigTask.Save(config, true));
+ execute(new PortalConfigTask.Save(config, true));
}
public void save(PortalData config) throws Exception
{
- executor.execute(new PortalConfigTask.Save(config, true));
+ execute(new PortalConfigTask.Save(config, true));
}
public void remove(PortalData config) throws Exception
{
- executor.execute(new PortalConfigTask.Remove(config.getKey()));
+ execute(new PortalConfigTask.Remove(config.getKey()));
}
public PageData getPage(PageKey key) throws Exception
{
- return executor.execute(new PageTask.Load(key)).getPage();
+ return execute(new PageTask.Load(key)).getPage();
}
public PageData clonePage(PageKey key, PageKey cloneKey)
throws Exception
{
- return executor.execute(new PageTask.Clone(key, cloneKey, true)).getPage();
+ return execute(new PageTask.Clone(key, cloneKey, true)).getPage();
}
public void remove(PageData page) throws Exception
{
- executor.execute(new PageTask.Remove(page));
+ execute(new PageTask.Remove(page));
}
public void create(PageData page) throws Exception
{
- executor.execute(new PageTask.Save(page));
+ execute(new PageTask.Save(page));
}
public List<ModelChange> save(PageData page) throws Exception
{
- return executor.execute(new PageTask.Save(page)).getChanges();
+ return execute(new PageTask.Save(page)).getChanges();
}
public NavigationData getPageNavigation(NavigationKey key) throws Exception
{
- return executor.execute(new PageNavigationTask.Load(key)).getPageNavigation();
+ return execute(new PageNavigationTask.Load(key)).getPageNavigation();
}
public void save(NavigationData navigation) throws Exception
{
- executor.execute(new PageNavigationTask.Save(navigation, true));
+ execute(new PageNavigationTask.Save(navigation, true));
}
public void create(NavigationData navigation) throws Exception
{
- executor.execute(new PageNavigationTask.Save(navigation, false));
+ execute(new PageNavigationTask.Save(navigation, false));
}
public void remove(NavigationData navigation) throws Exception
{
- executor.execute(new PageNavigationTask.Remove(navigation));
+ execute(new PageNavigationTask.Remove(navigation));
}
public void save(PortletPreferences portletPreferences) throws Exception
{
- executor.execute(new PortletPreferencesTask.Save(portletPreferences));
+ execute(new PortletPreferencesTask.Save(portletPreferences));
}
public <S> S load(ApplicationState<S> state) throws Exception
@@ -173,7 +203,7 @@
else
{
PreferencesTask.Load<S> load = new
PreferencesTask.Load<S>((PersistentApplicationState<S>)state);
- executor.execute(load);
+ execute(load);
return load.getState();
}
}
@@ -187,14 +217,14 @@
else
{
PreferencesTask.Save<S> save = new
PreferencesTask.Save<S>((PersistentApplicationState<S>)state, preferences);
- executor.execute(save);
+ execute(save);
return state;
}
}
public PortletPreferences getPortletPreferences(String windowID) throws Exception
{
- return executor.execute(new
PortletPreferencesTask.Load(windowID)).getPreferences();
+ return execute(new PortletPreferencesTask.Load(windowID)).getPreferences();
}
public <T> LazyPageList<T> find(Query<T> q) throws Exception
@@ -207,23 +237,23 @@
Class<T> type = q.getClassType();
if (PageData.class.equals(type))
{
- return (LazyPageList<T>)executor.execute(new
SearchTask.FindPage((Query<PageData>)q)).getResult();
+ return (LazyPageList<T>)execute(new
SearchTask.FindPage((Query<PageData>)q)).getResult();
}
else if (NavigationData.class.equals(type))
{
- return (LazyPageList<T>)executor.execute(new
SearchTask.FindNavigation((Query<NavigationData>)q)).getResult();
+ return (LazyPageList<T>)execute(new
SearchTask.FindNavigation((Query<NavigationData>)q)).getResult();
}
else if (PortletPreferences.class.equals(type))
{
- return (LazyPageList<T>)executor.execute(new
SearchTask.FindPortletPreferences((Query<PortletPreferences>)q)).getResult();
+ return (LazyPageList<T>)execute(new
SearchTask.FindPortletPreferences((Query<PortletPreferences>)q)).getResult();
}
else if (PortalData.class.equals(type))
{
- return (LazyPageList<T>)executor.execute(new
SearchTask.FindSite((Query<PortalData>)q)).getResult();
+ return (LazyPageList<T>)execute(new
SearchTask.FindSite((Query<PortalData>)q)).getResult();
}
else if (PortalKey.class.equals(type) &&
"portal".equals(q.getOwnerType()))
{
- return (LazyPageList<T>)executor.execute(new
SearchTask.FindSiteKey((Query<PortalKey>)q)).getResult();
+ return (LazyPageList<T>)execute(new
SearchTask.FindSiteKey((Query<PortalKey>)q)).getResult();
}
else
{
@@ -252,12 +282,12 @@
public DashboardData loadDashboard(String dashboardId) throws Exception
{
- return executor.execute(new DashboardTask.Load(dashboardId)).getDashboard();
+ return execute(new DashboardTask.Load(dashboardId)).getDashboard();
}
public void saveDashboard(DashboardData dashboard) throws Exception
{
- executor.execute(new DashboardTask.Save(dashboard));
+ execute(new DashboardTask.Save(dashboard));
}
public Container getSharedLayout() throws Exception
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSession.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSession.java 2009-11-03
12:58:47 UTC (rev 479)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSession.java 2009-11-03
15:40:51 UTC (rev 480)
@@ -20,6 +20,7 @@
package org.exoplatform.portal.pom.config;
import org.chromattic.api.ChromatticSession;
+import org.chromattic.api.UndeclaredRepositoryException;
import org.exoplatform.portal.application.PortletPreferences;
import org.exoplatform.portal.pom.data.Mapper;
import org.gatein.mop.api.Model;
@@ -33,6 +34,7 @@
import org.gatein.mop.core.api.workspace.NavigationImpl;
import org.gatein.mop.core.api.workspace.PageImpl;
+import javax.jcr.RepositoryException;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.HashSet;
@@ -78,20 +80,31 @@
return model;
}
- /*
- public ChromatticSession getSession() {
- try {
- Model model = getModel();
- Field f = model.getClass().getDeclaredField("session");
- f.setAccessible(true);
- return (ChromatticSession)f.get(model);
- }
- catch (Exception e) {
- throw new Error(e);
- }
- }
- */
+ // julien todo : investigate how expensive is the call to hasPendingChanges method
+ public boolean isModified()
+ {
+ try
+ {
+ return getSession().getJCRSession().hasPendingChanges();
+ }
+ catch (RepositoryException e)
+ {
+ throw new UndeclaredRepositoryException(e);
+ }
+ }
+ private ChromatticSession getSession() {
+ try {
+ Model model = getModel();
+ Field f = model.getClass().getDeclaredField("session");
+ f.setAccessible(true);
+ return (ChromatticSession)f.get(model);
+ }
+ catch (Exception e) {
+ throw new Error(e);
+ }
+ }
+
public Workspace getWorkspace()
{
return getModel().getWorkspace();
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 2009-11-03
12:58:47 UTC (rev 479)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSessionManager.java 2009-11-03
15:40:51 UTC (rev 480)
@@ -287,32 +287,4 @@
return true;
}
}
-
- /**
- * <p>Execute the task with a session. The method attempts first to get a
current session and if no such session
- * is found then a session will be created for the scope of the method.</p>
- *
- * @param task the task to execute
- * @throws Exception any exception thrown by the task
- */
- public void execute(POMTask task) throws Exception
- {
- POMSession session = getSession();
- if (session == null)
- {
- session = openSession();
- try
- {
- session.execute(task);
- }
- finally
- {
- closeSession(true);
- }
- }
- else
- {
- session.execute(task);
- }
- }
}
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/TaskExecutor.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/TaskExecutor.java 2009-11-03
12:58:47 UTC (rev 479)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/TaskExecutor.java 2009-11-03
15:40:51 UTC (rev 480)
@@ -25,6 +25,6 @@
public interface TaskExecutor
{
- <T extends POMTask> T execute(T task) throws Exception;
+ void execute(POMSession session, POMTask task) throws Exception;
}
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/DataCache.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/DataCache.java 2009-11-03
12:58:47 UTC (rev 479)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/DataCache.java 2009-11-03
15:40:51 UTC (rev 480)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.portal.pom.config.cache;
+import org.exoplatform.portal.pom.config.POMSession;
import org.exoplatform.portal.pom.config.POMTask;
import org.exoplatform.portal.pom.config.TaskExecutor;
import org.exoplatform.services.cache.CacheService;
@@ -44,53 +45,59 @@
this.cache = cacheService.getCacheInstance(DataCache.class.getSimpleName());
}
- public <T extends POMTask> T execute(T task) throws Exception
+ public void execute(POMSession session, POMTask task) throws Exception
{
if (task instanceof CacheableDataTask)
{
- CacheableDataTask<?, ?> loadTask = (CacheableDataTask<?,?>)task;
- switch (loadTask.getAccessMode())
+ if (!session.isModified())
{
- 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();
-
+ CacheableDataTask<?, ?> loadTask = (CacheableDataTask<?,?>)task;
+ switch (loadTask.getAccessMode())
+ {
+ case READ:
+ read(session, loadTask);
+ break;
+ case CREATE:
+ create(session, loadTask);
+ break;
+ case WRITE:
+ write(session, loadTask);
+ break;
+ case DESTROY:
+ remove(session, loadTask);
+ break;
+ default:
+ throw new UnsupportedOperationException();
+ }
}
}
else
{
- return next.execute(task);
+ next.execute(session, task);
}
}
- private <K extends Serializable, V, T extends CacheableDataTask<K, V>> T
remove(T task) throws Exception
+ private <K extends Serializable, V> void remove(POMSession session,
CacheableDataTask<K, V> task) throws Exception
{
K key = task.getKey();
cache.remove(key);
- return next.execute(task);
+ next.execute(session, task);
}
- private <K extends Serializable, V, T extends CacheableDataTask<K, V>> T
write(T task) throws Exception
+ private <K extends Serializable, V> void write(POMSession session,
CacheableDataTask<K, V> task) throws Exception
{
K key = task.getKey();
cache.remove(key);
- return next.execute(task);
+ next.execute(session, task);
}
- private <K extends Serializable, V, T extends CacheableDataTask<K, V>> T
create(T task) throws Exception
+ private <K extends Serializable, V> void create(POMSession session,
CacheableDataTask<K, V> task) throws Exception
{
// Nothing to do for now
- return next.execute(task);
+ next.execute(session, task);
}
- private <K extends Serializable, V, T extends CacheableDataTask<K, V>> T
read(T task) throws Exception
+ private <K extends Serializable, V> void read(POMSession session,
CacheableDataTask<K, V> task) throws Exception
{
K key = task.getKey();
Object o = cache.get(key);
@@ -112,7 +119,7 @@
else
{
//
- next.execute(task);
+ next.execute(session, task);
//
v = task.getValue();
@@ -121,8 +128,5 @@
cache.put(key, v);
}
}
-
- //
- return task;
}
}