01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.objectserver.persistence.impl;
06:
07: import com.tc.util.Assert;
08: import com.tc.util.UUID;
09: import com.tc.util.sequence.MutableSequence;
10:
11: public class InMemorySequenceProvider implements MutableSequence {
12:
13: private final String uid = UUID.getUUID().toString();
14: private long nextID = 0;
15:
16: public synchronized String getUID() {
17: return uid;
18: }
19:
20: public synchronized long next() {
21: return nextID++;
22: }
23:
24: public synchronized long current() {
25: return nextID - 1;
26: }
27:
28: public synchronized long nextBatch(int batchSize) {
29: long lid = nextID;
30: nextID += batchSize;
31: return lid;
32: }
33:
34: public synchronized void setNext(long next) {
35: Assert.assertTrue(nextID <= next);
36: nextID = next;
37: }
38:
39: }
|