Last active
August 29, 2015 14:20
-
-
Save karanmalhi/92d2e4e6e11d339b174f to your computer and use it in GitHub Desktop.
How to take custom action on raised alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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