The event bus

The event bus classes are important if you want your plugin to act on certain events in Opinio. For example, when a respondent has completed a survey, you want to do something with the data (like sending an email). To know when this respondent has completed, you need to receive an event notification.

To receive this notification, the plugin must register itself on the event bus. There are several bus types and many event types in each bus. See om.objectplanet.survey.event.EventBusManager in the plugin documentation.

Examples of bus types:

There are several addListener(**) methods in the EventBusManager. You can register to listen to:

IMPORTANT: Try to register events on as low level as possible to maximize the performance.

Example 1. Plugin example

Implement com.objectplanet.survey.event.IEventListener interface.

In the start() method of your plugin, you can register your plugin to listen to the administration events:

        public void start() {
                EventBusManager eventMgr = EventBusManager.instance();
                eventMgr.addListener(this, EventBusManager.BUS_TYPE_SURVEY_MANAGEMENT, EventBusManager. EVENT_TYPE_NEW_SURVEY);
        }
                                        

Implement the handleEvent() method from IEventListener interface, so that the events received are handled correctly. For example:

        public void handleEvent(PluginBusEvent event) {
                if (event instanceof NewSurveyEvent) {
                        NewSurveyEvent nsEvent = (NewSurveyEvent) event;
                        long surveyId = nsEvent.getSurveyId();

                        // Do something with the survey; send an email,
                        //  call an external system etc.

                        ....

                }
        }