Process Communication Queue Guide Document
Process Communication Queue
The OracleCXMobileSDK includes components that helps to add, update or remove the event data dynamically when event is generated.
OracleCXMobileSDK includes the ability of acting as Observable which is nothing but it publish events when they generated. Observers will subscribe to Observable and will get notified when the event is generated. Every event that SDK generates has its own Group name. This Group name plays a vital role while subscribing and when they get notified back.
Oracle Core Mobile SDK provides an interface ORAEventListener
which gives an ability to Observe and subscribe with Observables. These Observers override onEventFound
method where the add, update or deleting of data will be carried out.
Process Communication Queue Implementation
-
OracleCXMobileSDK includes the ability of acting as Observable and provides an interface
ORAEventListener
which gives an ability to Observe. -
OracleCXMobileSDK provides
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 16.
Time Delay is milliseconds. This is a waiting time for getting response from observer. We get more about them while we discuss implementation. The implementation steps are furnished below.
Add or Register observers
- Initially add event listeners i.e observers by invoking
addEventListener
method. This method is located inORACoreDataCollector
class. So the method calling looks like below:
ModuleListener *moduleListener = [[ModuleListener alloc] init];
[[ORACoreDataCollector sharedCollector] addEventListener: moduleListener
withName:@"ModuleListener"
withEventGroup:@[ORA_EG_INTERACTION, ORA_EG_SCREEN, ORA_EG_CUSTOM]
andPriority:1];
let moduleListener = ModuleListener()
ORACoreDataCollector.shared().addEventListener(moduleListener, withName: "ModuleListener", withEventGroup: [ORA_EG_INTERACTION, ORA_EG_SCREEN, ORA_EG_CUSTOM], andPriority: 1)
- In the above code,
ModuleListener
is the subclass of interfaceORAEventListener
where the methodonEventFound
will be overridden and resultant actions will be carried out. This method accepts one parameter i.eNSDictionary
which is a generated event and returns updated event object.
The example implementation is shown below:
- (void)onEventFound:(NSDictionary *)event
withCompletion:(void (^)(NSDictionary * _Nonnull))completion {
NSMutableDictionary *newEvent = [[NSMutableDictionary alloc] initWithDictionary:event];
[newEvent setValue:@"MODULE LISTENER ADDED EVENT" forKey:@"moduleListner"];
completion(newEvent);
}
func onEventFound(_ event: [AnyHashable : Any]?, withCompletion completion: @escaping ([AnyHashable : Any]) -> Void) {
var newEvent = event
newEvent["moduleListner"] = "MODULE ADDED EVENT"
completion(newEvent)
}
-
For every listener we register, we must name it for identification. This plays a vital role while de-registering the observer. We have to send a name string in
addEventListener()
method. Listener name must be alpha numeric only. -
Every event generated belongs to some category. This category is called as 'Group'. While subscribing to observable, we register to listen the events of which belong to some group, not for a single event. So, we need to pass a valid group name as parameter in the
addEventListener()
method. The valid group names for Core SDK events are listed inORAEventGroup
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
NSArray *group = @[ORA_EG_INTERACTION];
let group = [ORA_EG_INTERACTION]
Multiple Group names
NSArray *group = @[ORA_EG_INTERACTION, ORA_EG_SCREEN, ORA_EG_CUSTOM];
let group = [ORA_EG_INTERACTION, ORA_EG_SCREEN, ORA_EG_CUSTOM]
Subscribing for all groups
NSArray *group = @[ORA_EG_TYPE_ALL];
let group = [ORA_EG_TYPE_ALL]
We can subscribe all groups at a time with 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 is the highest priority and 16 is the lowest priority.
Time Delay and its Configuration
- Another very important configuration is Time Delay. Time Delay is the waiting time for updating the event and return back. For example, event is generated and observer has invoked. If we want to update event with the data from HTTP call, observer callback should wait sometime to complete the HTTP call and update the data depending on the response. But sometimes it becomes messy as HTTP call may not respond depending on the network connectivity.
To overcome these issues, we have provided a configuration in classORAConfigProcessQueueTimeInterval
to configure a particular number of milliseconds. Call back will wait until this time delay. If event returns in this time delay, then process move forward. If time delay exceeds, the old event object it self get returned automatically.
- This configuration is not mandatory to set. Its default value is 4000 milliseconds. So if we do not set any valid time, it takes a default one.
The example to set ORAConfigProcessQueueTimeInterval
configuration is given below:
ORACoreDataContainer *container = [[ORACoreDataContainer alloc]init];
ORAConfigProcessQueueTimeInterval *settingtimeinterval = [[ORAConfigProcessQueueTimeInterval alloc]init];
[container putValue:@"4000" forKey: settingtimeinterval];
var container = ORACoreDataContainer()
var settingtimeinterval = ORAConfigProcessQueueTimeInterval()
container.putValue("4000", forKey: setting)
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:
[[ORACoreDataCollector sharedCollector] removeEventListener:@"moduleListner"];
ORACoreDataCollector.shared().remove(listener: "moduleListner")