diff --git a/ingester-example/src/main/java/io/greptime/StreamWritePOJOsQuickStart.java b/ingester-example/src/main/java/io/greptime/StreamWritePOJOsQuickStart.java index 2771db2..ee743e1 100644 --- a/ingester-example/src/main/java/io/greptime/StreamWritePOJOsQuickStart.java +++ b/ingester-example/src/main/java/io/greptime/StreamWritePOJOsQuickStart.java @@ -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 myMetric1s = new ArrayList<>(); for (int i = 0; i < 10; i++) { diff --git a/ingester-example/src/main/java/io/greptime/StreamWriteTableRowsQuickStart.java b/ingester-example/src/main/java/io/greptime/StreamWriteTableRowsQuickStart.java index 515b3a4..6899bc0 100644 --- a/ingester-example/src/main/java/io/greptime/StreamWriteTableRowsQuickStart.java +++ b/ingester-example/src/main/java/io/greptime/StreamWriteTableRowsQuickStart.java @@ -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) // diff --git a/ingester-example/src/main/java/io/greptime/WritePOJOsQuickStart.java b/ingester-example/src/main/java/io/greptime/WritePOJOsQuickStart.java index b5ae877..7c20d16 100644 --- a/ingester-example/src/main/java/io/greptime/WritePOJOsQuickStart.java +++ b/ingester-example/src/main/java/io/greptime/WritePOJOsQuickStart.java @@ -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 myMetric1s = new ArrayList<>(); for (int i = 0; i < 10; i++) { diff --git a/ingester-example/src/main/java/io/greptime/WriteTableRowsQuickStart.java b/ingester-example/src/main/java/io/greptime/WriteTableRowsQuickStart.java index 9de27a0..8e49652 100644 --- a/ingester-example/src/main/java/io/greptime/WriteTableRowsQuickStart.java +++ b/ingester-example/src/main/java/io/greptime/WriteTableRowsQuickStart.java @@ -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) // diff --git a/ingester-protocol/src/main/java/io/greptime/GreptimeDB.java b/ingester-protocol/src/main/java/io/greptime/GreptimeDB.java index 0bf93f9..59712f6 100644 --- a/ingester-protocol/src/main/java/io/greptime/GreptimeDB.java +++ b/ingester-protocol/src/main/java/io/greptime/GreptimeDB.java @@ -79,7 +79,15 @@ public static List 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(); }