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. | |
virtual | ~RepoIdGenerator () |
RepoId | next (bool builtin=false) |
Obtain the next RepoId value. | |
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. | |
long | federation_ |
Unique identifier for the repository. | |
long | participant_ |
Unique identifier for the DomainParticipant. | |
long | lastKey_ |
Unique value for the EntityKey. |
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.
OpenDDS::DCPS::RepoIdGenerator::RepoIdGenerator | ( | long | federation, | |
long | participant = 0 , |
|||
EntityKind | kind = KIND_PARTICIPANT | |||
) |
construct with at least a FederationId value.
federation | identifier for the repository. | |
participant | identifier for the participant. | |
kind | type of Entities to generate Id values for. |
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.
00023 : kind_(kind) 00024 , federation_(federation) 00025 , participant_(participant) 00026 , lastKey_(0) 00027 { 00028 }
OpenDDS::DCPS::RepoIdGenerator::~RepoIdGenerator | ( | ) | [virtual] |
Definition at line 30 of file RepoIdGenerator.cpp.
void OpenDDS::DCPS::RepoIdGenerator::last | ( | long | key | ) |
Set the minimum of the last key (or participant) value used.
key | the 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_.
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().
RepoId OpenDDS::DCPS::RepoIdGenerator::next | ( | bool | builtin = false |
) |
Obtain the next RepoId value.
Definition at line 35 of file RepoIdGenerator.cpp.
References 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().
00036 { 00037 // Generate a new key value. 00038 ++lastKey_; 00039 00040 RepoIdBuilder builder; 00041 builder.federationId(federation_); 00042 00043 // Generate a Participant GUID value. 00044 if (kind_ == KIND_PARTICIPANT) { 00045 00046 // Rudimentary validity checking. 00047 if (lastKey_ == 0) { 00048 // We have rolled over and there can now exist objects with 00049 // the same key. 00050 ACE_ERROR((LM_ERROR, 00051 ACE_TEXT("(%P|%t) ERROR: RepoIdGenerator::next: ") 00052 ACE_TEXT("Exceeded Maximum number of participant keys!") 00053 ACE_TEXT("Next key will be a duplicate!\n"))); 00054 } 00055 00056 builder.participantId(lastKey_); 00057 builder.entityId(ENTITYID_PARTICIPANT); 00058 00059 // Generate an Entity GUID value. 00060 00061 } else { 00062 00063 // Rudimentary validity checking. 00064 if ((lastKey_ & ~KeyMask) != 0) { 00065 // We have rolled over and there can now exist objects with 00066 // the same key. 00067 ACE_ERROR((LM_ERROR, 00068 ACE_TEXT("(%P|%t) ERROR: RepoIdGenerator::next: ") 00069 ACE_TEXT("Exceeded Maximum number of entity keys!") 00070 ACE_TEXT("Next key will be a duplicate!\n"))); 00071 } 00072 00073 builder.participantId(participant_); 00074 builder.entityKey(lastKey_); 00075 builder.entityKind(kind_, builtin); 00076 } 00077 00078 return RepoId(builder); 00079 }
long OpenDDS::DCPS::RepoIdGenerator::federation_ [private] |
Unique identifier for the repository.
Definition at line 135 of file RepoIdGenerator.h.
Referenced by next().
const unsigned int OpenDDS::DCPS::RepoIdGenerator::KeyBits = 24 [static] |
Definition at line 94 of file RepoIdGenerator.h.
const unsigned int OpenDDS::DCPS::RepoIdGenerator::KeyMask = (1 << KeyBits) - 1 [static] |
Definition at line 96 of file RepoIdGenerator.h.
Referenced by next().
Type of Entity to generate GUID values for.
Definition at line 132 of file RepoIdGenerator.h.
Referenced by next().
long OpenDDS::DCPS::RepoIdGenerator::lastKey_ [private] |
Unique value for the EntityKey.
Definition at line 141 of file RepoIdGenerator.h.
long OpenDDS::DCPS::RepoIdGenerator::participant_ [private] |
Unique identifier for the DomainParticipant.
Definition at line 138 of file RepoIdGenerator.h.
Referenced by next().