Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
Remove notion of Failed status
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Apr 2, 2013
1 parent 604fd30 commit d997f24
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 36 deletions.
2 changes: 1 addition & 1 deletion embed/src/main/java/org/gatein/pc/embed/EmbedServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
public enum LifeCycleStatus
{

STOPPED, STARTED, FAILED
STOPPED, STARTED

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <a href="mailto:julien@jboss.org">Julien Viet</a>
* @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 + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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));
}

}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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();

//
Expand All @@ -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();

//
Expand All @@ -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();

Expand All @@ -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();
Expand All @@ -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();
}

Expand All @@ -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);
Expand All @@ -342,17 +345,18 @@ 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();

//
applicationLC.managedStop();

//
testState(
2, 0, LifeCycleStatus.FAILED, null,
2, 0, LifeCycleStatus.STOPPED, null,
0, 0, LifeCycleStatus.STOPPED, null,
0, 0, LifeCycleStatus.STOPPED, null);
events.assertEmpty();
Expand All @@ -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();
Expand All @@ -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();

Expand All @@ -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();

//
Expand All @@ -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();

//
Expand All @@ -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();

//
Expand All @@ -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();

//
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void testApplicationReentersApplication2()

//
assertNotNull(ise);
assertEquals(LifeCycleStatus.FAILED, applicationLF.getStatus());
assertNotNull(applicationLF.getFailure());
}

public void testContainerReentersContainer1()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -204,6 +204,6 @@ public void testContainerReentersApplication2()
//
assertNotNull(ise);
assertEquals(LifeCycleStatus.STARTED, applicationLF.getStatus());
assertEquals(LifeCycleStatus.FAILED, containerLF.getStatus());
assertNotNull(containerLF.getStatus());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit d997f24

Please sign in to comment.