From: <lk...@us...> - 2005-03-28 05:55:48
|
Update of /cvsroot/openorb/TransactionService/src/main/org/openorb/ots/Impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16358/src/main/org/openorb/ots/Impl Modified Files: XID.java Log Message: Fixed a potential bug in generation of unique XIDs, it allowed to generate the same id within the same millisecond. Index: XID.java =================================================================== RCS file: /cvsroot/openorb/TransactionService/src/main/org/openorb/ots/Impl/XID.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- XID.java 13 Dec 2004 10:39:59 -0000 1.11 +++ XID.java 28 Mar 2005 05:55:39 -0000 1.12 @@ -15,6 +15,10 @@ */ public class XID { + /** sequence id, used for generating unique ids. */ + private static int s_seqId = 0; + + /** Cache for the host address. */ private static String s_hostAddress = null; static @@ -173,13 +177,20 @@ */ private byte [] generate_id() { + // TODO: investigate java.util.UUID (introduced in JDK 1.5) + // should have much better performance and generate shorter byte arrays + synchronized ( XID.class ) { // First, we include the Time String id = "[" + System.currentTimeMillis() + "]"; + // add a sequence id to avoid generating the same UID within the same msec + // note that we need to sync access to s_seqId to avoid using the same id twice + id = id + ( s_seqId++ ); + // Now, we get OpenORB information about IP Address - id = id + getServerHostAddress(); + id = id + '@' + getServerHostAddress(); return id.getBytes(); } |