View Javadoc
1   /*
2    * Copyright 2016 The Lannister Project
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  		// DO NOTHING
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  }