[mule-scm] [mule] [15959] branches/mule-2.1.x/core/src/main/java/org/mule: MULE-4589 java.lang.IllegalStateException: Phase 'start' has already been executed

View: New views
1 Messages — Rating Filter:   Alert me  

[mule-scm] [mule] [15959] branches/mule-2.1.x/core/src/main/java/org/mule: MULE-4589 java.lang.IllegalStateException: Phase 'start' has already been executed

by dfeist :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
[mule] [15959] branches/mule-2.1.x/core/src/main/java/org/mule: MULE-4589 java.lang.IllegalStateException: Phase 'start' has already been executed

Diff

Modified: branches/mule-2.1.x/core/src/main/java/org/mule/DefaultMuleContext.java (15958 => 15959)

--- branches/mule-2.1.x/core/src/main/java/org/mule/DefaultMuleContext.java	2009-11-04 01:51:22 UTC (rev 15958)
+++ branches/mule-2.1.x/core/src/main/java/org/mule/DefaultMuleContext.java	2009-11-04 02:38:49 UTC (rev 15959)
@@ -107,7 +107,7 @@
     
     public synchronized void initialise() throws InitialisationException
     {
-        if (isInitialised())
+        if (lifecycleManager.getCurrentPhase().equals(Initialisable.PHASE_NAME))
         {
             return;
         }
@@ -150,33 +150,36 @@
 
     public synchronized void start() throws MuleException
     {
+        if (isStarted())
+        {
+            return;
+        }
+
         lifecycleManager.checkPhase(Startable.PHASE_NAME);
-        if (!isStarted())
+
+        if (getSecurityManager() == null)
         {
-            if (getSecurityManager() == null)
-            {
-                throw new MuleRuntimeException(CoreMessages.objectIsNull("securityManager"));
-            }
-            if (getQueueManager() == null)
-            {
-                throw new MuleRuntimeException(CoreMessages.objectIsNull("queueManager"));
-            }
+            throw new MuleRuntimeException(CoreMessages.objectIsNull("securityManager"));
+        }
+        if (getQueueManager() == null)
+        {
+            throw new MuleRuntimeException(CoreMessages.objectIsNull("queueManager"));
+        }
 
-            startDate = System.currentTimeMillis();
+        startDate = System.currentTimeMillis();
 
-            fireNotification(new MuleContextNotification(this, MuleContextNotification.CONTEXT_STARTING));
+        fireNotification(new MuleContextNotification(this, MuleContextNotification.CONTEXT_STARTING));
 
-            lifecycleManager.firePhase(this, Startable.PHASE_NAME);
+        lifecycleManager.firePhase(this, Startable.PHASE_NAME);
 
-            fireNotification(new MuleContextNotification(this, MuleContextNotification.CONTEXT_STARTED));
+        fireNotification(new MuleContextNotification(this, MuleContextNotification.CONTEXT_STARTED));
 
-            if (logger.isInfoEnabled())
-            {
-                SplashScreen splashScreen = SplashScreen.getInstance(ServerStartupSplashScreen.class);
-                splashScreen.setHeader(this);
-                splashScreen.setFooter(this);
-                logger.info(splashScreen.toString());
-            }
+        if (logger.isInfoEnabled())
+        {
+            SplashScreen splashScreen = SplashScreen.getInstance(ServerStartupSplashScreen.class);
+            splashScreen.setHeader(this);
+            splashScreen.setFooter(this);
+            logger.info(splashScreen.toString());
         }
     }
 
@@ -201,9 +204,10 @@
         {
             return;
         }
-             
+
+        lifecycleManager.checkPhase(Disposable.PHASE_NAME);
+        
         ServerNotificationManager notificationManager = getNotificationManager();
-        lifecycleManager.checkPhase(Disposable.PHASE_NAME);
         fireNotification(new MuleContextNotification(this, MuleContextNotification.CONTEXT_DISPOSING));
 
         try

Modified: branches/mule-2.1.x/core/src/main/java/org/mule/lifecycle/GenericLifecycleManager.java (15958 => 15959)

--- branches/mule-2.1.x/core/src/main/java/org/mule/lifecycle/GenericLifecycleManager.java	2009-11-04 01:51:22 UTC (rev 15958)
+++ branches/mule-2.1.x/core/src/main/java/org/mule/lifecycle/GenericLifecycleManager.java	2009-11-04 02:38:49 UTC (rev 15959)
@@ -169,19 +169,16 @@
 
     public void checkPhase(String name) throws IllegalStateException
     {
-        if (completedPhases.contains(name))
-        {
-            throw new IllegalStateException("Phase '" + name + "' has already been executed");
-        }
-
-        if (name.equalsIgnoreCase(executingPhase))
-        {
-            throw new IllegalStateException("Phase '" + name + "' is already currently being executed");
-        }
-
         if (executingPhase != null)
         {
-            throw new IllegalStateException("Currently executing lifecycle phase: " + executingPhase);
+            if (name.equalsIgnoreCase(executingPhase))
+            {
+                throw new IllegalStateException("Phase '" + name + "' is already currently being executed");
+            }
+            else
+            {
+                throw new IllegalStateException("Currently executing lifecycle phase: " + executingPhase);
+            }
         }
 
         Integer phaseIndex = index.get(name);
@@ -189,13 +186,6 @@
         {
             throw new IllegalStateException("Phase does not exist: " + name);
         }
-        if (NotInLifecyclePhase.PHASE_NAME.equals(currentPhase))
-        {
-            if (phaseIndex > 0)
-            {
-                throw new IllegalStateException("The first lifecycle phase has to be called before the '" + name + "' phase");
-            }
-        }
         else
         {
             LifecyclePhase phase = (LifecyclePhase) lifecycles.get(phaseIndex);

Modified: branches/mule-2.1.x/core/src/main/java/org/mule/lifecycle/phases/MuleContextInitialisePhase.java (15958 => 15959)

--- branches/mule-2.1.x/core/src/main/java/org/mule/lifecycle/phases/MuleContextInitialisePhase.java	2009-11-04 01:51:22 UTC (rev 15958)
+++ branches/mule-2.1.x/core/src/main/java/org/mule/lifecycle/phases/MuleContextInitialisePhase.java	2009-11-04 02:38:49 UTC (rev 15959)
@@ -22,5 +22,6 @@
     public MuleContextInitialisePhase()
     {
         super(Initialisable.PHASE_NAME, Initialisable.class, Disposable.PHASE_NAME);
+        registerSupportedPhase(NotInLifecyclePhase.PHASE_NAME);
     }
 }
\ No newline at end of file

Added: branches/mule-2.1.x/core/src/test/java/org/mule/context/MuleContextLifecycleTestCase.java (0 => 15959)

--- branches/mule-2.1.x/core/src/test/java/org/mule/context/MuleContextLifecycleTestCase.java	                        (rev 0)
+++ branches/mule-2.1.x/core/src/test/java/org/mule/context/MuleContextLifecycleTestCase.java	2009-11-04 02:38:49 UTC (rev 15959)
@@ -0,0 +1,263 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+
+package org.mule.context;
+
+import org.mule.MuleServer;
+import org.mule.api.MuleContext;
+import org.mule.api.MuleException;
+import org.mule.api.context.MuleContextBuilder;
+import org.mule.config.builders.DefaultsConfigurationBuilder;
+import org.mule.tck.AbstractMuleTestCase;
+
+public class MuleContextLifecycleTestCase extends AbstractMuleTestCase
+{
+
+    private MuleContextBuilder ctxBuilder = new DefaultMuleContextBuilder();
+
+    @Override
+    protected MuleContext createMuleContext() throws Exception
+    {
+        return null;
+    }
+
+    public void testInitialise() throws MuleException
+    {
+        MuleContext ctx = ctxBuilder.buildMuleContext();
+        MuleServer.setMuleContext(ctx);
+        assertFalse(ctx.isInitialised());
+        assertFalse(ctx.isInitialising());
+        assertFalse(ctx.isStarted());
+        assertFalse(ctx.isDisposed());
+        assertFalse(ctx.isDisposing());
+
+        ctx.initialise();
+        assertTrue(ctx.isInitialised());
+        assertFalse(ctx.isInitialising());
+        assertFalse(ctx.isStarted());
+        assertFalse(ctx.isDisposed());
+        assertFalse(ctx.isDisposing());
+
+        // Double initialisation does not fail.
+        // MuleContext state stays the same
+        ctx.initialise();
+        assertTrue(ctx.isInitialised());
+        assertFalse(ctx.isInitialising());
+        assertFalse(ctx.isStarted());
+        assertFalse(ctx.isDisposed());
+        assertFalse(ctx.isDisposing());
+
+        MuleServer.setMuleContext(ctx);
+        new DefaultsConfigurationBuilder().configure(ctx);
+        ctx.start();
+        // Attempt to initialise once started should fail!
+        try
+        {
+            ctx.initialise();
+            fail();
+        }
+        catch (Exception e)
+        {
+        }
+
+        ctx.stop();
+        // Attempt to initialise once stopped should fail!
+        try
+        {
+            ctx.initialise();
+            fail();
+        }
+        catch (Exception e)
+        {
+        }
+
+        ctx.dispose();
+        // Attempt to initialise once disposed should fail!
+        try
+        {
+            ctx.initialise();
+            fail();
+        }
+        catch (Exception e)
+        {
+        }
+    }
+
+    public void testStart() throws MuleException
+    {
+        MuleContext ctx = ctxBuilder.buildMuleContext();
+        MuleServer.setMuleContext(ctx);
+
+        // Attempt to start before initialise should fail!
+        try
+        {
+            ctx.start();
+            fail();
+        }
+        catch (Exception e)
+        {
+        }
+
+        ctx.initialise();
+        MuleServer.setMuleContext(ctx);
+        new DefaultsConfigurationBuilder().configure(ctx);
+        ctx.start();
+        assertTrue(ctx.isInitialised());
+        assertFalse(ctx.isInitialising());
+        assertTrue(ctx.isStarted());
+        assertFalse(ctx.isDisposed());
+        assertFalse(ctx.isDisposing());
+
+        // Double start does not fail.
+        // MuleContext state stays the same
+        ctx.start();
+        assertTrue(ctx.isInitialised());
+        assertFalse(ctx.isInitialising());
+        assertTrue(ctx.isStarted());
+        assertFalse(ctx.isDisposed());
+        assertFalse(ctx.isDisposing());
+
+        ctx.stop();
+        ctx.start();
+        assertTrue(ctx.isInitialised());
+        assertFalse(ctx.isInitialising());
+        assertTrue(ctx.isStarted());
+        assertFalse(ctx.isDisposed());
+        assertFalse(ctx.isDisposing());
+
+        ctx.dispose();
+        // Attempt to start once disposed should fail!
+        try
+        {
+            ctx.start();
+            fail();
+        }
+        catch (Exception e)
+        {
+        }
+    }
+
+    public void testStop() throws MuleException
+    {
+        MuleContext ctx = ctxBuilder.buildMuleContext();
+        MuleServer.setMuleContext(ctx);
+
+        // Attempt to stop before initialise should fail!
+        try
+        {
+            ctx.stop();
+            fail();
+        }
+        catch (Exception e)
+        {
+        }
+
+        ctx.initialise();
+        ctx.stop();
+        assertTrue(ctx.isInitialised());
+        assertFalse(ctx.isInitialising());
+        assertFalse(ctx.isStarted());
+        assertFalse(ctx.isDisposed());
+        assertFalse(ctx.isDisposing());
+
+        MuleServer.setMuleContext(ctx);
+        new DefaultsConfigurationBuilder().configure(ctx);
+        ctx.start();
+        ctx.stop();
+        assertTrue(ctx.isInitialised());
+        assertFalse(ctx.isInitialising());
+        assertFalse(ctx.isStarted());
+        assertFalse(ctx.isDisposed());
+        assertFalse(ctx.isDisposing());
+
+        ctx.start();
+        ctx.stop();
+        // Attempt to stop twice should fail!
+        try
+        {
+            ctx.stop();
+            fail();
+        }
+        catch (Exception e)
+        {
+        }
+
+        ctx.dispose();
+        // Attempt to start once disposed should fail!
+        try
+        {
+            ctx.stop();
+            fail();
+        }
+        catch (Exception e)
+        {
+        }
+    }
+
+    public void testDipose() throws MuleException
+    {
+        MuleContext ctx = ctxBuilder.buildMuleContext();
+        MuleServer.setMuleContext(ctx);
+
+        ctx.dispose();
+        assertFalse(ctx.isInitialised());
+        assertFalse(ctx.isInitialising());
+        assertFalse(ctx.isStarted());
+        assertTrue(ctx.isDisposed());
+        assertFalse(ctx.isDisposing());
+
+        ctx = ctxBuilder.buildMuleContext();
+        MuleServer.setMuleContext(ctx);
+        ctx.initialise();
+        ctx.dispose();
+        assertFalse(ctx.isInitialised());
+        assertFalse(ctx.isInitialising());
+        assertFalse(ctx.isStarted());
+        assertTrue(ctx.isDisposed());
+        assertFalse(ctx.isDisposing());
+
+        ctx = ctxBuilder.buildMuleContext();
+        MuleServer.setMuleContext(ctx);
+        ctx.initialise();
+        new DefaultsConfigurationBuilder().configure(ctx);
+        ctx.start();
+        ctx.dispose();
+        assertFalse(ctx.isInitialised());
+        assertFalse(ctx.isInitialising());
+        assertFalse(ctx.isStarted());
+        assertTrue(ctx.isDisposed());
+        assertFalse(ctx.isDisposing());
+
+        ctx = ctxBuilder.buildMuleContext();
+        MuleServer.setMuleContext(ctx);
+        ctx.initialise();
+        new DefaultsConfigurationBuilder().configure(ctx);
+        ctx.start();
+        ctx.stop();
+        ctx.dispose();
+        assertFalse(ctx.isInitialised());
+        assertFalse(ctx.isInitialising());
+        assertFalse(ctx.isStarted());
+        assertTrue(ctx.isDisposed());
+        assertFalse(ctx.isDisposing());
+
+        ctx = ctxBuilder.buildMuleContext();
+        MuleServer.setMuleContext(ctx);
+        ctx.initialise();
+        ctx.dispose();
+        ctx.dispose();
+        assertFalse(ctx.isInitialised());
+        assertFalse(ctx.isInitialising());
+        assertFalse(ctx.isStarted());
+        assertTrue(ctx.isDisposed());
+        assertFalse(ctx.isDisposing());
+
+    }
+}
Property changes on: branches/mule-2.1.x/core/src/test/java/org/mule/context/MuleContextLifecycleTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email