You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Andy Gumbrecht <an...@orprovision.com> on 2010/03/26 18:10:49 UTC

Shutdown

Howdy all,

Is there a reliable means of detecting a stand alone server shut-down 
from within an ejb?
I am currently using a thread, but know this is just a temporary solution.

Thanks in advance,

Andy.

Re: Shutdown

Posted by Andy Gumbrecht <an...@orprovision.com>.
On 30.03.2010 15:09, Stephen Connolly wrote:
> AFAIK though, the application server is not under contract to have the
> message driven EJB container active when it shuts down the RA
>
> On 30 March 2010 13:59, AndyG<an...@orprovision.com>  wrote:

True, but if an EJB has registered a unit of work as a listener with the 
'Shutdown' then it gets notified - which is what I was after.
It was more a case of being able to detect a complete shutdown in order 
to perform final actions, rather than an EJB unload.

Another option was to write a shutdown EJB, which in turn cleaned up 
then shut down the server. I decided it would be better if the server 
told 'me' that it was shutting down, rather than introduce app server 
specific shutdown code into an EJB.

Re: Shutdown

Posted by Stephen Connolly <st...@gmail.com>.
AFAIK though, the application server is not under contract to have the
message driven EJB container active when it shuts down the RA

On 30 March 2010 13:59, AndyG <an...@orprovision.com> wrote:

>
> OK, Came up with a viable solution - which is also portable.
>
> An application server is under contract to call 'stop' on all it's resource
> adapters.
>
> If an RA is deployed into 'openejb/lib' then it is 'pretty safe' to assume
> it will only be unloaded when the server is shutting down. The RA basically
> contains this class, and a standard META-INF/ra.xml.
>
> So, here I leave 'Shutdown' to your imagination, but basically it is a
> simple Singleton for registering listeners. I'd also remove the log when
> ready:
>
> public class ShutdownAdapter implements javax.resource.spi.ResourceAdapter
> {
>
>    protected static final Log log =
> LogFactory.getLog(ShutdownAdapter.class);
>    private static Shutdown instance = null;
>
>    @Override
>    public void endpointActivation(final MessageEndpointFactory factory,
> final ActivationSpec spec) throws ResourceException {
>
>    }
>
>    @Override
>    public void endpointDeactivation(final MessageEndpointFactory factory,
> final ActivationSpec spec) {
>
>    }
>
>    @Override
>    public void start(final BootstrapContext context) throws
> ResourceAdapterInternalException {
>        if (null == instance) {
>            instance = Shutdown.getInstance();
>            log.debug("Started ShutdownAdapter");
>        }
>    }
>
>    @Override
>    public void stop() {
>
>        if (null != instance) {
>            instance.fireShutdown();
>        }
>
>        instance = null;
>        log.debug("Stopped ShutdownAdapter");
>    }
>
>    @Override
>    public XAResource[] getXAResources(final ActivationSpec[] specs) throws
> ResourceException {
>        return new XAResource[0];
>    }
> }
> --
> View this message in context:
> http://n4.nabble.com/Shutdown-tp1692548p1745163.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Shutdown

Posted by AndyG <an...@orprovision.com>.
OK, Came up with a viable solution - which is also portable.

An application server is under contract to call 'stop' on all it's resource
adapters.

If an RA is deployed into 'openejb/lib' then it is 'pretty safe' to assume
it will only be unloaded when the server is shutting down. The RA basically
contains this class, and a standard META-INF/ra.xml.

So, here I leave 'Shutdown' to your imagination, but basically it is a
simple Singleton for registering listeners. I'd also remove the log when
ready:

public class ShutdownAdapter implements javax.resource.spi.ResourceAdapter {

    protected static final Log log =
LogFactory.getLog(ShutdownAdapter.class);
    private static Shutdown instance = null;

    @Override
    public void endpointActivation(final MessageEndpointFactory factory,
final ActivationSpec spec) throws ResourceException {

    }

    @Override
    public void endpointDeactivation(final MessageEndpointFactory factory,
final ActivationSpec spec) {

    }

    @Override
    public void start(final BootstrapContext context) throws
ResourceAdapterInternalException {
        if (null == instance) {
            instance = Shutdown.getInstance();
            log.debug("Started ShutdownAdapter");
        }
    }

    @Override
    public void stop() {

        if (null != instance) {
            instance.fireShutdown();            
        }

        instance = null;
        log.debug("Stopped ShutdownAdapter");
    }

    @Override
    public XAResource[] getXAResources(final ActivationSpec[] specs) throws
ResourceException {
        return new XAResource[0];
    }
} 
-- 
View this message in context: http://n4.nabble.com/Shutdown-tp1692548p1745163.html
Sent from the OpenEJB User mailing list archive at Nabble.com.