IdGenerator

The IdGenerator generates identifiers according to the generator type, and are created by the IdGeneratorFactory. Generated identifiers are always unique across the cluster, and are persisted across Rhapsody restarts.

Method Description

String getName()

Retrieves the name of the identifier.

IdGeneratorType getType()

Retrieves the identifier type.

long nextId()

Generates and returns the next identifier for this generator. The generated identifier is guaranteed to be unique across the cluster, and will be persisted correctly across Rhapsody restarts. However, the generated identifiers will not necessarily be in numerical order - the ordering is determined by the generator type.

Exceptions:

  • IdGeneratorException - if an error occurs allocating the next identifier. 

long getValue()

Retrieves the current value of this id generator without incrementing the value. This method is only provided for backwards compatibility for the JavaScript filter and its use is generally a bad idea. Instead, the nextId() method should be used.

void reset(long value)

Resets the next allocated identifier to the specified value. Note that this is not safe when generating identifiers with multiple threads or nodes simultaneously, and its use should be avoided.

Parameters:

  • value - the value to reset to.

Exceptions:

  • IdGeneratorException - if an error occurs allocating the next identifier. 

IdGeneratorFactory

The IdGeneratorFactory provides an id generation service.  It allows multiple id generators of different types to be created, and is responsible for generating identifiers uniquely across the cluster, and persisting them across restarts of Rhapsody.

Method Description

IdGenerator createIdGenerator(String name, IdGeneratorType type)

Creates an identifier generator with the specified type and name. If an id generator of the specified name and type already exists, then it is returned. Otherwise, a new ID generator (starting at 0) is created.

Set<IdGenerator> getIdGenerators()

Gets a set of identifier generator created by the identifier generator factor.

Save

Save