dev@glassfish.java.net

Re: new deployment events

From: Jerome Dochez <Jerome.Dochez_at_Sun.COM>
Date: Fri, 13 Feb 2009 09:00:50 -0800

On Feb 13, 2009, at 5:45 AM, Kedar Mhaswade wrote:

> This is very useful. Thanks for some details.
>
> A few questions:
>
> - How do you define "a loaded application"? For example, for a Java
> web
> application, is it that Origin.load event is sent
Origin.load is not an event, it just qualifies that the deployment
request is a LOAD (server restart) rather than a first time DEPLOY.
>
> after all the "load-on-startup" servlets are loaded,
> ServletContextListener
> called etc.?
>
it's after the ApplicationContainer<?>.start() method returned, so
it's the job of each container to do the appropriate components start.

> - Is the runtime state of an "app" available somewhere? (JSR-77
> MBean, maybe?)
>
yes and in some semi-private runtime structure (ApplicationInfo)

> - Exactly when are the listeners called? Are all listeners called in
> a separate
> thread, sequentially, in the order of registration?
>
separate thread for each listener, order undefined but since it's
asynchronous, I don't think adding ordering would be helpful.

> - Can this be used to find out exactly what failed during a
> deployment operation
> (e.g. deployment, code-generation if any, or loading)?
>
not yet but that can be arranged.

> -Kedar
>
> Jerome Dochez wrote:
>> A number of people have been asking for some new events to be sent
>> when deployment is happening
>> I have added 3 events that will be sent for each deployment
>> Those events are defined in the
>> org.glassfish.internal.deployment.Deployment contract definition
>> public final EventTypes<ExtendedDeploymentContext>
>> DEPLOYMENT_START
>> public final EventTypes<ExtendedDeploymentContext>
>> DEPLOYMENT_FAILURE
>> public final EventTypes<ApplicationInfo> DEPLOYMENT_SUCCESS
>> to be able to be notified of any application being deployed, you
>> can just do
>> @Inject
>> Events events;
>> ....
>> events.register(new EventListener() {
>> public void event(Event e) {
>> if (e.is(Deployment.DEPLOYMENT_START)) {
>> System.out.println("new deployment detected");
>> }
>> }
>> });
>> Each even carries the ExtendedDeploymentContext object which has
>> all relevant information about what's being deployed which can be
>> accessed typed safely like that :
>> ExtendedDeploymentContext dc =
>> Deployment.DEPLOYMENT_START.getHook(e);
>> Also some folks have been willing to know what caused a deployment
>> operation to happen. For instance there is different between first
>> time deployment and loading when server restart. In order to
>> disambiguate, each deployment operation has an origin attribute
>> which identified what caused the deployment operation.
>> public enum Origin { load, deploy, unload, undeploy }
>> so say you want to have code that do something when you are in
>> deploy (versus just a server restart), you would do with a
>> DeploymentContext (dc)
>> DeployCommandParameters params =
>> dc.getCommandParameters(DeployCommandParameters.class);
>> switch(params.origin) {
>> case Origin.Deploy :
>> System.out.println("This is a first time deployment of
>> this operation");
>> break;
>> case Origin.Load :
>> System.out.println("this is a reload after server
>> restart or disable/enable");
>> break;
>> }
>> Jerome
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>