KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > stack > Interval


1 // $Id: Interval.java,v 1.1.1.1 2003/09/09 01:24:12 belaban Exp $
2

3 package org.jgroups.stack;
4
5
6 /**
7  * Manages retransmission timeouts. Always returns the next timeout, until the last timeout in the
8  * array is reached. Returns the last timeout from then on, until reset() is called.
9  * @author John Giorgiadis
10  * @author Bela Ban
11  */

12 public class Interval {
13     private int next=0;
14     private long[] interval=null;
15
16     public Interval(long[] interval) {
17     if (interval.length == 0)
18         throw new IllegalArgumentException JavaDoc("Interval()");
19     this.interval=interval;
20     }
21
22     public long first() { return interval[0]; }
23     
24     /** @return the next interval */
25     public synchronized long next() {
26     if (next >= interval.length)
27         return(interval[interval.length-1]);
28     else
29         return(interval[next++]);
30     }
31     
32     public long[] getInterval() { return interval; }
33
34     public synchronized void reset() { next = 0; }
35 }
36
37
Popular Tags