Skip to content

Instantly share code, notes, and snippets.

@karanmalhi
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karanmalhi/92d2e4e6e11d339b174f to your computer and use it in GitHub Desktop.
Save karanmalhi/92d2e4e6e11d339b174f to your computer and use it in GitHub Desktop.
How to take custom action on raised alert
package com.mulesoft.tcat
import org.mule.galaxy.event.annotation.Async
import org.mule.galaxy.event.annotation.BindToEvent
import org.mule.galaxy.event.annotation.OnEvent
import org.mule.galaxy.event.EventManager;
import org.springframework.context.ApplicationContext;
@BindToEvent("com.mulesoft.console.alert.RaisedAlertEvent")
public class ScriptExecutor {
def ApplicationContext applicationContext;
def EventManager eventManager;
public ScriptExecutor(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
public void install() {
eventManager = applicationContext.getBean("eventManager");
// remove the previous listener, if any
eventManager.listeners.each {
if (it.class.simpleName == "ScriptExecutor") {
eventManager.removeListener(it)
println "Removed previous listener"
}
}
// add the event listener again
eventManager.addListener(this)
}
@Async
@OnEvent
void onEvent(com.mulesoft.console.alert.RaisedAlertEvent e) {
println e.raisedAlert;
println "We could restart server here or something custom could be done"
}
}
new ScriptExecutor(applicationContext).install();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment