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
java.lang.RuntimeException: 
com.whitestein.fe.embedded.launcher.LauncherException: 
com.whitestein.fe.embedded.launcher.LauncherException: 
javax.naming.NamingException: Cannot instantiate an IntraVM InitialContext. 
Exception: org.apache.openejb.core.ivm.naming.NamingException 
org.apache.xbean.recipe.ConstructionException: Error invoking factory method: 
public static 
org.apache.geronimo.transaction.manager.GeronimoTransactionManager 
org.apache.openejb.resource.GeronimoTransactionManagerFactory.create(int,byte[],java.lang.String,int,boolean,boolean,int,java.lang.String,java.lang.String,java.lang.String,int,int,int,int,int)
 throws java.lang.Exception: Error invoking factory method: public static 
org.apache.geronimo.transaction.manager.GeronimoTransactionManager 
org.apache.openejb.resource.GeronimoTransactionManagerFactory.create(int,byte[],java.lang.String,int,boolean,boolean,int,java.lang.String,java.lang.String,java.lang.String,int,int,int,int,int)
 throws java.lang.Exception [Root exception is 
org.apache.openejb.core.ivm.naming.NamingException: 
org.apache.xbean.recipe.ConstructionException: Error invoking factory method: 
public static 
org.apache.geronimo.transaction.manager.GeronimoTransactionManager 
org.apache.openejb.resource.GeronimoTransactionManagerFactory.create(int,byte[],java.lang.String,int,boolean,boolean,int,java.lang.String,java.lang.String,java.lang.String,int,int,int,int,int)
 throws java.lang.Exception: Error invoking factory method: public static 
org.apache.geronimo.transaction.manager.GeronimoTransactionManager 
org.apache.openejb.resource.GeronimoTransactionManagerFactory.create(int,byte[],java.lang.String,int,boolean,boolean,int,java.lang.String,java.lang.String,java.lang.String,int,int,int,int,int)
 throws java.lang.Exception]
        at com.whitestein.fe.it.cal.CalUtils.newComm(CalUtils.java:70)
        at 
com.whitestein.fe.it.cal.AbstractCalDbTest.setUp(AbstractCalDbTest.java:95)
        at 
com.whitestein.fe.it.tests.components.AgentEnvironmentTest.setUp(AgentEnvironmentTest.java:39)
        at junit.framework.TestCase.runBare(TestCase.java:125)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:118)
        at junit.framework.TestSuite.runTest(TestSuite.java:208)
        at junit.framework.TestSuite.run(TestSuite.java:203)
        at 
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
        at 
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: com.whitestein.fe.embedded.launcher.LauncherException: 
com.whitestein.fe.embedded.launcher.LauncherException: 
javax.naming.NamingException: Cannot instantiate an IntraVM InitialContext. 
Exception: org.apache.openejb.core.ivm.naming.NamingException 
org.apache.xbean.recipe.ConstructionException: Error invoking factory method: 
public static 
org.apache.geronimo.transaction.manager.GeronimoTransactionManager 
org.apache.openejb.resource.GeronimoTransactionManagerFactory.create(int,byte[],java.lang.String,int,boolean,boolean,int,java.lang.String,java.lang.String,java.lang.String,int,int,int,int,int)
 throws java.lang.Exception: Error invoking factory method: public static 
org.apache.geronimo.transaction.manager.GeronimoTransactionManager 
org.apache.openejb.resource.GeronimoTransactionManagerFactory.create(int,byte[],java.lang.String,int,boolean,boolean,int,java.lang.String,java.lang.String,java.lang.String,int,int,int,int,int)
 throws java.lang.Exception [Root exception is 
org.apache.openejb.core.ivm.naming.NamingException: 
org.apache.xbean.recipe.ConstructionException: Error invoking factory method: 
public static 
org.apache.geronimo.transaction.manager.GeronimoTransactionManager 
org.apache.openejb.resource.GeronimoTransactionManagerFactory.create(int,byte[],java.lang.String,int,boolean,boolean,int,java.lang.String,java.lang.String,java.lang.String,int,int,int,int,int)
 throws java.lang.Exception: Error invoking factory method: public static 
org.apache.geronimo.transaction.manager.GeronimoTransactionManager 
org.apache.openejb.resource.GeronimoTransactionManagerFactory.create(int,byte[],java.lang.String,int,boolean,boolean,int,java.lang.String,java.lang.String,java.lang.String,int,int,int,int,int)
 throws java.lang.Exception]
        at 
com.whitestein.fe.embedded.launcher.OpenEjbAndFELauncher.launch(OpenEjbAndFELauncher.java:162)
        at 
com.whitestein.fe.embedded.launcher.Launcher.launch(Launcher.java:133)
        at com.whitestein.fe.it.cal.CalUtils.newComm(CalUtils.java:54)
        ... 15 more
Caused by: com.whitestein.fe.embedded.launcher.LauncherException: 
javax.naming.NamingException: Cannot instantiate an IntraVM InitialContext. 
Exception: org.apache.openejb.core.ivm.naming.NamingException 
org.apache.xbean.recipe.ConstructionException: Error invoking factory method: 
public static 
org.apache.geronimo.transaction.manager.GeronimoTransactionManager 
org.apache.openejb.resource.GeronimoTransactionManagerFactory.create(int,byte[],java.lang.String,int,boolean,boolean,int,java.lang.String,java.lang.String,java.lang.String,int,int,int,int,int)
 throws java.lang.Exception: Error invoking factory method: public static 
