Skip to content

Commit

Permalink
feat: more quick start (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengjiachun authored Dec 21, 2023
1 parent 4d9fca9 commit 947ca88
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
GreptimeOptions opts = GreptimeOptions.newBuilder(endpoints, database) //
.build();

GreptimeDB greptimeDB = new GreptimeDB();

if (!greptimeDB.init(opts)) {
throw new RuntimeException("Failed to start GreptimeDB client");
}
GreptimeDB greptimeDB = GreptimeDB.create(opts);

List<MyMetric1> myMetric1s = new ArrayList<>();
for (int i = 0; i < 10; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
GreptimeOptions opts = GreptimeOptions.newBuilder(endpoints, database) //
.build();

GreptimeDB greptimeDB = new GreptimeDB();

if (!greptimeDB.init(opts)) {
throw new RuntimeException("Failed to start GreptimeDB client");
}
GreptimeDB greptimeDB = GreptimeDB.create(opts);

TableSchema myMetric3Schema = TableSchema.newBuilder("my_metric3") //
.addColumn("tag1", SemanticType.Tag, DataType.String) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
GreptimeOptions opts = GreptimeOptions.newBuilder(endpoints, database) //
.build();

GreptimeDB greptimeDB = new GreptimeDB();

if (!greptimeDB.init(opts)) {
throw new RuntimeException("Failed to start GreptimeDB client");
}
GreptimeDB greptimeDB = GreptimeDB.create(opts);

List<MyMetric1> myMetric1s = new ArrayList<>();
for (int i = 0; i < 10; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
GreptimeOptions opts = GreptimeOptions.newBuilder(endpoints, database) //
.build();

GreptimeDB greptimeDB = new GreptimeDB();

if (!greptimeDB.init(opts)) {
throw new RuntimeException("Failed to start GreptimeDB client");
}
GreptimeDB greptimeDB = GreptimeDB.create(opts);

TableSchema myMetric3Schema = TableSchema.newBuilder("my_metric3") //
.addColumn("tag1", SemanticType.Tag, DataType.String) //
Expand Down
10 changes: 9 additions & 1 deletion ingester-protocol/src/main/java/io/greptime/GreptimeDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ public static List<GreptimeDB> instances() {
return new ArrayList<>(INSTANCES.values());
}

public GreptimeDB() {
public static GreptimeDB create(GreptimeOptions opts) {
GreptimeDB greptimeDB = new GreptimeDB();
if (!greptimeDB.init(opts)) {
throw new RuntimeException("Failed to start GreptimeDB client");
}
return greptimeDB;
}

private GreptimeDB() {
this.id = ID.incrementAndGet();
}

Expand Down

0 comments on commit 947ca88

Please sign in to comment.