Previous Topic

Next Topic

Book Contents

Book Index

Creating Custom Handlers

Overview

To have a custom Handler implementation, which is the logic behind the instructions, the user should implement the appropriate interface:

The implemented handler should be registered as an OSGi service in the OSGi framework.

To try how the examples below work, install and start the Automation External Handlers Demo.

Creating an Action Handler

To have a custom action handler, the user has to implement ActionHandler interface to enable the action handler functionality. The NotificationHandler is an example of such implementation. It sends a message through the channel when the rule engine invokes the execute(Map<String, Object> inputValues, Map<String, Object> outputValues) method. Its file from the Automation External Handlers Demo is com.prosyst.mbs.impl.demo.automation.external.handlers.NotifucationHandler.java.

Creating a Condition Handler

To have a custom condition handler, the user has to implement ConditionHandler interface to enable the condition handler functionality. The WeatherHandler is an example of such implementation. The rule engine evaluates the condition by invoking the isSatisfied(Map<String, Object> outputValues) method. The method checks if the weather is the desired one, and if so, the condition is satisfied. Its file from the Automation External Handlers Demo is com.prosyst.mbs.impl.demo.automation.external.handlers.WeatherHandler.java.

Creating a Trigger Handler

To have a custom trigger handler, the user has to implement AutoCloseable interface to enable the trigger handler functionality. The SleepTrackerHandler is an example of such implementation. It registers an Event Handler that tracks the events from the Sleep Tracker Functional Item. When an event is received the SleepTrackerHandler notifies the rule engine for new triggered data. For this purpose it uses the associated TriggerHandlerCallback instance by invoking the triggered(Map<String, Object> outputValues) method. Its file from the Automation External Handlers Demo is com.prosyst.mbs.impl.demo.automation.external.handlers.SleepTrackerHandler.java.

Creating a Trigger Handler Factory

To expose the custom trigger handler available for usage, the user has to implement a custom TriggerHandlerFactory. It is used to create instances when the Automation Admin requests them. Refer to the example of TriggerHandlerFactory implementation – SleepTrackerHandlerFactory, providing the above custom trigger handler. Its file from the Automation External Handlers Demo is com.prosyst.mbs.impl.demo.automation.external.handlers.SleepTrackerHandlerFacktory.java.