@@ -36,6 +36,7 @@ public class BatchProcessor {
36
36
final int actions ;
37
37
private final TimeUnit flushIntervalUnit ;
38
38
private final int flushInterval ;
39
+ private final InfluxDB .ConsistencyLevel consistencyLevel ;
39
40
40
41
/**
41
42
* The Builder to create a BatchProcessor instance.
@@ -46,6 +47,7 @@ public static final class Builder {
46
47
private int actions ;
47
48
private TimeUnit flushIntervalUnit ;
48
49
private int flushInterval ;
50
+ private InfluxDB .ConsistencyLevel consistencyLevel ;
49
51
50
52
/**
51
53
* @param threadFactory
@@ -92,6 +94,18 @@ public Builder interval(final int interval, final TimeUnit unit) {
92
94
return this ;
93
95
}
94
96
97
+ /**
98
+ * Set the consistency level writes should use.
99
+ *
100
+ * @param consistencyLevel
101
+ * The consistency level.
102
+ * @return this Builder to use it fluent
103
+ */
104
+ public Builder consistencyLevel (final InfluxDB .ConsistencyLevel consistencyLevel ) {
105
+ this .consistencyLevel = consistencyLevel ;
106
+ return this ;
107
+ }
108
+
95
109
/**
96
110
* Create the BatchProcessor.
97
111
*
@@ -102,9 +116,10 @@ public BatchProcessor build() {
102
116
Preconditions .checkArgument (this .actions > 0 , "actions should > 0" );
103
117
Preconditions .checkArgument (this .flushInterval > 0 , "flushInterval should > 0" );
104
118
Preconditions .checkNotNull (this .flushIntervalUnit , "flushIntervalUnit may not be null" );
119
+ Preconditions .checkNotNull (this .consistencyLevel , "consistencyLevel must not be null" );
105
120
Preconditions .checkNotNull (this .threadFactory , "threadFactory may not be null" );
106
121
return new BatchProcessor (this .influxDB , this .threadFactory , this .actions , this .flushIntervalUnit ,
107
- this .flushInterval );
122
+ this .flushInterval , this . consistencyLevel );
108
123
}
109
124
}
110
125
@@ -164,12 +179,14 @@ public static Builder builder(final InfluxDB influxDB) {
164
179
}
165
180
166
181
BatchProcessor (final InfluxDBImpl influxDB , final ThreadFactory threadFactory , final int actions ,
167
- final TimeUnit flushIntervalUnit , final int flushInterval ) {
182
+ final TimeUnit flushIntervalUnit , final int flushInterval ,
183
+ final InfluxDB .ConsistencyLevel consistencyLevel ) {
168
184
super ();
169
185
this .influxDB = influxDB ;
170
186
this .actions = actions ;
171
187
this .flushIntervalUnit = flushIntervalUnit ;
172
188
this .flushInterval = flushInterval ;
189
+ this .consistencyLevel = consistencyLevel ;
173
190
this .scheduler = Executors .newSingleThreadScheduledExecutor (threadFactory );
174
191
if (actions > 1 && actions < Integer .MAX_VALUE ) {
175
192
this .queue = new LinkedBlockingQueue <>(actions );
@@ -207,6 +224,7 @@ void write() {
207
224
String batchKey = dbName + "_" + rp ;
208
225
if (!batchKeyToBatchPoints .containsKey (batchKey )) {
209
226
BatchPoints batchPoints = BatchPoints .database (dbName )
227
+ .consistency (consistencyLevel )
210
228
.retentionPolicy (rp ).build ();
211
229
batchKeyToBatchPoints .put (batchKey , batchPoints );
212
230
}
@@ -263,9 +281,15 @@ public void run() {
263
281
* called if no batch processing is needed anymore.
264
282
*
265
283
*/
266
- void flush () {
284
+ void flushAndShutdown () {
267
285
this .write ();
268
286
this .scheduler .shutdown ();
269
287
}
270
288
289
+ /**
290
+ * Flush the current open writes to InfluxDB. This will block until all pending points are written.
291
+ */
292
+ void flush () {
293
+ this .write ();
294
+ }
271
295
}
0 commit comments