[jboss-cvs] JBossAS SVN: r58580 - trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/sso
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Nov 18 06:39:41 EST 2006
Author: bstansberry at jboss.com
Date: 2006-11-18 06:39:41 -0500 (Sat, 18 Nov 2006)
New Revision: 58580
Modified:
trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/sso/TreeCacheSSOClusterManager.java
Log:
Use JBC 2 API; no JMX calls
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/sso/TreeCacheSSOClusterManager.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/sso/TreeCacheSSOClusterManager.java 2006-11-18 11:39:00 UTC (rev 58579)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/sso/TreeCacheSSOClusterManager.java 2006-11-18 11:39:41 UTC (rev 58580)
@@ -26,8 +26,6 @@
import java.util.HashSet;
import java.util.Set;
-import javax.management.AttributeNotFoundException;
-import javax.management.MBeanException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.transaction.Status;
@@ -37,14 +35,18 @@
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Session;
import org.apache.catalina.util.LifecycleSupport;
+import org.jboss.cache.AbstractCacheListener;
+import org.jboss.cache.Cache;
import org.jboss.cache.Fqn;
-import org.jboss.cache.TreeCache;
-import org.jboss.cache.TreeCacheListener;
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.Region;
+import org.jboss.cache.RegionNotEmptyException;
import org.jboss.cache.config.Option;
+import org.jboss.cache.jmx.CacheJmxWrapperMBean;
import org.jboss.logging.Logger;
+import org.jboss.mx.util.MBeanProxyExt;
import org.jboss.mx.util.MBeanServerLocator;
import org.jboss.util.NestedRuntimeException;
-import org.jgroups.View;
/**
* An implementation of SSOClusterManager that uses a TreeCache
@@ -54,7 +56,8 @@
* @version $Revision$ $Date$
*/
public final class TreeCacheSSOClusterManager
- implements SSOClusterManager, TreeCacheListener
+ extends AbstractCacheListener
+ implements SSOClusterManager
{
// ------------------------------------------------------------- Constants
@@ -87,25 +90,6 @@
public static final String DEFAULT_GLOBAL_CACHE_NAME =
"jboss.cache:service=TomcatClusteringCache";
- /**
- * Parameter signature used for TreeCache.get calls over JMX
- */
- private static final String[] GET_SIGNATURE =
- {Fqn.class.getName(), Object.class.getName(), Option.class.getName()};
-
- /**
- * Parameter signature used for TreeCache.put calls over JMX
- */
- private static final String[] PUT_SIGNATURE =
- {Fqn.class.getName(), Object.class.getName(),
- Object.class.getName(), Option.class.getName()};
-
- /**
- * Parameter signature used for TreeCache.remove calls over JMX
- */
- private static final String[] REMOVE_SIGNATURE =
- {Fqn.class.getName(), Option.class.getName()};
-
private static final Option GRAVITATE_OPTION = new Option();
static
@@ -139,6 +123,11 @@
* String version of the object name to use to access the TreeCache
*/
private String cacheName = null;
+
+ /**
+ * The cache itself.
+ */
+ private Cache cache = null;
/**
* Transaction Manager
@@ -251,7 +240,7 @@
return;
}
- removeAsTreeCacheListener();
+ removeAsCacheListener();
this.tm = null;
this.cacheObjectName = objectName;
@@ -612,53 +601,9 @@
}
- // ------------------------------------------------------ TreeCacheListener
+ // ------------------------------------------------------ CacheListener
/**
- * Does nothing
- */
- public void nodeCreated(Fqn fqn)
- {
- ; // do nothing
- }
-
- /**
- * Does nothing
- */
- public void nodeLoaded(Fqn fqn)
- {
- ; // do nothing
- }
-
-
- /**
- * Does nothing
- */
- public void nodeVisited(Fqn fqn)
- {
- ; // do nothing
- }
-
-
- /**
- * Does nothing
- */
- public void cacheStarted(TreeCache cache)
- {
- ; // do nothing
- }
-
-
- /**
- * Does nothing
- */
- public void cacheStopped(TreeCache cache)
- {
- ; // do nothing
- }
-
-
- /**
* Extracts an SSO session id from the Fqn and uses it in an invocation of
* {@link ClusteredSingleSignOn#deregister(String) ClusteredSingleSignOn.deregister(String)}.
* <p/>
@@ -698,7 +643,6 @@
}
-
/**
* Extracts an SSO session id from the Fqn and uses it in an invocation of
* {@link ClusteredSingleSignOn#update ClusteredSingleSignOn.update()}.
@@ -774,27 +718,6 @@
}
}
-
- /**
- * Does nothing
- */
- public void viewChange(View new_view)
- {
- ; // do nothing
- }
-
-
- /**
- * Does nothing. Called when a node is evicted (not the same as remove()).
- *
- * @param fqn
- */
- public void nodeEvicted(Fqn fqn)
- {
- // TODO do we need to handle this?
- ; // do nothing
- }
-
// ------------------------------------------------------------- Lifecycle
@@ -897,8 +820,17 @@
private Object getFromTreeCache(Fqn fqn) throws Exception
{
- Object[] args = new Object[]{fqn, KEY, GRAVITATE_OPTION};
- return server.invoke(getCacheObjectName(), "get", args, GET_SIGNATURE);
+ InvocationContext ctx = cache.getInvocationContext();
+ Option existing = ctx.getOptionOverrides();
+ try
+ {
+ ctx.setOptionOverrides(GRAVITATE_OPTION);
+ return cache.get(fqn, KEY);
+ }
+ finally
+ {
+ ctx.setOptionOverrides(existing);
+ }
}
private Fqn getCredentialsFqn(String ssoid)
@@ -973,27 +905,25 @@
*/
private void configureFromCache() throws Exception
{
- tm = (TransactionManager) server.getAttribute(getCacheObjectName(),
- "TransactionManager");
+ tm = cache.getTransactionManager();
if (tm == null)
{
- throw new IllegalStateException("TreeCache does not have a " +
+ throw new IllegalStateException("Cache does not have a " +
"transaction manager; please " +
"configure a valid " +
"TransactionManagerLookupClass");
}
// Find out our address
- Object address = server.getAttribute(cacheObjectName, "LocalAddress");
+ Object address = cache.getLocalAddress();
// In reality this is a JGroups IpAddress, but the API says
// "Object" so we have to be sure its Serializable
if (address instanceof Serializable)
localAddress = (Serializable) address;
else
localAddress = address.toString();
- }
-
+ }
private void endTransaction()
{
@@ -1069,21 +999,38 @@
private void putInTreeCache(Fqn fqn, Object data) throws Exception
{
- Object[] args = new Object[]{fqn, KEY, data, GRAVITATE_OPTION};
- server.invoke(getCacheObjectName(), "put", args, PUT_SIGNATURE);
+ InvocationContext ctx = cache.getInvocationContext();
+ Option existing = ctx.getOptionOverrides();
+ try
+ {
+ ctx.setOptionOverrides(GRAVITATE_OPTION);
+ cache.put(fqn, KEY, data);
+ }
+ finally
+ {
+ ctx.setOptionOverrides(existing);
+ }
}
private void integrateWithCache() throws Exception
{
- // Ensure we have a transaction manager and a cluster-wide unique address
- configureFromCache();
-
- // If the SSO region is inactive, activate it
- activateCacheRegion();
-
- registerAsTreeCacheListener();
-
- log.debug("Successfully integrated with cache service " + cacheObjectName);
+ if (cache == null)
+ {
+ // Get the cache
+ CacheJmxWrapperMBean mbean = (CacheJmxWrapperMBean) MBeanProxyExt.create(CacheJmxWrapperMBean.class,
+ getCacheObjectName());
+ cache = mbean.getCache();
+
+ // Ensure we have a transaction manager and a cluster-wide unique address
+ configureFromCache();
+
+ // If the SSO region is inactive, activate it
+ activateCacheRegion();
+
+ registerAsCacheListener();
+
+ log.debug("Successfully integrated with cache service " + cacheObjectName);
+ }
}
@@ -1095,43 +1042,21 @@
*/
private void activateCacheRegion() throws Exception
{
- // NOTE: to be compatible with 1.2.3, no direct use of the 1.2.4
- // region activation API can be used here even if the rest of this
- // class is converted to using MBean proxies
- try
+ if (cache.getConfiguration().isInactiveOnStartup())
{
- Boolean inactive = (Boolean) server.getAttribute(cacheObjectName, "InactiveOnStartup");
- if (inactive.booleanValue())
+ if (cache.getConfiguration().isUseRegionBasedMarshalling())
{
- Boolean useMarshalling = (Boolean) server.getAttribute(cacheObjectName, "UseMarshalling");
- if (useMarshalling.booleanValue())
+ Region region =cache.getRegion(Fqn.fromString("/" + SSO), true);
+ try
{
- // TODO replace this try/catch with a call to an isRegionActive API
- try
- {
- server.invoke(cacheObjectName, "activateRegion",
- new Object[]{ "/" + SSO },
- new String[]{ "java.lang.String"});
- }
- catch (MBeanException e)
- {
- Exception cause = e.getTargetException();
- if (cause != null
- && "org.jboss.cache.RegionNotEmptyException".equals(cause.getClass().getName()))
- {
- log.debug(SSO + " region already active", cause);
- }
- else
- throw e;
- }
+ region.activate();
}
+ catch (RegionNotEmptyException e)
+ {
+ log.debug(SSO + " region already active", e);
+ }
}
}
- catch (AttributeNotFoundException ignore)
- {
- log.debug("Attribute InactiveOnStartup not available; " +
- "must be using JBossCache 1.2.3 or earlier");
- }
}
/**
@@ -1140,11 +1065,9 @@
*
* @throws Exception
*/
- private void registerAsTreeCacheListener() throws Exception
+ private void registerAsCacheListener() throws Exception
{
- server.invoke(cacheObjectName, "addTreeCacheListener",
- new Object[]{this},
- new String[]{TreeCacheListener.class.getName()});
+ cache.addCacheListener(this);
registeredAsListener = true;
}
@@ -1155,21 +1078,28 @@
*
* @throws Exception
*/
- private void removeAsTreeCacheListener() throws Exception
+ private void removeAsCacheListener() throws Exception
{
- if (registeredAsListener && cacheObjectName != null)
+ if (registeredAsListener && cache != null)
{
- server.invoke(cacheObjectName, "removeTreeCacheListener",
- new Object[]{this},
- new String[]{TreeCacheListener.class.getName()});
+ cache.removeCacheListener(this);
+ registeredAsListener = false;
}
}
private void removeFromTreeCache(Fqn fqn) throws Exception
{
- server.invoke(getCacheObjectName(), "remove",
- new Object[]{fqn, GRAVITATE_OPTION},
- REMOVE_SIGNATURE);
+ InvocationContext ctx = cache.getInvocationContext();
+ Option existing = ctx.getOptionOverrides();
+ try
+ {
+ ctx.setOptionOverrides(GRAVITATE_OPTION);
+ cache.remove(fqn);
+ }
+ finally
+ {
+ ctx.setOptionOverrides(existing);
+ }
}
/**
More information about the jboss-cvs-commits
mailing list