ca.uhn.hl7v2.util
Class MessageIDGenerator

java.lang.Object
  extended by ca.uhn.hl7v2.util.MessageIDGenerator

public class MessageIDGenerator
extends Object

Creates unique message IDs. IDs are stored in a file called hapi.home/id_file for persistence across JVM sessions. Note that if one day you run the JVM with a new working directory, you must move or copy id_file into this directory so that new ID numbers will begin with the last one used, rather than starting over again.

Note that as of HAPI 2.0, by default this class will not fail even if the id_file can not be read/written. In this case, HAPI will try to fail gracefully by simply generating a numeric sequence starting at zero. This behaviour can be overwritten using NEVER_FAIL_PROPERTY

Author:
Neal Acharya

Field Summary
static String DEFAULT_ID_FILE
          Contains the complete path to the default ID file, which is a plain text file containing the number corresponding to the last generated ID
static String NEVER_FAIL_PROPERTY
          System property key which indicates that this class should never fail.
 
Method Summary
static MessageIDGenerator getInstance()
          Synchronized method used to return the single (static) instance of the class
 String getNewID()
          Synchronized method used to return the incremented id value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ID_FILE

public static final String DEFAULT_ID_FILE
Contains the complete path to the default ID file, which is a plain text file containing the number corresponding to the last generated ID


NEVER_FAIL_PROPERTY

public static final String NEVER_FAIL_PROPERTY
System property key which indicates that this class should never fail. If this system property is set to false (default is true), as in the following code:
System.setProperty(MessageIDGenerator.NEVER_FAIL_PROPERTY, Boolean.FALSE.toString());
this class will fail if the underlying disk file can not be read or written. This means you are roughly guaranteed a unique ID number between JVM sessions (barring the file getting lost or corrupted).

Method Detail

getInstance

public static MessageIDGenerator getInstance()
                                      throws IOException
Synchronized method used to return the single (static) instance of the class

Throws:
IOException

getNewID

public String getNewID()
                throws IOException
Synchronized method used to return the incremented id value

Throws:
IOException


Copyright © 2001-2012 University Health Network. All Rights Reserved.