399967 call Destroyable.destroy() when a managed been is removed from ContainerLifeCycle
This commit is contained in:
parent
7037bca94d
commit
b8473122de
|
@ -58,6 +58,7 @@ public class DataSourceCloser implements Destroyable
|
|||
_shutdown=shutdownSQL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
try
|
||||
|
|
|
@ -139,7 +139,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
Collections.reverse(reverse);
|
||||
for (Bean b : reverse)
|
||||
{
|
||||
if (b._bean instanceof Destroyable && b._managed==Managed.MANAGED)
|
||||
if (b._bean instanceof Destroyable && (b._managed==Managed.MANAGED || b._managed==Managed.POJO))
|
||||
{
|
||||
Destroyable d = (Destroyable)b._bean;
|
||||
d.destroy();
|
||||
|
@ -447,6 +447,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
{
|
||||
if (_beans.remove(bean))
|
||||
{
|
||||
boolean managed=bean.isManaged();
|
||||
unmanage(bean);
|
||||
|
||||
for (Container.Listener l:_listeners)
|
||||
|
@ -467,6 +468,19 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (managed && bean._bean instanceof Destroyable)
|
||||
{
|
||||
try
|
||||
{
|
||||
((Destroyable)bean._bean).destroy();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
LOG.warn(e);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -18,10 +18,12 @@
|
|||
|
||||
package org.eclipse.jetty.util.thread;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.eclipse.jetty.util.component.Destroyable;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
@ -79,7 +81,7 @@ public class ShutdownThread extends Thread
|
|||
catch(Exception e)
|
||||
{
|
||||
LOG.ignore(e);
|
||||
LOG.info("shutdown already commenced");
|
||||
LOG.debug("shutdown already commenced");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,6 +133,12 @@ public class ShutdownThread extends Thread
|
|||
lifeCycle.stop();
|
||||
LOG.debug("Stopped {}",lifeCycle);
|
||||
}
|
||||
|
||||
if (lifeCycle instanceof Destroyable)
|
||||
{
|
||||
((Destroyable)lifeCycle).destroy();
|
||||
LOG.debug("Destroyed {}",lifeCycle);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
@ -117,17 +117,17 @@ public class ContainerLifeCycleTest
|
|||
a0.destroy();
|
||||
Assert.assertEquals(3,started.get());
|
||||
Assert.assertEquals(2,stopped.get());
|
||||
Assert.assertEquals(1,destroyed.get());
|
||||
Assert.assertEquals(2,destroyed.get());
|
||||
|
||||
a1.stop();
|
||||
Assert.assertEquals(3,started.get());
|
||||
Assert.assertEquals(3,stopped.get());
|
||||
Assert.assertEquals(1,destroyed.get());
|
||||
Assert.assertEquals(2,destroyed.get());
|
||||
|
||||
a1.destroy();
|
||||
Assert.assertEquals(3,started.get());
|
||||
Assert.assertEquals(3,stopped.get());
|
||||
Assert.assertEquals(2,destroyed.get());
|
||||
Assert.assertEquals(3,destroyed.get());
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue