#include <RepoIdGenerator.h>
Public Member Functions | |
RepoIdGenerator (long federation, long participant=0, OpenDDS::DCPS::EntityKind kind=OpenDDS::DCPS::KIND_PARTICIPANT) | |
construct with at least a FederationId value. | |
virtual | ~RepoIdGenerator () |
Virtual destructor. | |
OpenDDS::DCPS::RepoId | next () |
Obtain the next RepoId value. | |
void | last (long key) |
Static Public Attributes | |
static const unsigned | KeyBits = 24 |
static const unsigned | KeyMask = (1 << KeyBits) - 1 |
Private Attributes | |
OpenDDS::DCPS::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. |
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 88 of file RepoIdGenerator.h.
RepoIdGenerator::RepoIdGenerator | ( | long | federation, | |
long | participant = 0 , |
|||
OpenDDS::DCPS::EntityKind | kind = OpenDDS::DCPS::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. |
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 18 of file RepoIdGenerator.cpp.
00021 : kind_(kind), 00022 federation_(federation), 00023 participant_(participant), 00024 lastKey_(0) 00025 { 00026 }
RepoIdGenerator::~RepoIdGenerator | ( | ) | [virtual] |
void 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 |
key
value is larger than the actual last generated key value, the new key value replaces the old one.
Definition at line 80 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().
00081 { 00082 if (key > this->lastKey_) { 00083 this->lastKey_ = key; 00084 } 00085 }
OpenDDS::DCPS::RepoId RepoIdGenerator::next | ( | ) |
Obtain the next RepoId value.
Definition at line 33 of file RepoIdGenerator.cpp.
References 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_, 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().
00034 { 00035 // Generate a new key value. 00036 ++this->lastKey_; 00037 00038 OpenDDS::DCPS::RepoIdBuilder builder; 00039 builder.federationId(federation_); 00040 00041 // Generate a Participant GUID value. 00042 if (this->kind_ == OpenDDS::DCPS::KIND_PARTICIPANT) { 00043 00044 // Rudimentary validity checking. 00045 if (this->lastKey_ == 0) { 00046 // We have rolled over and there can now exist objects with 00047 // the same key. 00048 ACE_ERROR((LM_ERROR, 00049 ACE_TEXT("(%P|%t) ERROR: RepoIdGenerator::next: ") 00050 ACE_TEXT("Exceeded Maximum number of participant keys!") 00051 ACE_TEXT("Next key will be a duplicate!\n"))); 00052 } 00053 00054 builder.participantId(lastKey_); 00055 builder.entityId(OpenDDS::DCPS::ENTITYID_PARTICIPANT); 00056 00057 // Generate an Entity GUID value. 00058 00059 } else { 00060 00061 // Rudimentary validity checking. 00062 if ((this->lastKey_ & ~KeyMask) != 0) { 00063 // We have rolled over and there can now exist objects with 00064 // the same key. 00065 ACE_ERROR((LM_ERROR, 00066 ACE_TEXT("(%P|%t) ERROR: RepoIdGenerator::next: ") 00067 ACE_TEXT("Exceeded Maximum number of entity keys!") 00068 ACE_TEXT("Next key will be a duplicate!\n"))); 00069 } 00070 00071 builder.participantId(participant_); 00072 builder.entityKey(lastKey_); 00073 builder.entityKind(kind_); 00074 } 00075 00076 return OpenDDS::DCPS::RepoId(builder); 00077 }
long RepoIdGenerator::federation_ [private] |
Unique identifier for the repository.
Definition at line 132 of file RepoIdGenerator.h.
Referenced by next().
const unsigned RepoIdGenerator::KeyBits = 24 [static] |
Definition at line 90 of file RepoIdGenerator.h.
const unsigned RepoIdGenerator::KeyMask = (1 << KeyBits) - 1 [static] |
Type of Entity to generate GUID values for.
Definition at line 129 of file RepoIdGenerator.h.
Referenced by next().
long RepoIdGenerator::lastKey_ [private] |
long RepoIdGenerator::participant_ [private] |
Unique identifier for the DomainParticipant.
Definition at line 135 of file RepoIdGenerator.h.
Referenced by next().