OpenDDS  Snapshot(2023/04/28-20:55)
Public Member Functions | Static Public Attributes | Private Attributes | List of all members
OpenDDS::DCPS::RepoIdGenerator Class Reference

Create RepoId values for use within DDS. More...

#include <RepoIdGenerator.h>

Public Member Functions

 RepoIdGenerator (long federation, long participant=0, EntityKind kind=KIND_PARTICIPANT)
 construct with at least a FederationId value. More...
 
virtual ~RepoIdGenerator ()
 
GUID_t next (bool builtin=false)
 Obtain the next GUID_t value. More...
 
void last (long key)
 

Static Public Attributes

static const unsigned int KeyBits = 24
 
static const unsigned int KeyMask = (1 << KeyBits) - 1
 

Private Attributes

EntityKind kind_
 Type of Entity to generate GUID values for. More...
 
long federation_
 Unique identifier for the repository. More...
 
long participant_
 Unique identifier for the DomainParticipant. More...
 
long lastKey_
 Unique value for the EntityKey. More...
 

Detailed Description

Create RepoId values for use within DDS.

Internal to the OpenDDS repository, the Repository Identifiers that uniquely identify all DDS Entities within the service managed by this (and other federated) repositories consist of GUID values.

These GUID (Global Unique IDentifiers) values are based on the RTPS specification (formal/08-04-09) GUID_t values. They use the same structure. The VendorId value is applied in the first 2 bytes of the prefix. The remainder of the Participant Id value is composed of the OpenDDS specific Federation Id value (the identifier of the repository where the Entity was created) and a DomainParticipant identifier within that repository. In addition to the standard EntityKind values, the EntityKind byte has an added value of ENTITYKIND_OPENDDS_TOPIC allowed to permit the use of GUID values for Topic entities as well. This is an OpenDDS specific extension.

The EntityKey field is used to distinguish Topics, Publications and Subscriptions within a single Participant. Each of these is within its own number (address) space. The EntityKind byte will ensure that identical EntityKey values of these different types will not conflict in the final GUID value.

Values are generated using the specified FederationId and DomainParticipant identifiers. The EntityKey for a type is incremented each time a value is generated.

The ability to reset the last used value is provided to allow the reloading of Entities from persistent storage without inducing conflicts with newly created Entities. This is a simplistic mechanism and requires that all information from the persistent storage be processed prior to any new Entities being created within the repository. After this processing is complete, the last used value should be reset to ensure that any new values will not conflict with the restored values.

NOTE: This mechanism does not work well for values that have wrapped around the 24 bit EntityKey space. It is possible to extend the current mapping to overflow into the two '0' bytes (2 and 3) with the Key value number (address) space to increase the possible unique identifiers if this becomes an issue. Doing that would alleviate the need to manage an arena of Key values.

Even though each Domain could have a separate GUID (address) space, since we do not currently include the domain value within the GUID mapping, all domains within a repository will use the same generator instance to ensure no conflicting GUID values. This will restrict the total number of DomainParticipants within all domains of a repository to be within the 32 bit (2**32) DomainParticipant address space. It is likely that other limits will be exceeded before this one is approached.

The current mapping of meanings to the GUID component values is:

Content: | VendorId| 0 | 0 | FederationId | DomainParticpant | EntityKey |Kind| GUID_t bytes: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | GuidPrefix_t GUID_t.guidPrefix bytes: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | EntityId_t GUID_t.entityId bytes: | 0 | 1 | 2 | 3 | EntityKey_t GUID_t.entityId.entityKey bytes: | 0 | 1 | 2 |

Where the VendorId value used for OpenDDS is defined in GuidUtils.h

Definition at line 92 of file RepoIdGenerator.h.

Constructor & Destructor Documentation

◆ RepoIdGenerator()

OpenDDS::DCPS::RepoIdGenerator::RepoIdGenerator ( long  federation,
long  participant = 0,
EntityKind  kind = KIND_PARTICIPANT 
)

construct with at least a FederationId value.

Parameters
federationidentifier for the repository.
participantidentifier for the participant.
kindtype of Entities to generate Id values for.
Returns
GUID_t generated unique identifier value.

If the kind is KIND_PARTICIPANT then the generator will generate Participant RepoId values. Otherwise it will generate the specified type of Entity values within the specified Participant.

Definition at line 22 of file RepoIdGenerator.cpp.

23  : kind_(kind)
24  , federation_(federation)
25  , participant_(participant)
26  , lastKey_(0)
27 {
28 }
long participant_
Unique identifier for the DomainParticipant.
long federation_
Unique identifier for the repository.
long lastKey_
Unique value for the EntityKey.
EntityKind kind_
Type of Entity to generate GUID values for.

◆ ~RepoIdGenerator()

OpenDDS::DCPS::RepoIdGenerator::~RepoIdGenerator ( )
virtual

Definition at line 30 of file RepoIdGenerator.cpp.

31 {
32 }

Member Function Documentation

◆ last()

void OpenDDS::DCPS::RepoIdGenerator::last ( long  key)

Set the minimum of the last key (or participant) value used.

Parameters
keythe smallest value that the last generated key can be

