KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > rmi > server > UIDGenerator


1 package org.sapia.ubik.rmi.server;
2
3
4 /**
5  * A generator of unique longs for this VM.
6  *
7  * @author Yanick Duchesne
8  *
9  * <dl>
10  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2004 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
11  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
12  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
13  * </dl>
14  */

15 public class UIDGenerator {
16   private static long _uid = System.currentTimeMillis();
17   private static short _offset;
18
19   /**
20    * @return a unique long for this VM.
21    */

22   public synchronized static long createdUID() {
23     long uid = _uid + (_offset++);
24
25     if (uid < 0 || _offset < 0) {
26       _uid = System.currentTimeMillis();
27       _offset = 0;
28       uid = _uid + (_offset++);
29     }
30     return uid;
31   }
32 }
33
Popular Tags