Discussion:
Best choice to listen for notifications on mule 3 server/app start stop
Victor Romero
2011-01-20 11:21:57 UTC
Permalink
I need to write a module that need to do some work when the mule 3 server or an mule application start/stop.

For the applications, as they are only going to be a subset of the applications I wrote a custom agent that should do the work in the start/stop methods and seems to work fine.

But now I'm wondering where to put the logic that should be attached to the mule server start stop itself. As notification listeners can't be dynamically added it makes no sense to put this logic inside a mule app (It did make no sense anyway ;) ) I'm assuming this should be some kind of mule module.

Do you have any hint about this?

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Andrew Perepelytsya
2011-01-20 13:47:48 UTC
Permalink
On Thu, Jan 20, 2011 at 6:21 AM, Victor Romero <
Post by Victor Romero
I need to write a module that need to do some work when the mule 3 server
or an mule application start/stop.
These are 2 very different events. For application just listen to a
MuleContextNotification.CONTEXT_STARTED/STOPPED.
Post by Victor Romero
For the applications, as they are only going to be a subset of the
applications I wrote a custom agent that should do the work in the
start/stop methods and seems to work fine.
That works, although listening to the above notification is a more correct
way.
Post by Victor Romero
But now I'm wondering where to put the logic that should be attached to the
mule server start stop itself.
In Mule 3.1.1 there is a callback for container 'start' event. Nothing for
stop, as there were no uses for it. Please describe what you're trying to
do, are you sure you need to hook into container lifecycle?
Post by Victor Romero
As notification listeners can't be dynamically added
They can be.
Post by Victor Romero
it makes no sense to put this logic inside a mule app (It did make no sense
anyway ;) ) I'm assuming this should be some kind of mule module.
Can't tell much until you describe what you're trying to do :)

HTH,
Andrew
Victor Romero
2011-01-20 16:16:10 UTC
Permalink
We can forget about the agent and the mule app start/stop process.

I need to initialize some stuff that will put a connection factory in JNDI when Mule starts and remove it when Mule stops.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Andrew Perepelytsya
2011-01-20 16:18:24 UTC
Permalink
How is Mule deployed? MuleContext notification didn't work?

Andrew

On Thu, Jan 20, 2011 at 11:16 AM, Victor Romero <
Post by Victor Romero
We can forget about the agent and the mule app start/stop process.
I need to initialize some stuff that will put a connection factory in JNDI
when Mule starts and remove it when Mule stops.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Victor Romero
2011-01-20 16:39:55 UTC
Permalink
It's just a vanilla mule-standalone 3.1 where I plan to deploy some mule apps in the apps directory, and started using $MULE_HOME/bin/mule.

The tests I've tried to do so far with the notifications didn't work. AFAIK because this (http://www.mulesoft.org/documentation/display/MULE3USER/Mule+Server+Notifications#MuleServerNotifications-interfaces)

bq. Registering Listeners Dynamically
bq. By default, you cannot register listeners in the Mule context after Mule has started. Therefore, you would register your listeners in your code before starting Mule. For example: \\ MuleContext context = new DefaultMuleContextFactory().createMuleContext \\ (new SpringXmlConfigurationBuilder("foo-config.xml")); \\ context.registerListener(listener, "*Service*"); \\ context.start(); \\ To change this behavior so that you can add listeners dynamically at run time, you can set the dynamic attribute on the &lt;notifications&gt; element. If you just want to enable dynamic notifications for a specific connector, you can set the dynamicNotification attribute on the connector.
Anyway as I'm starting it as mule standalone server, I wonder where to put the notification listener. Perhaps a bean inside the org.mule package so it's hopefully scanned by some scan-package of mule?


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Andrew Perepelytsya
2011-01-20 16:44:14 UTC
Permalink
How are you trying to add notification listeners? Programmatically?

Here's a working snippet from production code, should help:

final ServerNotificationManager notificationManager =
muleContext.getNotificationManager();
notificationManager.setNotificationDynamic(true);

if (!mapping.containsKey(EndpointMessageNotificationListener.class))
{
notificationManager.addInterfaceToType(
EndpointMessageNotificationListener.class,
EndpointMessageNotification.class);
}

HTH,
Andrew
Victor Romero
2011-01-20 17:16:37 UTC
Permalink
I tried this from an Agent and does not seems to work :

final ServerNotificationManager notificationManager = muleContext.getNotificationManager();
notificationManager.setNotificationDynamic(true);
muleContext.registerListener(new ServerNotificationListener<MuleContextNotification>() {


public void onNotification(MuleContextNotification notification) {
logger.error(notification.getType());
logger.error(notification.getActionName());
}
});

But anyway I'd love to be able to create a jar and place it in lib/user for instance and be able to do something when mule starts/stops.

Thanks for your support!

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Andrew Perepelytsya
2011-01-20 17:27:21 UTC
Permalink
On Thu, Jan 20, 2011 at 12:16 PM, Victor Romero <
Post by Victor Romero
muleContext.registerListener(new
ServerNotificationListener<MuleContextNotification>() {
This should be new MuleContextNotificationListener<MuleContextNotification>.

Another important point to understand is when container starts, there's no
MuleContext yet, and as such, no notification subsystem available. Still not
sure you actually need one for the container based on your use case. If you
just want listeners registered automatically without any config *on your app
startup*, then use the registry bootstrap:
http://blogs.mulesoft.org/start-me-oh-so-gently/

HTH,
Andrew
Victor Romero
2011-01-20 18:30:37 UTC
Permalink
Awesome Andrew!

Thank you

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
apvolkov
2012-06-22 14:22:44 UTC
Permalink
I have a question related to context events fired by Mule.

I have implemented MuleContextNotificationListener<MuleContextNotification>
to listen to the context starting and stopping events. There are two apps
(say app1 and app2 in the alphabetical order) that are deployed. After
deployment of both apps and starting/stopping Mule for the first time I see
that both apps get context starting and stopping events. On a second Mule
start/stop I see that both apps receive context starting event while only
one app (app2) receives context stopping event. Same context events are
received when I redeploy app1 (the one that does not receive context
stopping event).

Will appreciate any help.

--
View this message in context: http://mule.1045714.n5.nabble.com/Best-choice-to-listen-for-notifications-on-mule-3-server-app-start-stop-tp3349425p5714190.html
Sent from the Mule - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Loading...