synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asan...@apache.org
Subject svn commit: r535635 - /webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/UUIDGenerator.java
Date Sun, 06 May 2007 16:37:54 GMT
Author: asankha
Date: Sun May  6 09:37:48 2007
New Revision: 535635

URL: http://svn.apache.org/viewvc?view=rev&rev=535635
Log:
minor improvement to check if System.nanoTime() could be used to only once

Modified:
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/UUIDGenerator.java

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/UUIDGenerator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/UUIDGenerator.java?view=diff&rev=535635&r1=535634&r2=535635
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/UUIDGenerator.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/UUIDGenerator.java
Sun May  6 09:37:48 2007
@@ -35,6 +35,7 @@
     private static long incrementingValue = 0;
 
     private static Random myRand = null;
+    private static boolean useNano = false;
 
     /**
      * MD5 a random string with localhost/date etc will return 128 bits construct a string
of 18
@@ -50,20 +51,26 @@
         if (++incrementingValue >= Long.MAX_VALUE) {
             incrementingValue = 0;
         }
-        
-        try {
-            if (System.class.getMethod("nanoTime", new Class[0]) != null) {
-                return baseUUID + (System.nanoTime() + incrementingValue) +
-                    Integer.toString(myRand.nextInt());
-            }
-        } catch (NoSuchMethodException ignore) {}
 
-        return baseUUID + (System.currentTimeMillis() + incrementingValue +
-            Integer.toString(myRand.nextInt()));
+        if (useNano) {
+            return baseUUID + (System.nanoTime() + incrementingValue) +
+                Integer.toString(myRand.nextInt());
+        } else {
+
+            return baseUUID + (System.currentTimeMillis() + incrementingValue +
+                Integer.toString(myRand.nextInt()));
+        }
 
     }
 
     protected static String getInitialUUID() {
+
+        try {
+            if (System.class.getMethod("nanoTime", new Class[0]) != null) {
+                useNano = true;
+            }
+        } catch (NoSuchMethodException ignore) {}
+
         if (myRand == null) {
             myRand = new Random();
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org


Mime
View raw message