openejb-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Vysny <...@whitestein.com>
Subject Re: Shutdown an embedded instance of OpenEJB programatically
Date Mon, 04 Aug 2008 12:41:15 GMT
On Sat, 2008-08-02 at 15:23 -0700, David Blevins wrote:
> On Jul 30, 2008, at 12:34 AM, Martin Vysny wrote:
> 
> > Hello,
> >  currently we are starting OpenEJB as an embedded service (by
> > performing a lookup of
> > org.apache.openejb.client.LocalInitialContextFactory in JNDI
> > InitialContext). Is there a way to perform a clean shutdown of this
> > embedded instance? We are using OpenEJB in testing environment and I
> > need to shutdown OpenEJB cleanly, for example to stop uncanceled  
> > timers.
> 
> Hi Martin,
> 
> If you don't mind being tied to some OpenEJB code you could try  
> something like this:
> 
> import org.apache.openejb.loader.SystemInstance;
> import org.apache.openejb.assembler.classic.Assembler;
> import org.apache.openejb.assembler.classic.AppInfo;
> import org.apache.openejb.OpenEJB;
> 
> public class Shutdown {
>      public static void shutdown() throws Exception {
>          Assembler assembler =  
> SystemInstance.get().getComponent(Assembler.class);
>          for (AppInfo appInfo : assembler.getDeployedApplications()) {
>              assembler.destroyApplication(appInfo.jarPath);
>          }
>          OpenEJB.destroy();
>      }
> }
> 
> We could probably wrap this up into a better package and allow it to  
> be called from the initialContext.close() method so you don't have to  
> have any OpenEJB code in your test case.
> 
> Let me know if this does the trick for you and we'll get the cleaner  
> version in.
> 
> -David
> 

Hi David,
  thanks for the solution, it works for me! The timers are canceled
correctly in our project now. However the shutdown code is not perfect
yet. Out of curiosity I tried the following scenario: start OpenEJB,
stop it and start it again in the same VM. The following exception was
thrown:
[stacktrace attachment]

This is probably just a corner case (I can't imagine why would anyone
need to start, stop and start the OpenEJB again in same VM :), it's just
for the sake of completeness.
Thanks!
Martin

Mime
View raw message