The Name Service
The Name Service allows users to associate a string with a piece of arbitrary data (often a Handle). Both cluster-wide, node-wide, and process-only data can be associated with the name. This allows name service users to also associate shared memory pointers and local pointers to a particular name. For example, these pointers could reference objects which represent the local instantiation of an entity.
All SAFplus API calls that accept a string name use the Name Service to resolve the string into the actual Handle or object. Since components and services accept a strings in their "create" APIs, it is possible that the end user will never explicitly use the Name Service yet it be heavily utilized.
The name service can also be used independently of other SAFplus APIs by user applications. In this case, its use is a cluster wide name:value dictionary. For example, a handle to the "Active" server application could be stored under a name so that clients can discover which server is active easily.
Implementation
The Name Service is a client library that is linked with every component that uses it. It opens a cluster-wide, shared memory, non-persistent checkpoint using the name service's well-known Handle.
The name service uses this checkpoint to resolve string names into objects.
Header
#include <clNameApi.hxx>
APIs
1 class NameException: public std::exception
2 {
3 ...
4 };
5
6 class NameRegistrar
7 {
8 public:
9
10 typedef enum {
11 MODE_REDUNDANCY,
12 MODE_ROUND_ROBIN,
13 MODE_PREFER_LOCAL/* return a handle that points to this process (if it exists)
14 if it does not exist return a handle that points to this NODE.
15 if that does not exist, return any handle
16 So choose "closer" handles over ones that are far away
17 this mode makes communications more efficient
18 */
19 MODE_NO_CHANGE, /* This is not a mode; it tells the API to not change the existing mode (or use MODE_REDUNDANCY if creating) */
20
21 } MappingMode;
22 /* For more convenience and logical, should move mapping mode setting to set functions
23 For more clearance on this parameter, see the comments of the functions
24 */
25 //void setMode(const char* name, MappingMode m);
26
27
28 /* Associate a name with a handle and pointer and associate a handle with a pointer.
29 If the name does not exist, it is created. If it exists, it is overwritten.
30 If the handle format contains a node or process designator, then this mapping will be removed when the node/process fails.
31
32 the void* object pointer is local to this process; it does not need to be part of the checkpoint.
33
34 This association is valid for all SAFplus API name lookups, and for AMF entity names.
35 The mapping mode parameter is mandatory and specifies what the mapping mode is, based on it, the get functions retrieves appropriate handles
36 */
37 void set(const char* name, SAFplus::Handle handle, MappingMode m, void* object=NULL);
38 void set(const std::string& name, SAFplus::Handle handle, MappingMode m, void* object=NULL);
39
40
41 /* Associate a name with a handle and pointer and associate a handle with a pointer (if object != NULL).
42 If the name does not exist, it is created. If the name exists, this mapping is appended (the original mapping is not removed).
43 If there are multiple associations, the first association will always be returned.
44 If the handle format contains a node or process designator, then this mapping will be removed when the node/process fails.
45 If the name has more than one mapping another mapping will become the default response for this name.
46
47 This association is valid for all SAFplus API name lookups, and for AMF entity names.
48 The mapping mode parameter is mandatory and specifies what the mapping mode is, based on it, the get functions look up appropriate handle: if it's different from MappingMode::MODE_NO_CHANGE, the mapping mode that was set for this name before will be replaced with it, otherwise (omitted), the mapping mode that was set for this name before will be kept as it was (no change)
49 */
50 void append(const char* name, SAFplus::Handle handle, MappingMode m, void* object=NULL);
51 void append(const std::string& name, SAFplus::Handle handle, MappingMode m, void* object=NULL);
52 // Associate name with arbitrary data. A copy of the data is made.
53 void set(const char* name, const void* data, int length);
54 void set(const std::string& name, const void* data, int length);
55
56 // Associate name with arbitrary data. A copy of the data is NOT made; this call transfers the reference count (ownership) to the callee.
57 void set(const char* name, SAFplus::Buffer*);
58 void set(const std::string& name, SAFplus::Buffer*);
59
60 // Get a handle associated with the data
61 // The SAFplus APIs use these calls to resolve names to handles or objects.
62 std::pair<SAFplus::Handle&,void* object> get(const char* name) throws(NameException&);
63 std::pair<SAFplus::Handle&,void* object> get(const std::string& name) throws(NameException&);
64
65 SAFplus::Handle& get(const char* name) throws(NameException&);
66 SAFplus::Handle& get(const std::string& name) throws(NameException&);
67
68 // Get object based on handle
69 void* get(const SAFplus::Handle&) throws(NameException&);
70
71
72 // Get a handle associated with the data
73 // The SAFplus APIs use these calls to resolve names to handles or objects.
74 // Do not free the returned buffer, call Buffer.decRef();
75 SAFplus::Buffer& get(const char* name) throws(NameException&);
76 SAFplus::Buffer& get(const std::string& name) throws(NameException&);
77
78
79 };
80
81 // Name is a singleton class; only one per process.
82 extern NameRegistrar name;