/
QueryCacheConfig.java
453 lines (390 loc) · 13.9 KB
/
QueryCacheConfig.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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
/*
* Copyright (c) 2008-2017, Hazelcast, Inc. All Rights Reserved.
*
* 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 com.hazelcast.config;
import java.util.ArrayList;
import java.util.List;
import static com.hazelcast.util.Preconditions.checkFalse;
import static com.hazelcast.util.Preconditions.checkHasText;
import static com.hazelcast.util.Preconditions.checkNotNegative;
import static com.hazelcast.util.Preconditions.checkNotNull;
import static com.hazelcast.util.Preconditions.checkPositive;
/**
* Contains configuration for {@code QueryCache}.
*
* @since 3.5
*/
public class QueryCacheConfig {
/**
* By default, after reaching this minimum size, node immediately sends buffered events to {@code QueryCache}.
*/
public static final int DEFAULT_BATCH_SIZE = 1;
/**
* By default, only buffer last {@value #DEFAULT_BUFFER_SIZE} events fired from a partition.
*/
public static final int DEFAULT_BUFFER_SIZE = 16;
/**
* Default value of delay seconds which an event wait in the buffer of a node, before sending to {@code QueryCache}.
*/
public static final int DEFAULT_DELAY_SECONDS = 0;
/**
* By default, also cache values of entries besides keys.
*/
public static final boolean DEFAULT_INCLUDE_VALUE = true;
/**
* By default, execute an initial population query prior to creation of the {@code QueryCache}.
*/
public static final boolean DEFAULT_POPULATE = true;
/**
* Default value of coalesce property.
*/
public static final boolean DEFAULT_COALESCE = false;
/**
* By default, hold values of entries in {@code QueryCache} as binary.
*/
public static final InMemoryFormat DEFAULT_IN_MEMORY_FORMAT = InMemoryFormat.BINARY;
/**
* After reaching this minimum size, node immediately sends buffered events to {@code QueryCache}.
*/
private int batchSize = DEFAULT_BATCH_SIZE;
/**
* Maximum number of events which can be stored in a buffer of partition.
*/
private int bufferSize = DEFAULT_BUFFER_SIZE;
/**
* The minimum number of delay seconds which an event waits in the buffer of node.
*/
private int delaySeconds = DEFAULT_DELAY_SECONDS;
/**
* Flag to enable/disable value caching.
*/
private boolean includeValue = DEFAULT_INCLUDE_VALUE;
/**
* Flag to enable/disable initial population of the {@code QueryCache}.
*/
private boolean populate = DEFAULT_POPULATE;
/**
* Flag to enable/disable coalescing.
*
* @see #setCoalesce
*/
private boolean coalesce = DEFAULT_COALESCE;
/**
* Memory format of values of entries in {@code QueryCache}.
*/
private InMemoryFormat inMemoryFormat = DEFAULT_IN_MEMORY_FORMAT;
/**
* The name of {@code QueryCache}.
*/
private String name;
/**
* The predicate to filter events which wil be applied to the {@code QueryCache}.
*/
private PredicateConfig predicateConfig = new PredicateConfig();
private EvictionConfig evictionConfig = new EvictionConfig();
private List<EntryListenerConfig> entryListenerConfigs;
private List<MapIndexConfig> indexConfigs;
private QueryCacheConfigReadOnly readOnly;
public QueryCacheConfig() {
}
public QueryCacheConfig(String name) {
setName(name);
}
public QueryCacheConfig(QueryCacheConfig other) {
this.batchSize = other.batchSize;
this.bufferSize = other.bufferSize;
this.delaySeconds = other.delaySeconds;
this.includeValue = other.includeValue;
this.populate = other.populate;
this.coalesce = other.coalesce;
this.inMemoryFormat = other.inMemoryFormat;
this.name = other.name;
this.predicateConfig = other.predicateConfig;
this.evictionConfig = other.evictionConfig;
this.entryListenerConfigs = other.entryListenerConfigs;
this.indexConfigs = other.indexConfigs;
}
/**
* Gets immutable version of this configuration.
*
* @return Immutable version of this configuration.
* @deprecated this method will be removed in 4.0; it is meant for internal usage only.
*/
public QueryCacheConfigReadOnly getAsReadOnly() {
if (readOnly == null) {
readOnly = new QueryCacheConfigReadOnly(this);
}
return readOnly;
}
/**
* Returns the name of {@code QueryCache}.
*
* @return the name of {@code QueryCache}.
*/
public String getName() {
return name;
}
/**
* Sets the name of {@code QueryCache}.
*
* @param name the name of {@code QueryCache}.
* @return this {@code QueryCacheConfig} instance.
*/
public QueryCacheConfig setName(String name) {
checkHasText(name, "name");
this.name = name;
return this;
}
/**
* Returns the predicate of {@code QueryCache}.
*
* @return the predicate of {@code QueryCache}.
*/
public PredicateConfig getPredicateConfig() {
return predicateConfig;
}
/**
* Sets the predicate of {@code QueryCache}.
*
* @param predicateConfig config for predicate.
* @return this {@code QueryCacheConfig} instance.
*/
public QueryCacheConfig setPredicateConfig(PredicateConfig predicateConfig) {
this.predicateConfig = checkNotNull(predicateConfig, "predicateConfig can not be null");
return this;
}
/**
* After reaching this size, node sends buffered events to {@code QueryCache}.
*
* @return the batch size.
*/
public int getBatchSize() {
return batchSize;
}
/**
* Sets the batch size which will be used to determine number of events to be sent in a batch to {@code QueryCache}
*
* @param batchSize the batch size.
* @return this {@code QueryCacheConfig} instance.
*/
public QueryCacheConfig setBatchSize(int batchSize) {
checkPositive(batchSize, "batchSize");
this.batchSize = batchSize;
return this;
}
/**
* Returns the maximum number of events which can be stored in a buffer of partition.
*
* @return the maximum number of events which can be stored in a buffer of partition.
*/
public int getBufferSize() {
return bufferSize;
}
/**
* Sets the maximum number of events which can be stored in a buffer of partition.
*
* @param bufferSize the buffer size.
* @return this {@code QueryCacheConfig} instance.
*/
public QueryCacheConfig setBufferSize(int bufferSize) {
checkPositive(bufferSize, "bufferSize");
this.bufferSize = bufferSize;
return this;
}
/**
* Returns the minimum number of delay seconds which an event waits in the buffer of node
* before sending to a {@code QueryCache}
*
* @return delay seconds.
*/
public int getDelaySeconds() {
return delaySeconds;
}
/**
* Sets the minimum number of delay seconds which an event waits in the buffer of node
* before sending to a {@code QueryCache}
*
* @param delaySeconds the delay seconds.
* @return this {@code QueryCacheConfig} instance.
*/
public QueryCacheConfig setDelaySeconds(int delaySeconds) {
checkNotNegative(delaySeconds, "delaySeconds");
this.delaySeconds = delaySeconds;
return this;
}
/**
* Returns memory format of values of entries in {@code QueryCache}.
* <p/>
* Default value is binary.
*
* @return memory format of values of entries in {@code QueryCache}.
*/
public InMemoryFormat getInMemoryFormat() {
return inMemoryFormat;
}
/**
* Sets memory format of values of entries in {@code QueryCache}.
* <p/>
* Default value is binary.
*
* @param inMemoryFormat the memory format
* @return this {@code QueryCacheConfig} instance.
*/
public QueryCacheConfig setInMemoryFormat(InMemoryFormat inMemoryFormat) {
checkNotNull(inMemoryFormat, "inMemoryFormat cannot be null");
checkFalse(inMemoryFormat == InMemoryFormat.NATIVE, "InMemoryFormat." + inMemoryFormat + " is not supported.");
this.inMemoryFormat = inMemoryFormat;
return this;
}
/**
* Returns {@code true} if value caching enabled, otherwise returns {@code false}.
* <p/>
* Default value is {@value #DEFAULT_INCLUDE_VALUE}.
*
* @return {@code true} if value caching enabled, otherwise returns {@code false}.
*/
public boolean isIncludeValue() {
return includeValue;
}
/**
* Set {@code true} to enable value caching, otherwise set {@code false}.
* <p/>
* Default value is {@value #DEFAULT_INCLUDE_VALUE}.
*
* @param includeValue Set {@code true} if value caching is enabled, otherwise set {@code false}.
* @return this {@code QueryCacheConfig} instance.
*/
public QueryCacheConfig setIncludeValue(boolean includeValue) {
this.includeValue = includeValue;
return this;
}
/**
* Returns {@code true} if initial population of {@code QueryCache} is enabled, otherwise returns {@code false}.
* * <p/>
* Default value is {@value #DEFAULT_POPULATE}.
*
* @return {@code true} if initial population of {@code QueryCache} is enabled, otherwise returns {@code false}.
*/
public boolean isPopulate() {
return populate;
}
/**
* Set {@code true} to enable initial population, otherwise set {@code false}.
* <p/>
* Default value is {@value #DEFAULT_POPULATE}.
*
* @param populate set {@code true} to enable initial population, otherwise set {@code false}
* @return this {@code QueryCacheConfig} instance.
*/
public QueryCacheConfig setPopulate(boolean populate) {
this.populate = populate;
return this;
}
/**
* Returns {@code true} if coalescing is is enabled, otherwise returns {@code false}.
* <p/>
* Default value is {@value #DEFAULT_COALESCE}.
*
* @return {@code true} if coalescing is is enabled, otherwise returns {@code false}.
* @see #setCoalesce
*/
public boolean isCoalesce() {
return coalesce;
}
/**
* Set {@code true} to enable coalescing, otherwise set {@code false}.
* This setting is only valid if {@code QueryCacheConfig#delaySeconds} is greater than 0.
* <p/>
* Default value is {@value #DEFAULT_COALESCE}.
*
* @param coalesce set {@code true} to enable, otherwise set {@code false}
*/
public QueryCacheConfig setCoalesce(boolean coalesce) {
this.coalesce = coalesce;
return this;
}
/**
* Returns {@link EvictionConfig} instance for this {@code QueryCache}
*
* @return the {@link EvictionConfig} instance for this {@code QueryCache}.
*/
public EvictionConfig getEvictionConfig() {
return evictionConfig;
}
/**
* Sets the {@link EvictionConfig} instance for this {@code QueryCache}
*
* @param evictionConfig the {@link EvictionConfig} instance for eviction configuration to set
* @return this {@code QueryCacheConfig} instance.
*/
public QueryCacheConfig setEvictionConfig(EvictionConfig evictionConfig) {
checkNotNull(evictionConfig, "evictionConfig cannot be null");
this.evictionConfig = evictionConfig;
return this;
}
/**
* Adds {@link EntryListenerConfig} to this {@code QueryCacheConfig}.
*
* @param listenerConfig the {@link EntryListenerConfig} to add
* @return this {@code QueryCacheConfig} instance.
*/
public QueryCacheConfig addEntryListenerConfig(EntryListenerConfig listenerConfig) {
checkNotNull(listenerConfig, "listenerConfig cannot be null");
getEntryListenerConfigs().add(listenerConfig);
return this;
}
public List<EntryListenerConfig> getEntryListenerConfigs() {
if (entryListenerConfigs == null) {
entryListenerConfigs = new ArrayList<EntryListenerConfig>();
}
return entryListenerConfigs;
}
public QueryCacheConfig setEntryListenerConfigs(List<EntryListenerConfig> listenerConfigs) {
checkNotNull(listenerConfigs, "listenerConfig cannot be null");
this.entryListenerConfigs = listenerConfigs;
return this;
}
public QueryCacheConfig addIndexConfig(MapIndexConfig mapIndexConfig) {
getIndexConfigs().add(mapIndexConfig);
return this;
}
public List<MapIndexConfig> getIndexConfigs() {
if (indexConfigs == null) {
indexConfigs = new ArrayList<MapIndexConfig>();
}
return indexConfigs;
}
public QueryCacheConfig setIndexConfigs(List<MapIndexConfig> indexConfigs) {
this.indexConfigs = indexConfigs;
return this;
}
@Override
public String toString() {
return "QueryCacheConfig{"
+ "batchSize=" + batchSize
+ ", bufferSize=" + bufferSize
+ ", delaySeconds=" + delaySeconds
+ ", includeValue=" + includeValue
+ ", populate=" + populate
+ ", coalesce=" + coalesce
+ ", inMemoryFormat=" + inMemoryFormat
+ ", name='" + name + '\''
+ ", predicateConfig=" + predicateConfig
+ ", evictionConfig=" + evictionConfig
+ ", entryListenerConfigs=" + entryListenerConfigs
+ ", indexConfigs=" + indexConfigs
+ '}';
}
}