1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.anyflow.lannister.cluster;
17
18 import com.hazelcast.core.IdGenerator;
19
20 public class SingleIdGenerator implements IdGenerator {
21
22 private final String name;
23 private long id;
24
25 public SingleIdGenerator(String name) {
26 this.name = name;
27 }
28
29 @Override
30 public String getName() {
31 return name;
32 }
33
34 @Override
35 public void destroy() {
36
37 }
38
39 @Override
40 public boolean init(long id) {
41 if (id < 0) { return false; }
42
43 this.id = id;
44 return true;
45 }
46
47 @Override
48 public long newId() {
49 return ++id;
50 }
51
52 @Override
53 public String getPartitionKey() {
54 throw new Error("The method should not be called");
55 }
56
57 @Override
58 public String getServiceName() {
59 throw new Error("The method should not be called");
60 }
61 }