You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2009/02/20 23:36:41 UTC
svn commit: r746392 -
/activemq/sandbox/activemq-flow/src/main/java/org/apache/activemq/dispatch/TimerHeap.java
Author: chirino
Date: Fri Feb 20 22:36:41 2009
New Revision: 746392
URL: http://svn.apache.org/viewvc?rev=746392&view=rev
Log:
Applying colins patch https://issues.apache.org/activemq/browse/AMQ-2133
Modified:
activemq/sandbox/activemq-flow/src/main/java/org/apache/activemq/dispatch/TimerHeap.java
Modified: activemq/sandbox/activemq-flow/src/main/java/org/apache/activemq/dispatch/TimerHeap.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/src/main/java/org/apache/activemq/dispatch/TimerHeap.java?rev=746392&r1=746391&r2=746392&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/src/main/java/org/apache/activemq/dispatch/TimerHeap.java (original)
+++ activemq/sandbox/activemq-flow/src/main/java/org/apache/activemq/dispatch/TimerHeap.java Fri Feb 20 22:36:41 2009
@@ -5,11 +5,12 @@
import java.util.concurrent.TimeUnit;
public class TimerHeap {
- final TreeMap<Long, LinkedList<Runnable>> timers = new TreeMap<Long, LinkedList<Runnable>>();
-
+ private final TreeMap<Long, LinkedList<Runnable>> timers = new TreeMap<Long, LinkedList<Runnable>>();
+ private final TimeUnit resolution = TimeUnit.NANOSECONDS;
+
public final void add(Runnable runnable, long delay, TimeUnit timeUnit) {
- long nanoDelay = timeUnit.convert(delay, TimeUnit.NANOSECONDS);
+ long nanoDelay = resolution.convert(delay, timeUnit);
long eTime = System.nanoTime() + nanoDelay;
LinkedList<Runnable> list = new LinkedList<Runnable>();
list.add(runnable);
@@ -19,19 +20,18 @@
list.addAll(old);
}
}
-
+
/**
- * Returns the time of the next scheduled event.
- * @return -1 if there are no events, otherwise the time that the next timer should fire.
+ * Returns the time of the next scheduled event.
+ *
+ * @return -1 if there are no events, otherwise the time that the next timer
+ * should fire.
*/
- public final long timeToNext() {
- if(timers.isEmpty())
- {
+ public final long timeToNext(TimeUnit unit) {
+ if (timers.isEmpty()) {
return -1;
- }
- else
- {
- return Math.max(0, timers.firstKey() - System.nanoTime());
+ } else {
+ return unit.convert(Math.max(0, timers.firstKey() - System.nanoTime()), resolution);
}
}
@@ -50,7 +50,7 @@
}
ready = new LinkedList<Runnable>();
- while (first < now) {
+ while (first <= now) {
ready.addAll(timers.remove(first));
if (timers.isEmpty()) {
break;