Unique ID Service

The UniqueId Service is an identifier generator that provides access to Turbine instance specific ID's in several different formats.

Configuration

# -------------------------------------------------------------------
#
#  S E R V I C E S
#
# -------------------------------------------------------------------
# Classes for Turbine Services should be defined here.
# Format: services.[name].classname=[implementing class]
#
# To specify properties of a service use the following syntax:
# service.[name].[property]=[value]

services.UniqueIdService.classname=org.apache.turbine.services.uniqueid.TurbineUniqueIdService
.
.
.

Usage

The Facade class, TurbineUniqueId, exposes three methods that produce unique identifiers:

  • getInstanceId() returns an identifier for this Turbine instance that is unique both on the server and worldwide.
  • getPseudorandomId() returns a unique identifier that looks like random data.
  • getUniqueId() returns an identifier that is unique within this instance but does not have random-like appearance.
  • As an example of the output for these Id's, the following is a screen:

     public class IdExample extends VelocityScreen
     {
    
    
        public void doBuildTemplate(RunData data , Context context)
            throws Exception
        {
    
            context.put("instanceid", TurbineUniqueId.getInstanceId());
            context.put("pseudorandomid", TurbineUniqueId.getPseudorandomId());
            context.put("uniqueid", TurbineUniqueId.getUniqueId());
    
            super.doBuildTemplate(data,context);
    
    
        }
     }
    

    With the Velocity template IdExample.vm being:

    
     InstanceId() Output example  = $instanceid
    
     <br />
    
     PseudorandomId() Output example  = $pseudorandom
    
     <br />
    
     UniqueId() Output example  = $uniqueid
    
    

    The output is:

    
     InstanceId() Output example  = EC77218EC1291E714260FDF04BCB5008
     PseudorandomId() Output example  = otzhj954w1
     UniqueId() Output example  = 00000000
    
    

    Internally Turbine uses the service for naming of temporary files stored on the server as part of the Upload Service. The FileItem is named with the getInstanceId() method to avoid temporary file clashes until the system retrieves the file.