[jboss-cvs] JBossCache/src/org/jboss/cache/pojo/jmx ...
Brian Stansberry
brian.stansberry at jboss.com
Tue May 22 18:52:52 EDT 2007
User: bstansberry
Date: 07/05/22 18:52:52
Modified: src/org/jboss/cache/pojo/jmx PojoCacheJmxWrapperMBean.java
PojoCacheJmxWrapper.java
Log:
[JBCACHE-1068] Get rid of LifeCycle interface
[JBCACHE-1047] Revert manageCacheLifecycle attribute
Revision Changes Path
1.5 +34 -44 JBossCache/src/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapperMBean.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PojoCacheJmxWrapperMBean.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapperMBean.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- PojoCacheJmxWrapperMBean.java 12 May 2007 03:52:55 -0000 1.4
+++ PojoCacheJmxWrapperMBean.java 22 May 2007 22:52:52 -0000 1.5
@@ -23,25 +23,53 @@
import org.jboss.cache.Cache;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.jmx.LifeCycle;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheAlreadyDetachedException;
+import org.jboss.cache.pojo.PojoCacheException;
/**
* StandardMBean interface for {@link PojoCacheJmxWrapperMBean}.
*
* @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public interface PojoCacheJmxWrapperMBean
- extends LifeCycle
{
/**
+ * Lifecycle method to start PojoCache.
+ *
+ * @throws PojoCacheException
+ */
+ void create() throws PojoCacheException;
+
+ /**
+ * Lifecycle method to start PojoCache.
+ *
+ * @throws PojoCacheException
+ */
+ void start() throws PojoCacheException;
+
+ /**
+ * Lifecycle method to stop PojoCache. Note that PojoCache can be stopped and started
+ * repeatedly.
+ *
+ * @throws PojoCacheException
+ */
+ void stop() throws PojoCacheException;
+
+ /**
+ * Lifecycle method to destroy PojoCache.
+ *
+ * @throws PojoCacheException
+ */
+ void destroy() throws PojoCacheException;
+
+ /**
* Returns the PojoCache.
*
* @return the PojoCache
*/
- public PojoCache getPojoCache();
+ PojoCache getPojoCache();
/**
* Retrieves an immutable configuration.
@@ -64,7 +92,7 @@
* <p/>
* If <code>true</code>, the <code>CacheJmxWrapperMBean</code> will be
* instantiated and registered either as part of the registration of
- * this object, or during the call to {@link LifeCycle#create() create()}.
+ * this object, or during the call to {@link #create()}.
*/
public void setRegisterPlainCache(boolean registerPlainCache);
@@ -91,44 +119,6 @@
void setRegisterInterceptors(boolean register);
/**
- * Gets whether this object should call through to the underlying
- * {@link PojoCache} when any of the {@link Lifecycle} methods are invoked.
- * <p>
- * The value returned from this method will be determined as follows:
- *
- * <ol>
- * <li>If {@link #setManageCacheLifecycle(boolean)} has been called, the
- * provided value will be returned.</li>
- * <li>If a <code>PojoCache</code> has been injected into the object implementing
- * this interface, this method will return <code>false</code> (i.e. assume
- * whatever code injected the <code>PojoCache</code> will manage its lifecycle.)</li>
- * <li>If the object implementing this interface itself constructed the
- * <code>PojoCache</code> (using an injected <code>Configuration</code>), this
- * method will return <code>true</code> (i.e. assume since we created
- * the <code>PojoCache</code> we will manage its lifecycle.)</li>
- * </ol>
- * </p>
- *
- * @return <code>true</code> if calls to the lifecycle methods will be
- * passed through to the underlying cache, <code>false</code>
- * otherwise
- */
- boolean getManageCacheLifecycle();
-
- /**
- * Sets whether this object should call through to the underlying
- * {@link PojoCache} when any of the {@link Lifecycle} methods are invoked.
- * <p>
- * See {@link #getManageCacheLifecycle()} for an explanation of the
- * default values of this property.
- *
- * @param manage <code>true</code> if calls to the lifecycle methods should
- * be passed through to the underlying cache, <code>false</code>
- * otherwise
- */
- void setManageCacheLifecycle(boolean manage);
-
- /**
* Return number of POJO attach operations for this particular id.
* @return Number of attach operation.
*/
1.7 +93 -31 JBossCache/src/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PojoCacheJmxWrapper.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- PojoCacheJmxWrapper.java 12 May 2007 03:53:20 -0000 1.6
+++ PojoCacheJmxWrapper.java 22 May 2007 22:52:52 -0000 1.7
@@ -21,17 +21,22 @@
*/
package org.jboss.cache.pojo.jmx;
+import javax.management.JMException;
import javax.management.MBeanRegistration;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.LifecycleState;
+import org.jboss.cache.LifecycleUtil;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.jmx.CacheJmxWrapper;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheAlreadyDetachedException;
+import org.jboss.cache.pojo.PojoCacheException;
import org.jboss.cache.pojo.PojoCacheFactory;
import org.jboss.cache.pojo.impl.PojoCacheImpl;
@@ -50,7 +55,7 @@
private CacheJmxWrapper plainCacheWrapper;
private boolean registerPlainCache = true;
private boolean plainCacheRegistered;
- private boolean created;
+ private LifecycleState lifecycleState;
/**
* Default constructor.
@@ -58,6 +63,7 @@
*/
public PojoCacheJmxWrapper()
{
+ lifecycleState = LifecycleState.INSTANTIATED;
}
/**
@@ -67,6 +73,7 @@
*/
public PojoCacheJmxWrapper(PojoCache toWrap)
{
+ lifecycleState = LifecycleState.INSTANTIATED;
setPojoCache(toWrap);
}
@@ -92,8 +99,16 @@
return plainCacheWrapper == null ? null : plainCacheWrapper.getCacheObjectName();
}
- public void create() throws Exception
+ public void create() throws PojoCacheException
{
+ if (LifecycleUtil.createAllowed(lifecycleState) == false)
+ {
+ if (LifecycleUtil.needToDestroyFailedCache(lifecycleState))
+ destroy();
+ else
+ return;
+ }
+
if (pojoCache == null)
{
if (config == null)
@@ -105,52 +120,91 @@
constructCache();
}
- if (getManageCacheLifecycle())
- {
pojoCache.create();
- }
registerPlainCache();
plainCacheWrapper.create();
-
- created = true;
}
- public void start() throws Exception
+ public void start() throws PojoCacheException
{
- if (getManageCacheLifecycle())
+ if (LifecycleUtil.startAllowed(lifecycleState) == false)
{
- pojoCache.start();
+ if (LifecycleUtil.needToDestroyFailedCache(lifecycleState))
+ destroy();
+ if (LifecycleUtil.needCreateBeforeStart(lifecycleState))
+ create();
+ else
+ return;
}
+ lifecycleState = LifecycleState.STARTING;
+
+ try
+ {
+ pojoCache.start();
+
plainCacheWrapper.start();
+ lifecycleState = LifecycleState.STARTED;
+ }
+ catch (RuntimeException e)
+ {
+ lifecycleState = LifecycleState.FAILED;
+ throw e;
+ }
}
public void stop()
{
- if (getManageCacheLifecycle())
+ if (LifecycleUtil.stopAllowed(lifecycleState) == false)
{
- pojoCache.stop();
+ if (LifecycleUtil.needToDestroyFailedCache(lifecycleState))
+ destroy();
+ else
+ return;
}
+ lifecycleState = LifecycleState.STOPPING;
+
+ try
+ {
+ pojoCache.stop();
+
plainCacheWrapper.stop();
+ lifecycleState = LifecycleState.STOPPED;
+ }
+ catch (RuntimeException e)
+ {
+ lifecycleState = LifecycleState.FAILED;
+ throw e;
+ }
}
public void destroy()
{
- if (getManageCacheLifecycle())
+ if (LifecycleUtil.destroyAllowed(lifecycleState) == false)
{
+ if (LifecycleUtil.needStopBeforeDestroy(lifecycleState))
+ stop();
+ else
+ return;
+ }
+
pojoCache.destroy();
// The cache is destroyed, so we shouldn't leave it registered
// in JMX even if we didn't register it in create()
unregisterPlainCache();
- }
plainCacheWrapper.destroy();
- created = false;
+ lifecycleState = LifecycleState.DESTROYED;
+ }
+
+ public LifecycleState getLifecycleState()
+ {
+ return lifecycleState;
}
public boolean getRegisterPlainCache()
@@ -263,7 +317,8 @@
public void setPojoCache(PojoCache cache)
{
- if (created)
+ if (lifecycleState != LifecycleState.INSTANTIATED
+ && lifecycleState != LifecycleState.DESTROYED)
throw new IllegalStateException("Cannot set underlying cache after call to create()");
this.pojoCache = cache;
@@ -299,10 +354,12 @@
return plainCache;
}
- private boolean registerPlainCache() throws Exception
+ private boolean registerPlainCache() throws CacheException
{
if (registerPlainCache && !plainCacheRegistered && server != null)
{
+ try
+ {
ObjectName ourName = new ObjectName(cacheObjectName);
ObjectName plainName = JmxUtil.getPlainCacheObjectName(ourName);
log.debug("Registering plain cache under name " + plainName.getCanonicalName());
@@ -310,6 +367,11 @@
plainCacheRegistered = true;
return true;
}
+ catch (JMException e)
+ {
+ throw new CacheException("Failed to register plain cache", e);
+ }
+ }
return false;
}
More information about the jboss-cvs-commits
mailing list