KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > util > sequence > ObjectIDSequenceProvider


1 /**
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tc.util.sequence;
6
7 public class ObjectIDSequenceProvider implements ObjectIDSequence {
8
9   private long current;
10
11   public ObjectIDSequenceProvider(long start) {
12     this.current = start;
13   }
14
15   public synchronized long nextObjectIDBatch(int batchSize) {
16     final long start = current;
17     current += batchSize;
18     return start;
19   }
20
21   public void setNextAvailableObjectID(long startID) {
22     if (current > startID) { throw new AssertionError JavaDoc("Current value + " + current + " is greater than " + startID); }
23     current = startID;
24   }
25
26 }
27
Popular Tags