[jboss-cvs] JBossCache/src/org/jboss/cache ...
Brian Stansberry
brian.stansberry at jboss.com
Tue May 22 18:44:00 EDT 2007
User: bstansberry
Date: 07/05/22 18:44:00
Modified: src/org/jboss/cache CacheImpl.java
Log:
[JBCACHE-1058] Handle different combinations of invoking lifecycle methods.
Revision Changes Path
1.69 +180 -129 JBossCache/src/org/jboss/cache/CacheImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/CacheImpl.java,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -b -r1.68 -r1.69
--- CacheImpl.java 22 May 2007 16:12:14 -0000 1.68
+++ CacheImpl.java 22 May 2007 22:44:00 -0000 1.69
@@ -201,9 +201,9 @@
private ReplicationQueue repl_queue = null;
/**
- * True if create() was called.
+ * The current lifecycle state.
*/
- private boolean createCalled = false;
+ private LifecycleState lifecycleState;
/**
* Buddy Manager
@@ -225,8 +225,6 @@
*/
private CacheJmxWrapperMBean cacheMBean;
- private boolean started;
-
private ThreadLocal<InvocationContext> invocationContextContainer = new ThreadLocal<InvocationContext>()
{
@Override
@@ -247,6 +245,7 @@
{
notifier = new Notifier<K, V>(this);
regionManager = new RegionManager(this);
+ lifecycleState = LifecycleState.INSTANTIATED;
}
public StateTransferManager getStateTransferManager()
@@ -545,6 +544,14 @@
*/
public void create() throws CacheException
{
+ if (LifecycleUtil.createAllowed(lifecycleState) == false)
+ {
+ if (LifecycleUtil.needToDestroyFailedCache(lifecycleState))
+ destroy();
+ else
+ return;
+ }
+
// Include our clusterName in our log category
configureLogCategory();
@@ -598,7 +605,8 @@
createEvictionPolicy();
getRegionManager().setDefaultInactive(configuration.isInactiveOnStartup());
- createCalled = true;
+
+ lifecycleState = LifecycleState.CREATED;
}
private void createTransactionManager()
@@ -660,13 +668,20 @@
*/
public void start() throws CacheException
{
-
- // Get around the problem of standalone user forgets to call create.
- if (!createCalled)
+ if (LifecycleUtil.startAllowed(lifecycleState) == false)
{
+ if (LifecycleUtil.needToDestroyFailedCache(lifecycleState))
+ destroy();
+ if (LifecycleUtil.needCreateBeforeStart(lifecycleState))
create();
+ else
+ return;
}
+ lifecycleState = LifecycleState.STARTING;
+
+ try
+ {
createTransactionManager();
// cache loaders should be initialised *before* any state transfers take place to prevent
@@ -750,8 +765,6 @@
}
notifier.notifyCacheStarted(this, true);
- started = true;
- log.info("JBoss Cache version: " + getVersion());
// install a VM shutdown hook
Thread shutdownHook = new Thread()
@@ -763,6 +776,16 @@
};
Runtime.getRuntime().addShutdownHook(shutdownHook);
+
+ log.info("JBoss Cache version: " + getVersion());
+
+ lifecycleState = LifecycleState.STARTED;
+ }
+ catch (RuntimeException e)
+ {
+ lifecycleState = LifecycleState.FAILED;
+ throw e;
+ }
}
/**
@@ -770,10 +793,17 @@
*/
public void destroy()
{
- if (started) stop();
- createCalled = false;
+ if (LifecycleUtil.destroyAllowed(lifecycleState) == false)
+ {
+ if (LifecycleUtil.needStopBeforeDestroy(lifecycleState))
+ stop();
+ else
+ return;
+ }
+
regionManager = null;
notifier = null;
+ lifecycleState = LifecycleState.DESTROYED;
}
/**
@@ -781,6 +811,18 @@
*/
public void stop()
{
+ if (LifecycleUtil.stopAllowed(lifecycleState) == false)
+ {
+ if (LifecycleUtil.needToDestroyFailedCache(lifecycleState))
+ destroy();
+ else
+ return;
+ }
+
+ lifecycleState = LifecycleState.STOPPING;
+
+ try
+ {
if (channel != null)
{
log.info("stop(): closing the channel");
@@ -824,9 +866,18 @@
// unset transaction manager reference
tm = null;
- // JBCACHE-1045
-// createCalled = false;
- started = false;
+ lifecycleState = LifecycleState.STOPPED;
+ }
+ catch (RuntimeException e)
+ {
+ lifecycleState = LifecycleState.FAILED;
+ throw e;
+ }
+ }
+
+ public LifecycleState getLifecycleState()
+ {
+ return lifecycleState;
}
/* ----------------------- End of MBeanSupport ----------------------- */
@@ -4170,7 +4221,7 @@
public boolean isStarted()
{
- return started;
+ return getLifecycleState() == LifecycleState.STARTED;
}
protected void setMessageListener(MessageListenerAdaptor ml)
More information about the jboss-cvs-commits
mailing list