[jboss-cvs] JBossAS SVN: r106466 - in projects/cluster/ha-server-cache-jbc/branches/Session_Ownership: src/main and 12 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jul 6 14:42:32 EDT 2010
Author: bstansberry at jboss.com
Date: 2010-07-06 14:42:31 -0400 (Tue, 06 Jul 2010)
New Revision: 106466
Added:
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionOwnershipCache.java
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionOwnershipCacheManager.java
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionOwnershipPojoCache.java
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/resources/
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/resources/org/
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/resources/org/jboss/
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/resources/org/jboss/web/
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/resources/org/jboss/web/tomcat/
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/resources/org/jboss/web/tomcat/service/
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/resources/org/jboss/web/tomcat/service/session/
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/resources/org/jboss/web/tomcat/service/session/distributedcache/
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/resources/org/jboss/web/tomcat/service/session/distributedcache/impl/
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/resources/org/jboss/web/tomcat/service/session/distributedcache/impl/test-stacks.xml
Removed:
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionOwnershipCache.java
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionOwnershipCacheManager.java
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionOwnershipPojoCache.java
Modified:
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/pom.xml
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/ha/cachemanager/CacheManager.java
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/ha/cachemanager/MuxHandlerChannel.java
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryImpl.java
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/TestDistributedCacheManagerFactoryImpl.java
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AttributeBasedJBossCacheService.java
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/FieldBasedJBossCacheService.java
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/JBossCacheWrapper.java
projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionBasedJBossCacheService.java
Log:
[JBCLUSTER-260] Add support for acquiring session ownership and using same to detect failover
[JBCLUSTER-283] Remove standalone tomcat support
Update to JGroups 2.10.0.CR1
Modified: projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/pom.xml
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/pom.xml 2010-07-06 18:41:24 UTC (rev 106465)
+++ projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/pom.xml 2010-07-06 18:42:31 UTC (rev 106466)
@@ -31,10 +31,10 @@
<properties>
<version.jboss.ha.server.cache.spi>0.0.1-SNAPSHOT</version.jboss.ha.server.cache.spi>
- <version.jboss.ha.server.api>2.0.0-SNAPSHOT</version.jboss.ha.server.api>
+ <version.jboss.ha.server.api>2.0.0.Alpha4</version.jboss.ha.server.api>
<version.jboss.ha.server.core>1.0.0-SNAPSHOT</version.jboss.ha.server.core>
<version.jboss.common.core>2.2.17.GA</version.jboss.common.core>
- <version.jboss.logging.spi>2.0.5.GA</version.jboss.logging.spi>
+ <version.jboss.logging>3.0.0.Beta2</version.jboss.logging>
<version.jboss.cache>3.2.5.GA</version.jboss.cache>
<!-- This should be [2.6.2,3.0.0) but maven complains about it -->
<version.jgroups>2.10.0.Beta2</version.jgroups>
@@ -119,9 +119,9 @@
<dependency>
<groupId>org.jboss.logging</groupId>
- <artifactId>jboss-logging-spi</artifactId>
- <version>${version.jboss.logging.spi}</version>
- </dependency>
+ <artifactId>jboss-logging</artifactId>
+ <version>${version.jboss.logging}</version>
+ </dependency>
<dependency>
<groupId>org.jboss.cache</groupId>
Modified: projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/ha/cachemanager/CacheManager.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/ha/cachemanager/CacheManager.java 2010-07-06 18:41:24 UTC (rev 106465)
+++ projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/ha/cachemanager/CacheManager.java 2010-07-06 18:42:31 UTC (rev 106466)
@@ -45,6 +45,7 @@
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.ConfigurationRegistry;
+import org.jboss.cache.config.RuntimeConfig;
import org.jboss.cache.config.XmlParsingConfigurationRegistry;
import org.jboss.cache.notifications.annotation.CacheListener;
import org.jboss.cache.notifications.annotation.CacheStarted;
@@ -54,12 +55,15 @@
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
import org.jboss.cache.pojo.jmx.PojoCacheJmxWrapper;
+import org.jboss.ha.core.jgroups.blocks.mux.MuxUpHandler;
import org.jboss.ha.framework.server.CacheManagerLocator;
import org.jboss.ha.framework.server.PojoCacheManager;
import org.jboss.ha.framework.server.PojoCacheManagerLocator;
import org.jboss.logging.Logger;
import org.jboss.util.naming.NonSerializableFactory;
+import org.jgroups.Channel;
import org.jgroups.ChannelFactory;
+import org.jgroups.JChannel;
/**
* JBoss AS specific implementation of {@link CacheManager}. Extends the core JBoss Cache
@@ -613,9 +617,11 @@
* @param config the Configuration for the cache
* @return the PojoCache
*/
- protected PojoCache createPojoCache(Configuration config)
+ protected PojoCache createPojoCache(Configuration config) throws Exception
{
- return PojoCacheFactory.createCache(config, false);
+ PojoCache pc = PojoCacheFactory.createCache(config, false);
+ configureMuxUpHandlerChannel(pc.getCache());
+ return pc;
}
/**
@@ -626,9 +632,11 @@
* @param config the Configuration for the cache
* @return the Cache
*/
- protected Cache<Object, Object> createCache(Configuration config)
+ protected Cache<Object, Object> createCache(Configuration config) throws Exception
{
- return new DefaultCacheFactory<Object, Object>().createCache(config, false);
+ Cache<Object, Object> cache = new DefaultCacheFactory<Object, Object>().createCache(config, false);
+ configureMuxUpHandlerChannel(cache);
+ return cache;
}
@@ -817,6 +825,43 @@
return base + ":" + attributesBase + configName;
}
+ private void configureMuxUpHandlerChannel(Cache<?, ?> cache) throws Exception
+ {
+ RuntimeConfig rc = cache.getConfiguration().getRuntimeConfig();
+ Channel channel = rc.getChannel();
+
+ if (channel == null)
+ {
+ // TODO we could deal with other JBC mechanisms of configuring Channels, but in
+ // reality the AS use cases that want MuxUpHandler shouldn't configure their
+ // JBC that way
+ ChannelFactory cf = rc.getMuxChannelFactory();
+ if (cf == null)
+ {
+ log.debug("Cache " + cache.getConfiguration().getClusterName() +
+ " does not have a ChannelFactory injected so MuxUpHandler cannot be integrated");
+ }
+ String stack = cache.getConfiguration().getMuxStackName();
+ if (stack == null)
+ {
+ log.debug("Cache " + cache.getConfiguration().getClusterName() +
+ " does not have a MuxStackName configured so MuxUpHandler cannot be integrated");
+ }
+ if (cf != null && stack != null)
+ {
+ // This doesn't result in JMX reg of channel
+ //channel = cf.createChannel(stack);
+ channel = cf.createMultiplexerChannel(stack, cache.getConfiguration().getClusterName());
+ rc.setChannel(new MuxHandlerChannel((JChannel) channel));
+ }
+ }
+ else if (channel.getUpHandler() == null)
+ {
+ channel.setUpHandler(new MuxUpHandler());
+ }
+ // else the Channel was injected and already had a handler -- shouldn't happen
+ }
+
@CacheListener
public static class StartStopListener
{
Modified: projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/ha/cachemanager/MuxHandlerChannel.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/ha/cachemanager/MuxHandlerChannel.java 2010-07-06 18:41:24 UTC (rev 106465)
+++ projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/ha/cachemanager/MuxHandlerChannel.java 2010-07-06 18:42:31 UTC (rev 106466)
@@ -27,14 +27,14 @@
import java.util.Map;
import java.util.Vector;
-import org.jboss.ha.core.framework.server.MuxUpHandler;
+import org.jboss.ha.core.jgroups.blocks.mux.MuxUpHandler;
import org.jgroups.Address;
-import org.jgroups.Channel;
import org.jgroups.ChannelClosedException;
import org.jgroups.ChannelException;
import org.jgroups.ChannelListener;
import org.jgroups.ChannelNotConnectedException;
import org.jgroups.Event;
+import org.jgroups.JChannel;
import org.jgroups.Message;
import org.jgroups.Receiver;
import org.jgroups.TimeoutException;
@@ -45,35 +45,28 @@
import org.jgroups.stack.ProtocolStack;
/**
+ * JGroups <code>JChannel</code> subclass that delegates everything to a
+ * wrapped ordinary <code>JChannel</code> except for calls related to the
+ * {@link #setUpHandler(UpHandler) upHandler} property.
*
- *
* @author Brian Stansberry
*
* @version $Revision$
*/
-public class MuxHandlerChannel extends Channel
+public class MuxHandlerChannel extends JChannel
{
private final Log log=LogFactory.getLog(MuxHandlerChannel.class);
- private final Channel delegate;
+ private final JChannel delegate;
private MuxUpHandler upHandler;
- public MuxHandlerChannel(Channel delegate)
+ public MuxHandlerChannel(JChannel delegate) throws ChannelException
{
- this.delegate = delegate;
- UpHandler uh = delegate.getUpHandler();
- if (uh == null)
+ super(false);
+ if (delegate.getUpHandler() != null)
{
- this.upHandler = new MuxUpHandler();
- this.delegate.setUpHandler(upHandler);
+ throw new IllegalStateException("delegate Channel already has an UpHandler");
}
- else if (uh instanceof MuxUpHandler)
- {
- this.upHandler = (MuxUpHandler) uh;
- }
- else
- {
- throw new IllegalStateException("delegate Channel already has a non-Mux UpHandler");
- }
+ this.delegate = delegate;
}
@Override
@@ -371,8 +364,7 @@
@Override
public UpHandler getUpHandler()
{
- // We hide the upHandler from callers so they will set it. Yuck!
- return null;
+ return delegate.getUpHandler();
}
@Override
@@ -410,6 +402,138 @@
delegate.setUpHandler(this.upHandler);
}
+
+
+
+
+
+
+
+
+
+
+ @Override
+ public synchronized void connect(String arg0, Address arg1, String arg2, long arg3, boolean arg4)
+ throws ChannelException
+ {
+ delegate.connect(arg0, arg1, arg2, arg3, arg4);
+ }
+
+ @Override
+ public synchronized void connect(String arg0, boolean arg1) throws ChannelException
+ {
+ delegate.connect(arg0, arg1);
+ }
+
+ @Override
+ public Map<String, Object> dumpStats(String protocolName)
+ {
+ return delegate.dumpStats(protocolName);
+ }
+
+ @Override
+ public String dumpTimerQueue()
+ {
+ return delegate.dumpTimerQueue();
+ }
+
+ @Override
+ public void enableStats(boolean stats)
+ {
+ delegate.enableStats(stats);
+ }
+
+ @Override
+ public String getAddressAsString()
+ {
+ return delegate.getAddressAsString();
+ }
+
+ @Override
+ public String getAddressAsUUID()
+ {
+ return delegate.getAddressAsUUID();
+ }
+
+ @Override
+ public int getNumberOfTasksInTimer()
+ {
+ return delegate.getNumberOfTasksInTimer();
+ }
+
+ @Override
+ public long getReceivedBytes()
+ {
+ return delegate.getReceivedBytes();
+ }
+
+ @Override
+ public long getReceivedMessages()
+ {
+ return delegate.getReceivedMessages();
+ }
+
+ @Override
+ public long getSentBytes()
+ {
+ return delegate.getSentBytes();
+ }
+
+ @Override
+ public long getSentMessages()
+ {
+ return delegate.getSentMessages();
+ }
+
+ @Override
+ public boolean getState(Address target, String stateId, long timeout, boolean useFlushIfPresent)
+ throws ChannelNotConnectedException, ChannelClosedException
+ {
+ return delegate.getState(target, stateId, timeout, useFlushIfPresent);
+ }
+
+ @Override
+ public int getTimerThreads()
+ {
+ return delegate.getTimerThreads();
+ }
+
+ @Override
+ public String getViewAsString()
+ {
+ return delegate.getViewAsString();
+ }
+
+ @Override
+ public String printProtocolSpec(boolean includeProperties)
+ {
+ return delegate.printProtocolSpec(includeProperties);
+ }
+
+ @Override
+ public void resetStats()
+ {
+ delegate.resetStats();
+ }
+
+ @Override
+ public boolean statsEnabled()
+ {
+ return delegate.statsEnabled();
+ }
+
+ @Override
+ public String toString(boolean details)
+ {
+ return delegate.toString(details);
+ }
+
+ @Override
+ public Object up(Event arg0)
+ {
+ return delegate.up(arg0);
+ }
+
public MuxUpHandler getMuxUpHandler()
{
return upHandler;
Modified: projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryImpl.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryImpl.java 2010-07-06 18:41:24 UTC (rev 106465)
+++ projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryImpl.java 2010-07-06 18:42:31 UTC (rev 106466)
@@ -22,18 +22,6 @@
package org.jboss.web.tomcat.service.session.distributedcache.impl;
-import java.io.File;
-
-import javax.management.MBeanServer;
-import javax.management.MBeanServerInvocationHandler;
-import javax.management.ObjectName;
-
-import org.jboss.cache.Cache;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.pojo.PojoCache;
-import org.jboss.cache.pojo.PojoCacheFactory;
-import org.jboss.cache.pojo.jmx.PojoCacheJmxWrapper;
-import org.jboss.cache.pojo.jmx.PojoCacheJmxWrapperMBean;
import org.jboss.metadata.web.jboss.ReplicationGranularity;
import org.jboss.web.tomcat.service.session.distributedcache.impl.jbc.AttributeBasedJBossCacheService;
import org.jboss.web.tomcat.service.session.distributedcache.impl.jbc.FieldBasedJBossCacheService;
@@ -41,38 +29,18 @@
import org.jboss.web.tomcat.service.session.distributedcache.impl.jbc.Util;
import org.jboss.web.tomcat.service.session.distributedcache.spi.ClusteringNotSupportedException;
import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManagerFactory;
import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.TomcatClusterConfig;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.TomcatClusterDistributedCacheManagerFactory;
/**
+ * Standard implementation of DistributedCacheManagerFactory.
+ *
* @author Brian Stansberry
- *
*/
-public class DistributedCacheManagerFactoryImpl implements TomcatClusterDistributedCacheManagerFactory
+public class DistributedCacheManagerFactoryImpl implements DistributedCacheManagerFactory
{
- public static final String DEFAULT_CLUSTER_NAME = "Tomcat-Cluster";
-
- /** TreeCache's isolation level */
- public static final String DEFAULT_ISOLATION_LEVEL = "REPEATABLE_READ";
+ private SessionOwnershipCacheManager sessionOwnershipManager;
- /** TreeCache's cache mode */
- public static final String DEFAULT_CACHE_MODE = "REPL_ASYNC";
-
- /** TreeCache's lock aquisition timeout */
- public static final long DEFAULT_LOCK_TIMEOUT = 15000;
-
- /** TransactionManagerLookup implementation that the TreeCache should use. */
- @SuppressWarnings("deprecation")
- public static final String DEFAULT_TM_LOOKUP =
- org.jboss.cache.transaction.BatchModeTransactionManagerLookup.class.getName();
-
- private TomcatClusterConfig tomcatConfig;
- private boolean pojoCacheLocal = false;
-
- private PojoCache pojoCache;
- private Cache<Object, Object> plainCache;
-
@SuppressWarnings("unchecked")
public DistributedCacheManager getDistributedCacheManager(LocalDistributableSessionManager localManager)
throws ClusteringNotSupportedException
@@ -81,152 +49,33 @@
switch(granularity)
{
case SESSION:
- return plainCache == null? new SessionBasedJBossCacheService(localManager) : new SessionBasedJBossCacheService(localManager, plainCache);
+ return new SessionBasedJBossCacheService(localManager, getSessionOwnershipCacheManager());
case ATTRIBUTE:
- return plainCache == null? new AttributeBasedJBossCacheService(localManager) : new AttributeBasedJBossCacheService(localManager, plainCache);
+ return new AttributeBasedJBossCacheService(localManager, getSessionOwnershipCacheManager());
case FIELD:
- return pojoCache == null? new FieldBasedJBossCacheService(localManager) : new FieldBasedJBossCacheService(localManager, pojoCache);
+ return new FieldBasedJBossCacheService(localManager, getSessionOwnershipCacheManager());
default:
throw new IllegalStateException("Unknown ReplicationGranularity " + granularity);
}
}
- public TomcatClusterConfig getTomcatClusterConfig()
- {
- return tomcatConfig;
- }
-
- public void setTomcatClusterConfig(TomcatClusterConfig clusterConfig)
- {
- this.tomcatConfig = clusterConfig;
- }
-
public void start() throws Exception
{
- if (tomcatConfig != null)
- {
- initializePojoCache();
- }
+ // no-op
}
public void stop() throws Exception
{
- if (pojoCache != null)
- {
- pojoCache.stop();
- pojoCache.destroy();
-
- if (pojoCacheLocal && tomcatConfig.getMBeanServer() != null && tomcatConfig.getCacheObjectName() != null)
- {
- tomcatConfig.getMBeanServer().unregisterMBean(new ObjectName(tomcatConfig.getCacheObjectName()));
- }
- }
+ // no-op
}
-
- public PojoCache getPojoCache()
- {
- return pojoCache;
- }
-
- /**
- * Hook for test fixtures to inject a PojoCache, which if present will
- * be used to create the DistributedCacheManager in preference to any
- * passed <code>cacheConfigName</code>.
- */
- public void setPojoCache(PojoCache pojoCache)
- {
- this.pojoCache = pojoCache;
- this.plainCache = pojoCache.getCache();
- }
-
- public Cache<Object, Object> getPlainCache()
- {
- return plainCache;
- }
-
- /**
- * Hook for test fixtures to inject a Cache, which if present will
- * be used to create the DistributedCacheManager in preference to any
- * passed <code>cacheConfigName</code>.
- */
- public void setPlainCache(Cache<Object, Object> plainCache)
- {
- this.plainCache = plainCache;
- this.pojoCache = null;
- }
- /**
- * Convenience method for test fixtures to clear any injected cache.
- */
- public void clearCaches()
+ private synchronized SessionOwnershipCacheManager getSessionOwnershipCacheManager() throws ClusteringNotSupportedException
{
- this.plainCache = null;
- this.pojoCache = null;
- }
-
- /**
- * Gets our PojCache, either from a local reference or the JMX
- * server. If one is not found, creates and configures it.
- */
- private void initializePojoCache() throws Exception
- {
- if (pojoCache == null) {
-
- PojoCacheJmxWrapperMBean pcWrapper = null;
- MBeanServer server = tomcatConfig.getMBeanServer();
- String cfgName = tomcatConfig.getCacheObjectName();
- ObjectName objName = cfgName == null ? null : new ObjectName(tomcatConfig.getCacheObjectName());
- if (server != null && objName != null && server.isRegistered(objName))
- {
- // Get a proxy to the existing TreeCache
- pcWrapper = ((PojoCacheJmxWrapperMBean)
- MBeanServerInvocationHandler.newProxyInstance(server, objName, PojoCacheJmxWrapperMBean.class, false));
- }
- else
- {
- // See if there is an XML descriptor file to configure the cache
- File configFile = tomcatConfig.getCacheConfigFile();
- String clusterName = tomcatConfig.getClusterName();
-
- if (configFile != null)
- {
- pcWrapper = new PojoCacheJmxWrapper(PojoCacheFactory.createCache(configFile.getAbsolutePath(), false));
-
- if (clusterName != null)
- {
- // Override the XML config with the name provided in
- // server.xml. Method setClusterName is specified in the
- // Cluster interface, otherwise we would not do this
- pcWrapper.getPojoCache().getCache().getConfiguration().setClusterName(clusterName);
- }
- }
- else
- {
- // User did not try to configure the cache.
- // Configure it using defaults. Only exception
- // is the clusterName, which user can specify in server.xml.
- Configuration config = new Configuration();
- String channelName = (clusterName == null) ? DEFAULT_CLUSTER_NAME
- : clusterName;
- config.setClusterName(channelName);
- config.setIsolationLevel(DEFAULT_ISOLATION_LEVEL);
- config.setCacheMode(DEFAULT_CACHE_MODE);
- config.setLockAcquisitionTimeout(DEFAULT_LOCK_TIMEOUT);
- config.setTransactionManagerLookupClass(DEFAULT_TM_LOOKUP);
-
- pcWrapper = new PojoCacheJmxWrapper(PojoCacheFactory.createCache(config, false));
- }
-
- if (server != null && objName != null)
- {
- server.registerMBean(pcWrapper, objName);
- }
-
- pojoCacheLocal = true;
- }
-
- setPojoCache(pcWrapper.getPojoCache());
+ if (this.sessionOwnershipManager == null)
+ {
+ this.sessionOwnershipManager = new SessionOwnershipCacheManager(Util.findPlainCacheManager(), Util.findPojoCacheManager());
}
+ return this.sessionOwnershipManager;
}
}
Copied: projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionOwnershipCache.java (from rev 105346, projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionOwnershipCache.java)
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionOwnershipCache.java (rev 0)
+++ projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionOwnershipCache.java 2010-07-06 18:42:31 UTC (rev 106466)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.session.distributedcache.impl;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.jboss.cache.Cache;
+import org.jboss.ha.framework.server.lock.SharedLocalYieldingClusterLockManager;
+
+/**
+ * Encapsulates a Cache and an associated SharedLocalYieldingClusterLockManager.
+ *
+ * @author Brian Stansberry
+ *
+ * @version $Revision$
+ */
+public class SessionOwnershipCache
+{
+ private final Cache<Object, Object> cache;
+ private final SharedLocalYieldingClusterLockManager lockManager;
+ private final AtomicInteger refCount;
+
+ public SessionOwnershipCache(Cache<Object, Object> cache, SharedLocalYieldingClusterLockManager lockManager)
+ {
+ this(cache, lockManager, new AtomicInteger(0));
+ }
+
+ protected SessionOwnershipCache(Cache<Object, Object> cache, SharedLocalYieldingClusterLockManager lockManager, AtomicInteger refCount)
+ {
+ this.cache = cache;
+ this.lockManager = lockManager;
+ this.refCount = refCount;
+ }
+
+ public Cache<Object, Object> getCache()
+ {
+ return cache;
+ }
+
+ public SharedLocalYieldingClusterLockManager getLockManager()
+ {
+ return lockManager;
+ }
+
+ AtomicInteger getRefCount()
+ {
+ return refCount;
+ }
+
+ int incrementRefCount()
+ {
+ return refCount.incrementAndGet();
+ }
+
+ int decrementRefCount()
+ {
+ return refCount.decrementAndGet();
+ }
+
+
+}
Copied: projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionOwnershipCacheManager.java (from rev 105346, projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionOwnershipCacheManager.java)
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionOwnershipCacheManager.java (rev 0)
+++ projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionOwnershipCacheManager.java 2010-07-06 18:42:31 UTC (rev 106466)
@@ -0,0 +1,185 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.session.distributedcache.impl;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheManager;
+import org.jboss.cache.CacheStatus;
+import org.jboss.cache.config.RuntimeConfig;
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.ha.core.framework.server.CoreGroupCommunicationService;
+import org.jboss.ha.framework.server.PojoCacheManager;
+import org.jboss.ha.framework.server.lock.SharedLocalYieldingClusterLockManager;
+import org.jgroups.Channel;
+import org.jgroups.blocks.mux.Muxer;
+
+/**
+ *
+ *
+ * @author Brian Stansberry
+ *
+ * @version $Revision$
+ */
+public class SessionOwnershipCacheManager
+{
+ /** The scope we assign to our CoreGroupCommunicationService */
+ public static final Short HTTP_SESSION_MGR_SCOPE_ID = Short.valueOf((short) 222);
+
+ private final CacheManager plainCacheManager;
+ private final PojoCacheManager pojoCacheManager;
+
+ private final Map<String, SessionOwnershipCache> managers = new ConcurrentHashMap<String, SessionOwnershipCache>();
+
+ public SessionOwnershipCacheManager(CacheManager plainCacheManager, PojoCacheManager pojoCacheManager)
+ {
+ this.plainCacheManager = plainCacheManager;
+ this.pojoCacheManager = pojoCacheManager;
+ }
+
+ public synchronized SessionOwnershipCache getSessionOwnershipCache(String configName)
+ {
+ SessionOwnershipCache soc = managers.get(configName);
+ if (soc == null)
+ {
+ try
+ {
+ Cache<Object, Object> plainCache = getPlainCacheManager().getCache(configName, true);
+ SharedLocalYieldingClusterLockManager lockManager = createLockManager(plainCache, configName);
+ soc = new SessionOwnershipCache(plainCache, lockManager);
+ managers.put(configName, soc);
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed creating " + SessionOwnershipCache.class.getSimpleName(), e);
+ }
+ }
+ soc.incrementRefCount();
+ return soc;
+ }
+
+ public synchronized void releasePlainCache(String configName)
+ {
+ SessionOwnershipCache soc = managers.get(configName);
+ if (soc != null)
+ {
+ getPlainCacheManager().releaseCache(configName);
+ if (soc.decrementRefCount() == 0)
+ {
+ managers.remove(configName);
+ }
+ }
+ }
+
+ public synchronized SessionOwnershipPojoCache getSessionOwnershipPojoCache(String configName)
+ {
+ SessionOwnershipCache soc = managers.get(configName);
+ if (!(soc instanceof SessionOwnershipPojoCache))
+ {
+ try
+ {
+ PojoCache pojoCache = getPojoCacheManager().getPojoCache(configName, true);
+ SharedLocalYieldingClusterLockManager lockManager = createLockManager(pojoCache.getCache(), configName);
+ soc = soc == null ? new SessionOwnershipPojoCache(pojoCache, lockManager) : new SessionOwnershipPojoCache(pojoCache, lockManager, soc.getRefCount());
+ managers.put(configName, soc);
+ pojoCache.start();
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed creating " + SessionOwnershipPojoCache.class.getSimpleName(), e);
+ }
+
+ }
+ soc.incrementRefCount();
+ return (SessionOwnershipPojoCache) soc;
+ }
+
+ public synchronized void releasePojoCache(String configName)
+ {
+ SessionOwnershipCache soc = managers.get(configName);
+ if (soc != null)
+ {
+ getPojoCacheManager().releaseCache(configName);
+ if (soc.decrementRefCount() == 0)
+ {
+ managers.remove(configName);
+ }
+ }
+ }
+
+ private SharedLocalYieldingClusterLockManager createLockManager(Cache<?, ?> cache, String configName) throws Exception
+ {
+ RuntimeConfig rc = cache.getConfiguration().getRuntimeConfig();
+ Channel channel = rc.getChannel();
+ if (channel == null)
+ {
+ // TODO create and use a Channel just for locking???
+ throw new IllegalStateException("Cache has no Channel");
+ }
+
+ // Cache must be started before the CoreGCS that shares its channel
+ if (cache.getCacheStatus() != CacheStatus.STARTED)
+ {
+ if (cache.getCacheStatus() != CacheStatus.CREATED)
+ {
+ cache.create();
+ }
+ cache.start();
+ }
+
+ // At this point the Channel should have a Muxer as its UpHandler
+ if (!(channel.getUpHandler() instanceof Muxer<?>))
+ {
+ throw new IllegalStateException("Cache " + configName + " has a Channel that does not use a Muxer as its UpHandler");
+ }
+
+ CoreGroupCommunicationService gcs = new CoreGroupCommunicationService();
+ gcs.setChannel(channel);
+ gcs.setScopeId(HTTP_SESSION_MGR_SCOPE_ID);
+ gcs.start();
+
+ SharedLocalYieldingClusterLockManager lockManager = new SharedLocalYieldingClusterLockManager("HTTPSESSIONOWNER", gcs, gcs);
+ lockManager.start();
+ return lockManager;
+ }
+
+ public PojoCacheManager getPojoCacheManager()
+ {
+ return pojoCacheManager;
+ }
+
+ public CacheManager getPlainCacheManager()
+ {
+ return plainCacheManager;
+ }
+}
Copied: projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionOwnershipPojoCache.java (from rev 105346, projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionOwnershipPojoCache.java)
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionOwnershipPojoCache.java (rev 0)
+++ projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionOwnershipPojoCache.java 2010-07-06 18:42:31 UTC (rev 106466)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.session.distributedcache.impl;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.ha.framework.server.lock.SharedLocalYieldingClusterLockManager;
+
+/**
+ *
+ *
+ * @author Brian Stansberry
+ *
+ * @version $Revision$
+ */
+public class SessionOwnershipPojoCache extends SessionOwnershipCache
+{
+ private final PojoCache pojoCache;
+
+ public SessionOwnershipPojoCache(PojoCache cache, SharedLocalYieldingClusterLockManager lockManager)
+ {
+ this(cache, lockManager, new AtomicInteger(0));
+ }
+
+ public SessionOwnershipPojoCache(PojoCache cache, SharedLocalYieldingClusterLockManager lockManager, AtomicInteger refCount)
+ {
+ super(cache.getCache(), lockManager, refCount);
+ this.pojoCache = cache;
+ }
+
+ public PojoCache getPojoCache()
+ {
+ return pojoCache;
+ }
+}
Modified: projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/TestDistributedCacheManagerFactoryImpl.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/TestDistributedCacheManagerFactoryImpl.java 2010-07-06 18:41:24 UTC (rev 106465)
+++ projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/TestDistributedCacheManagerFactoryImpl.java 2010-07-06 18:42:31 UTC (rev 106466)
@@ -22,15 +22,18 @@
package org.jboss.web.tomcat.service.session.distributedcache.impl;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
+import org.jboss.cache.Cache;
import org.jboss.cache.CacheStatus;
import org.jboss.cache.Fqn;
import org.jboss.cache.buddyreplication.NextMemberBuddyLocatorConfig;
import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.RuntimeConfig;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.config.Configuration.NodeLockingScheme;
@@ -39,16 +42,27 @@
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
import org.jboss.cache.transaction.BatchModeTransactionManagerLookup;
+import org.jboss.ha.core.channelfactory.JChannelFactory;
+import org.jboss.ha.core.framework.server.CoreGroupCommunicationService;
+import org.jboss.ha.framework.server.lock.SharedLocalYieldingClusterLockManager;
import org.jboss.logging.Logger;
+import org.jboss.metadata.web.jboss.ReplicationGranularity;
+import org.jboss.web.tomcat.service.session.distributedcache.impl.jbc.AttributeBasedJBossCacheService;
+import org.jboss.web.tomcat.service.session.distributedcache.impl.jbc.FieldBasedJBossCacheService;
+import org.jboss.web.tomcat.service.session.distributedcache.impl.jbc.SessionBasedJBossCacheService;
+import org.jboss.web.tomcat.service.session.distributedcache.impl.jbc.Util;
import org.jboss.web.tomcat.service.session.distributedcache.spi.ClusteringNotSupportedException;
import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager;
import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingDistributableSessionData;
import org.jboss.web.tomcat.service.session.distributedcache.spi.TestDistributedCacheManagerFactory;
+import org.jgroups.Channel;
+import org.jgroups.blocks.mux.MuxUpHandler;
+import org.jgroups.blocks.mux.Muxer;
/**
+ * Standard implementation of {@link TestDistributedCacheManagerFactory}
*
- *
* @author Brian Stansberry
*
* @version $Revision$
@@ -57,67 +71,170 @@
{
private static final Logger log = Logger.getLogger(TestDistributedCacheManagerFactoryImpl.class);
- private DistributedCacheManagerFactoryImpl delegate = new DistributedCacheManagerFactoryImpl();
-
+ private static int id_count = 0;
+
+ private static final JChannelFactory channelFactory;
+ static
+ {
+ String pkg = TestDistributedCacheManagerFactoryImpl.class.getPackage().getName().replace('.', '/');
+ URL stacks_url = TestDistributedCacheManagerFactoryImpl.class.getClassLoader().getResource(pkg + "/test-stacks.xml");
+ channelFactory = new JChannelFactory();
+ channelFactory.setExposeChannels(false);
+ channelFactory.setExposeProtocols(false);
+ channelFactory.setAddMissingSingletonName(false);
+ try
+ {
+ channelFactory.setMultiplexerConfig(stacks_url);
+ channelFactory.start();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private PojoCache pojoCache;
+ private Cache<Object, Object> plainCache;
+ private SharedLocalYieldingClusterLockManager lockManager;
+ private CoreGroupCommunicationService gcs;
+
+
public void configure(boolean local, String passivationDir, boolean totalReplication, boolean marshalling,
boolean purgeCacheLoader)
{
- PojoCache pc = createCache(local, passivationDir, totalReplication, marshalling, purgeCacheLoader);
- delegate.setPojoCache(pc);
+ this.pojoCache = createCache(local, passivationDir, totalReplication, marshalling, purgeCacheLoader, channelFactory);
+ this.plainCache = pojoCache.getCache();
+ establishLockManager();
}
@SuppressWarnings("unchecked")
public <T extends OutgoingDistributableSessionData> DistributedCacheManager<T> getDistributedCacheManager(
LocalDistributableSessionManager localManager) throws ClusteringNotSupportedException
{
- return delegate.getDistributedCacheManager(localManager);
+ ReplicationGranularity granularity = Util.getReplicationGranularity(localManager);
+ switch(granularity)
+ {
+ case SESSION:
+ return (DistributedCacheManager<T>) new SessionBasedJBossCacheService(localManager, new SessionOwnershipCache(plainCache, lockManager));
+ case ATTRIBUTE:
+ return (DistributedCacheManager<T>) new AttributeBasedJBossCacheService(localManager, new SessionOwnershipCache(plainCache, lockManager));
+ case FIELD:
+ return (DistributedCacheManager<T>) new FieldBasedJBossCacheService(localManager, new SessionOwnershipPojoCache(pojoCache, lockManager));
+ default:
+ throw new IllegalStateException("Unknown ReplicationGranularity " + granularity);
+ }
}
public void cleanup(boolean doRemove)
{
- PojoCache cache = delegate.getPojoCache();
- if (cache == null)
+ if (pojoCache == null)
return;
- if (doRemove && CacheStatus.STARTED.equals(cache.getCache().getCacheStatus()))
+ if (doRemove && CacheStatus.STARTED.equals(pojoCache.getCache().getCacheStatus()))
{
// Try to clean up so we avoid loading sessions
// from storage in later tests
try
{
- log.info("Removing /JSESSION from " + cache.getCache().getLocalAddress());
- cache.getCache().removeNode(Fqn.fromString("/JSESSION"));
+ log.info("Removing /JSESSION from " + pojoCache.getCache().getLocalAddress());
+ pojoCache.getCache().removeNode(Fqn.fromString("/JSESSION"));
}
catch (Exception e)
{
- log.error("Cache " + cache + ": " + e.getMessage(), e);
+ log.error("Cache " + pojoCache + ": " + e.getMessage(), e);
}
}
+
try
- {
- cache.stop();
- cache.destroy();
+ {
+ this.lockManager.stop();
+ this.gcs.stop();
+ this.pojoCache.stop();
+ this.pojoCache.destroy();
}
catch (Exception e)
{
- log.error("Cache " + cache + ": " + e.getMessage(), e);
+ log.error("Cache " + pojoCache + ": " + e.getMessage(), e);
}
+ finally
+ {
+ this.pojoCache = null;
+ this.plainCache = null;
+ this.lockManager = null;
+ }
}
+ private void establishLockManager()
+ {
+ RuntimeConfig rc = this.plainCache.getConfiguration().getRuntimeConfig();
+ Channel channel = rc.getChannel();
+ if (channel == null)
+ {
+ throw new IllegalStateException("Cache has no Channel");
+ }
+
+ // Cache must be started before the CoreGCS that shares its channel
+ if (this.plainCache.getCacheStatus() != CacheStatus.STARTED)
+ {
+ if (this.plainCache.getCacheStatus() != CacheStatus.CREATED)
+ {
+ this.plainCache.create();
+ }
+ this.plainCache.start();
+ }
+
+ // At this point the Channel should have a Muxer as its UpHandler
+ if (!(channel.getUpHandler() instanceof Muxer<?>))
+ {
+ throw new IllegalStateException("Cache has a Channel that does not use a Muxer as its UpHandler");
+ }
+
+ gcs = new CoreGroupCommunicationService();
+ gcs.setChannel(channel);
+ gcs.setScopeId(SessionOwnershipCacheManager.HTTP_SESSION_MGR_SCOPE_ID);
+
+ try
+ {
+ gcs.start();
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed starting " + CoreGroupCommunicationService.class.getSimpleName(), e);
+ }
+
+ this.lockManager = new SharedLocalYieldingClusterLockManager("HTTPSESSIONOWNER", gcs, gcs);
+ try
+ {
+ this.lockManager.start();
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed starting " + lockManager.getClass().getSimpleName(), e);
+ }
+ }
+
private static PojoCache createCache(boolean local, String passivationDir,
- boolean totalReplication, boolean marshalling, boolean purgeCacheLoader)
+ boolean totalReplication, boolean marshalling, boolean purgeCacheLoader, JChannelFactory channelFactory)
{
- Configuration cfg = getConfiguration(local, passivationDir, totalReplication, marshalling, purgeCacheLoader);
+ Configuration cfg = getConfiguration(local, passivationDir, totalReplication, marshalling, purgeCacheLoader, channelFactory);
return PojoCacheFactory.createCache(cfg, true);
}
private static Configuration getConfiguration(boolean local, String passivationDir,
- boolean totalReplication, boolean marshalling, boolean purgeCacheLoader)
+ boolean totalReplication, boolean marshalling, boolean purgeCacheLoader, JChannelFactory channelFactory)
{
Configuration config = new Configuration();
config.setClusterName("Tomcat-TestCluster");
@@ -176,19 +293,35 @@
config.setBuddyReplicationConfig(brc);
}
+ config.getRuntimeConfig().setChannel(createChannel(channelFactory));
+
return config;
}
+
+ private static Channel createChannel(JChannelFactory channelFactory)
+ {
+ String stack = System.getProperty("jboss.default.jgroups.stack", "udp");
+ try
+ {
+ Channel ch = channelFactory.createChannel(stack);
+ ch.setUpHandler(new MuxUpHandler());
+ ch.setName("test-" + id_count++);
+ return ch;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
public Object getLocalAddress()
{
- PojoCache pc = delegate.getPojoCache();
- return pc == null ? null : pc.getCache().getLocalAddress();
+ return pojoCache == null ? null : pojoCache.getCache().getLocalAddress();
}
public List<Object> getMembers()
{
- PojoCache pc = delegate.getPojoCache();
- return pc == null ? null : new ArrayList<Object>(pc.getCache().getMembers());
+ return pojoCache == null ? null : new ArrayList<Object>(pojoCache.getCache().getMembers());
}
}
Modified: projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java 2010-07-06 18:41:24 UTC (rev 106465)
+++ projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java 2010-07-06 18:42:31 UTC (rev 106466)
@@ -37,7 +37,6 @@
import org.jboss.cache.Cache;
import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheManager;
import org.jboss.cache.CacheStatus;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
@@ -53,6 +52,8 @@
import org.jboss.ha.framework.server.lock.TimeoutException;
import org.jboss.logging.Logger;
import org.jboss.util.loading.ContextClassLoaderSwitcher;
+import org.jboss.web.tomcat.service.session.distributedcache.impl.SessionOwnershipCache;
+import org.jboss.web.tomcat.service.session.distributedcache.impl.SessionOwnershipCacheManager;
import org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager;
import org.jboss.web.tomcat.service.session.distributedcache.spi.ClusteringNotSupportedException;
import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSessionMetadata;
@@ -113,9 +114,10 @@
protected Logger log_ = Logger.getLogger(getClass());
- private CacheManager cacheManager_;
+ private SessionOwnershipCacheManager cacheManager_;
// FIXME make private when FieldBasedJBossCacheService is gone
protected Cache<Object, Object> plainCache_;
+ private SharedLocalYieldingClusterLockManager lockManager_;
/** Context path for webapp + hostName; this + session id is a unique combo. */
protected String combinedPath_;
@@ -140,18 +142,22 @@
private boolean purgeOnStartStop_ = true;
- protected AbstractJBossCacheService(LocalDistributableSessionManager localManager) throws ClusteringNotSupportedException
+ protected AbstractJBossCacheService(LocalDistributableSessionManager localManager, SessionOwnershipCacheManager cacheManager) throws ClusteringNotSupportedException
{
if (localManager == null)
{
throw new IllegalArgumentException("localManager is null");
}
+ if (cacheManager == null)
+ {
+ throw new IllegalArgumentException("cacheManager is null");
+ }
this.manager_ = localManager;
- establishCacheManager();
+ this.cacheManager_ = cacheManager;
this.cacheConfigName_ = Util.getCacheConfigName(localManager);
}
- protected AbstractJBossCacheService(LocalDistributableSessionManager localManager, Cache<Object, Object> cache)
+ protected AbstractJBossCacheService(LocalDistributableSessionManager localManager, SessionOwnershipCache cache)
{
if (localManager == null)
{
@@ -163,7 +169,8 @@
}
this.manager_ = localManager;
- this.plainCache_ = cache;
+ this.plainCache_ = cache.getCache();
+ this.lockManager_ = cache.getLockManager();
}
protected LocalDistributableSessionManager getManager()
@@ -171,6 +178,11 @@
return manager_;
}
+ protected SessionOwnershipCacheManager getSessionOwnershipCacheManager()
+ {
+ return this.cacheManager_;
+ }
+
protected Cache<Object, Object> getCache()
{
return plainCache_;
@@ -180,6 +192,11 @@
{
this.plainCache_ = cache;
}
+
+ protected void setLockManager(SharedLocalYieldingClusterLockManager lockManager)
+ {
+ this.lockManager_ = lockManager;
+ }
public void start()
{
@@ -218,6 +235,18 @@
{
plainCache_.start();
}
+ try
+ {
+ this.lockManager_.start();
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to start lock manager", e);
+ }
// We require the cache batchingManager to be BatchModeTransactionManager now.
TransactionManager tm = plainCache_.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -447,11 +476,6 @@
cacheWrapper_.put(fqn, map);
}
-
- protected void establishCacheManager() throws ClusteringNotSupportedException
- {
- this.cacheManager_ = Util.findPlainCacheManager();
- }
protected void establishCache()
{
@@ -491,7 +515,9 @@
{
throw new IllegalStateException("No cache configuration name available");
}
- this.plainCache_ = Util.findPlainCache(this.cacheConfigName_, this.cacheManager_);
+ SessionOwnershipCache soc = this.cacheManager_.getSessionOwnershipCache(this.cacheConfigName_);
+ this.plainCache_ = (Cache<Object, Object>) soc.getCache();
+ this.lockManager_ = soc.getLockManager();
}
/**
@@ -725,6 +751,11 @@
return usePassivation_;
}
+ public void setForceSynchronous(boolean forceSynchronous)
+ {
+ this.cacheWrapper_.setForceSynchronous(forceSynchronous);
+ }
+
protected Fqn<String> getWebappFqn()
{
// /SESSION/webAppPath_hostName
@@ -798,8 +829,11 @@
private SharedLocalYieldingClusterLockManager getLockManager()
{
- // FIXME
- throw new UnsupportedOperationException("implement me");
+ if (lockManager_ == null)
+ {
+ establishCache();
+ }
+ return lockManager_;
}
private long getLockTimeout()
@@ -812,7 +846,7 @@
{
try
{
- this.cacheManager_.releaseCache(cacheConfigName);
+ this.cacheManager_.releasePlainCache(cacheConfigName);
}
catch (Exception e)
{
Modified: projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AttributeBasedJBossCacheService.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AttributeBasedJBossCacheService.java 2010-07-06 18:41:24 UTC (rev 106465)
+++ projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AttributeBasedJBossCacheService.java 2010-07-06 18:42:31 UTC (rev 106466)
@@ -26,10 +26,11 @@
import java.util.Map;
import java.util.Set;
-import org.jboss.cache.Cache;
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
+import org.jboss.web.tomcat.service.session.distributedcache.impl.SessionOwnershipCache;
+import org.jboss.web.tomcat.service.session.distributedcache.impl.SessionOwnershipCacheManager;
import org.jboss.web.tomcat.service.session.distributedcache.spi.ClusteringNotSupportedException;
import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingAttributeGranularitySessionData;
@@ -39,12 +40,12 @@
*/
public class AttributeBasedJBossCacheService extends AbstractJBossCacheService<OutgoingAttributeGranularitySessionData>
{
- public AttributeBasedJBossCacheService(LocalDistributableSessionManager localManager) throws ClusteringNotSupportedException
+ public AttributeBasedJBossCacheService(LocalDistributableSessionManager localManager, SessionOwnershipCacheManager cacheManager) throws ClusteringNotSupportedException
{
- super(localManager);
+ super(localManager, cacheManager);
}
- public AttributeBasedJBossCacheService(LocalDistributableSessionManager localManager, Cache<Object, Object> cache)
+ public AttributeBasedJBossCacheService(LocalDistributableSessionManager localManager, SessionOwnershipCache cache)
{
super(localManager, cache);
}
Modified: projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/FieldBasedJBossCacheService.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/FieldBasedJBossCacheService.java 2010-07-06 18:41:24 UTC (rev 106465)
+++ projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/FieldBasedJBossCacheService.java 2010-07-06 18:42:31 UTC (rev 106466)
@@ -27,11 +27,14 @@
import java.util.Set;
import java.util.StringTokenizer;
+import org.jboss.cache.Cache;
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.ha.framework.server.PojoCacheManager;
-import org.jboss.ha.framework.server.PojoCacheManagerLocator;
+import org.jboss.web.tomcat.service.session.distributedcache.impl.SessionOwnershipCache;
+import org.jboss.web.tomcat.service.session.distributedcache.impl.SessionOwnershipCacheManager;
+import org.jboss.web.tomcat.service.session.distributedcache.impl.SessionOwnershipPojoCache;
import org.jboss.web.tomcat.service.session.distributedcache.spi.ClusteringNotSupportedException;
import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingDistributableSessionData;
@@ -76,9 +79,10 @@
private PojoCacheManager pojoCacheManager_;
private PojoCache pojoCache_;
- public FieldBasedJBossCacheService(LocalDistributableSessionManager localManager) throws ClusteringNotSupportedException
+ public FieldBasedJBossCacheService(LocalDistributableSessionManager localManager, SessionOwnershipCacheManager cacheManager) throws ClusteringNotSupportedException
{
- super(localManager);
+ super(localManager, cacheManager);
+ this.pojoCacheManager_ = cacheManager.getPojoCacheManager();
}
/**
@@ -86,10 +90,10 @@
*
* @param cache
*/
- public FieldBasedJBossCacheService(LocalDistributableSessionManager localManager, PojoCache cache)
+ public FieldBasedJBossCacheService(LocalDistributableSessionManager localManager, SessionOwnershipPojoCache cache)
{
- super(localManager, cache.getCache());
- this.pojoCache_ = cache;
+ super(localManager, cache);
+ this.pojoCache_ = cache.getPojoCache();
}
public boolean getSupportsAttributeOperations()
@@ -198,13 +202,6 @@
Fqn<String> fqn = getSessionFqn(combinedPath_, realId);
setupSessionRegion(fqn);
}
-
-
- @Override
- protected void establishCacheManager() throws ClusteringNotSupportedException
- {
- this.pojoCacheManager_ = Util.findPojoCacheManager();
- }
@Override
protected void obtainCacheFromManager()
@@ -217,8 +214,10 @@
{
throw new IllegalStateException("No cache configuration name available");
}
- this.pojoCache_ = Util.findPojoCache(this.cacheConfigName_, this.pojoCacheManager_);
- this.plainCache_ = this.pojoCache_.getCache();
+ SessionOwnershipPojoCache soc = getSessionOwnershipCacheManager().getSessionOwnershipPojoCache(this.cacheConfigName_);
+ setLockManager(soc.getLockManager());
+ this.pojoCache_ = soc.getPojoCache();
+ setCache(this.pojoCache_.getCache());
}
@Override
@@ -263,7 +262,7 @@
{
try
{
- this.pojoCacheManager_.releaseCache(cacheConfigName);
+ getSessionOwnershipCacheManager().releasePojoCache(cacheConfigName);
}
catch (Exception e)
{
Modified: projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/JBossCacheWrapper.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/JBossCacheWrapper.java 2010-07-06 18:41:24 UTC (rev 106465)
+++ projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/JBossCacheWrapper.java 2010-07-06 18:42:31 UTC (rev 106466)
@@ -21,7 +21,6 @@
*/
package org.jboss.web.tomcat.service.session.distributedcache.impl.jbc;
-import java.util.Collections;
import java.util.Map;
import java.util.Random;
@@ -29,6 +28,7 @@
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.SuspectException;
+import org.jboss.cache.config.Option;
import org.jboss.cache.lock.TimeoutException;
public class JBossCacheWrapper
@@ -40,6 +40,7 @@
private static final int[] BACK_OFF_INTERVALS = { 10, 100 };
private Cache<Object, Object> plainCache_;
private final Random random = new Random(System.currentTimeMillis());
+ private volatile boolean forceSynchronous = false;
JBossCacheWrapper(Cache<Object, Object> cache)
{
@@ -52,12 +53,9 @@
for (int i = 0; i < RETRY; i++)
{
try
- {
- if (gravitate)
- {
- plainCache_.getInvocationContext().getOptionOverrides()
- .setForceDataGravitation(true);
- }
+ {
+ this.getOptionOverrides().setForceDataGravitation(gravitate);
+
return plainCache_.getData(fqn);
}
catch (TimeoutException e)
@@ -102,12 +100,9 @@
for (int i = 0; i < RETRY; i++)
{
try
- {
- if (gravitate)
- {
- plainCache_.getInvocationContext().getOptionOverrides()
- .setForceDataGravitation(true);
- }
+ {
+ this.getOptionOverrides().setForceDataGravitation(gravitate);
+
return plainCache_.get(fqn, id);
}
catch (TimeoutException e)
@@ -143,6 +138,7 @@
{
try
{
+ this.getOptionOverrides();
plainCache_.put(fqn, id, value);
return;
}
@@ -178,6 +174,7 @@
{
try
{
+ this.getOptionOverrides();
plainCache_.put(fqn, map);
return;
}
@@ -213,6 +210,7 @@
{
try
{
+ this.getOptionOverrides();
return plainCache_.remove(fqn, id);
}
catch (TimeoutException e)
@@ -247,8 +245,8 @@
{
try
{
- plainCache_.getInvocationContext().getOptionOverrides()
- .setCacheModeLocal(true);
+ this.getOptionOverrides().setCacheModeLocal(true);
+
return plainCache_.remove(fqn, id);
}
catch (TimeoutException e)
@@ -277,6 +275,7 @@
{
try
{
+ this.getOptionOverrides();
plainCache_.removeNode(fqn);
return;
}
@@ -310,8 +309,8 @@
{
try
{
- plainCache_.getInvocationContext().getOptionOverrides()
- .setCacheModeLocal(true);
+ this.getOptionOverrides().setCacheModeLocal(true);
+
plainCache_.removeNode(fqn);
return;
}
@@ -336,6 +335,7 @@
{
try
{
+ this.getOptionOverrides();
plainCache_.evict(fqn, true);
return;
@@ -354,6 +354,11 @@
throw new RuntimeException(RETRY_FAIL_MSG, ex);
}
+ void setForceSynchronous(boolean forceSynchronous)
+ {
+ this.forceSynchronous = forceSynchronous;
+ }
+
/**
* Causes the calling thread to sleep a random amount of time up to
* BACK_OFF_INTERVALS[attempt].
@@ -380,4 +385,11 @@
}
return true;
}
+
+ private Option getOptionOverrides()
+ {
+ Option option = this.plainCache_.getInvocationContext().getOptionOverrides();
+ option.setForceSynchronous(this.forceSynchronous);
+ return option;
+ }
}
Modified: projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionBasedJBossCacheService.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionBasedJBossCacheService.java 2010-07-06 18:41:24 UTC (rev 106465)
+++ projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionBasedJBossCacheService.java 2010-07-06 18:42:31 UTC (rev 106466)
@@ -24,8 +24,9 @@
import java.util.Map;
import java.util.Set;
-import org.jboss.cache.Cache;
import org.jboss.metadata.web.jboss.ReplicationGranularity;
+import org.jboss.web.tomcat.service.session.distributedcache.impl.SessionOwnershipCache;
+import org.jboss.web.tomcat.service.session.distributedcache.impl.SessionOwnershipCacheManager;
import org.jboss.web.tomcat.service.session.distributedcache.spi.ClusteringNotSupportedException;
import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingSessionGranularitySessionData;
@@ -39,12 +40,12 @@
new UnsupportedOperationException("Attribute operations not supported " +
"with ReplicationGranularity " + ReplicationGranularity.SESSION);
- public SessionBasedJBossCacheService(LocalDistributableSessionManager localManager) throws ClusteringNotSupportedException
+ public SessionBasedJBossCacheService(LocalDistributableSessionManager localManager, SessionOwnershipCacheManager cacheManager) throws ClusteringNotSupportedException
{
- super(localManager);
+ super(localManager, cacheManager);
}
- public SessionBasedJBossCacheService(LocalDistributableSessionManager localManager, Cache<Object, Object> cache)
+ public SessionBasedJBossCacheService(LocalDistributableSessionManager localManager, SessionOwnershipCache cache)
{
super(localManager, cache);
}
Deleted: projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionOwnershipCache.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionOwnershipCache.java 2010-07-06 18:41:24 UTC (rev 106465)
+++ projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionOwnershipCache.java 2010-07-06 18:42:31 UTC (rev 106466)
@@ -1,57 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.session.distributedcache.impl.jbc;
-
-import org.jboss.cache.Cache;
-import org.jboss.ha.framework.server.lock.SharedLocalYieldingClusterLockManager;
-
-/**
- *
- *
- * @author Brian Stansberry
- *
- * @version $Revision$
- */
-public class SessionOwnershipCache
-{
- private final Cache<?, ?> cache;
- private final SharedLocalYieldingClusterLockManager lockManager;
-
- public SessionOwnershipCache(Cache<?, ?> cache, SharedLocalYieldingClusterLockManager lockManager)
- {
- this.cache = cache;
- this.lockManager = lockManager;
- }
-
- public Cache<?, ?> getCache()
- {
- return cache;
- }
-
- public SharedLocalYieldingClusterLockManager getLockManager()
- {
- return lockManager;
- }
-
-
-}
Deleted: projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionOwnershipCacheManager.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionOwnershipCacheManager.java 2010-07-06 18:41:24 UTC (rev 106465)
+++ projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionOwnershipCacheManager.java 2010-07-06 18:42:31 UTC (rev 106466)
@@ -1,158 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.session.distributedcache.impl.jbc;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.jboss.cache.Cache;
-import org.jboss.cache.CacheManager;
-import org.jboss.cache.CacheStatus;
-import org.jboss.cache.config.RuntimeConfig;
-import org.jboss.cache.pojo.PojoCache;
-import org.jboss.ha.cachemanager.MuxHandlerChannel;
-import org.jboss.ha.framework.interfaces.GroupMembershipNotifier;
-import org.jboss.ha.framework.interfaces.GroupRpcDispatcher;
-import org.jboss.ha.framework.server.PojoCacheManager;
-import org.jboss.ha.framework.server.lock.SharedLocalYieldingClusterLockManager;
-import org.jgroups.Channel;
-import org.jgroups.ChannelFactory;
-import org.jgroups.blocks.mux.Muxer;
-
-/**
- *
- *
- * @author Brian Stansberry
- *
- * @version $Revision$
- */
-public class SessionOwnershipCacheManager
-{
- private final CacheManager plainCacheManager;
- private final PojoCacheManager pojoCacheManager;
-
- private final Map<String, SessionOwnershipCache> managers = new ConcurrentHashMap<String, SessionOwnershipCache>();
-
- public SessionOwnershipCacheManager(CacheManager plainCacheManager, PojoCacheManager pojoCacheManager)
- {
- this.plainCacheManager = plainCacheManager;
- this.pojoCacheManager = pojoCacheManager;
- }
-
- public synchronized SessionOwnershipCache getSessionOwnershipCache(String configName) throws Exception
- {
- SessionOwnershipCache soc = managers.get(configName);
- if (soc == null)
- {
- Cache<?, ?> plainCache = plainCacheManager.getCache(configName, false);
- SharedLocalYieldingClusterLockManager lockManager = configureCache(null, plainCache, configName);
- soc = new SessionOwnershipCache(plainCache, lockManager);
- managers.put(configName, soc);
- }
- return soc;
- }
-
- public synchronized SessionOwnershipPojoCache getSessionOwnershipPojoCache(String configName) throws Exception
- {
- SessionOwnershipCache soc = managers.get(configName);
- if (!(soc instanceof SessionOwnershipPojoCache))
- {
- PojoCache pojoCache = pojoCacheManager.getPojoCache(configName, false);
- SharedLocalYieldingClusterLockManager lockManager = configureCache(pojoCache, pojoCache.getCache(), configName);
- soc = new SessionOwnershipPojoCache(pojoCache, lockManager);
- managers.put(configName, soc);
- pojoCache.start();
-
- }
- return (SessionOwnershipPojoCache) soc;
- }
-
- private SharedLocalYieldingClusterLockManager configureCache(PojoCache pojoCache, Cache<?, ?> cache, String configName) throws Exception
- {
- RuntimeConfig rc = cache.getConfiguration().getRuntimeConfig();
- Channel channel = rc.getChannel();
- if (cache.getCacheStatus() == CacheStatus.STARTED)
- {
- if (channel == null)
- {
- // TODO create and use a Channel just for locking???
- throw new IllegalStateException("Cache is started but has no Channel");
- }
- }
- else {
- if (channel == null)
- {
- ChannelFactory cf = rc.getMuxChannelFactory();
- if (cf == null)
- {
- throw new IllegalStateException("Cache configuration " + configName + " does not have a ChannelFactory injected");
- }
- String stack = cache.getConfiguration().getMuxStackName();
- if (stack == null)
- {
- throw new IllegalStateException("Cache configuration " + configName + " does not have a MuxStackName configured");
- }
- channel = cf.createChannel(stack);
- rc.setChannel(new MuxHandlerChannel(channel));
- }
- else if (channel.getUpHandler() == null)
- {
- // replace
- rc.setChannel(new MuxHandlerChannel(channel));
- }
- // else the Channel was injected and already had a handler -- shouldn't happen
-
- // Start the Cache so it injects it's UpHandler into MuxHandlerChannel
- if (pojoCache != null)
- {
- pojoCache.start();
- }
- else if (cache != null)
- {
- if (cache.getCacheStatus() != CacheStatus.CREATED)
- {
- cache.create();
- }
- cache.start();
- }
- }
-
- // At this point the Channel should have a Muxer as its UpHandler, either because
- // it came that way or we used MuxHandlerChannel to set it
- if (!(channel.getUpHandler() instanceof Muxer<?>))
- {
- throw new IllegalStateException("Cache " + configName + " has a Channel that does not use a Muxer as its UpHandler");
- }
-
- // TODO create the GroupRpcDispatcher/GroupMembershipNotifier
- GroupRpcDispatcher dispatcher = createGroupRpcDispatcher();
- GroupMembershipNotifier notifier = (GroupMembershipNotifier) dispatcher;
-
- return new SharedLocalYieldingClusterLockManager("HTTPSESSIONOWNER", dispatcher, notifier);
- }
-
- private GroupRpcDispatcher createGroupRpcDispatcher()
- {
- throw new UnsupportedOperationException("Implement me");
- }
-}
Deleted: projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionOwnershipPojoCache.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionOwnershipPojoCache.java 2010-07-06 18:41:24 UTC (rev 106465)
+++ projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionOwnershipPojoCache.java 2010-07-06 18:42:31 UTC (rev 106466)
@@ -1,49 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.session.distributedcache.impl.jbc;
-
-import org.jboss.cache.pojo.PojoCache;
-import org.jboss.ha.framework.server.lock.SharedLocalYieldingClusterLockManager;
-
-/**
- *
- *
- * @author Brian Stansberry
- *
- * @version $Revision$
- */
-public class SessionOwnershipPojoCache extends SessionOwnershipCache
-{
- private final PojoCache pojoCache;
-
- public SessionOwnershipPojoCache(PojoCache cache, SharedLocalYieldingClusterLockManager lockManager)
- {
- super(cache.getCache(), lockManager);
- this.pojoCache = cache;
- }
-
- public PojoCache getPojoCache()
- {
- return pojoCache;
- }
-}
Added: projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/resources/org/jboss/web/tomcat/service/session/distributedcache/impl/test-stacks.xml
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/resources/org/jboss/web/tomcat/service/session/distributedcache/impl/test-stacks.xml (rev 0)
+++ projects/cluster/ha-server-cache-jbc/branches/Session_Ownership/src/main/resources/org/jboss/web/tomcat/service/session/distributedcache/impl/test-stacks.xml 2010-07-06 18:42:31 UTC (rev 106466)
@@ -0,0 +1,152 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ JGroups protocol stacks definitions for use by TestDistributedCacheManagerFactoryImpl.
+
+ Author: Bela Ban, Brian Stansberry
+ Version: $Id:jgroups-channelfactory-stacks.xml 71313 2008-03-26 19:46:59Z bstansberry at jboss.com $
+-->
+<protocol_stacks>
+ <stack name="udp"
+ description="Default: IP multicast based stack, with flow control.">
+ <config>
+ <!-- UDP transport config meant for general usage. Message bundling
+ is disabled, as it can add latency to synchronous group RPCs.
+ Services that only make asynchronous RPCs (e.g. JBoss Cache
+ configured for REPL_ASYNC) and do so in high volume may be able
+ to improve performance by configuring their cache to use the
+ udp-async stack below.
+ Services that only make synchronous RPCs (e.g. JBoss Cache
+ configured for REPL_SYNC or INVALIDATION_SYNC) may be able
+ to improve performance by using the udp-sync stack below, which
+ does not include flow control. -->
+ <UDP
+ mcast_port="${jboss.jgroups.udp.mcast_port:45688}"
+ mcast_addr="${jboss.jgroups.udp.mcast_addr,jboss.partition.udpGroup:228.11.11.11}"
+ bind_port="${jboss.jgroups.udp.bind_port:55200}"
+ tos="8"
+ ucast_recv_buf_size="20000000"
+ ucast_send_buf_size="640000"
+ mcast_recv_buf_size="25000000"
+ mcast_send_buf_size="640000"
+ loopback="true"
+ discard_incompatible_packets="true"
+ enable_bundling="false"
+ ip_ttl="${jgroups.udp.ip_ttl:2}"
+ thread_naming_pattern="cl"
+ timer.num_threads="12"
+ enable_diagnostics="${jboss.jgroups.enable_diagnostics:true}"
+ diagnostics_addr="${jboss.jgroups.diagnostics_addr:224.0.75.75}"
+ diagnostics_port="${jboss.jgroups.diagnostics_port:7500}"
+
+ thread_pool.enabled="true"
+ thread_pool.min_threads="20"
+ thread_pool.max_threads="200"
+ thread_pool.keep_alive_time="5000"
+ thread_pool.queue_enabled="true"
+ thread_pool.queue_max_size="1000"
+ thread_pool.rejection_policy="discard"
+
+ oob_thread_pool.enabled="true"
+ oob_thread_pool.min_threads="20"
+ oob_thread_pool.max_threads="200"
+ oob_thread_pool.keep_alive_time="1000"
+ oob_thread_pool.queue_enabled="false"
+ oob_thread_pool.rejection_policy="discard"/>
+ <PING timeout="2000" num_initial_members="3"/>
+ <MERGE2 max_interval="100000" min_interval="20000"/>
+ <FD_SOCK start_port="${jboss.jgroups.udp.fd_sock_port:54200}"/>
+ <FD timeout="6000" max_tries="5"/>
+ <VERIFY_SUSPECT timeout="1500"/>
+ <BARRIER/>
+ <pbcast.NAKACK use_mcast_xmit="true" gc_lag="0"
+ retransmit_timeout="300,600,1200,2400,4800"
+ discard_delivered_msgs="true"/>
+ <UNICAST timeout="300,600,1200,2400,3600"/>
+ <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
+ max_bytes="400000"/>
+ <VIEW_SYNC avg_send_interval="10000"/>
+ <pbcast.GMS print_local_addr="true"
+ join_timeout="3000"
+ view_bundling="true"
+ view_ack_collection_timeout="5000"
+ resume_task_timeout="7500"/>
+ <FC max_credits="2000000" min_threshold="0.10"
+ ignore_synchronous_response="true"/>
+ <FRAG2 frag_size="60000"/>
+ <!-- pbcast.STREAMING_STATE_TRANSFER/ -->
+ <pbcast.STATE_TRANSFER/>
+ <pbcast.FLUSH timeout="0" start_flush_timeout="10000"/>
+ </config>
+ </stack>
+
+
+ <stack name="tcp"
+ description="TCP based stack, with flow control and message bundling.
+ TCP stacks are usually used when IP multicasting cannot
+ be used in a network, e.g. because it is disabled (e.g.
+ routers discard multicast)">
+ <config>
+ <TCP
+ start_port="${jboss.jgroups.tcp.tcp_port:7600}"
+ tcp_nodelay="true"
+ loopback="true"
+ recv_buf_size="20000000"
+ send_buf_size="640000"
+ discard_incompatible_packets="true"
+ max_bundle_size="64000"
+ max_bundle_timeout="30"
+ use_incoming_packet_handler="true"
+ enable_bundling="false"
+ use_send_queues="false"
+ sock_conn_timeout="300"
+ skip_suspected_members="true"
+ timer.num_threads="12"
+ enable_diagnostics="${jboss.jgroups.enable_diagnostics:true}"
+ diagnostics_addr="${jboss.jgroups.diagnostics_addr:224.0.75.75}"
+ diagnostics_port="${jboss.jgroups.diagnostics_port:7500}"
+
+ thread_pool.enabled="true"
+ thread_pool.min_threads="20"
+ thread_pool.max_threads="200"
+ thread_pool.keep_alive_time="5000"
+ thread_pool.queue_enabled="true"
+ thread_pool.queue_max_size="1000"
+ thread_pool.rejection_policy="discard"
+
+ oob_thread_pool.enabled="true"
+ oob_thread_pool.min_threads="20"
+ oob_thread_pool.max_threads="200"
+ oob_thread_pool.keep_alive_time="1000"
+ oob_thread_pool.queue_enabled="false"
+ oob_thread_pool.rejection_policy="discard"/>
+ <!-- For TCP tests assume we are doing EC2 testing and use S3 for discovery. -->
+ <S3_PING access_key="${jboss.jgroups.s3_ping.access_key:}" secret_access_key="${jboss.jgroups.s3_ping.secret_access_key:}" location="${jboss.jgroups.s3_ping.bucket:}" />
+ <MERGE2 max_interval="100000" min_interval="20000"/>
+ <FD_SOCK start_port="${jboss.jgroups.tcp.fd_sock_port:57600}"/>
+ <FD timeout="6000" max_tries="5"/>
+ <VERIFY_SUSPECT timeout="1500"/>
+ <BARRIER/>
+ <pbcast.NAKACK use_mcast_xmit="false" gc_lag="0"
+ retransmit_timeout="300,600,1200,2400,4800"
+ discard_delivered_msgs="true"/>
+ <UNICAST timeout="300,600,1200,2400,3600"/>
+ <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
+ max_bytes="400000"/>
+ <VIEW_SYNC avg_send_interval="10000"/>
+ <pbcast.GMS print_local_addr="true" join_timeout="3000"
+ view_bundling="true"
+ view_ack_collection_timeout="5000"
+ resume_task_timeout="7500"/>
+ <FC max_credits="2000000" min_threshold="0.10"
+ ignore_synchronous_response="true"/>
+ <FRAG2 frag_size="60000"/>
+ <!-- pbcast.STREAMING_STATE_TRANSFER/ -->
+ <pbcast.STATE_TRANSFER/>
+ <pbcast.FLUSH timeout="0" start_flush_timeout="10000"/>
+ </config>
+ </stack>
+
+</protocol_stacks>
+
+
More information about the jboss-cvs-commits
mailing list