[jboss-cvs] JBoss Messaging SVN: r5051 - in trunk: tests/src/org/jboss/messaging/tests/unit/util and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Sep 30 12:50:21 EDT 2008
Author: clebert.suconic at jboss.com
Date: 2008-09-30 12:50:20 -0400 (Tue, 30 Sep 2008)
New Revision: 5051
Modified:
trunk/src/main/org/jboss/messaging/util/TimeAndCounterIDGenerator.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/TimeAndCounterIDGeneratorTest.java
Log:
ID Wrapping logic (throw an exception if the TimeIDGenerator capacity is overflowed)
Modified: trunk/src/main/org/jboss/messaging/util/TimeAndCounterIDGenerator.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/TimeAndCounterIDGenerator.java 2008-09-30 16:36:49 UTC (rev 5050)
+++ trunk/src/main/org/jboss/messaging/util/TimeAndCounterIDGenerator.java 2008-09-30 16:50:20 UTC (rev 5051)
@@ -52,6 +52,8 @@
private final AtomicLong counter = new AtomicLong(0);
+ private volatile boolean wrapped = false;
+
private volatile long tmMark;
// Static --------------------------------------------------------
@@ -73,18 +75,16 @@
if ((idReturn & ID_MASK) == ID_MASK)
{
- final long timePortion = (idReturn & TIME_ID_MASK);
-
+ final long timePortion = idReturn & TIME_ID_MASK;
+
// Wrapping ID logic
if (timePortion > newTM())
{
// Unlikely too happen
-
- // This will only happen if a computer can generate more than ID_MASK ids (268.43 million IDs per 250 milliseconds)
- // If this wrapping code starts to happen too often, it needs revision as we need to wait until the time component is updated
- throw new IllegalStateException("The IDGenerator is being overlaped, and it needs revision as the system generated more than " + (idReturn & ID_MASK) +
- " ids per 250 milliseconds which exceeded the IDgenerator limit");
+
+ wrapped = true;
+
}
else
{
@@ -95,6 +95,15 @@
}
}
+ if (wrapped)
+ {
+ // This will only happen if a computer can generate more than ID_MASK ids (268.43 million IDs per 250
+ // milliseconds)
+ // If this wrapping code starts to happen, it needs revision
+ throw new IllegalStateException("The IDGenerator is being overlaped, and it needs revision as the system generated more than " + (idReturn & ID_MASK) +
+ " ids per 250 milliseconds which exceeded the IDgenerator limit");
+ }
+
return idReturn;
}
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/util/TimeAndCounterIDGeneratorTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/util/TimeAndCounterIDGeneratorTest.java 2008-09-30 16:36:49 UTC (rev 5050)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/TimeAndCounterIDGeneratorTest.java 2008-09-30 16:50:20 UTC (rev 5051)
@@ -165,7 +165,7 @@
{
final ConcurrentHashSet<Long> hashSet = new ConcurrentHashSet<Long>();
- final TimeAndCounterIDGenerator seq = new TimeAndCounterIDGenerator();
+ TimeAndCounterIDGenerator seq = new TimeAndCounterIDGenerator();
System.out.println("Current Time = " + hex(System.currentTimeMillis()));
@@ -183,6 +183,7 @@
{
}
+ seq = new TimeAndCounterIDGenerator();
seq.setInternalDate(System.currentTimeMillis() - 10000l); // 10 seconds in the past
More information about the jboss-cvs-commits
mailing list