CERN -> IPT Group -> FrameMaker at CERN
Information Service User's Guide

5.4 Subscription modes

IS API provides two modes for subscribing to the IS repository. Examples from the previous sections use the default mode in which subscribing application will get the whole information object as part of the notification message. Sometime this introduces an unnecessary overhead since some subscribers may just need to be aware that the information is been changed in the IS repository, but they might not need to read the information value at that moment. For such applications there is a way of telling to the IS that it should not pass the information value as part of the notification message.


Developers, which use to subscribe to the IS repository, should always consider using the notification only mode of the subscription, because this may dramatically reduce the network traffic in the cases where information value is not always necessary.

The notification only mode can be chosen by providing a different callback function as the last parameter of the ISInfoReceiver.subscribe call. "Listing 5.3" shows how an application can do that.

 

Listing 5.3   Subscribe using different subscription modes

1: // include main IS header file
2: #include <Person.h>
3: #include <is/inforeceiver.h>
4: #include <ipc/core.h>
5:
6: // This callback will always get the whole info
7: void info_callback(ISCallbackInfo * isc){
8: std::cout << "INFO CALLBACK:: " << isc->name() << std::endl;
9: std::cout << "Reason code : " << isc->reason() << std::endl;
10:
11: ISInfoAny isi;
12: isc->value(isa);
13: std::cout << isa;
14: }
15:
16: // This callback will always get just the notification
17: // In order to read the the information value one must
18: // use the ISInfoDictionary::getValue function
19: void event_callback(ISCallbackEvent * isc){
20: std::cout << "EVENT CALLBACK:: " << isc->name() << std::endl;
21: std::cout << "Reason code : " << isc->reason() << std::endl;
22: }
23:
24: int main( int ac, char ** av ){
25: // Initialise communication library
26: IPCCore::init( ac, av );
27:
28: // Create the instance of partition
29: IPCPartition partition("MyPartition");
30:
31: // Create the IS receiver instance the specific partitition
32: ISInfoReceiver rec(partitition);
33:
34: // Subscribe for all - infomation values will not be transferred
35: rec.subscribe( "MyServer", ".*", event_callback );
36:
37: // Subscribe for all objects of type Person
38: // information values will be transferred for every callback
39: rec.subscribe( "MyServer", Person::type(), info_callback );
40:
41: // call method run to block the current thread until
42: // somebody will call the stop for the rec object
43: rec.run();
44:
45: // Remove subscription
46: rec.unsubscribe( "MyServer", ".*" );
47:
48: return 0;
49: }

 


2 July 1998 - WebMaster
Copyright © CERN 1998