Global ID Generator

Search Solutions & Best Practices
Searching Solutions and Best Practices
Browse Solutions & Best Practices

                                                              

Summary: Unique Global ID Generator
Author: Shay Hassidim, Deputy CTO, GigaSpaces
Recently tested with GigaSpaces version: XAP 7.1
Last Update: Jan 2011
Your Rating: Results: PatheticBadOKGoodOutstanding! 14 rates

Overview

When writing objects into the space, you may need to generate a global unique ID for your space objects. The ID will be used later to fetch the object based on its ID via the readById/readByIds methods, or associate it with another object by placing the object ID as a field value within another object.

GigaSpaces generates a unique global ID when writing new objects using its built-in internal ID generator utility used when enabling the auto-generate ID property. Still, you may want to have your own custom global unique ID generator.

You can download the custom Unique Global ID Generator source code used with this example.

The following example includes a custom global unique ID generator PU and a client side utility. The Unique Global ID Generator features the following:

  • Spring based configured.
  • Store the last generated ID within a space object (IdCounterEntry).
  • Provides range of IDs to a client application. This avoids the need to perform read and update space operations with each generated ID.
  • Provides a numeric ID.
  • Support persisting the IdCounterEntry object within a database. This allows the IdCounterEntry object to be loaded from a database in case the Unique Global ID Generator PU is fully re-started.
  • Once a Unique Global ID Generator is deployed, a IdObjectInitializer is created and generates the IdCounterEntry object within the Unique Global ID Generator space. Only one IdCounterEntry will be created.

Using the ID Generator

To use the ID Generator you should:
1. Deploy the ID Generator PU using the pu.xml below. You should deploy it using one partition and a backup.
2. With your application, inject a SpaceBasedIdGenerator Bean. You should have it with every application instance.
3. With your client application call the following when you need a unique global ID:

SpaceBasedIdGenerator idGenerator;
Integer myNextID = idGenerator.generateId();
The SpaceBasedIdGenerator using Spring Transactions to update the IdCounterEntry object.

The ID Generator Components

The following should be used to enable the ID Generator:

Rate this page:
Your Rating: Results: PatheticBadOKGoodOutstanding! 14 rates

Additional resources: XAP Application Server | XAP Data Grid | XAP for Cloud Computing | XAP J2EE Support

Labels

 
(None)