Author: nfilotto
Date: 2011-03-17 07:52:36 -0400 (Thu, 17 Mar 2011)
New Revision: 4105
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionImpl.java
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/configuration/exo-jcr-configuration.xml
Log:
EXOJCR-1254: Add a mode that throws an Exception when we use a session that is not alive
anymore.
To enable the mode simply set the system property exo.jcr.prohibit.closed.session.usage to
true
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionImpl.java 2011-03-17
10:14:45 UTC (rev 4104)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionImpl.java 2011-03-17
11:52:36 UTC (rev 4105)
@@ -108,6 +108,19 @@
*/
private static Log log =
ExoLogger.getLogger("exo.jcr.component.core.SessionImpl");
+ /**
+ * Indicates if it must fail in case we use a closed session.
+ */
+ private static final boolean PROHIBIT_CLOSED_SESSION_USAGE =
+
Boolean.valueOf(PropertyManager.getProperty("exo.jcr.prohibit.closed.session.usage"));
+ static
+ {
+ if (PROHIBIT_CLOSED_SESSION_USAGE)
+ {
+ log.info("The JCR will throw an exception anytime we will try to use a dead
session.");
+ }
+ }
+
public static final int DEFAULT_LAZY_READ_THRESHOLD = 100;
private final RepositoryImpl repository;
@@ -135,6 +148,8 @@
protected final String workspaceName;
private boolean live;
+
+ private Exception closedByCallStack;
private final List<SessionLifecycleListener> lifecycleListeners;
@@ -877,13 +892,17 @@
{
if (!live)
{
+ if (PROHIBIT_CLOSED_SESSION_USAGE)
+ {
+ throw new RepositoryException("This kind of operation is forbidden after
a session.logout().", closedByCallStack);
+ }
// warn in debug mode only
- if (PropertyManager.isDevelopping())
+ else if (PropertyManager.isDevelopping())
{
log
.warn(
"This kind of operation is forbidden after a session.logout(),
please note that an exception will be raised in the next jcr version.",
- new Exception());
+ new Exception(closedByCallStack));
}
}
}
@@ -917,6 +936,10 @@
}
this.sessionRegistry.unregisterSession(getId());
this.live = false;
+ if (PROHIBIT_CLOSED_SESSION_USAGE || PropertyManager.isDevelopping())
+ {
+ this.closedByCallStack = new Exception("The session has been closed by the
following call stack");
+ }
}
/**
Modified:
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/configuration/exo-jcr-configuration.xml
===================================================================
---
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/configuration/exo-jcr-configuration.xml 2011-03-17
10:14:45 UTC (rev 4104)
+++
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/configuration/exo-jcr-configuration.xml 2011-03-17
11:52:36 UTC (rev 4105)
@@ -434,4 +434,42 @@
<!ELEMENT properties (property+)>
<!ELEMENT property EMPTY></programlisting>
</section>
+
+ <section>
+ <title>Help application to prohibit the use of closed sessions</title>
+
+ <para>Products that use eXo JCR, sometimes missuse it since they continue
+ to use a session that has been closed through a method call on a node, a
+ property or even the session itself. To prevent bad practices we propose
+ three modes which are the folllowing:</para>
+
+ <orderedlist>
+ <listitem>
+ <para>If the system property
+ <emphasis>exo.jcr.prohibit.closed.session.usage</emphasis> has been
+ set to <emphasis>true</emphasis>, then a RepositoryException will be
+ thrown any time an application will try to access to a closed session.
+ In the stack trace, you will be able to know the call stack that
+ closes the session.</para>
+ </listitem>
+
+ <listitem>
+ <para>If the system property
+ <emphasis>exo.jcr.prohibit.closed.session.usage</emphasis> has not
+ been set and the system property
+ <emphasis>exo.product.developing</emphasis> has been set to
+ <emphasis>true</emphasis>, then a warning will be logged in the log
+ file with the full stack trace in order to help identifying the root
+ cause of the issue. In the stack trace, you will be able to know the
+ call stack that closes the session.</para>
+ </listitem>
+
+ <listitem>
+ <para>If none of the previous system properties have been set, then we
+ will ignore that the issue and let the application use the closed
+ session as it was possible before without doing anything in order to
+ allow applications to migrate step by step.</para>
+ </listitem>
+ </orderedlist>
+ </section>
</chapter>
Show replies by date