[jboss-cvs] JBossAS SVN: r107399 - in projects/cluster/ha-server-cache-ispn/trunk/src: test/java/org/jboss/web/tomcat/service and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Aug 4 17:17:28 EDT 2010
Author: pferraro
Date: 2010-08-04 17:17:27 -0400 (Wed, 04 Aug 2010)
New Revision: 107399
Added:
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/AbstractSSOKey.java
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/CredentialKey.java
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/SSOKey.java
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/SessionKey.java
projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/sso/
projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/sso/ispn/
projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/sso/ispn/SSOClusterManagerTest.java
Removed:
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/CacheKey.java
projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/sso/ispn/SSOClusterManagerTest.java
Modified:
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/SSOClusterManager.java
Log:
Refactor CacheKey into subclasses - resulting key is smaller. Utilize subclasses to handle cache casting.
Refactor SSOClusterManager test into correct package.
Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/AbstractSSOKey.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/AbstractSSOKey.java (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/AbstractSSOKey.java 2010-08-04 21:17:27 UTC (rev 107399)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.web.tomcat.service.sso.ispn;
+
+import java.io.Serializable;
+
+import org.infinispan.Cache;
+
+/**
+ * @author Paul Ferraro
+ *
+ * @param <V>
+ */
+public abstract class AbstractSSOKey<V> implements SSOKey, Serializable
+{
+ private static final long serialVersionUID = -4838885706919457570L;
+
+ private String id;
+
+ AbstractSSOKey(String id)
+ {
+ this.id = id;
+ }
+
+ @Override
+ public String getId()
+ {
+ return this.id;
+ }
+
+ public abstract Cache<SSOKey, V> cast(Cache<SSOKey, ?> cache);
+
+ @Override
+ public boolean equals(Object object)
+ {
+ if ((object == null) || !this.getClass().isInstance(object)) return false;
+
+ AbstractSSOKey<?> key = (AbstractSSOKey<?>) object;
+
+ return this.id.equals(key.id);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return this.id.hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return this.id;
+ }
+}
Deleted: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/CacheKey.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/CacheKey.java 2010-08-04 20:54:50 UTC (rev 107398)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/CacheKey.java 2010-08-04 21:17:27 UTC (rev 107399)
@@ -1,73 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2010, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.jboss.web.tomcat.service.sso.ispn;
-
-/**
- * Used to represent the different types of entries in the cache store.
- *
- * Note that we purposely do not implement equals, which allows many different
- * entries with the same key to be added.
- *
- */
-public class CacheKey
-{
- public static enum Type { SESSION, CREDENTIAL }
-
- private final String ssoId;
- private final Type type;
-
- public CacheKey(String ssoId, Type type)
- {
- this.ssoId = ssoId;
- this.type = type;
- }
-
- public String getSSOID()
- {
- return this.ssoId;
- }
-
- public Type getType()
- {
- return this.type;
- }
-
- @Override
- public int hashCode()
- {
- int result = 17;
- result = 37*result + this.ssoId.hashCode();
- result = 37*result + this.type.ordinal();
- return result;
- }
-
- @Override
- public boolean equals(Object object)
- {
- if ((object == null) || !(object instanceof CacheKey)) return false;
-
- CacheKey key = (CacheKey) object;
-
- return (this.type == key.type) && this.ssoId.equals(key.ssoId);
- }
-}
Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/CredentialKey.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/CredentialKey.java (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/CredentialKey.java 2010-08-04 21:17:27 UTC (rev 107399)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.web.tomcat.service.sso.ispn;
+
+import org.infinispan.Cache;
+import org.jboss.web.tomcat.service.sso.spi.SSOCredentials;
+
+/**
+ * @author Paul Ferraro
+ */
+public class CredentialKey extends AbstractSSOKey<SSOCredentials>
+{
+ private static final long serialVersionUID = -8471571051604211936L;
+
+ public CredentialKey(String ssoId)
+ {
+ super(ssoId);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Cache<SSOKey, SSOCredentials> cast(Cache<SSOKey, ?> cache)
+ {
+ return (Cache<SSOKey, SSOCredentials>) cache;
+ }
+}
Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/SSOClusterManager.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/SSOClusterManager.java 2010-08-04 20:54:50 UTC (rev 107398)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/SSOClusterManager.java 2010-08-04 21:17:27 UTC (rev 107399)
@@ -24,6 +24,8 @@
import org.infinispan.atomic.AtomicMap;
import org.infinispan.config.Configuration;
+import org.infinispan.lifecycle.ComponentStatus;
+import org.infinispan.manager.CacheContainer;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved;
import org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent;
@@ -32,7 +34,8 @@
import org.infinispan.notifications.cachemanagerlistener.event.ViewChangedEvent;
import org.infinispan.Cache;
import org.infinispan.remoting.transport.Address;
-import org.jboss.ha.framework.server.ispn.InfinispanHAPartitionCacheHandler;
+import org.jboss.ha.ispn.CacheContainerRegistry;
+import org.jboss.ha.ispn.DefaultCacheContainerRegistry;
import org.jboss.ha.ispn.atomic.AtomicMapFactory;
import org.jboss.ha.ispn.atomic.DefaultAtomicMapFactory;
import org.jboss.logging.Logger;
@@ -90,8 +93,9 @@
* The clustered cache that holds the SSO credentials and the sessions.
* The CacheKey will indicate which type it is (CacheKey.CREDENTIAL or CacheKey.SESSION);
*/
- private volatile Cache<CacheKey, Object> cache = null;
-
+ private volatile Cache<SSOKey, ?> cache = null;
+ private volatile boolean stopCache = false;
+
/**
* Transaction Manager
*/
@@ -107,11 +111,6 @@
private static final Logger log = Logger.getLogger(SSOClusterManager.class);;
/**
- * Whether we are registered as a CacheListener anywhere
- */
- private volatile boolean registeredAsListener = false;
-
- /**
* The MBean server we use to access external components (TODO: convert to injection)
*/
private volatile MBeanServer server = null;
@@ -144,22 +143,10 @@
/** Mutex lock to ensure only one view change at a time is being processed */
private final Object cleanupMutex = new Object();
- private volatile InfinispanHAPartitionCacheHandler<CacheKey, Object> cacheHandler;
-
private final AtomicMapFactory atomicMapFactory;
// ------------------------------------------------------------ Properties
- public InfinispanHAPartitionCacheHandler getCacheHandler()
- {
- return cacheHandler;
- }
-
- public void setCacheHandler(InfinispanHAPartitionCacheHandler cacheHandler)
- {
- this.cacheHandler = cacheHandler;
- }
-
public String getThreadPoolName()
{
return threadPoolName;
@@ -174,7 +161,7 @@
public SSOClusterManager()
{
- this.atomicMapFactory = new DefaultAtomicMapFactory();
+ this(new DefaultAtomicMapFactory());
}
/**
@@ -194,6 +181,7 @@
* @param ssoId the id of the SSO session
* @param sessionId id of the Session that has been added
*/
+ @Override
public void addSession(String ssoId, FullyQualifiedSessionId sessionId)
{
if (ssoId == null || sessionId == null)
@@ -257,6 +245,7 @@
*
* @return the <code>SingleSignOn</code> valve.
*/
+ @Override
public SSOLocalManager getSSOLocalManager()
{
return ssoValve;
@@ -271,6 +260,7 @@
*
* @param localManager a <code>SingleSignOn</code> valve.
*/
+ @Override
public void setSSOLocalManager(SSOLocalManager localManager)
{
ssoValve = localManager;
@@ -295,6 +285,7 @@
*
* @param ssoId
*/
+ @Override
public void logout(String ssoId)
{
if (!isCacheAvailable())
@@ -334,6 +325,7 @@
}
+ @Override
public SSOCredentials lookup(String ssoId)
{
if (!isCacheAvailable())
@@ -341,18 +333,16 @@
return null;
}
- SSOCredentials credentials = null;
- // Find the latest credential info from the cluster
try
{
- credentials = getCredentialsFromCache(ssoId);
+ return getCredentialsFromCache(ssoId);
}
catch (Exception e)
{
- log.error("caught exception looking up SSOCredentials for SSO id " +
- ssoId, e);
+ log.error("caught exception looking up SSOCredentials for SSO id " + ssoId, e);
+
+ return null;
}
- return credentials;
}
@@ -365,8 +355,8 @@
* @param username the username (if any) used for the authentication
* @param password the password (if any) used for the authentication
*/
- public void register(String ssoId, String authType,
- String username, String password)
+ @Override
+ public void register(String ssoId, String authType, String username, String password)
{
if (!isCacheAvailable())
{
@@ -388,6 +378,7 @@
* @param ssoId the id of the SSO session
* @param sessionId id of the Session that has been removed
*/
+ @Override
public void removeSession(String ssoId, FullyQualifiedSessionId sessionId)
{
if (ssoId == null || sessionId == null)
@@ -424,10 +415,10 @@
// Don't do anything if there is already a transaction
// context associated with this thread.
- if(tm.getTransaction() == null)
+ if (tm.getTransaction() == null)
doTx = true;
- if(doTx)
+ if (doTx)
tm.begin();
// remove session
@@ -437,7 +428,7 @@
{
try
{
- if(doTx)
+ if (doTx)
tm.setRollbackOnly();
}
catch (Exception x)
@@ -475,8 +466,8 @@
* @param username the username (if any) used for the authentication
* @param password the password (if any) used for the authentication
*/
- public void updateCredentials(String ssoId, String authType,
- String username, String password)
+ @Override
+ public void updateCredentials(String ssoId, String authType, String username, String password)
{
if (!isCacheAvailable())
{
@@ -507,14 +498,12 @@
@CacheEntryRemoved
public void cacheEntryRemoved(CacheEntryRemovedEvent event)
{
- if (event.isPre())
- return;
+ if (event.isPre()) return;
- CacheKey key = (CacheKey)event.getKey();
- String ssoId = key.getSSOID();
+ SSOKey key = (SSOKey) event.getKey();
+ String ssoId = key.getId();
- if (ssoId == null ||
- key.getType() != CacheKey.Type.SESSION)
+ if (ssoId == null || !(key instanceof SessionKey))
{
return;
}
@@ -583,7 +572,6 @@
*/
private void launchSSOCleaner(boolean notifyIfEmpty)
{
-
SSOCleanerTask cleaner = new SSOCleanerTask(notifyIfEmpty);
if (threadPool != null)
{
@@ -661,14 +649,16 @@
if (event.isPre() || event.isOriginLocal())
return;
- CacheKey key = (CacheKey)event.getKey();
- if (key.getType() == CacheKey.Type.CREDENTIAL)
+ SSOKey key = (SSOKey) event.getKey();
+ String ssoId = key.getId();
+
+ if (key instanceof CredentialKey)
{
- handleCredentialModifiedEvent(key.getSSOID(), (SSOCredentials)event.getValue());
+ handleCredentialModifiedEvent(ssoId, (SSOCredentials) event.getValue());
}
- else if (key.getType() == CacheKey.Type.SESSION)
+ else if (key instanceof SessionKey)
{
- handleSessionModifiedEvent(key.getSSOID());
+ handleSessionModifiedEvent(ssoId);
}
}
@@ -723,6 +713,7 @@
* @throws Exception if this component detects a fatal error
* that prevents this component from being used
*/
+ @Override
public void start() throws Exception
{
// Validate and update our current component state
@@ -730,9 +721,34 @@
{
throw new IllegalStateException("SSOClusterManagerImpl already Started");
}
- this.cache = cacheHandler.getCache();
+
+ String containerName = null;
+ String cacheName = this.ssoValve.getCacheConfig();
+
+ if ((cacheName != null) && !cacheName.trim().isEmpty())
+ {
+ // Parse cache container name
+ String[] parts = cacheName.split(":");
+ if (parts.length == 2)
+ {
+ containerName = parts[0];
+ cacheName = parts[1];
+ }
+ }
+
+ CacheContainerRegistry registry = DefaultCacheContainerRegistry.getInstance();
+ CacheContainer container = registry.getCacheContainer(containerName);
+ this.cache = container.getCache(cacheName);
+
+ if (this.cache.getStatus() != ComponentStatus.RUNNING)
+ {
+ this.cache.start();
+ this.stopCache = true;
+ }
+
initThreadPool();
- registerAsCacheListener();
+
+ this.cache.addListener(this);
this.tm = this.cache.getAdvancedCache().getTransactionManager();
@@ -749,6 +765,7 @@
* @throws Exception if this component detects a fatal error
* that needs to be reported
*/
+ @Override
public void stop() throws Exception
{
// Validate and update our current component state
@@ -757,7 +774,13 @@
throw new IllegalStateException("SSOClusterManagerImpl not Started");
}
- removeAsCacheListener();
+ this.cache.removeListener(this);
+
+ if (this.stopCache)
+ {
+ this.cache.stop();
+ this.stopCache = false;
+ }
started = false;
}
@@ -778,15 +801,11 @@
private Set<String> getSSOIds() throws Exception
{
- Set keys = cache.keySet();
- Set result = new HashSet<String>();
- for (Object key: keys)
+ Set<String> result = new HashSet<String>();
+
+ for (SSOKey key: this.cache.keySet())
{
- CacheKey ck = (CacheKey)key;
- if (ck.getType() == CacheKey.Type.SESSION)
- {
- result.add(ck.getSSOID());
- }
+ result.add(key.getId());
}
return result;
@@ -800,9 +819,9 @@
*/
private Set<FullyQualifiedSessionId> getSSOSessions(String ssoId) throws Exception
{
- CacheKey key = new CacheKey(ssoId,CacheKey.Type.SESSION);
- AtomicMap m = this.atomicMapFactory.getAtomicMap( (Cache<CacheKey, AtomicMap<Object, Object>>)(Cache)cache, key, true);
- return m!=null ? m.keySet() : Collections.EMPTY_SET;
+ SessionKey key = new SessionKey(ssoId);
+ AtomicMap<FullyQualifiedSessionId, Void> map = this.atomicMapFactory.getAtomicMap(key.cast(this.cache), key, false);
+ return (map != null) ? map.keySet() : Collections.<FullyQualifiedSessionId>emptySet();
}
/**
@@ -901,9 +920,9 @@
*/
private void putSessionInCache(String ssoId, FullyQualifiedSessionId fullyQualifiedSessionId) throws Exception
{
- CacheKey key = new CacheKey(ssoId,CacheKey.Type.SESSION);
- AtomicMap m = this.atomicMapFactory.getAtomicMap( (Cache<CacheKey, AtomicMap<Object, Object>>)(Cache)cache, key, true);
- m.put(fullyQualifiedSessionId, null);
+ SessionKey key = new SessionKey(ssoId);
+ AtomicMap<FullyQualifiedSessionId, Void> map = this.atomicMapFactory.getAtomicMap(key.cast(this.cache), key, true);
+ map.put(fullyQualifiedSessionId, null);
}
/**
@@ -914,43 +933,17 @@
*/
private void putCredentialsInCache(String ssoId, SSOCredentials credentials) throws Exception
{
- CacheKey key = new CacheKey(ssoId,CacheKey.Type.CREDENTIAL);
- cache.put(key, credentials);
+ CredentialKey key = new CredentialKey(ssoId);
+ key.cast(this.cache).put(key, credentials);
}
private SSOCredentials getCredentialsFromCache(String ssoId)
{
- CacheKey key = new CacheKey(ssoId,CacheKey.Type.CREDENTIAL);
- return (SSOCredentials)cache.get(key);
+ CredentialKey key = new CredentialKey(ssoId);
+ return key.cast(this.cache).get(key);
}
/**
- * register as a cache listener.
- *
- * @throws Exception
- */
- private void registerAsCacheListener() throws Exception
- {
- cache.addListener(this);
- registeredAsListener = true;
- }
-
-
- /**
- * stop listening on the cache.
- *
- * @throws Exception
- */
- private void removeAsCacheListener() throws Exception
- {
- if (registeredAsListener && cache != null)
- {
- cache.removeListener(this);
- registeredAsListener = false;
- }
- }
-
- /**
* Remove the specified session from the cache (used for session.logout)
*
* @param ssoId the session id representing the shared single session
@@ -958,10 +951,10 @@
*/
private void removeSSOFromCache(String ssoId) throws Exception
{
- 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
+ SSOKey key = new SessionKey(ssoId);
+ this.cache.remove(key);
+ key = new CredentialKey(ssoId);
+ this.cache.remove(key);
}
/**
@@ -972,11 +965,11 @@
*/
private void removeSessionFromCache(String ssoId, FullyQualifiedSessionId fullyQualifiedSessionId) throws Exception
{
- CacheKey key = new CacheKey(ssoId,CacheKey.Type.SESSION);
- AtomicMap m = this.atomicMapFactory.getAtomicMap( (Cache<CacheKey, AtomicMap<Object, Object>>)(Cache)cache, key, false);
- if (m != null)
+ SessionKey key = new SessionKey(ssoId);
+ AtomicMap<FullyQualifiedSessionId, Void> map = this.atomicMapFactory.getAtomicMap(key.cast(this.cache), key, false);
+ if (map != null)
{
- m.remove(fullyQualifiedSessionId);
+ map.remove(fullyQualifiedSessionId);
}
}
@@ -989,8 +982,7 @@
* @param username the username (if any) used for the authentication
* @param password the password (if any) used for the authentication
*/
- private void storeCredentials(String ssoId, String authType, String username,
- String password)
+ private void storeCredentials(String ssoId, String authType, String username, String password)
{
SSOCredentials credentials = new SSOCredentials(authType, username, password);
@@ -1077,7 +1069,7 @@
{
private final boolean checkForEmpty;
- private SSOCleanerTask(boolean checkForEmpty)
+ SSOCleanerTask(boolean checkForEmpty)
{
this.checkForEmpty = checkForEmpty;
}
Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/SSOKey.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/SSOKey.java (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/SSOKey.java 2010-08-04 21:17:27 UTC (rev 107399)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.web.tomcat.service.sso.ispn;
+
+/**
+ * @author Paul Ferraro
+ */
+public interface SSOKey
+{
+ String getId();
+}
Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/SessionKey.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/SessionKey.java (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/sso/ispn/SessionKey.java 2010-08-04 21:17:27 UTC (rev 107399)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.web.tomcat.service.sso.ispn;
+
+import org.infinispan.Cache;
+import org.infinispan.atomic.AtomicMap;
+import org.jboss.web.tomcat.service.sso.spi.FullyQualifiedSessionId;
+
+/**
+ * @author Paul Ferraro
+ */
+public class SessionKey extends AbstractSSOKey<AtomicMap<FullyQualifiedSessionId, Void>>
+{
+ private static final long serialVersionUID = 5846784540873611578L;
+
+ public SessionKey(String ssoId)
+ {
+ super(ssoId);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Cache<SSOKey, AtomicMap<FullyQualifiedSessionId, Void>> cast(Cache<SSOKey, ?> cache)
+ {
+ return (Cache<SSOKey, AtomicMap<FullyQualifiedSessionId, Void>>) cache;
+ }
+}
Deleted: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/sso/ispn/SSOClusterManagerTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/sso/ispn/SSOClusterManagerTest.java 2010-08-04 20:54:50 UTC (rev 107398)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/sso/ispn/SSOClusterManagerTest.java 2010-08-04 21:17:27 UTC (rev 107399)
@@ -1,93 +0,0 @@
-package org.jboss.web.tomcat.service.session.sso.ispn;
-
-import org.easymock.EasyMock;
-import org.infinispan.AdvancedCache;
-import org.infinispan.Cache;
-import org.infinispan.atomic.AtomicMap;
-import org.jboss.ha.framework.server.ispn.InfinispanHAPartitionCacheHandler;
-import org.jboss.ha.ispn.atomic.AtomicMapFactory;
-import org.jboss.web.tomcat.service.session.sso.ispn.SSOClusterManager;
-import org.jboss.web.tomcat.service.sso.spi.FullyQualifiedSessionId;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.Before;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import java.util.HashSet;
-
-public class SSOClusterManagerTest
-{
-
- SSOClusterManager ssoManager;
- Cache<Object, AtomicMap<Object, Object>>cache;
-
- String ssoId;
- FullyQualifiedSessionId fqs;
-
-
- @Test
- public void addSession() throws Exception
- {
- // Prepare for the test (TODO: consider refactoring initialization into @Before step)
- ssoId = "sso session 1";
- fqs = new FullyQualifiedSessionId(ssoId, "context", "Boston");
-
- AtomicMapFactory atomicMapFactory = EasyMock.createNiceMock(AtomicMapFactory.class);
- AtomicMap atomicMap = EasyMock.createMock(AtomicMap.class);
-
- ssoManager = new SSOClusterManager(atomicMapFactory);
- cache = EasyMock.createMock(Cache.class);
-
- CacheKey key = new CacheKey(ssoId, CacheKey.Type.SESSION);
- EasyMock.expect(atomicMapFactory.getAtomicMap( cache, key, true)).andReturn(atomicMap);
- EasyMock.expectLastCall().anyTimes();
- EasyMock.expect(atomicMapFactory.getAtomicMap( cache, key, false)).andReturn(atomicMap);
- EasyMock.expectLastCall().anyTimes();
-
- InfinispanHAPartitionCacheHandler cacheHandler = EasyMock.createMock(InfinispanHAPartitionCacheHandler.class);
- EasyMock.expect(cacheHandler.getCache()).andReturn(cache);
- EasyMock.expectLastCall().anyTimes();
-
- cache.addListener(ssoManager);
-
- AdvancedCache advancedCache = EasyMock.createMock(AdvancedCache.class);
- EasyMock.expect(cache.getAdvancedCache()).andReturn(advancedCache);
- EasyMock.expectLastCall().anyTimes();
-
- Transaction transaction = EasyMock.createMock(Transaction.class);
- TransactionManager tm = EasyMock.createMock(TransactionManager.class);
- EasyMock.expect(tm.getTransaction()).andReturn(transaction);
- EasyMock.expectLastCall().anyTimes();
-
- tm.begin();
- EasyMock.expectLastCall().anyTimes();
- tm.rollback();
- EasyMock.expectLastCall().anyTimes();
- tm.commit();
- EasyMock.expectLastCall().anyTimes();
-
- EasyMock.expect(advancedCache.getTransactionManager()).andReturn(tm);
- EasyMock.expectLastCall().anyTimes();
-
- ssoManager.setCacheHandler(cacheHandler);
-
- EasyMock.expect(cache.get(EasyMock.anyObject())).andReturn(atomicMap);
- EasyMock.expectLastCall().anyTimes();
-
- EasyMock.expect(atomicMap.put(fqs, null)).andReturn(null);
- EasyMock.expectLastCall().anyTimes();
- HashSet result = new HashSet();
- result.add(fqs);
- EasyMock.expect(atomicMap.keySet()).andReturn(result);
-
- EasyMock.replay(cache, cacheHandler, advancedCache, tm, transaction, atomicMap, atomicMapFactory);
-
- // Start testing
- ssoManager.start();
-
- ssoManager.addSession(ssoId, fqs);
- Assert.assertEquals("should have 1 session.",1,ssoManager.getSessionCount(ssoId));
- }
-
-
-}
Copied: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/sso/ispn/SSOClusterManagerTest.java (from rev 107398, projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/sso/ispn/SSOClusterManagerTest.java)
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/sso/ispn/SSOClusterManagerTest.java (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/sso/ispn/SSOClusterManagerTest.java 2010-08-04 21:17:27 UTC (rev 107399)
@@ -0,0 +1,86 @@
+package org.jboss.web.tomcat.service.sso.ispn;
+
+import java.util.HashSet;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+import org.easymock.EasyMock;
+import org.infinispan.AdvancedCache;
+import org.infinispan.Cache;
+import org.infinispan.atomic.AtomicMap;
+import org.jboss.ha.ispn.atomic.AtomicMapFactory;
+import org.jboss.web.tomcat.service.sso.spi.FullyQualifiedSessionId;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class SSOClusterManagerTest
+{
+
+ SSOClusterManager ssoManager;
+ Cache<Object, AtomicMap<Object, Object>>cache;
+
+ String ssoId;
+ FullyQualifiedSessionId fqs;
+
+
+ @Test
+ public void addSession() throws Exception
+ {
+ // Prepare for the test (TODO: consider refactoring initialization into @Before step)
+ ssoId = "sso session 1";
+ fqs = new FullyQualifiedSessionId(ssoId, "context", "Boston");
+
+ AtomicMapFactory atomicMapFactory = EasyMock.createNiceMock(AtomicMapFactory.class);
+ AtomicMap atomicMap = EasyMock.createMock(AtomicMap.class);
+
+ ssoManager = new SSOClusterManager(atomicMapFactory);
+ cache = EasyMock.createMock(Cache.class);
+
+ SessionKey key = new SessionKey(ssoId);
+ EasyMock.expect(atomicMapFactory.getAtomicMap( cache, key, true)).andReturn(atomicMap);
+ EasyMock.expectLastCall().anyTimes();
+ EasyMock.expect(atomicMapFactory.getAtomicMap( cache, key, false)).andReturn(atomicMap);
+ EasyMock.expectLastCall().anyTimes();
+
+ cache.addListener(ssoManager);
+
+ AdvancedCache advancedCache = EasyMock.createMock(AdvancedCache.class);
+ EasyMock.expect(cache.getAdvancedCache()).andReturn(advancedCache);
+ EasyMock.expectLastCall().anyTimes();
+
+ Transaction transaction = EasyMock.createMock(Transaction.class);
+ TransactionManager tm = EasyMock.createMock(TransactionManager.class);
+ EasyMock.expect(tm.getTransaction()).andReturn(transaction);
+ EasyMock.expectLastCall().anyTimes();
+
+ tm.begin();
+ EasyMock.expectLastCall().anyTimes();
+ tm.rollback();
+ EasyMock.expectLastCall().anyTimes();
+ tm.commit();
+ EasyMock.expectLastCall().anyTimes();
+
+ EasyMock.expect(advancedCache.getTransactionManager()).andReturn(tm);
+ EasyMock.expectLastCall().anyTimes();
+
+ EasyMock.expect(cache.get(EasyMock.anyObject())).andReturn(atomicMap);
+ EasyMock.expectLastCall().anyTimes();
+
+ EasyMock.expect(atomicMap.put(fqs, null)).andReturn(null);
+ EasyMock.expectLastCall().anyTimes();
+ HashSet result = new HashSet();
+ result.add(fqs);
+ EasyMock.expect(atomicMap.keySet()).andReturn(result);
+
+ EasyMock.replay(cache, advancedCache, tm, transaction, atomicMap, atomicMapFactory);
+
+ // Start testing
+ ssoManager.start();
+
+ ssoManager.addSession(ssoId, fqs);
+ Assert.assertEquals("should have 1 session.",1,ssoManager.getSessionCount(ssoId));
+ }
+
+
+}
More information about the jboss-cvs-commits
mailing list