org.apache.geronimo.transaction.manager.GeronimoTransactionManager 
org.apache.openejb.resource.GeronimoTransactionManagerFactory.create(int,byte[],java.lang.String,int,boolean,boolean,int,java.lang.String,java.lang.String,java.lang.String,int,int,int,int,int)
 throws java.lang.Exception [Root exception is 
org.apache.openejb.core.ivm.naming.NamingException: 
org.apache.xbean.recipe.ConstructionException: Error invoking factory method: 
public static 
org.apache.geronimo.transaction.manager.GeronimoTransactionManager 
org.apache.openejb.resource.GeronimoTransactionManagerFactory.create(int,byte[],java.lang.String,int,boolean,boolean,int,java.lang.String,java.lang.String,java.lang.String,int,int,int,int,int)
 throws java.lang.Exception: Error invoking factory method: public static 
org.apache.geronimo.transaction.manager.GeronimoTransactionManager 
org.apache.openejb.resource.GeronimoTransactionManagerFactory.create(int,byte[],java.lang.String,int,boolean,boolean,int,java.lang.String,java.lang.String,java.lang.String,int,int,int,int,int)
 throws java.lang.Exception]
        at 
com.whitestein.fe.embedded.launcher.OpenEjbAndFELauncher.launch(OpenEjbAndFELauncher.java:162)
        at 
com.whitestein.fe.embedded.launcher.OpenEjbAndFELauncher.launch(OpenEjbAndFELauncher.java:160)
        ... 17 more
Caused by: javax.naming.NamingException: Cannot instantiate an IntraVM 
InitialContext. Exception: org.apache.openejb.core.ivm.naming.NamingException 
org.apache.xbean.recipe.ConstructionException: Error invoking factory method: 
public static 
org.apache.geronimo.transaction.manager.GeronimoTransactionManager 
org.apache.openejb.resource.GeronimoTransactionManagerFactory.create(int,byte[],java.lang.String,int,boolean,boolean,int,java.lang.String,java.lang.String,java.lang.String,int,int,int,int,int)
 throws java.lang.Exception: Error invoking factory method: public static 
org.apache.geronimo.transaction.manager.GeronimoTransactionManager 
org.apache.openejb.resource.GeronimoTransactionManagerFactory.create(int,byte[],java.lang.String,int,boolean,boolean,int,java.lang.String,java.lang.String,java.lang.String,int,int,int,int,int)
 throws java.lang.Exception [Root exception is 
org.apache.openejb.core.ivm.naming.NamingException: 
org.apache.xbean.recipe.ConstructionException: Error invoking factory method: 
public static 
org.apache.geronimo.transaction.manager.GeronimoTransactionManager 
org.apache.openejb.resource.GeronimoTransactionManagerFactory.create(int,byte[],java.lang.String,int,boolean,boolean,int,java.lang.String,java.lang.String,java.lang.String,int,int,int,int,int)
 throws java.lang.Exception: Error invoking factory method: public static 
org.apache.geronimo.transaction.manager.GeronimoTransactionManager 
org.apache.openejb.resource.GeronimoTransactionManagerFactory.create(int,byte[],java.lang.String,int,boolean,boolean,int,java.lang.String,java.lang.String,java.lang.String,int,int,int,int,int)
 throws java.lang.Exception]
        at 
org.apache.openejb.client.LocalInitialContextFactory.getIntraVmContext(LocalInitialContextFactory.java:116)
        at 
org.apache.openejb.client.LocalInitialContextFactory.getInitialContext(LocalInitialContextFactory.java:41)
        at 
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
        at 
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
        at javax.naming.InitialContext.init(InitialContext.java:223)
        at javax.naming.InitialContext.<init>(InitialContext.java:197)
        at 
com.whitestein.fe.embedded.launcher.OpenEjbAndFELauncher.initOpenEJB(OpenEjbAndFELauncher.java:233)
        at 
com.whitestein.fe.embedded.launcher.OpenEjbAndFELauncher.launch(OpenEjbAndFELauncher.java:155)
        ... 18 more
Caused by: org.apache.openejb.core.ivm.naming.NamingException: 
org.apache.xbean.recipe.ConstructionException: Error invoking factory method: 
public static 
org.apache.geronimo.transaction.manager.GeronimoTransactionManager 
org.apache.openejb.resource.GeronimoTransactionManagerFactory.create(int,byte[],java.lang.String,int,boolean,boolean,int,java.lang.String,java.lang.String,java.lang.String,int,int,int,int,int)
 throws java.lang.Exception: Error invoking factory method: public static 
org.apache.geronimo.transaction.manager.GeronimoTransactionManager 
org.apache.openejb.resource.GeronimoTransactionManagerFactory.create(int,byte[],java.lang.String,int,boolean,boolean,int,java.lang.String,java.lang.String,java.lang.String,int,int,int,int,int)
 throws java.lang.Exception
        at 
org.apache.openejb.core.ivm.naming.InitContextFactory.initializeOpenEJB(InitContextFactory.java:85)
        at 
org.apache.openejb.core.ivm.naming.InitContextFactory.getInitialContext(InitContextFactory.java:35)
        at 
org.apache.openejb.client.LocalInitialContextFactory.getIntraVmContext(LocalInitialContextFactory.java:114)
        ... 25 more


Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to