Class GenerateUniqueId


  • public class GenerateUniqueId
    extends Object
    This class generates a unique 10+ character id. This is good for authenticating users or tracking users around.

    This code was borrowed from Apache JServ.JServServletManager.java. It is what Apache JServ uses to generate session ids for users. Unfortunately, it was not included in Apache JServ as a class, so I had to create one here in order to use it.

    Version:
    $Id$
    Author:
    Jon S. Stevens, Neeme Praks
    • Field Detail

      • maxRandomLen

        public static final long maxRandomLen
        We want to have a random string with a length of 6 characters. Since we encode it BASE 36, we've to modulo it with the following value:
        See Also:
        Constant Field Values
      • maxSessionLifespanTics

        public static final long maxSessionLifespanTics
        The session identifier must be unique within the typical lifespan of a Session; the value can roll over after that. 3 characters: (this means a roll over after over a day, which is much larger than a typical lifespan)
        See Also:
        Constant Field Values
      • ticDifference

        public static final long ticDifference
        Millisecons between different tics. So this means that the 3-character time string has a new value every 2 seconds:
        See Also:
        Constant Field Values
    • Method Detail

      • getIdentifier

        public static String getIdentifier()
        Get the unique id.

        NOTE: This must work together with get_jserv_session_balance() in jserv_balance.c

        Returns:
        A String with the new unique id.
      • getIdentifier

        public String getIdentifier​(String jsIdent)
        Get the unique id.
        Parameters:
        jsIdent - A String.
        Returns:
        A String with the new unique id.
      • main

        public static void main​(String[] args)
        Simple test of the functionality.
        Parameters:
        args - A String[] with the command line arguments.