Moab Web Services > Plugins > Plugin Services > Plugin Event Service

Plugin Event Service

The event service is provided to ease the burden and reduce boilerplate code for creating new events and updating notification conditions. For more information on how to use this service, see Creating Events and Notifications.

The pluginEventService property will be injected with a class of type IPluginEventService in all plugin types. Note that it is not available for injection in translators or custom components.

Examples

Creating a custom event
------------------------------------

package example

import com.adaptc.mws.plugins.IPluginEventService.Severity
import com.adaptc.mws.plugins.IPluginEventService.EscalationLevel
import com.adaptc.mws.plugins.IPluginEventService.AssociatedObject

public class ExamplePlugin {
	def pluginEventService

	public void poll() {
		// Create a completely custom event
		pluginEventService.createEvent(Severity.INFO, EscalationLevel.USER, 0x4F, "Custom Type",
                                       	"poll", "My event occurred", null, null)
	}
}
Creating a custom event with messages
------------------------------------

package example

import com.adaptc.mws.plugins.IPluginEventService.Severity
import com.adaptc.mws.plugins.IPluginEventService.EscalationLevel
import com.adaptc.mws.plugins.IPluginEventService.AssociatedObject

public class ExamplePlugin {
	def pluginEventService

	public void poll() {
    	// Use i18n messages for another event
    	def args = ["arg1", "arg2"]
		pluginEventService.createEvent(Severity.WARN, EscalationLevel.POWER_USER, 0x5F, "Custom Type",
                                       	"poll", message(code:"examplePlugin.customEvent.message", args:args), args,
                                       	// AssociatedObjects or simple maps may be used
                                       	[new AssociatedObject(type:"type1", id:"id1"), [type:"type2", id:"id2"])
	}
}
Creating an event from EventEnumeration
------------------------------------

package example

import com.adaptc.mws.plugins.EventEnumeration
import com.adaptc.mws.plugins.IPluginEventService.Severity
import com.adaptc.mws.plugins.IPluginEventService.EscalationLevel
import com.adaptc.mws.plugins.IPluginEventService.AssociatedObject

public class ExamplePlugin {
	def pluginEventService

	public void poll() {
		// Messages are pulled for messages.properties file(s) and the arguments are used
    	def args = ["arg1", "arg2"]
		pluginEventService.createEvent(MyEvents.EVENT_INFO, args, [[type:"type1", id:"id1"])
		pluginEventService.createEvent(MyEvents.EVENT_WARN, args, [[type:"type2", id:"id2"])
	}
}

@EventEnumeration
enum MyEvents {
	EVENT_INFO("Information", INFO, USER),
	EVENT_ERROR("Warning", WARN, USER)

	static final String EVENT_TYPE_PREFIX = "Example Plugin"
	static final String ORIGIN_SUFFIX = "poll"
}
Create or update a notification
------------------------------------

package example

import com.adaptc.mws.plugins.IPluginEventService.EscalationLevel
import com.adaptc.mws.plugins.IPluginEventService.AssociatedObject

public class ExamplePlugin {
	def pluginEventService

	public void poll() {
		pluginEventService.updateNotification(EscalationLevel.POWER_USER, "There is an error with node1",
					// If non-null, this must always be an associated object, never a simple map
					new AssociatedObject(id:"node1", type:"node"), null)
	}
}

Related Topics 

© 2015 Adaptive Computing