[exo-jcr-commits] exo-jcr SVN: r1452 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl: dataflow/session and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Sun Jan 17 08:19:54 EST 2010
Author: pnedonosko
Date: 2010-01-17 08:19:54 -0500 (Sun, 17 Jan 2010)
New Revision: 1452
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionFactory.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableResourceManager.java
Log:
EXOJCR-405 XASessionImpl enlistResource lifecycle rework, cleanup
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionFactory.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionFactory.java 2010-01-17 13:17:52 UTC (rev 1451)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionFactory.java 2010-01-17 13:19:54 UTC (rev 1452)
@@ -41,23 +41,22 @@
public class SessionFactory
{
- protected static Log log = ExoLogger.getLogger("jcr.SessionFactory");
+ protected static Log LOG = ExoLogger.getLogger("jcr.SessionFactory");
- // private OrganizationService organizationService;
+ private final ExoContainer container;
- private ExoContainer container;
+ private final TransactionService tService;
- private TransactionService tService;
+ private final String workspaceName;
- private String workspaceName;
+ private final TransactionableResourceManager txResourceManager;
- private TransactionableResourceManager txResourceManager = null;
-
/**
- * @param orgService
- * @param tService
- * @param config
- * @param containerContext
+ * JCR Session factory.
+ *
+ * @param tService TransactionService
+ * @param config WorkspaceEntry
+ * @param containerContext ExoContainerContext
*/
public SessionFactory(TransactionService tService, WorkspaceEntry config, ExoContainerContext containerContext)
{
@@ -67,7 +66,6 @@
this.tService = tService;
this.txResourceManager = new TransactionableResourceManager();
- //
boolean tracking = "true".equalsIgnoreCase(System.getProperty("exo.jcr.session.tracking.active", "false"));
if (tracking)
{
@@ -103,9 +101,10 @@
}
/**
- * @param orgService
- * @param config
- * @param containerContext
+ * JCR Session factory.
+ *
+ * @param config WorkspaceEntry
+ * @param containerContext ExoContainerContext
*/
public SessionFactory(WorkspaceEntry config, ExoContainerContext containerContext)
{
@@ -121,10 +120,6 @@
*/
SessionImpl createSession(ConversationState user) throws RepositoryException, LoginException
{
-
- // Check privilegies to access workspace first?
- // ....
-
if (tService == null)
{
if (SessionReference.isStarted())
@@ -137,26 +132,14 @@
}
}
- XASessionImpl xaSession;
if (SessionReference.isStarted())
{
- xaSession = new TrackedXASession(workspaceName, user, container, tService, txResourceManager);
+ return new TrackedXASession(workspaceName, user, container, tService, txResourceManager);
}
else
{
- xaSession = new XASessionImpl(workspaceName, user, container, tService, txResourceManager);
+ return new XASessionImpl(workspaceName, user, container, tService, txResourceManager);
}
-
- try
- {
- xaSession.enlistResource();
-
- }
- catch (XAException e)
- {
- throw new RepositoryException(e);
- }
- return xaSession;
}
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java 2010-01-17 13:17:52 UTC (rev 1451)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java 2010-01-17 13:19:54 UTC (rev 1452)
@@ -97,7 +97,16 @@
this.txTimeout = tService.getDefaultTimeout();
this.tService = tService;
this.txResourceManager = txResourceManager;
- this.txResourceManager.add(this);
+
+ // enlist on login instead of this.txResourceManager.add(this);
+ try
+ {
+ this.enlistResource();
+ }
+ catch (XAException e)
+ {
+ throw new RepositoryException(e);
+ }
}
/**
@@ -117,7 +126,10 @@
try
{
if (LOG.isDebugEnabled())
+ {
LOG.debug("Delist session: " + getSessionInfo() + ", " + this);
+ }
+
txResourceManager.remove(this);
tService.delistResource(this);
}
@@ -136,12 +148,14 @@
*/
public void enlistResource() throws XAException
{
-
// TODO if session is dead? can we enlist it?
try
{
if (LOG.isDebugEnabled())
+ {
LOG.debug("Enlist session: " + getSessionInfo() + ", " + this);
+ }
+
txResourceManager.add(this);
tService.enlistResource(this);
}
@@ -170,7 +184,9 @@
}
if (LOG.isDebugEnabled())
+ {
LOG.debug("Commit. Xid:" + xid + ", session: " + getSessionInfo() + ", " + this);
+ }
}
/**
@@ -179,7 +195,10 @@
public void end(Xid xid, int flags) throws XAException
{
if (LOG.isDebugEnabled())
+ {
LOG.debug("End. Xid:" + xid + ", " + flags + ", session: " + getSessionInfo() + ", " + this);
+ }
+
startFlags = flags;
}
@@ -208,8 +227,10 @@
XASessionImpl session = (XASessionImpl)resource;
boolean isSame = getUserID().equals(session.getUserID());
if (LOG.isDebugEnabled())
+ {
LOG.debug("isSameRM: " + getSessionInfo() + " -- " + session.getSessionInfo() + " : " + isSame + ", "
+ this + " -- " + session + ", Flags:" + startFlags);
+ }
return isSame;
}
return false;
@@ -221,7 +242,10 @@
public int prepare(Xid xid) throws XAException
{
if (LOG.isDebugEnabled())
+ {
LOG.debug("Prepare. Xid:" + xid + ", session: " + getSessionInfo() + ", " + this);
+ }
+
return XA_OK;
}
@@ -239,8 +263,11 @@
public void rollback(Xid xid) throws XAException
{
txResourceManager.rollback(this);
+
if (LOG.isDebugEnabled())
+ {
LOG.debug("Rollback. Xid:" + xid + ", session: " + getSessionInfo() + ", " + this);
+ }
}
/**
@@ -267,8 +294,11 @@
{
txResourceManager.start(this);
startFlags = flags;
+
if (LOG.isDebugEnabled())
+ {
LOG.debug("Start. Xid:" + xid + ", " + flags + ", session: " + getSessionInfo() + ", " + this);
+ }
}
/**
@@ -278,23 +308,30 @@
public void logout()
{
if (LOG.isDebugEnabled())
+ {
LOG.debug("Logout. Session: " + getSessionInfo() + ", " + this);
+ }
- // Rolling back this session only
- getTransientNodesManager().getTransactManager().rollback();
-
- // Remove session from this user sessions list
- txResourceManager.remove(this);
-
- super.logout();
try
{
- delistResource();
- startFlags = TMNOFLAGS;
+ // Rolling back this session only
+ getTransientNodesManager().getTransactManager().rollback();
+
+ super.logout();
}
- catch (XAException e)
+ finally
{
- LOG.error("Logut error " + e, e);
+ // Delist and remove session from this user sessions list in TransactionableDataManager
+ // txResourceManager.remove(this) will be called in delistResource()
+ try
+ {
+ delistResource();
+ startFlags = TMNOFLAGS;
+ }
+ catch (XAException e)
+ {
+ LOG.error("Logut error " + e, e);
+ }
}
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableResourceManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableResourceManager.java 2010-01-17 13:17:52 UTC (rev 1451)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableResourceManager.java 2010-01-17 13:19:54 UTC (rev 1452)
@@ -50,7 +50,7 @@
/**
* XASessions involved in transaction. Sessions stored by userId.
*/
- private Map<String, List<SoftReference<XASessionImpl>>> txManagers =
+ private Map<String, List<SoftReference<XASessionImpl>>> txResources =
new HashMap<String, List<SoftReference<XASessionImpl>>>();
/**
@@ -68,7 +68,7 @@
*/
synchronized public void add(XASessionImpl userSession)
{
- final List<SoftReference<XASessionImpl>> joinedList = txManagers.get(userSession.getUserID());
+ final List<SoftReference<XASessionImpl>> joinedList = txResources.get(userSession.getUserID());
if (joinedList != null)
{
// remove unused session from user list and put this list at the end
@@ -94,9 +94,13 @@
final List<SoftReference<XASessionImpl>> newJoinedList = new ArrayList<SoftReference<XASessionImpl>>();
final List<SoftReference<XASessionImpl>> previous = putIfAbsent(userSession.getUserID(), newJoinedList);
if (previous != null)
+ {
previous.add(new SoftReference<XASessionImpl>(userSession));
+ }
else
+ {
newJoinedList.add(new SoftReference<XASessionImpl>(userSession));
+ }
}
}
@@ -108,7 +112,7 @@
*/
synchronized public void remove(XASessionImpl userSession)
{
- final List<SoftReference<XASessionImpl>> joinedList = txManagers.get(userSession.getUserID());
+ final List<SoftReference<XASessionImpl>> joinedList = txResources.get(userSession.getUserID());
if (joinedList != null)
{
// traverse and remove unused sessions and given one
@@ -124,7 +128,9 @@
// if list is empty - remove mapping to the list
if (joinedList.size() <= 0)
- txManagers.remove(userSession.getUserID());
+ {
+ txResources.remove(userSession.getUserID());
+ }
}
}
@@ -138,8 +144,9 @@
*/
synchronized public void commit(XASessionImpl userSession) throws TransactionException
{
- List<SoftReference<XASessionImpl>> joinedList = txManagers.remove(userSession.getUserID());
+ List<SoftReference<XASessionImpl>> joinedList = txResources.remove(userSession.getUserID());
if (joinedList != null)
+ {
for (SoftReference<XASessionImpl> sr : joinedList)
{
XASessionImpl xaSession = sr.get();
@@ -149,9 +156,51 @@
txManager.commit();
}
}
+ }
}
/**
+ * TODO proposal
+ * @param userSession
+ * @throws TransactionException
+ */
+ private void commit1(XASessionImpl userSession) throws TransactionException
+ {
+ List<XASessionImpl> xaSessions = null;
+ synchronized (this)
+ {
+ List<SoftReference<XASessionImpl>> joinedList = txResources.remove(userSession.getUserID());
+ if (joinedList != null)
+ for (SoftReference<XASessionImpl> sr : joinedList)
+ {
+ XASessionImpl xaSession = sr.get();
+ if (xaSession != null)
+ {
+ if (xaSessions == null)
+ {
+ xaSessions = new ArrayList<XASessionImpl>();
+ }
+ xaSessions.add(xaSession);
+ }
+ }
+ }
+ if (xaSessions != null)
+ {
+ for (XASessionImpl xaSession : xaSessions)
+ {
+ synchronized (xaSession)
+ {
+ if (xaSession.isLive())
+ {
+ TransactionableDataManager txManager = xaSession.getTransientNodesManager().getTransactManager();
+ txManager.commit();
+ }
+ }
+ }
+ }
+ }
+
+ /**
* Start transaction on all sessions.
*
* @param userSession
@@ -159,8 +208,9 @@
*/
synchronized public void start(XASessionImpl userSession)
{
- List<SoftReference<XASessionImpl>> joinedList = txManagers.get(userSession.getUserID());
+ List<SoftReference<XASessionImpl>> joinedList = txResources.get(userSession.getUserID());
if (joinedList != null)
+ {
for (SoftReference<XASessionImpl> sr : joinedList)
{
XASessionImpl xaSession = sr.get();
@@ -170,6 +220,7 @@
txManager.start();
}
}
+ }
}
/**
@@ -180,8 +231,9 @@
*/
synchronized public void rollback(XASessionImpl userSession)
{
- List<SoftReference<XASessionImpl>> joinedList = txManagers.remove(userSession.getUserID());
+ List<SoftReference<XASessionImpl>> joinedList = txResources.remove(userSession.getUserID());
if (joinedList != null)
+ {
for (SoftReference<XASessionImpl> sr : joinedList)
{
XASessionImpl xaSession = sr.get();
@@ -191,17 +243,18 @@
txManager.rollback();
}
}
+ }
}
private List<SoftReference<XASessionImpl>> putIfAbsent(String key, List<SoftReference<XASessionImpl>> value)
{
- if (!txManagers.containsKey(key))
+ if (!txResources.containsKey(key))
{
- return txManagers.put(key, value);
+ return txResources.put(key, value);
}
else
{
- return txManagers.get(key);
+ return txResources.get(key);
}
}
More information about the exo-jcr-commits
mailing list