Skip to content

Commit 9d54466

Browse files
committed
modified the signature of the Builder creation for Point and BatchPoints.
1 parent 4d02940 commit 9d54466

File tree

6 files changed

+37
-13
lines changed

6 files changed

+37
-13
lines changed

src/main/java/org/influxdb/dto/BatchPoints.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ public class BatchPoints {
3737
// Only visible in the Builder
3838
}
3939

40+
/**
41+
* Create a new BatchPoints build to create a new BatchPoints in a fluent manner-
42+
*
43+
* @param database
44+
* the name of the Database
45+
* @return the Builder to be able to add further Builder calls.
46+
*/
47+
public static Builder database(final String database) {
48+
return new Builder(database);
49+
}
50+
4051
/**
4152
* The Builder to create a new BatchPoints instance.
4253
*/
@@ -52,7 +63,7 @@ public static class Builder {
5263
/**
5364
* @param database
5465
*/
55-
public Builder(final String database) {
66+
Builder(final String database) {
5667
super();
5768
this.database = database;
5869
}

src/main/java/org/influxdb/dto/Point.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ public class Point {
2828
Point() {
2929
}
3030

31+
/**
32+
* Create a new Point Build build to create a new Point in a fluent manner-
33+
*
34+
* @param measurement
35+
* the name of the measurement.
36+
* @return the Builder to be able to add further Builder calls.
37+
*/
38+
39+
public static Builder measurement(final String measurement) {
40+
return new Builder(measurement);
41+
}
42+
3143
/**
3244
* Builder for a new Point.
3345
*
@@ -44,7 +56,7 @@ public static class Builder {
4456
/**
4557
* @param measurement
4658
*/
47-
public Builder(final String measurement) {
59+
Builder(final String measurement) {
4860
this.measurement = measurement;
4961
}
5062

src/main/java/org/influxdb/impl/BatchProcessor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@ void write() {
152152
for (BatchEntry batchEntry : this.cache) {
153153
String dbName = batchEntry.getDb();
154154
if (!databaseToBatchPoints.containsKey(dbName)) {
155-
BatchPoints batchPoints = new BatchPoints.Builder(dbName)
156-
.retentionPolicy(batchEntry.getRp())
157-
.build();
155+
BatchPoints batchPoints = BatchPoints.database(dbName).retentionPolicy(batchEntry.getRp()).build();
158156
databaseToBatchPoints.put(dbName, batchPoints);
159157
}
160158
Point point = batchEntry.getPoint();

src/main/java/org/influxdb/impl/InfluxDBImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void write(final String database, final String retentionPolicy, final Poi
135135
BatchEntry batchEntry = new BatchEntry(point, database, retentionPolicy);
136136
this.batchProcessor.put(batchEntry);
137137
} else {
138-
BatchPoints batchPoints = new BatchPoints.Builder(database).retentionPolicy(retentionPolicy).build();
138+
BatchPoints batchPoints = BatchPoints.database(database).retentionPolicy(retentionPolicy).build();
139139
batchPoints.point(point);
140140
this.write(batchPoints);
141141
this.unBatchedCount.incrementAndGet();

src/test/java/org/influxdb/InfluxDBTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,14 @@ public void testWrite() {
166166
String dbName = "write_unittest_" + System.currentTimeMillis();
167167
this.influxDB.createDatabase(dbName);
168168

169-
BatchPoints batchPoints = new BatchPoints.Builder(dbName)
169+
BatchPoints batchPoints = BatchPoints
170+
.database(dbName)
170171
.time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
171172
.tag("async", "true")
172173
.retentionPolicy("default")
173174
.build();
174-
Point point1 = new Point.Builder("cpu").field("idle", 90L).field("user", 9L).field("system", 1L).build();
175-
Point point2 = new Point.Builder("disk").field("used", 80L).field("free", 1L).build();
175+
Point point1 = Point.measurement("cpu").field("idle", 90L).field("user", 9L).field("system", 1L).build();
176+
Point point2 = Point.measurement("disk").field("used", 80L).field("free", 1L).build();
176177
batchPoints.point(point1);
177178
batchPoints.point(point2);
178179
this.influxDB.write(batchPoints);

src/test/java/org/influxdb/PerformanceTests.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void writeSinglePointPerformance() throws InterruptedException {
3030
this.influxDB.enableBatch(2000, 100, TimeUnit.MILLISECONDS);
3131
Stopwatch watch = Stopwatch.createStarted();
3232
for (int j = 0; j < SINGLE_POINT_COUNT; j++) {
33-
Point point = new Point.Builder("cpu").field("idle", j).field("user", 2 * j).field("system", 3 * j).build();
33+
Point point = Point.measurement("cpu").field("idle", j).field("user", 2 * j).field("system", 3 * j).build();
3434
this.influxDB.write(dbName, "default", point);
3535
}
3636
this.influxDB.disableBatch();
@@ -46,13 +46,15 @@ public void writePerformance() {
4646
Stopwatch watch = Stopwatch.createStarted();
4747
for (int i = 0; i < COUNT; i++) {
4848

49-
BatchPoints batchPoints = new BatchPoints.Builder(dbName)
49+
BatchPoints batchPoints = BatchPoints
50+
.database(dbName)
5051
.time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
5152
.tag("blubber", "bla")
5253
.retentionPolicy("default")
5354
.build();
5455
for (int j = 0; j < POINT_COUNT; j++) {
55-
Point point = new Point.Builder("cpu")
56+
Point point = Point
57+
.measurement("cpu")
5658
.field("idle", j)
5759
.field("user", 2 * j)
5860
.field("system", 3 * j)
@@ -74,7 +76,7 @@ public void maxWritePointsPerformance() {
7476

7577
Stopwatch watch = Stopwatch.createStarted();
7678
for (int i = 0; i < 2000000; i++) {
77-
Point point = new Point.Builder("s").field("v", 1).build();
79+
Point point = Point.measurement("s").field("v", 1).build();
7880
this.influxDB.write(dbName, "default", point);
7981
}
8082
System.out.println("5Mio points:" + watch);

0 commit comments

Comments
 (0)