If the supplied key value is larger than the actual last generated key value, the new key value replaces the old one.

Definition at line 82 of file RepoIdGenerator.cpp.

References lastKey_, and OPENDDS_END_VERSIONED_NAMESPACE_DECL.

Referenced by DCPS_IR_Domain::last_participant_key(), DCPS_IR_Participant::last_publication_key(), DCPS_IR_Participant::last_subscription_key(), DCPS_IR_Participant::last_topic_key(), and TAO_DDS_DCPSInfo_i::receive_image().

83 {
84  if (key > lastKey_) {
85  lastKey_ = key;
86  }
87 }
sequence< octet > key
long lastKey_
Unique value for the EntityKey.

◆ next()

GUID_t OpenDDS::DCPS::RepoIdGenerator::next ( bool  builtin = false)

Obtain the next GUID_t value.

Definition at line 35 of file RepoIdGenerator.cpp.

References ACE_ERROR, ACE_TEXT(), OpenDDS::DCPS::GuidBuilder::entityId(), OpenDDS::DCPS::ENTITYID_PARTICIPANT, OpenDDS::DCPS::GuidBuilder::entityKey(), OpenDDS::DCPS::GuidBuilder::entityKind(), federation_, OpenDDS::DCPS::RepoIdBuilder::federationId(), KeyMask, kind_, OpenDDS::DCPS::KIND_PARTICIPANT, lastKey_, LM_ERROR, participant_, and OpenDDS::DCPS::RepoIdBuilder::participantId().

Referenced by DCPS_IR_Domain::get_next_participant_id(), DCPS_IR_Participant::get_next_publication_id(), DCPS_IR_Participant::get_next_subscription_id(), and DCPS_IR_Participant::get_next_topic_id().

36 {
37  // Generate a new key value.
38  ++lastKey_;
39 
40  RepoIdBuilder builder;
41  builder.federationId(federation_);
42 
43  // Generate a Participant GUID value.
44  if (kind_ == KIND_PARTICIPANT) {
45 
46  // Rudimentary validity checking.
47  if (lastKey_ == 0) {
48  // We have rolled over and there can now exist objects with
49  // the same key.
50  ACE_ERROR((LM_ERROR,
51  ACE_TEXT("(%P|%t) ERROR: RepoIdGenerator::next: ")
52  ACE_TEXT("Exceeded Maximum number of participant keys!")
53  ACE_TEXT("Next key will be a duplicate!\n")));
54  }
55 
56  builder.participantId(lastKey_);
57  builder.entityId(ENTITYID_PARTICIPANT);
58 
59  // Generate an Entity GUID value.
60 
61  } else {
62 
63  // Rudimentary validity checking.
64  if ((lastKey_ & ~KeyMask) != 0) {
65  // We have rolled over and there can now exist objects with
66  // the same key.
67  ACE_ERROR((LM_ERROR,
68  ACE_TEXT("(%P|%t) ERROR: RepoIdGenerator::next: ")
69  ACE_TEXT("Exceeded Maximum number of entity keys!")
70  ACE_TEXT("Next key will be a duplicate!\n")));
71  }
72 
73  builder.participantId(participant_);
74  builder.entityKey(lastKey_);
75  builder.entityKind(kind_, builtin);
76  }
77 
78  return GUID_t(builder);
79 }
long participant_
Unique identifier for the DomainParticipant.
#define ACE_ERROR(X)
ENTITYKIND_BUILTIN_PARTICIPANT.
Definition: GuidUtils.h:68
long federation_
Unique identifier for the repository.
const EntityId_t ENTITYID_PARTICIPANT
Definition: GuidUtils.h:37
static const unsigned int KeyMask
long lastKey_
Unique value for the EntityKey.
EntityKind kind_
Type of Entity to generate GUID values for.
ACE_TEXT("TCP_Factory")

Member Data Documentation

◆ federation_

long OpenDDS::DCPS::RepoIdGenerator::federation_
private

Unique identifier for the repository.

Definition at line 135 of file RepoIdGenerator.h.

Referenced by next().

◆ KeyBits

const unsigned int OpenDDS::DCPS::RepoIdGenerator::KeyBits = 24
static

Definition at line 94 of file RepoIdGenerator.h.

◆ KeyMask

const unsigned int OpenDDS::DCPS::RepoIdGenerator::KeyMask = (1 << KeyBits) - 1
static

Definition at line 96 of file RepoIdGenerator.h.

Referenced by next().

◆ kind_

EntityKind OpenDDS::DCPS::RepoIdGenerator::kind_
private

Type of Entity to generate GUID values for.

Definition at line 132 of file RepoIdGenerator.h.

Referenced by next().

◆ lastKey_

long OpenDDS::DCPS::RepoIdGenerator::lastKey_
private

Unique value for the EntityKey.

Definition at line 141 of file RepoIdGenerator.h.

Referenced by last(), and next().

◆ participant_

long OpenDDS::DCPS::RepoIdGenerator::participant_
private

Unique identifier for the DomainParticipant.

Definition at line 138 of file RepoIdGenerator.h.

Referenced by next().


The documentation for this class was generated from the following files: