KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > persistence > impl > InMemorySequenceProvider


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

5 package com.tc.objectserver.persistence.impl;
6
7 import com.tc.objectserver.persistence.api.PersistentSequence;
8 import com.tc.util.Assert;
9 import com.tc.util.UUID;
10
11 public class InMemorySequenceProvider implements PersistentSequence {
12
13   private final String JavaDoc uid = UUID.getUUID().toString();
14   private long id = 0;
15
16   public synchronized String JavaDoc getUID() {
17     return uid;
18   }
19
20   public synchronized long next() {
21     return id++;
22   }
23
24   public synchronized long nextBatch(int batchSize) {
25     long lid = id;
26     id += batchSize;
27     return lid;
28   }
29
30   public synchronized void setNext(long next) {
31     Assert.assertTrue(id <= next);
32     id = next;
33   }
34
35 }
36
Popular Tags