You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by Quintin Beukes <qu...@last.za.net> on 2009/10/25 21:22:16 UTC

Container Shutdown

Hey,

I love the way Options.get() was done for enum types. Brilliant :> Had
to share my excitement!

Either way. Regarding the JUnit runner.  I want to add an option into
the configuration annotation, for shutting down the container, either
after a test method (if specified on the method), or after the test
class (if specified on the class).

This isn't an easy task, and if I don't find a solution I'm rather
going to leave it out for now. The problem is that Java's
InitialContext class creates a new factory and thus a new
InitialContext with every instance. One would have thought it cache
the factory perhaps? This poses a problem, as only the first
LocalInitialContextFactory has the power to destroy the container
system.

So I had a look at LocalInitialContext.close(). Is it enough to simply
do the following:

ContainerSystem containerSystem =
SystemInstance.get().getComponent(ContainerSystem.class);
Context context = containerSystem.getJNDIContext().lookup("openejb/local");
context.close();
OpenEJB.destroy();

With this, all I do is leave the factory.close() out. All it does is
set it's openejb member to null. Doing this, once I release my
InitialContext instance, it will be GC'ed, in which case the factory
will be GC'ed, in which case the only reference it would have set to
null with it's .close() will be GC'ed in anyway as well?

So the above code seems fine for something which is sort of "part of
OpenEJB", so to speak. If it ever gets integrated, and this part of
OpenEJB changes, then the tests will fail and it gets updated. If it
doesn't, I will maintain it, notice the tests fail, and change it. So
I figure it's safe to use the internal ways. My question is just if
what I'm doing is allowed at all, and if it's VERY package specific,
meaning nothing outside openejb-core is allowed to do it - so it's a
question of whether it follows OpenEJB's design/API policies?

The above will also only work if the person is using
LocalInitialContext. Which is sort of the only time you have control
over the destruction, and the only time the destroy property has an
effect, so I figured it's pretty safe if I only do the above if the
LocalInitialContextFactory is used.

Quintin Beukes