no.feide.moria.store
Class RandomId

java.lang.Object
  extended by no.feide.moria.store.RandomId

public final class RandomId
extends java.lang.Object

Returns an id that is random and unique across a cluster of JVMs. Each JVM needs to be configured with a unique node id, identifying each node. This is done by setting the system property no.feide.moria.store.nodeid. The value must be a ascii string of 3 character length. The returned id is an encoded String (pseudo Base64, see method documentation for details) constructed from the node id, the current time and a random string. This should guarantee unique ids across the cluster and node restarts.

Version:
$Revision: 1.11 $
Author:
Bjørn Ola Smievoll <b.o@smievoll.no>

Field Summary
private static byte[] CHAR_64
          The characters used in our version of base64.
private static int NO_OF_RANDOM_BITS
          The number of random bits to get from the PRNG.
private static java.security.SecureRandom random
          The random generator.
 
Constructor Summary
private RandomId()
          Default private constructor.
 
Method Summary
(package private) static byte[] longToByteArray(long in)
          Takes a long value (64 bit) and returns it as an eight element byte array.
static java.lang.String newId(java.lang.String nodeId)
          Generate a new random id.
(package private) static byte[] nodeIdToByteArray(java.lang.String nodeId)
           
(package private) static java.lang.String pseudoBase64Encode(byte[] bytes)
          Takes a byte array and returns a string encoded with a slightly modified version of Base64.
(package private) static byte[] unsignedShortToByteArray(int in)
          Takes an unsigned short value (16 bit, as an 32 bit int value) and returns it as an two element byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

random

private static java.security.SecureRandom random
The random generator.


CHAR_64

private static final byte[] CHAR_64
The characters used in our version of base64.


NO_OF_RANDOM_BITS

private static final int NO_OF_RANDOM_BITS
The number of random bits to get from the PRNG.

See Also:
Constant Field Values
Constructor Detail

RandomId

private RandomId()
Default private constructor.

Method Detail

newId

public static java.lang.String newId(java.lang.String nodeId)
Generate a new random id.

Returns:
an encoded random string

pseudoBase64Encode

static java.lang.String pseudoBase64Encode(byte[] bytes)
Takes a byte array and returns a string encoded with a slightly modified version of Base64. The difference to standard Base64 is that the extra two chars, "+" and "/" have been exchanged for the more url-friendly "-" and "*", and the resulting string is not padded with = as required by the spec (rfc 2045). Parts of code Copyright (c) 2003, Sverre H. Huseby <shh@thathost.com>

Parameters:
bytes - The data to convert.
Returns:
The encoded version of the input.

longToByteArray

static byte[] longToByteArray(long in)
Takes a long value (64 bit) and returns it as an eight element byte array.

Parameters:
in - The long value to be converted.
Returns:
A byte array representation of the long value given as input.

unsignedShortToByteArray

static byte[] unsignedShortToByteArray(int in)
Takes an unsigned short value (16 bit, as an 32 bit int value) and returns it as an two element byte array.

Parameters:
in - the unsigned short value to be converted.
Returns:
a byte array representation of the short value given as input

nodeIdToByteArray

static byte[] nodeIdToByteArray(java.lang.String nodeId)


Copyright © 2001-2006 UNINETT FAS. All Rights Reserved.