[jboss-cvs] JBossAS SVN: r107795 - in projects/cluster/ha-server-cache-ispn/trunk/src: test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Aug 25 22:59:27 EDT 2010
Author: pferraro
Date: 2010-08-25 22:59:27 -0400 (Wed, 25 Aug 2010)
New Revision: 107795
Modified:
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DefaultCacheSource.java
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManager.java
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerFactory.java
projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerTest.java
Log:
Minor tweaks - code formatting fixes.
Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DefaultCacheSource.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DefaultCacheSource.java 2010-08-25 22:14:53 UTC (rev 107794)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DefaultCacheSource.java 2010-08-26 02:59:27 UTC (rev 107795)
@@ -43,8 +43,10 @@
*/
public class DefaultCacheSource implements CacheSource, LockManagerSource
{
- /** The scope we assign to our CoreGroupCommunicationService */
- public static final Short HTTP_SESSION_MGR_SCOPE_ID = Short.valueOf((short) 222);
+ /** The scope assigned to our group communication service */
+ public static final Short SCOPE_ID = Short.valueOf((short) 222);
+ /** The service name of the group communication service */
+ public static final String SERVICE_NAME = "HTTPSESSIONOWNER";
public static final String DEFAULT_CACHE_CONTAINER = "session";
@@ -62,75 +64,89 @@
@Override
public SharedLocalYieldingClusterLockManager getLockManager(LocalDistributableSessionManager manager)
{
-
String containerName = getContainerName(manager.getReplicationConfig());
- SharedLocalYieldingClusterLockManager lockManager = null;
+
synchronized (lockManagers)
{
- lockManager = lockManagers.get(containerName);
- if(lockManager == null){
+ SharedLocalYieldingClusterLockManager lockManager = lockManagers.get(containerName);
+
+ if (lockManager == null)
+ {
EmbeddedCacheManager container = this.registry.getCacheContainer(containerName);
- String cacheName = cacheName(manager);
+ String cacheName = getCacheName(manager);
Cache<Object, Object> cache = container.getCache(cacheName);
JGroupsTransport transport = (JGroupsTransport) cache.getAdvancedCache().getRpcManager().getTransport();
Channel channel = transport.getChannel();
+ CoreGroupCommunicationService gcs = new CoreGroupCommunicationService();
+ gcs.setChannel(channel);
+ gcs.setScopeId(SCOPE_ID);
+
try
{
- CoreGroupCommunicationService gcs = new CoreGroupCommunicationService();
- gcs.setChannel(channel);
- gcs.setScopeId(HTTP_SESSION_MGR_SCOPE_ID);
gcs.start();
-
- lockManager = new SharedLocalYieldingClusterLockManager("HTTPSESSIONOWNER", gcs, gcs);
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException("Unexpected exception while starting group communication service for " + containerName);
+ }
+
+ lockManager = new SharedLocalYieldingClusterLockManager(SERVICE_NAME, gcs, gcs);
+
+ try
+ {
lockManager.start();
- lockManagers.put(containerName, lockManager);
+
+ this.lockManagers.put(containerName, lockManager);
}
catch (Exception e)
{
- throw new IllegalStateException("Unexpected exception while starting lock manager for " + cacheName);
+ gcs.stop();
+ throw new IllegalStateException("Unexpected exception while starting lock manager for " + containerName);
}
}
- }
- return lockManager;
+
+ return lockManager;
+ }
}
@Override
public <K, V> Cache<K, V> getCache(LocalDistributableSessionManager manager)
{
- ReplicationConfig replConfig = manager.getReplicationConfig();
- String containerName = getContainerName(replConfig);
+ ReplicationConfig replConfig = manager.getReplicationConfig();
+ String containerName = getContainerName(replConfig);
- EmbeddedCacheManager container = this.registry.getCacheContainer(containerName);
- String cacheName = cacheName(manager);
+ EmbeddedCacheManager container = this.registry.getCacheContainer(containerName);
+ String cacheName = getCacheName(manager);
Cache<?, ?> templateCache = container.getCache();
- Configuration configuration = templateCache.getConfiguration().clone();
- CacheMode mode = selectMode(replConfig, configuration);
- configuration.setCacheMode(mode);
- container.defineConfiguration(cacheName, configuration);
+ Configuration configuration = templateCache.getConfiguration().clone();
+ CacheMode mode = getCacheMode(replConfig, configuration);
+ configuration.setCacheMode(mode);
+ container.defineConfiguration(cacheName, configuration);
return container.getCache(cacheName);
}
- private String getContainerName(ReplicationConfig replConfig){
+ private String getContainerName(ReplicationConfig replConfig)
+ {
String templateCacheName = replConfig.getCacheName();
+ String containerName = this.defaultContainerName;
- String containerName = this.defaultContainerName;;
-
if (templateCacheName != null)
{
String[] parts = templateCacheName.split(":");
if (parts.length == 2)
{
- containerName = parts[0];
+ containerName = parts[0];
}
}
+
return containerName;
}
- private CacheMode selectMode(ReplicationConfig replConfig, Configuration configuration)
+ private CacheMode getCacheMode(ReplicationConfig replConfig, Configuration configuration)
{
Integer backups = replConfig.getBackups();
ReplicationMode replMode = replConfig.getReplicationMode();
@@ -180,7 +196,8 @@
return mode;
}
- private String cacheName(LocalDistributableSessionManager manager){
+ private String getCacheName(LocalDistributableSessionManager manager)
+ {
String hostName = manager.getHostName();
String host = (hostName == null) || hostName.isEmpty() ? "localhost" : hostName;
Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManager.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManager.java 2010-08-25 22:14:53 UTC (rev 107794)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManager.java 2010-08-26 02:59:27 UTC (rev 107795)
@@ -21,6 +21,8 @@
*/
package org.jboss.web.tomcat.service.session.distributedcache.ispn;
+import java.io.Serializable;
+import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -56,7 +58,7 @@
* @author Paul Ferraro
*/
@Listener
-public class DistributedCacheManager<T extends OutgoingDistributableSessionData> implements org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager<T>,SessionOwnershipSupport
+public class DistributedCacheManager<T extends OutgoingDistributableSessionData> implements org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager<T>, SessionOwnershipSupport
{
static String mask(String sessionId)
{
@@ -65,7 +67,7 @@
int length = sessionId.length();
if (length <= 8) return sessionId;
-
+
return sessionId.substring(0, 2) + "****" + sessionId.substring(length - 6, length);
}
@@ -78,6 +80,16 @@
private static final Logger log = Logger.getLogger(DistributedCacheManager.class);
+ private static Map<SharedLocalYieldingClusterLockManager.LockResult, LockResult> lockResultMap = lockResultMap();
+ private static Map<SharedLocalYieldingClusterLockManager.LockResult, LockResult> lockResultMap()
+ {
+ Map<SharedLocalYieldingClusterLockManager.LockResult, LockResult> map = new EnumMap<SharedLocalYieldingClusterLockManager.LockResult, LockResult>(SharedLocalYieldingClusterLockManager.LockResult.class);
+ map.put(SharedLocalYieldingClusterLockManager.LockResult.ACQUIRED_FROM_CLUSTER, LockResult.ACQUIRED_FROM_CLUSTER);
+ map.put(SharedLocalYieldingClusterLockManager.LockResult.ALREADY_HELD, LockResult.ALREADY_HELD);
+ map.put(SharedLocalYieldingClusterLockManager.LockResult.NEW_LOCK, LockResult.NEW_LOCK);
+ return map;
+ }
+
private final LocalDistributableSessionManager manager;
private final SharedLocalYieldingClusterLockManager lockManager;
private final SessionAttributeStorage<T> attributeStorage;
@@ -89,10 +101,12 @@
private final AtomicBoolean startedCache = new AtomicBoolean(false);
- public DistributedCacheManager(LocalDistributableSessionManager manager,
- SharedLocalYieldingClusterLockManager lockManager, Cache<String, AtomicMap<Object, Object>> cache,
- SessionAttributeStorage<T> attributeStorage, BatchingManager batchingManager, CacheInvoker invoker,
- AtomicMapFactory atomicMapFactory)
+ // FIXME make configurable
+ private long lockTimeout = 30000;
+
+ public DistributedCacheManager(LocalDistributableSessionManager manager, Cache<String, AtomicMap<Object, Object>> cache,
+ SharedLocalYieldingClusterLockManager lockManager, SessionAttributeStorage<T> attributeStorage,
+ BatchingManager batchingManager, CacheInvoker invoker, AtomicMapFactory atomicMapFactory)
{
this.manager = manager;
this.lockManager = lockManager;
@@ -104,8 +118,7 @@
CacheLoaderManagerConfig loaderManagerConfig = this.cache.getConfiguration().getCacheLoaderManagerConfig();
- this.passivationEnabled = (loaderManagerConfig != null) ? loaderManagerConfig.isPassivation().booleanValue()
- && !loaderManagerConfig.isShared().booleanValue() : false;
+ this.passivationEnabled = (loaderManagerConfig != null) ? loaderManagerConfig.isPassivation().booleanValue() && !loaderManagerConfig.isShared().booleanValue() : false;
}
/**
@@ -121,7 +134,7 @@
this.startedCache.set(true);
}
- this.cache.addListener(this);
+ this.cache.addListener(this);
}
/**
@@ -394,43 +407,24 @@
}
@Override
- public LockResult acquireSessionOwnership(String realId, boolean newLock) throws TimeoutException, InterruptedException
+ public LockResult acquireSessionOwnership(String sessionId, boolean newLock) throws TimeoutException, InterruptedException
{
- String lockName = getSessionLockName(cache.getName(), realId);
- SharedLocalYieldingClusterLockManager.LockResult result = lockManager.lock(lockName, getLockTimeout(), newLock);
- LockResult ourResult = null;
- switch (result)
- {
- case ACQUIRED_FROM_CLUSTER:
- ourResult = LockResult.ACQUIRED_FROM_CLUSTER;
- break;
- case ALREADY_HELD:
- ourResult = LockResult.ALREADY_HELD;
- break;
- case NEW_LOCK:
- ourResult = LockResult.NEW_LOCK;
- }
- return ourResult;
+ LockResult result = lockResultMap.get(this.lockManager.lock(this.getSessionLockKey(sessionId), this.lockTimeout, newLock));
+
+ return (result != null) ? result : LockResult.UNSUPPORTED;
}
@Override
- public void relinquishSessionOwnership(String realId, boolean remove)
+ public void relinquishSessionOwnership(String sessionId, boolean remove)
{
- String lockName = getSessionLockName(cache.getName(), realId);
- lockManager.unlock(lockName, remove);
+ this.lockManager.unlock(this.getSessionLockKey(sessionId), remove);
}
- protected String getSessionLockName(String contextHostPath, String sessionId)
+ private Serializable getSessionLockKey(String sessionId)
{
- return contextHostPath + "_" + sessionId;
+ return this.cache.getName() + "/" + sessionId;
}
- protected long getLockTimeout()
- {
- // FIXME
- return 30000;
- }
-
/**
* {@inheritDoc}
* @see org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager#isLocal(java.lang.String)
@@ -491,6 +485,6 @@
// Simplified CacheInvoker.Operation using assigned key/value types
static interface Operation<R> extends CacheInvoker.Operation<String, AtomicMap<Object, Object>, R>
- {
+ {
}
}
Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerFactory.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerFactory.java 2010-08-25 22:14:53 UTC (rev 107794)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerFactory.java 2010-08-26 02:59:27 UTC (rev 107795)
@@ -54,7 +54,7 @@
private AtomicMapFactory atomicMapFactory = new DefaultAtomicMapFactory();
public DistributedCacheManagerFactory()
- {
+ {
DefaultCacheSource dcmSource = new DefaultCacheSource(DefaultCacheContainerRegistry.getInstance());
this.source = dcmSource;
this.lmSource = dcmSource;
@@ -63,7 +63,7 @@
@Override
public <T extends OutgoingDistributableSessionData> org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager<T> getDistributedCacheManager(LocalDistributableSessionManager manager)
{
- Cache<String, AtomicMap<Object, Object>> cache = this.source.getCache(manager);
+ Cache<String, AtomicMap<Object, Object>> cache = this.source.getCache(manager);
SharedLocalYieldingClusterLockManager lockManager = this.lmSource.getLockManager(manager);
TransactionManager tm = cache.getAdvancedCache().getTransactionManager();
@@ -76,7 +76,7 @@
SessionAttributeMarshaller marshaller = this.marshallerFactory.createMarshaller(manager);
SessionAttributeStorage<T> storage = this.storageFactory.createStorage(manager.getReplicationConfig().getReplicationGranularity(), marshaller);
- return new DistributedCacheManager<T>(manager, lockManager, cache, storage, batchingManager, this.invoker, this.atomicMapFactory);
+ return new DistributedCacheManager<T>(manager, cache, lockManager, storage, batchingManager, this.invoker, this.atomicMapFactory);
}
public void setCacheSource(CacheSource source)
Modified: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerTest.java 2010-08-25 22:14:53 UTC (rev 107794)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerTest.java 2010-08-26 02:59:27 UTC (rev 107795)
@@ -75,7 +75,7 @@
EasyMock.replay(this.sessionManager, this.storage, this.cache, this.batchingManager, this.invoker, this.atomicMapFactory);
- this.manager = new DistributedCacheManager<OutgoingDistributableSessionData>(this.sessionManager, lockManager, this.cache, this.storage, this.batchingManager, this.invoker, this.atomicMapFactory);
+ this.manager = new DistributedCacheManager<OutgoingDistributableSessionData>(this.sessionManager, this.cache, this.lockManager, this.storage, this.batchingManager, this.invoker, this.atomicMapFactory);
EasyMock.verify(this.sessionManager, this.storage, this.cache, this.batchingManager, this.invoker, this.atomicMapFactory);
this.reset();
More information about the jboss-cvs-commits
mailing list