Description of the Functional Item Events subscription mechanism.
Overview
Functional Items Management uses the OSGi Event Admin service to publish events asynchronously on:
Each event contains the properties describing the event and all the Functional Item attributes also.
The FunctionalItemEventConstants interface defines a set of constants related to FunctionalItem events.
Event Topic Constants
static final String FIM_PACKAGE = "com/prosyst/mbs/services/fim/FunctionalItemEvent/";
static final String TOPIC_ALL = FIM_PACKAGE + '*';
static final String TOPIC_REGISTERED = FIM_PACKAGE + "REGISTERED";
static final String TOPIC_UNREGISTERED = FIM_PACKAGE + "UNREGISTERED";
static final String TOPIC_PROPERTY_CHANGED = FIM_PACKAGE + "PROPERTY_CHANGED";
static final String TOPIC_OPERATION_EXECUTED = FIM_PACKAGE + "OPERATION_EXECUTED";
Additional Property Constants
static final String PROPERTY_NAME = "property.name";
static final String PROPERTY_NEW_VALUE = "property.value.new";
static final String PROPERTY_OLD_VALUE = "property.value.old";
static final String OPERATION_NAME = "operation.name";
Other Constants Related to FunctionalItem Events
FunctionalItemEvent Utility
The FunctionalItemEvent is a utility, part of the com.prosyst.mbs.services.fim.util package, that wraps a Functional Item Management event under the com/prosyst/mbs/services/fim/FunctionalItemEvent/ event topic. The constructor creates a FunctionalItemEvent for an event which topic is part of FunctionalItemEventConstants.FIM_PACKAGE, and the utility can be used for simple access to the added event properties.
Bellow you can find an example how to get the UID, old and new value of the property when using the FunctionalItemEvent.
...
FunctionalItemEvent stateEvent = new FunctionalItemEvent(event);
final String uid = stateEvent.getUID();
final State oldState = stateEvent.getPropertyChangedOldValue();
final State newState = stateEvent.getPropertyChangedNewValue();
System.out.println("Binary switch '" + uid + "' state was changed from '"
+ oldState + "' to '" + newState + '\'');
}
Examples
If Functional Item access is set to eventable in case of Operation executions it throws information for the event (to be able to view the event information one must be subscribed for events):
fim>$subscribe -t * /*** Subscription to all events. ***/Subscription ID: 1fim>$sub# Topics Filter Include-----------------------------------------------------------------------------------------------------------------------1 REG UNREG PROP OPERfim>$ex demo:fim:BinarySwitch:1 toggleOperation executed successfully.No result returned.fim>$FI EVENT HANDLER: 1-----------------------------------------------------------------------------------------------------------------------FI EVENT PROPERTY_CHANGEDevent.topics com/prosyst/mbs/services/fim/FunctionalItemEvent/PROPERTY_CHANGEDobjectClass [com.prosyst.mbs.demo.fim.BinarySwitch,com.prosyst.mbs.services.fim.FunctionalItem]property.name stateproperty.value.new Switched Onproperty.value.old Switched Offtimestamp 1426926411766uid demo:fim:BinarySwitch:1
The OSGi EventAdmin service is used to send events when a new group is added, removed, group items are changed, etc. For example, to receive events when functional item is added as subgroup of a group, the application must register EventHandler with topic FunctionalItemEventConstants.TOPIC_PROPERTY_CHANGED and event property Constants.OBJECTCLASS that has value com.prosyst.mbs.services.fim.groups.Group. If a group is successfully created/removed an operation executed event is fired with topic FunctionalItemEventConstants.TOPIC_OPERATION_EXECUTED.
It contains the properties:
In order to receive the event the subscriber should have FunctionalItemPermission.ACCESS_TYPE_VALUE_READ for Group.ITEMS property. Additionally, Group.ADD_ITEM / Group.REMOVE_ITEM operation executed events are fired for each group that the created/removed group is added to/removed from.
fim>$FI EVENT HANDLER: 1-----------------------------------------------------------------------------------------------------------------------FI EVENT REGISTEREDevent.topics com/prosyst/mbs/services/fim/FunctionalItemEvent/REGISTEREDfactory.uid fim:group:adminobjectClass {com.prosyst.mbs.services.fim.groups.Group,com.prosyst.mbs.services.fim.FunctionalItem}timestamp 1428044123721uid fim:group:24FI EVENT HANDLER: 1-----------------------------------------------------------------------------------------------------------------------FI EVENT OPERATION_EXECUTEDevent.topics com/prosyst/mbs/services/fim/FunctionalItemEvent/OPERATION_EXECUTEDitem fim:group:24name Group AdminobjectClass {com.prosyst.mbs.services.fim.groups.GroupAdmin,com.prosyst.mbs.services.fim.FunctionalItemFactory,com.prosyst.mbs.services.fim.FunctionalItem}operation.name createsupportedClasses {com.prosyst.mbs.services.fim.groups.Group}timestamp 1428044123721uid fim:group:admin