[jboss-cvs] JBossAS SVN: r107234 - projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/sso.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jul 30 09:30:02 EDT 2010
Author: smarlow at redhat.com
Date: 2010-07-30 09:30:01 -0400 (Fri, 30 Jul 2010)
New Revision: 107234
Modified:
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/sso/SSOClusterManagerImpl.java
Log:
JBCLUSTER-286 more cleanup
Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/sso/SSOClusterManagerImpl.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/sso/SSOClusterManagerImpl.java 2010-07-30 13:01:30 UTC (rev 107233)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/sso/SSOClusterManagerImpl.java 2010-07-30 13:30:01 UTC (rev 107234)
@@ -45,11 +45,12 @@
import javax.management.ObjectName;
import javax.transaction.Status;
import javax.transaction.TransactionManager;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
- * An implementation of SSOClusterManager that uses a TreeCache
+ * An implementation of SSOClusterManager that uses a Infinispan cache
* to share SSO information between cluster nodes.
*
* @author Brian E. Stansberry
@@ -86,13 +87,7 @@
*/
private volatile ThreadLocal<String> beingRemotelyRemoved = new ThreadLocal<String>();
-
/**
- * ObjectName of the TreeCache if legacy JMX integration is used
- */
- //private ObjectName cacheObjectName = null;
-
- /**
* The clustered cache that holds the SSO credentials and the sessions.
* The CacheKey will indicate which type it is (CacheKey.CREDENTIAL or CacheKey.SESSION);
*/
@@ -113,7 +108,7 @@
private static final Logger log = Logger.getLogger(SSOClusterManagerImpl.class);;
/**
- * Whether we are registered as a TreeCacheListener anywhere
+ * Whether we are registered as a CacheListener anywhere
*/
private volatile boolean registeredAsListener = false;
@@ -142,11 +137,8 @@
*/
private volatile Object localAddress = null;
- private volatile boolean masterNode = false;
-
/**
* The new members of the last view passed to viewChange()
- * TODO: figure out how to get cluster view members at startup time
*/
private final Set<Object> currentView = new HashSet<Object>();;
@@ -206,7 +198,7 @@
boolean doTx = false;
try
{
- // Confirm we have a transaction manager; if not get it from TreeCache
+ // Confirm we have a transaction manager; if not get it from Cache
// failure to find will throw an IllegalStateException
if (tm == null)
configureFromCache();
@@ -408,7 +400,7 @@
boolean removing = false;
try
{
- // Confirm we have a transaction manager; if not get it from TreeCache
+ // Confirm we have a transaction manager; if not get it from Cache
// failure to find will throw an IllegalStateException
if (tm == null)
configureFromCache();
@@ -487,16 +479,16 @@
// ------------------------------------------------------ CacheListener
/**
- * Extracts an SSO session id from the Fqn and uses it in an invocation of
+ * Extracts an SSO session id and uses it in an invocation of
* {@link ClusteredSingleSignOn#deregister(String) ClusteredSingleSignOn.deregister(String)}.
* <p/>
- * Ignores invocations resulting from TreeCache changes originated by
+ * Ignores invocations resulting from Cache changes originated by
* this object.
*
* @param event
*/
@CacheEntryRemoved
- public void entryRemoved(CacheEntryRemovedEvent event)
+ public void cacheEntryRemoved(CacheEntryRemovedEvent event)
{
if (event.isPre())
return;
@@ -512,12 +504,13 @@
// Entire SSO is being removed; i.e. an invalidation
// Ignore messages generated by our own logout activity
+ // TODO: can we check event.isOriginLocal instead of beingLocallyRemoved?
if (!ssoId.equals(beingLocallyRemoved.get()))
{
- handleRemoteInvalidation(ssoId);
+ deregisterSSO(ssoId);
}
// signal the case that we have zero sessions for this ssoId
- handlePeerRemoval(ssoId);
+ notifySSOEmpty(ssoId);
}
/**
@@ -531,7 +524,7 @@
public void viewChange(ViewChangedEvent event)
{
log.debug("Received ViewChangedEvent " + event);
-
+ boolean masterNode = false; // true if we are the first node in the cluster group.
Set<Object> oldMembers = new HashSet<Object>(event.getOldMembers());
synchronized (currentView)
{
@@ -547,17 +540,16 @@
{
masterNode = true;
}
- else
- {
- masterNode = false;
- }
// Remove all the current members from the old set; any left
// are the dead members
oldMembers.removeAll(currentView);
}
- if (oldMembers.size() > 0)
+ /**
+ * if we are the master node, clean up any dead sessions left behind from a node that left the cluster group
+ */
+ if (oldMembers.size() > 0 && masterNode)
{
log.debug("Members have been removed; will launch cleanup task. Dead members: " + oldMembers);
@@ -574,6 +566,7 @@
*/
private void launchSSOCleaner(boolean notifyIfEmpty)
{
+
SSOCleanerTask cleaner = new SSOCleanerTask(notifyIfEmpty);
if (threadPool != null)
{
@@ -593,7 +586,7 @@
*
* @param ssoId id of the removed SSO
*/
- private void handleRemoteInvalidation(String ssoId)
+ private void deregisterSSO(String ssoId)
{
beingRemotelyRemoved.set(ssoId);
@@ -618,12 +611,11 @@
*
* @param ssoId
*/
- private void handlePeerRemoval(String ssoId)
+ private void notifySSOEmpty(String ssoId)
{
try
{
- Set<FullyQualifiedSessionId> peers = getSSOSessions(ssoId);
- if (peers.size() == 0)
+ if (getSSOSessions(ssoId).size() == 0)
{
ssoValve.notifySSOEmpty(ssoId);
}
@@ -635,13 +627,10 @@
}
/**
- * Extracts an SSO session id from the Fqn and uses it in an invocation of
+ * Extracts an SSO session id and uses it in an invocation of
* {@link ClusteredSingleSignOn#update ClusteredSingleSignOn.update()}.
* <p/>
- * Only responds to modifications of nodes whose FQN's final segment is
- * "credentials".
- * <p/>
- * Ignores invocations resulting from TreeCache changes originated by
+ * Ignores invocations resulting from Cache changes originated by
* this object.
* <p/>
* Ignores invocations for SSO session id's that are not registered
@@ -650,7 +639,7 @@
* @param event
*/
@CacheEntryModified
- public void nodeModified(CacheEntryModifiedEvent event)
+ public void cacheEntryModified(CacheEntryModifiedEvent event)
{
if (event.isPre() || event.isOriginLocal())
return;
@@ -658,11 +647,11 @@
CacheKey key = (CacheKey)event.getKey();
if (key.getType() == CacheKey.Type.CREDENTIAL)
{
- handleCredentialUpdate(key.getSSOID(), (SSOCredentials)event.getValue());
+ handleCredentialModifiedEvent(key.getSSOID(), (SSOCredentials)event.getValue());
}
else if (key.getType() == CacheKey.Type.SESSION)
{
- handleSessionSetChange(key.getSSOID());
+ handleSessionModifiedEvent(key.getSSOID());
}
}
@@ -670,9 +659,10 @@
* @param ssoId the id of the sso
* @param credentials
*/
- private void handleCredentialUpdate(String ssoId,SSOCredentials credentials)
+ private void handleCredentialModifiedEvent(String ssoId,SSOCredentials credentials)
{
// Ignore invocations that come as a result of our additions
+ // TODO: can this local check be removed since we already ignore local events in caller
if (ssoId.equals(beingLocallyAdded.get()))
{
return;
@@ -700,7 +690,7 @@
*
* @param ssoId single sign-on session id
*/
- private void handleSessionSetChange(String ssoId)
+ private void handleSessionModifiedEvent(String ssoId)
{
// Peers remove their entire node when it's empty, so any
// other modification means it's not empty
@@ -795,12 +785,12 @@
{
CacheKey key = new CacheKey(ssoId,CacheKey.Type.SESSION);
AtomicMap m = AtomicMapLookup.getAtomicMap(cache, key, true);
- return m.keySet();
+ return m!=null ? m.keySet() : Collections.EMPTY_SET;
}
/**
- * Obtains needed configuration information from the tree cache.
- * Invokes "getTransactionManager" on the tree cache, caching the
+ * Obtains needed configuration information from the cache.
+ * Invokes "getTransactionManager" on the cache, caching the
* result or throwing an IllegalStateException if one is not found.
* Also gets our cluster-wide unique local address from the cache.
*
@@ -918,8 +908,7 @@
}
/**
- * Invokes an operation on the JMX server to register ourself as a
- * listener on the TreeCache service.
+ * register as a cache listener.
*
* @throws Exception
*/
@@ -931,8 +920,7 @@
/**
- * Invokes an operation on the JMX server to register ourself as a
- * listener on the TreeCache service.
+ * stop listening on the cache.
*
* @throws Exception
*/
@@ -955,6 +943,8 @@
{
CacheKey key = new CacheKey(ssoId,CacheKey.Type.SESSION);
cache.remove(key);
+ key = new CacheKey(ssoId,CacheKey.Type.CREDENTIAL);
+ cache.remove(key); // remove user credentials too
}
/**
@@ -997,7 +987,7 @@
}
catch (Exception e)
{
- log.error("Exception attempting to add TreeCache nodes for SSO " +
+ log.error("Exception attempting to add Cache nodes for SSO " +
ssoId, e);
}
finally
@@ -1081,19 +1071,15 @@
{
try
{
- // only do this clean up work on the master node (instead of burning cycles on every node)
- if (masterNode)
- {
- log.debug("check if we have to clean up SSO for any members that left the cluster.");
- // Ensure we have a TransactionManager
- if (tm == null)
- configureFromCache();
+ log.debug("check if we have to clean up SSO for any members that left the cluster.");
+ // Ensure we have a TransactionManager
+ if (tm == null)
+ configureFromCache();
- Set<String> ids = getSSOIds();
- for (String sso : ids)
- {
- cleanSSO(sso);
- }
+ Set<String> ids = getSSOIds();
+ for (String sso : ids)
+ {
+ cleanSSO(sso);
}
}
catch (Exception e)
@@ -1116,7 +1102,7 @@
tm.begin();
Set<FullyQualifiedSessionId> fullyQualifiedSessionIds = getSSOSessions(ssoId);
- if (fullyQualifiedSessionIds != null && fullyQualifiedSessionIds.size() > 0)
+ if (fullyQualifiedSessionIds.size() > 0)
{
for (FullyQualifiedSessionId fullyQualifiedSessionId : fullyQualifiedSessionIds)
{
More information about the jboss-cvs-commits
mailing list