Fixes #854 - If container.destroy() is called, calling container.start() again should throw an IllegalStateException.
This commit is contained in:
parent
7a7d5e2f1e
commit
10f994a0a2
|
@ -78,6 +78,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
private final List<Bean> _beans = new CopyOnWriteArrayList<>();
|
||||
private final List<Container.Listener> _listeners = new CopyOnWriteArrayList<>();
|
||||
private boolean _doStarted;
|
||||
private boolean _destroyed;
|
||||
|
||||
/**
|
||||
* Starts the managed lifecycle beans in the order they were added.
|
||||
|
@ -85,6 +86,9 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
@Override
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
if (_destroyed)
|
||||
throw new IllegalStateException("Destroyed container cannot be restarted");
|
||||
|
||||
// indicate that we are started, so that addBean will start other beans added.
|
||||
_doStarted = true;
|
||||
|
||||
|
@ -164,6 +168,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
_destroyed = true;
|
||||
List<Bean> reverse = new ArrayList<>(_beans);
|
||||
Collections.reverse(reverse);
|
||||
for (Bean b : reverse)
|
||||
|
|
|
@ -139,6 +139,18 @@ public class ContainerLifeCycleTest
|
|||
Assert.assertEquals(2,destroyed.get());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testIllegalToStartAfterDestroy() throws Exception
|
||||
{
|
||||
ContainerLifeCycle container = new ContainerLifeCycle();
|
||||
container.start();
|
||||
container.stop();
|
||||
container.destroy();
|
||||
|
||||
// Should throw IllegalStateException.
|
||||
container.start();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisJoint() throws Exception
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue