Process communication queue for Oracle CX Core SDK

The Oracle CX Core SDK includes components that help you to add/update or remove the event data dynamically when event is generated.

Oracle CX Core SDK includes the ability of acting as Observable which publish events as and when generated/received. Observers will subscribe to Observable and get notify when the event is generated/received. Every event that SDK generate has its Group name. This Group name plays vital role while subscribing.

Oracle CX Core SDK provide an interface IORAEventListener which gives an ability to subscribe for events. These Observers override onEventFound() method where the add/update or deleting of data will be carried out.

Oracle CX Core SDK includes the ability of acting as Observable and provide an interface IORAEventListener which gives an ability to Observe. This page briefs how to implement Process Communication queues and how to work with it.

Implementing Process Communication Queues

Oracle CX Core SDK provides ORABaseDataCollector.addEventListener() method which registers observer on observable. Before registering we have to know couple of other components. They are Priority and Time Delay.

Here Priority is the positive integer ranges from 1 to 16. 1 is highest priority and 16 is lowest priority. If we pass out of this range, SDK will automatically consider as least priority.

Time Delay is in milliseconds. This is an waiting time for getting response from observer. We get more about them while we discuss implementation. The implementation steps are furnished below.

Register or Add Observers

  • Initially add event listeners i.e observers by invoking 'addEventListener' method. This method is located in 'ORABaseDataCollector' class. So the method calling looks like below.
ORABaseDataCollector dataCollector = ORABaseDataCollector.getInstance();
dataCollector.addEventListener(IORAEventListener listener, String moduleId, String listenerName, ArrayList<String> groups, int priority);
  • In Above code, 'IORAEventListener' is the interface where the method 'public ORAEventMap onEventFound(ORAEventMap object)' will be overridden and resultant actions will be carried out. This method accepts one parameter i.e 'ORAEventMap' which is generated event and returns updated event object.

The example implementation is shown below.

new IORAEventListener() {
@Override
public ORAEventMap onEventFound(ORAEventMap object) {
object.put("custom", "my_custom_data");
object.put("wt.sdk_v", "2.0");
return object;
}
}
  • A unique identifier for the Module.
  • For every listener we register, we must name it for identification. This plays vital role while de-registering the observer. We have to send name string in addEventListener() method. Listener name must be alpha numeric only.
  • Every event generated belongs to come category. This category is called as 'Group'. While subscribing to observable, we register to listen the events which are belongs to some group, not for single event. So we need to pass valid group name as parameter in 'addEventListener' method. The valid group names for Oracle CX Core SDK events are listed in 'ORAEventGroup' class.

Single observer can register to multiple event groups by sending array of group names. So that we don't need to call 'addEventListener' again and again for different groups.

The example for passing the group name is shown below.

Single Group name

ArrayList<String> groupArray = new ArrayList<>();
groupArray.add(ORAEventGroup.ORA_EG_INTERACTION);

Multiple Group names

ArrayList<String> groupArray = new ArrayList<>();
groupArray.add(ORAEventGroup.ORA_EG_INTERACTION);
groupArray.add(ORAEventGroup.ORA_EG_SCREEN);
groupArray.add(ORAEventGroup.ORA_EG_CUSTOM);

Subscribing for all groups

ArrayList<String> groupArray = new ArrayList<>();
groupArray.add(ORAEventGroup.ORA_EG_TYPE_ALL);

We can subscribe all groups at a time with 'ORAEventGroup.ORA_EG_TYPE_ALL'. This will subscribe to all groups to listen every event which will generate.

  • Priority is the positive integer ranges from 1 to 16. Value which is out of this range is considered as 16 automatically in validation. 1 being the highest priority and 16 is the lowest priority.

The example for complete implementation is furnished below.

ORABaseDataCollector dataCollector =
ORABaseDataCollector.getInstance();
dataCollector.addEventListener(new IORAEventListener() {
@Override
public ORAEventMap onEventFound(ORAEventMap object) {
object.put("custom", "my_name");
object.put("wt.sdk_v", "2.0");
return object;
}
}, "CoreTestModuleId", "CoreTestListener", groupArray, 3);

Remove or De-register observers

Once we register the observers, they will be triggered when ever the registered group of events are generated. Similarly we can de-register observers to avoid unnecessary triggers and mutation. To de-register observers, we need to invoke 'removeEventListener( String moduleId, String listenerName)' method on 'ORABaseDataCollector' object. The pragmatical example is shown below.

ORABaseDataCollector dataCollector = ORABaseDataCollector.getInstance();
dataCollector.removeEventListener("CoreTestModuleId", "CoreTestListener");

In above code, we have passed Listener name as parameter. Here the Listener name represents the identifier which we sent in dataCollector.addEventListener() method in above.