Author: julien_viet
Date: 2010-03-11 07:49:58 -0500 (Thu, 11 Mar 2010)
New Revision: 2166
Removed:
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/LoginContext.java
Modified:
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/AbstractContext.java
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/ChromatticLifeCycle.java
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/LocalContext.java
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/Synchronization.java
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/SynchronizedContext.java
portal/trunk/component/common/src/test/java/org/exoplatform/commons/chromattic/ChromatticIntegrationTestCase.java
Log:
GTNPORTAL-852 : Memory leak caused by uncleaned JCR sessions in some HTTP requests
Modified:
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/AbstractContext.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/AbstractContext.java 2010-03-11
12:45:39 UTC (rev 2165)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/AbstractContext.java 2010-03-11
12:49:58 UTC (rev 2166)
@@ -19,7 +19,10 @@
package org.exoplatform.commons.chromattic;
import org.chromattic.api.ChromatticSession;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -31,7 +34,7 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-class AbstractContext implements SessionContext
+abstract class AbstractContext implements SessionContext
{
/** . */
@@ -41,7 +44,7 @@
private Map<String, Object> attributes;
/** The related life cycle. */
- private final ChromatticLifeCycle lifeCycle;
+ final ChromatticLifeCycle lifeCycle;
/** . */
private HashSet<SynchronizationListener> listeners;
@@ -87,6 +90,20 @@
}
}
+ public abstract Session doLogin() throws RepositoryException;
+
+ /**
+ * Open and returns a session. Should be used by subclasses.
+ *
+ * @return a session
+ * @throws RepositoryException any repository exception
+ */
+ protected final Session openSession() throws RepositoryException
+ {
+ ManageableRepository repo =
lifeCycle.manager.repositoryService.getCurrentRepository();
+ return repo.getSystemSession(lifeCycle.getWorkspaceName());
+ }
+
public void close(boolean save)
{
if (listeners != null)
Modified:
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/ChromatticLifeCycle.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/ChromatticLifeCycle.java 2010-03-11
12:45:39 UTC (rev 2165)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/ChromatticLifeCycle.java 2010-03-11
12:49:58 UTC (rev 2166)
@@ -23,7 +23,6 @@
import org.exoplatform.container.component.BaseComponentPlugin;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.PropertiesParam;
-import org.exoplatform.services.jcr.core.ManageableRepository;
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
@@ -139,14 +138,14 @@
return manager;
}
- LoginContext getLoginContext()
+ AbstractContext getLoginContext()
{
Synchronization sync = manager.getSynchronization();
//
if (sync != null)
{
- return sync;
+ return sync.getContext(domainName);
}
//
@@ -304,7 +303,7 @@
Session doLogin() throws RepositoryException
{
- LoginContext loginContext = getLoginContext();
+ AbstractContext loginContext = getLoginContext();
//
if (loginContext == null)
@@ -313,16 +312,7 @@
}
//
- ManageableRepository repo = manager.repositoryService.getCurrentRepository();
-
- //
- Session session = repo.getSystemSession(workspaceName);
-
- //
- loginContext.loggedIn(session);
-
- //
- return session;
+ return loginContext.doLogin();
}
public final void start() throws Exception
Modified:
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/LocalContext.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/LocalContext.java 2010-03-11
12:45:39 UTC (rev 2165)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/LocalContext.java 2010-03-11
12:49:58 UTC (rev 2166)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.commons.chromattic;
+import javax.jcr.RepositoryException;
import javax.jcr.Session;
/**
@@ -26,7 +27,7 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-class LocalContext extends AbstractContext implements LoginContext
+class LocalContext extends AbstractContext
{
/** The related JCR session. */
@@ -37,9 +38,14 @@
super(configurator);
}
- public void loggedIn(Session session)
+ public Session doLogin() throws RepositoryException
{
- this.jcrSession = session;
+ if (jcrSession != null)
+ {
+ throw new IllegalStateException("Already logged in");
+ }
+ jcrSession = openSession();
+ return jcrSession;
}
@Override
Deleted:
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/LoginContext.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/LoginContext.java 2010-03-11
12:45:39 UTC (rev 2165)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/LoginContext.java 2010-03-11
12:49:58 UTC (rev 2166)
@@ -1,36 +0,0 @@
-/**
- * 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.chromattic;
-
-import javax.jcr.Session;
-
-/**
- * Allows the implementor to be aware of external session life cycle management.
- *
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
- * @version $Revision$
- */
-interface LoginContext
-{
-
- void loggedIn(Session session);
-
- void close(boolean save);
-
-}
Modified:
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/Synchronization.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/Synchronization.java 2010-03-11
12:45:39 UTC (rev 2165)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/Synchronization.java 2010-03-11
12:49:58 UTC (rev 2166)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.commons.chromattic;
+import javax.jcr.RepositoryException;
import javax.jcr.Session;
import java.util.HashMap;
import java.util.Map;
@@ -28,7 +29,7 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-public class Synchronization implements LoginContext
+public class Synchronization
{
/** The sessions mapped by workspace name. */
@@ -80,9 +81,24 @@
return context;
}
- public void loggedIn(Session session)
+ public Session doLogin(SynchronizedContext ctx) throws RepositoryException
{
- repositorySessions.put(session.getWorkspace().getName(), session);
+ if (ctx == null)
+ {
+ throw new NullPointerException();
+ }
+ if (ctx.synchronization != this)
+ {
+ throw new IllegalArgumentException();
+ }
+ String workspaceName = ctx.lifeCycle.getWorkspaceName();
+ Session session = repositorySessions.get(workspaceName);
+ if (session == null)
+ {
+ session = ctx.openSession();
+ repositorySessions.put(workspaceName, session);
+ }
+ return session;
}
public void close(boolean save)
Modified:
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/SynchronizedContext.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/SynchronizedContext.java 2010-03-11
12:45:39 UTC (rev 2165)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/SynchronizedContext.java 2010-03-11
12:49:58 UTC (rev 2166)
@@ -18,6 +18,9 @@
*/
package org.exoplatform.commons.chromattic;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
/**
* The synchronized context is associated with a {@link
org.exoplatform.commons.chromattic.Synchronization} object.
*
@@ -37,4 +40,9 @@
//
this.synchronization = synchronization;
}
+
+ public Session doLogin() throws RepositoryException
+ {
+ return synchronization.doLogin(this);
+ }
}
Modified:
portal/trunk/component/common/src/test/java/org/exoplatform/commons/chromattic/ChromatticIntegrationTestCase.java
===================================================================
---
portal/trunk/component/common/src/test/java/org/exoplatform/commons/chromattic/ChromatticIntegrationTestCase.java 2010-03-11
12:45:39 UTC (rev 2165)
+++
portal/trunk/component/common/src/test/java/org/exoplatform/commons/chromattic/ChromatticIntegrationTestCase.java 2010-03-11
12:49:58 UTC (rev 2166)
@@ -237,17 +237,12 @@
}
public void testTwoLifeCycleWithSameRepository() {
-/*
chromatticManager.beginRequest();
-
SessionContext ctx1 = test1LF.openContext();
Session session1 = ctx1.getSession().getJCRSession();
SessionContext ctx2 = test2LF.openContext();
Session session2 = ctx2.getSession().getJCRSession();
-// assertSame(session1, session2);
-
+ assertSame(session1, session2);
chromatticManager.endRequest(false);
-*/
}
-
}