// FIX ME: May be create this lazily?
if (smrt == null)
smrt = ServerMessageRuntime.create(LISTENER, __logger);
if (event.getEventType() == ApplicationEvent.AFTER_APPLICATION_LOAD) {
ApplicationLoadEventListener loaderListener = __handleEvent(event);
String appName = event.getApplication().getRegistrationName();
if (loaderListener != null) {
MessageCallBackImpl impl =
new MessageCallBackImpl(loaderListener);
impl.setLoading(true);
ClassLoader toSet = loaderListener.getClass().getClassLoader();
ClassLoader saved = setContextClassLoader(toSet);
// Invoke the per-instance listener.
loaderListener.handleLoad();
setContextClassLoader(saved);
//During load, aggregate the results. So, all the instances
//will send the notification to the elected instnace. So, the
//route is ALLTOONE.
Barrier b = getServerMessageRuntime().initiateMessaging(appName,
Message.Route.ALLTOONE,impl);
if (b != null)
b.start(timeout);
}
return;
}
if (event.getEventType() == ApplicationEvent.BEFORE_APPLICATION_UNLOAD){
ApplicationLoadEventListener loaderListener = __handleEvent(event);
String appName = event.getApplication().getRegistrationName();
if (loaderListener != null) {
MessageCallBackImpl impl =
new MessageCallBackImpl(loaderListener);
// In case of unload, an ONETOALL message should be sent so that
// all instances will wait for clusterwide uload to complete.
// FIX ME. Would ALLTOONE be better here also?
getServerMessageRuntime().initiateMessagingAndWait(appName,
Message.Route.ONETOALL,impl);
ClassLoader toSet = loaderListener.getClass().getClassLoader();
ClassLoader saved = setContextClassLoader(toSet);
loaderListener.handleUnLoad();
setContextClassLoader(saved);
//Lets make sure that message runtime doesnt keep this app any more.
getServerMessageRuntime().purge(appName);
}
return;
}
if (event.getEventType() == ApplicationEvent.APPLICATION_LOADFAIL) {
ApplicationLoadEventListener loaderListener = __handleEvent(event);
String appName = event.getApplication().getRegistrationName();
if (loaderListener != null) {
MessageCallBackImpl impl =
new MessageCallBackImpl(loaderListener);
impl.setFailure(true);
ClassLoader toSet = loaderListener.getClass().getClassLoader();
ClassLoader saved = setContextClassLoader(toSet);
// Invoke the per-instance listener.
loaderListener.handleLoadFailure();
setContextClassLoader(saved);
//ALLTOONE message to aggregate failure messages.
Barrier b = getServerMessageRuntime().initiateMessaging
(appName+"__fail", Message.Route.ALLTOONE, impl);