Author: mmillson
Date: 2008-03-06 12:42:20 -0500 (Thu, 06 Mar 2008)
New Revision: 10234
Modified:
branches/JBoss_Portal_2_6_1_JBPORTAL-1942/core/src/main/org/jboss/portal/core/aspects/server/UserInterceptor.java
Log:
Fix Hibernate/JBoss Cache locking for [JBPORTAL-1942].
Modified:
branches/JBoss_Portal_2_6_1_JBPORTAL-1942/core/src/main/org/jboss/portal/core/aspects/server/UserInterceptor.java
===================================================================
---
branches/JBoss_Portal_2_6_1_JBPORTAL-1942/core/src/main/org/jboss/portal/core/aspects/server/UserInterceptor.java 2008-03-06
16:26:41 UTC (rev 10233)
+++
branches/JBoss_Portal_2_6_1_JBPORTAL-1942/core/src/main/org/jboss/portal/core/aspects/server/UserInterceptor.java 2008-03-06
17:42:20 UTC (rev 10234)
@@ -23,8 +23,8 @@
package org.jboss.portal.core.aspects.server;
import org.jboss.logging.Logger;
+import org.jboss.portal.common.invocation.AttributeResolver;
import org.jboss.portal.common.invocation.InvocationException;
-import org.jboss.portal.common.invocation.AttributeResolver;
import org.jboss.portal.core.CoreConstants;
import org.jboss.portal.identity.CachedUserImpl;
import org.jboss.portal.identity.NoSuchUserException;
@@ -41,11 +41,13 @@
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
+import javax.transaction.UserTransaction;
+import javax.transaction.Transaction;
import java.io.Serializable;
import java.security.Principal;
import java.util.Date;
+import java.util.HashMap;
import java.util.Map;
-import java.util.HashMap;
/**
* The interceptor is responsible for managing the user identity lifecycle based on the
principal name returned by the
@@ -132,7 +134,6 @@
User user = null;
Map profile = null;
-
// Fetch user if we can
if (userPrincipal != null)
{
@@ -240,7 +241,7 @@
}
try
- {
+ {
// Continue the invocation
invocation.invokeNext();
}
@@ -297,50 +298,85 @@
}
catch (Exception e)
{
- log.error("Cannot finalize user " + userId, e);
+ log.warn("Cannot set last login date for user with id '" +
userId + "' : " + e.getMessage());
+ log.debug("Failed to set user last login date (may happen during server
shutdown): ", e);
}
}
protected void finalizeUser() throws Exception
- {
- //
- if (log.isTraceEnabled())
+ {
+ /**
+ * Note: Due to a possible bug in JBoss Cache Transaction propagation within a
cluster,
+ * We need to spawn a separate thread with its own new transaction to perform
the finalizeUser
+ * logic.
+ *
+ * Without that, it results in data deadlocks in the cluster.
+ */
+ Thread thread = new Thread(new FinalizeRunner());
+ thread.start();
+ thread.join();
+ }
+
+ /**
+ *
+ * @author soshah
+ *
+ */
+ private class FinalizeRunner implements Runnable
+ {
+ public void run()
{
- log.trace("Finalizing user " + userId);
- }
-
- //
- // Here we use JNDI to locate the module as this finalizer could have been
- // migrated in the session of another node of the cluster
- UserModule userModule = null;
- UserProfileModule userProfileModule = null;
-
- try
- {
- userModule = (UserModule)new
InitialContext().lookup("java:portal/UserModule");
- userProfileModule = (UserProfileModule)new
InitialContext().lookup("java:portal/UserProfileModule");
- }
- catch (NameNotFoundException ignore)
- {
- // Name is not bound anymore, it could happen during a shutdown, we don't
do anything
- }
-
- // Get user and set last visit date to now if we can
- if (userModule != null && userProfileModule != null)
- {
+ UserTransaction tx = null;
try
{
- User user = userModule.findUserById(userId);
- //user.setLastVisitDate(new Date());
- userProfileModule.setProperty(user, User.INFO_USER_LAST_LOGIN_DATE, new
Date().toString());
-
+ //
+ if (log.isTraceEnabled())
+ {
+ log.trace("Finalizing user " + userId);
+ }
+
+ //
+ // Here we use JNDI to locate the module as this finalizer could have
been
+ // migrated in the session of another node of the cluster
+ UserModule userModule = null;
+ UserProfileModule userProfileModule = null;
+ InitialContext ctx = new InitialContext();
+ tx = (UserTransaction)ctx.lookup("UserTransaction");
+ tx.begin();
+ try
+ {
+ userModule = (UserModule)new
InitialContext().lookup("java:portal/UserModule");
+ userProfileModule = (UserProfileModule)new
InitialContext().lookup("java:portal/UserProfileModule");
+ }
+ catch (NameNotFoundException ignore)
+ {
+ // Name is not bound anymore, it could happen during a shutdown, we
don't do anything
+ }
+
+ // Get user and set last visit date to now if we can
+ if (userModule != null && userProfileModule != null)
+ {
+ try
+ {
+ User user = userModule.findUserById(userId);
+ //user.setLastVisitDate(new Date());
+ userProfileModule.setProperty(user, User.INFO_USER_LAST_LOGIN_DATE,
new Date().toString());
+
+ }
+ catch (NoSuchUserException e)
+ {
+ // User is not found
+ log.warn("Trying to finalize non existing user " +
userId);
+ }
+ }
+ tx.commit();
}
- catch (NoSuchUserException e)
+ catch(Exception e)
{
- // User is not found
- log.warn("Trying to finalize non existing user " + userId);
- }
+ try{tx.rollback();}catch(Exception rbe){}
+ log.debug(this, e);
+ }
}
}
- }
+ }
}
Show replies by date