diff --git a/embed/src/main/java/org/gatein/pc/embed/EmbedServlet.java b/embed/src/main/java/org/gatein/pc/embed/EmbedServlet.java index ef954a1c..b581896f 100644 --- a/embed/src/main/java/org/gatein/pc/embed/EmbedServlet.java +++ b/embed/src/main/java/org/gatein/pc/embed/EmbedServlet.java @@ -110,7 +110,7 @@ public void init(ServletConfig config) throws ServletException private void checkLifeCycle(ManagedObject managed) throws ServletException { - if (managed.getStatus() == LifeCycleStatus.FAILED) + if (managed.getStatus() != LifeCycleStatus.STARTED) { throw new ServletException("Portlet application start failed", managed.getFailure()); } diff --git a/portlet/src/main/java/org/gatein/pc/portlet/container/managed/LifeCycleStatus.java b/portlet/src/main/java/org/gatein/pc/portlet/container/managed/LifeCycleStatus.java index d884c737..88f661f9 100644 --- a/portlet/src/main/java/org/gatein/pc/portlet/container/managed/LifeCycleStatus.java +++ b/portlet/src/main/java/org/gatein/pc/portlet/container/managed/LifeCycleStatus.java @@ -29,6 +29,6 @@ public enum LifeCycleStatus { - STOPPED, STARTED, FAILED + STOPPED, STARTED } diff --git a/portlet/src/main/java/org/gatein/pc/portlet/container/managed/ManagedObject.java b/portlet/src/main/java/org/gatein/pc/portlet/container/managed/ManagedObject.java index bb390921..ef52fd77 100644 --- a/portlet/src/main/java/org/gatein/pc/portlet/container/managed/ManagedObject.java +++ b/portlet/src/main/java/org/gatein/pc/portlet/container/managed/ManagedObject.java @@ -37,8 +37,7 @@ public interface ManagedObject LifeCycleStatus getStatus(); /** - * Returns the last known failure when the managed object is in {@link LifeCycleStatus#FAILED} status, - * otherwise return null. + * Returns the last known failure when the managed object attempted a transition, otherwise return null. * * @return the failure */ diff --git a/portlet/src/main/java/org/gatein/pc/portlet/container/managed/ManagedObjectFailedEvent.java b/portlet/src/main/java/org/gatein/pc/portlet/container/managed/ManagedObjectFailedEvent.java new file mode 100644 index 00000000..3057b7ee --- /dev/null +++ b/portlet/src/main/java/org/gatein/pc/portlet/container/managed/ManagedObjectFailedEvent.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2012 eXo Platform SAS. + * + * 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.gatein.pc.portlet.container.managed; + +/** + * @author Julien Viet + * @version $Revision: 630 $ + */ +public final class ManagedObjectFailedEvent extends ManagedObjectEvent +{ + + /** . */ + private final LifeCycleStatus status; + + public ManagedObjectFailedEvent(ManagedObject managedObject, LifeCycleStatus status) + { + super(managedObject); + + // + this.status = status; + } + + public LifeCycleStatus getStatus() + { + return status; + } + + @Override + public String toString() + { + return getClass().getSimpleName() + "[status=" + status + ",managed=" + managedObject + "]"; + } +} diff --git a/portlet/src/main/java/org/gatein/pc/portlet/impl/container/LifeCycle.java b/portlet/src/main/java/org/gatein/pc/portlet/impl/container/LifeCycle.java index e8a45a11..4528516c 100644 --- a/portlet/src/main/java/org/gatein/pc/portlet/impl/container/LifeCycle.java +++ b/portlet/src/main/java/org/gatein/pc/portlet/impl/container/LifeCycle.java @@ -25,6 +25,8 @@ import org.gatein.common.logging.LoggerFactory; import org.gatein.pc.portlet.container.managed.ManagedObject; import org.gatein.pc.portlet.container.managed.LifeCycleStatus; +import org.gatein.pc.portlet.container.managed.ManagedObjectEvent; +import org.gatein.pc.portlet.container.managed.ManagedObjectFailedEvent; import org.gatein.pc.portlet.container.managed.ManagedObjectRegistryEventListener; import org.gatein.pc.portlet.container.managed.ManagedObjectLifeCycleEvent; import org.gatein.common.logging.Logger; @@ -91,13 +93,10 @@ else if (faileds.get().contains(this)) return; } - // - LifeCycleStatus previousStatus = status; - // if (status != LifeCycleStatus.STARTED) { - LifeCycleStatus status = LifeCycleStatus.FAILED; + LifeCycleStatus status = LifeCycleStatus.STOPPED; try { invokeStart(); @@ -122,17 +121,25 @@ else if (faileds.get().contains(this)) this.status = status; // - if (status == LifeCycleStatus.FAILED) + if (failure != null) { faileds.get().add(this); } } - } - // - if (status != previousStatus) - { - getListener().onEvent(new ManagedObjectLifeCycleEvent(this, status)); + // + if (failure == null) + { + if (status == LifeCycleStatus.STARTED) + { + getListener().onEvent(new ManagedObjectLifeCycleEvent(this, status)); + } + } + else + { + getListener().onEvent(new ManagedObjectFailedEvent(this, status)); + } + } // diff --git a/portlet/src/test/java/org/gatein/pc/portlet/container/LifeCycle1TestCase.java b/portlet/src/test/java/org/gatein/pc/portlet/container/LifeCycle1TestCase.java index 5c0d34d6..1fdf28b6 100644 --- a/portlet/src/test/java/org/gatein/pc/portlet/container/LifeCycle1TestCase.java +++ b/portlet/src/test/java/org/gatein/pc/portlet/container/LifeCycle1TestCase.java @@ -244,7 +244,7 @@ public void testContainerFailsOnStart() // testState( 1, 0, LifeCycleStatus.STARTED, null, - 1, 0, LifeCycleStatus.FAILED, containerLC.getFailure(), + 1, 0, LifeCycleStatus.STOPPED, containerLC.getFailure(), 1, 0, LifeCycleStatus.STARTED, null); events.assertStartedEvent(applicationLC); events.assertStartedEvent(filterLC); @@ -257,7 +257,7 @@ public void testContainerFailsOnStart() // testState( 1, 1, LifeCycleStatus.STOPPED, null, - 1, 0, LifeCycleStatus.FAILED, null, + 1, 0, LifeCycleStatus.STOPPED, null, 1, 1, LifeCycleStatus.STOPPED, null); events.assertStoppedEvent(filterLC); events.assertStoppedEvent(applicationLC); @@ -269,10 +269,11 @@ public void testContainerFailsOnStart() // testState( 2, 1, LifeCycleStatus.STARTED, null, - 2, 0, LifeCycleStatus.FAILED, null, + 2, 0, LifeCycleStatus.STOPPED, null, 2, 1, LifeCycleStatus.STARTED, null); events.assertStartedEvent(applicationLC); events.assertStartedEvent(filterLC); + events.assertFailedEvent(containerLC); events.assertEmpty(); // @@ -281,8 +282,9 @@ public void testContainerFailsOnStart() // testState( 2, 1, LifeCycleStatus.STARTED, null, - 3, 0, LifeCycleStatus.FAILED, failure.getFailure(), + 3, 0, LifeCycleStatus.STOPPED, failure.getFailure(), 2, 1, LifeCycleStatus.STARTED, null); + events.assertFailedEvent(containerLC); events.assertEmpty(); // @@ -291,7 +293,7 @@ public void testContainerFailsOnStart() // testState( 2, 1, LifeCycleStatus.STARTED, null, - 3, 0, LifeCycleStatus.FAILED, null, + 3, 0, LifeCycleStatus.STOPPED, null, 2, 1, LifeCycleStatus.STARTED, null); events.assertEmpty(); @@ -301,7 +303,7 @@ public void testContainerFailsOnStart() // testState( 2, 1, LifeCycleStatus.STARTED, null, - 3, 0, LifeCycleStatus.FAILED, null, + 3, 0, LifeCycleStatus.STOPPED, null, 2, 2, LifeCycleStatus.STOPPED, null); events.assertStoppedEvent(filterLC); events.assertEmpty(); @@ -312,9 +314,10 @@ public void testContainerFailsOnStart() // testState( 2, 1, LifeCycleStatus.STARTED, null, - 4, 0, LifeCycleStatus.FAILED, failure.getFailure(), + 4, 0, LifeCycleStatus.STOPPED, failure.getFailure(), 3, 2, LifeCycleStatus.STARTED, null); events.assertStartedEvent(filterLC); + events.assertFailedEvent(containerLC); events.assertEmpty(); } @@ -331,7 +334,7 @@ public void testApplicationFailsOnStart() // testState( - 1, 0, LifeCycleStatus.FAILED, applicationLC.getFailure(), + 1, 0, LifeCycleStatus.STOPPED, applicationLC.getFailure(), 0, 0, LifeCycleStatus.STOPPED, null, 0, 0, LifeCycleStatus.STOPPED, null); events.assertFailedEvent(applicationLC); @@ -342,9 +345,10 @@ public void testApplicationFailsOnStart() // testState( - 2, 0, LifeCycleStatus.FAILED, failure.getFailure(), + 2, 0, LifeCycleStatus.STOPPED, failure.getFailure(), 0, 0, LifeCycleStatus.STOPPED, null, 0, 0, LifeCycleStatus.STOPPED, null); + events.assertFailedEvent(applicationLC); events.assertEmpty(); // @@ -352,7 +356,7 @@ public void testApplicationFailsOnStart() // testState( - 2, 0, LifeCycleStatus.FAILED, null, + 2, 0, LifeCycleStatus.STOPPED, null, 0, 0, LifeCycleStatus.STOPPED, null, 0, 0, LifeCycleStatus.STOPPED, null); events.assertEmpty(); @@ -373,7 +377,7 @@ public void testFilterFailsOnStart() testState( 1, 0, LifeCycleStatus.STARTED, null, 0, 0, LifeCycleStatus.STOPPED, null, - 1, 0, LifeCycleStatus.FAILED, filterLC.getFailure()); + 1, 0, LifeCycleStatus.STOPPED, filterLC.getFailure()); events.assertStartedEvent(applicationLC); events.assertFailedEvent(filterLC); events.assertEmpty(); @@ -385,7 +389,7 @@ public void testFilterFailsOnStart() testState( 1, 1, LifeCycleStatus.STOPPED, null, 0, 0, LifeCycleStatus.STOPPED, null, - 1, 0, LifeCycleStatus.FAILED, null); + 1, 0, LifeCycleStatus.STOPPED, null); events.assertStoppedEvent(applicationLC); events.assertEmpty(); @@ -396,8 +400,9 @@ public void testFilterFailsOnStart() testState( 2, 1, LifeCycleStatus.STARTED, null, 0, 0, LifeCycleStatus.STOPPED, null, - 2, 0, LifeCycleStatus.FAILED, failure.getFailure()); + 2, 0, LifeCycleStatus.STOPPED, failure.getFailure()); events.assertStartedEvent(applicationLC); + events.assertFailedEvent(filterLC); events.assertEmpty(); // @@ -407,7 +412,8 @@ public void testFilterFailsOnStart() testState( 2, 1, LifeCycleStatus.STARTED, null, 0, 0, LifeCycleStatus.STOPPED, null, - 3, 0, LifeCycleStatus.FAILED, failure.getFailure()); + 3, 0, LifeCycleStatus.STOPPED, failure.getFailure()); + events.assertFailedEvent(filterLC); events.assertEmpty(); // @@ -417,7 +423,7 @@ public void testFilterFailsOnStart() testState( 2, 1, LifeCycleStatus.STARTED, null, 0, 0, LifeCycleStatus.STOPPED, null, - 3, 0, LifeCycleStatus.FAILED, null); + 3, 0, LifeCycleStatus.STOPPED, null); events.assertEmpty(); // @@ -427,7 +433,8 @@ public void testFilterFailsOnStart() testState( 2, 1, LifeCycleStatus.STARTED, null, 0, 0, LifeCycleStatus.STOPPED, null, - 4, 0, LifeCycleStatus.FAILED, failure.getFailure()); + 4, 0, LifeCycleStatus.STOPPED, failure.getFailure()); + events.assertFailedEvent(filterLC); events.assertEmpty(); // @@ -437,7 +444,7 @@ public void testFilterFailsOnStart() testState( 2, 1, LifeCycleStatus.STARTED, null, 0, 0, LifeCycleStatus.STOPPED, null, - 4, 0, LifeCycleStatus.FAILED, failure.getFailure()); + 4, 0, LifeCycleStatus.STOPPED, failure.getFailure()); events.assertEmpty(); } diff --git a/portlet/src/test/java/org/gatein/pc/portlet/container/LifeCycleReentranceDetectionTestCase.java b/portlet/src/test/java/org/gatein/pc/portlet/container/LifeCycleReentranceDetectionTestCase.java index 8f5050ba..d5be58f9 100644 --- a/portlet/src/test/java/org/gatein/pc/portlet/container/LifeCycleReentranceDetectionTestCase.java +++ b/portlet/src/test/java/org/gatein/pc/portlet/container/LifeCycleReentranceDetectionTestCase.java @@ -124,7 +124,7 @@ public void testApplicationReentersApplication2() // assertNotNull(ise); - assertEquals(LifeCycleStatus.FAILED, applicationLF.getStatus()); + assertNotNull(applicationLF.getFailure()); } public void testContainerReentersContainer1() @@ -164,7 +164,7 @@ public void testContainerReentersContainer2() // assertNotNull(ise); assertEquals(LifeCycleStatus.STARTED, applicationLF.getStatus()); - assertEquals(LifeCycleStatus.FAILED, containerLF.getStatus()); + assertNotNull(containerLF.getStatus()); } public void testContainerReentersApplication1() @@ -204,6 +204,6 @@ public void testContainerReentersApplication2() // assertNotNull(ise); assertEquals(LifeCycleStatus.STARTED, applicationLF.getStatus()); - assertEquals(LifeCycleStatus.FAILED, containerLF.getStatus()); + assertNotNull(containerLF.getStatus()); } } diff --git a/portlet/src/test/java/org/gatein/pc/portlet/container/ManagedObjectRegistryEventList.java b/portlet/src/test/java/org/gatein/pc/portlet/container/ManagedObjectRegistryEventList.java index 3028d520..f8c921db 100644 --- a/portlet/src/test/java/org/gatein/pc/portlet/container/ManagedObjectRegistryEventList.java +++ b/portlet/src/test/java/org/gatein/pc/portlet/container/ManagedObjectRegistryEventList.java @@ -23,6 +23,8 @@ package org.gatein.pc.portlet.container; import junit.framework.Assert; +import junit.framework.AssertionFailedError; +import org.gatein.pc.portlet.container.managed.ManagedObjectFailedEvent; import org.gatein.pc.portlet.container.managed.ManagedObjectRegistryEventListener; import org.gatein.pc.portlet.container.managed.ManagedObjectRegistryEvent; import org.gatein.pc.portlet.container.managed.ManagedObject; @@ -65,7 +67,8 @@ public void assertStoppedEvent(ManagedObject managedObject) public void assertFailedEvent(ManagedObject managedObject) { - assertLifeCycleEvent(managedObject, LifeCycleStatus.FAILED); + ManagedObjectFailedEvent event = nextEvent(ManagedObjectFailedEvent.class); + Assert.assertSame(managedObject, event.getManagedObject()); } public void assertLifeCycleEvent(ManagedObject managedObject, LifeCycleStatus status) @@ -77,7 +80,7 @@ public void assertLifeCycleEvent(ManagedObject managedObject, LifeCycleStatus st public void assertEmpty() { - Assert.assertTrue(list.isEmpty()); + Assert.assertTrue("Was expecting " + list + " to be empty", list.isEmpty()); } public void clear()