/
Copycat.java
306 lines (274 loc) · 8.58 KB
/
Copycat.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.kuujo.copycat;
import net.kuujo.copycat.atomic.*;
import net.kuujo.copycat.cluster.Cluster;
import net.kuujo.copycat.cluster.ClusterConfig;
import net.kuujo.copycat.collections.*;
import net.kuujo.copycat.election.LeaderElection;
import net.kuujo.copycat.election.LeaderElectionConfig;
import net.kuujo.copycat.event.EventLog;
import net.kuujo.copycat.event.EventLogConfig;
import net.kuujo.copycat.internal.DefaultCopycat;
import net.kuujo.copycat.state.StateLog;
import net.kuujo.copycat.state.StateLogConfig;
import net.kuujo.copycat.state.StateMachine;
import net.kuujo.copycat.state.StateMachineConfig;
import net.kuujo.copycat.util.Managed;
/**
* Copycat.
*
* @author <a href="http://github.com/kuujo">Jordan Halterman</a>
*/
public interface Copycat extends Managed<Copycat> {
/**
* Creates a new Copycat instance with the default Copycat and cluster configuration.
*
* @return The Copycat instance.
*/
static Copycat create() {
return create(new CopycatConfig().withClusterConfig(new ClusterConfig()));
}
/**
* Creates a new Copycat instance, overriding the default cluster configuration.
*
* @param cluster The global cluster configuration.
* @return The Copycat instance.
*/
static Copycat create(ClusterConfig cluster) {
return create(new CopycatConfig().withClusterConfig(cluster));
}
/**
* Creates a new Copycat instance.
*
* @param config The global Copycat configuration.
* @return The Copycat instance.
*/
static Copycat create(CopycatConfig config) {
return new DefaultCopycat(config);
}
/**
* Returns the global Copycat configuration.
*
* @return The global Copycat configuration.
*/
CopycatConfig config();
/**
* Returns the core Copycat cluster.
*
* @return The core Copycat cluster.
*/
Cluster cluster();
/**
* Creates a new event log.
*
* @param name The name of the event log to create.
* @param <T> the event log entry type.
* @return The event log instance.
*/
<T> EventLog<T> eventLog(String name);
/**
* Creates a new event log.
*
* @param name The name of the event log to create.
* @param config The event log configuration.
* @param <T> The event log entry type.
* @return The event log instance.
*/
<T> EventLog<T> eventLog(String name, EventLogConfig config);
/**
* Creates a new state log.
*
* @param name The name of the state log to create.
* @param <T> The state log entry type.
* @return The state log instance.
*/
<T> StateLog<T> stateLog(String name);
/**
* Creates a new state log.
*
* @param name The name of the state log to create.
* @param config The state log configuration.
* @param <T> The state log entry type.
* @return The state log instance.
*/
<T> StateLog<T> stateLog(String name, StateLogConfig config);
/**
* Creates a new replicated state machine.
*
* @param name The name of the state machine to create.
* @param stateType The state machine state type.
* @param initialState The state machine's initial state.
* @param <T> The state machine state type.
* @return The state machine instance.
*/
<T> StateMachine<T> stateMachine(String name, Class<T> stateType, Class<? extends T> initialState);
/**
* Creates a new replicated state machine.
*
* @param name The name of the state machine to create.
* @param config The state machine configuration.
* @param <T> The state machine state type.
* @return The state machine instance.
*/
<T> StateMachine<T> stateMachine(String name, StateMachineConfig config);
/**
* Creates a new leader election.
*
* @param name The leader election name.
* @return The leader election instance.
*/
LeaderElection leaderElection(String name);
/**
* Creates a new leader election.
*
* @param name The leader election name.
* @param config The leader election configuration.
* @return The leader election instance.
*/
LeaderElection leaderElection(String name, LeaderElectionConfig config);
/**
* Creates a named asynchronous map.
*
* @param name The map name.
* @param <K> The map key type.
* @param <V> The map value type.
* @return The asynchronous map instance.
*/
<K, V> AsyncMap<K, V> map(String name);
/**
* Creates a named asynchronous map.
*
* @param name The map name.
* @param config The map configuration.
* @param <K> The map key type.
* @param <V> The map value type.
* @return The asynchronous map instance.
*/
<K, V> AsyncMap<K, V> map(String name, AsyncMapConfig config);
/**
* Creates a named asynchronous multimap.
*
* @param name The multimap name.
* @param <K> The map key type.
* @param <V> The map entry type.
* @return The asynchronous multimap instance.
*/
<K, V> AsyncMultiMap<K, V> multiMap(String name);
/**
* Creates a named asynchronous multimap.
*
* @param name The multimap name.
* @param config The multimap configuration.
* @param <K> The map key type.
* @param <V> The map entry type.
* @return The asynchronous multimap instance.
*/
<K, V> AsyncMultiMap<K, V> multiMap(String name, AsyncMultiMapConfig config);
/**
* Creates a named asynchronous list.
*
* @param name The list name.
* @param <T> The list entry type.
* @return The asynchronous list instance.
*/
<T> AsyncList<T> list(String name);
/**
* Creates a named asynchronous list.
*
* @param name The list name.
* @param config The list configuration.
* @param <T> The list entry type.
* @return The asynchronous list instance.
*/
<T> AsyncList<T> list(String name, AsyncListConfig config);
/**
* Creates a named asynchronous set.
*
* @param name The set name.
* @param <T> The set entry type.
* @return The asynchronous set instance.
*/
<T> AsyncSet<T> set(String name);
/**
* Creates a named asynchronous set.
*
* @param name The set name.
* @param config The set configuration.
* @param <T> The set entry type.
* @return The asynchronous set instance.
*/
<T> AsyncSet<T> set(String name, AsyncSetConfig config);
/**
* Creates a named asynchronous lock.
*
* @param name The lock name.
* @return The asynchronous lock instance.
*/
AsyncLock lock(String name);
/**
* Creates a named asynchronous lock.
*
* @param name The lock name.
* @param config The lock configuration.
* @return The asynchronous lock instance.
*/
AsyncLock lock(String name, AsyncLockConfig config);
/**
* Creates a named asynchronous atomic long value.
*
* @param name The atomic long name.
* @return The asynchronous atomic long instance.
*/
AsyncAtomicLong atomicLong(String name);
/**
* Creates a named asynchronous atomic long value.
*
* @param name The atomic long name.
* @param config The long configuration.
* @return The asynchronous atomic long instance.
*/
AsyncAtomicLong atomicLong(String name, AsyncAtomicLongConfig config);
/**
* Creates a named asynchronous atomic boolean value.
*
* @param name The atomic boolean name.
* @return The asynchronous atomic boolean instance.
*/
AsyncAtomicBoolean atomicBoolean(String name);
/**
* Creates a named asynchronous atomic boolean value.
*
* @param name The atomic boolean name.
* @param config The boolean configuration.
* @return The asynchronous atomic boolean instance.
*/
AsyncAtomicBoolean atomicBoolean(String name, AsyncAtomicBooleanConfig config);
/**
* Creates a named asynchronous atomic reference value.
*
* @param name The atomic reference name.
* @return The asynchronous atomic reference instance.
*/
<T> AsyncAtomicReference<T> atomicReference(String name);
/**
* Creates a named asynchronous atomic reference value.
*
* @param name The atomic reference name.
* @param config The reference configuration.
* @return The asynchronous atomic reference instance.
*/
<T> AsyncAtomicReference<T> atomicReference(String name, AsyncAtomicReferenceConfig config);
}