Skip to content

Commit e34f72b

Browse files
authored
feat: add HStreamClient.describeCluster for getting uptime (#146)
1 parent 5ce4dc0 commit e34f72b

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package io.hstream;
2+
3+
public class Cluster {
4+
/** unit: Seconds. */
5+
long uptime;
6+
7+
public long getUptime() {
8+
return uptime;
9+
}
10+
11+
public static class Builder {
12+
long uptime;
13+
14+
public Builder uptime(long uptime) {
15+
this.uptime = uptime;
16+
return this;
17+
}
18+
19+
public Cluster build() {
20+
return new Cluster(uptime);
21+
}
22+
}
23+
24+
public static Builder newBuilder() {
25+
return new Builder();
26+
}
27+
28+
Cluster(long uptime) {
29+
this.uptime = uptime;
30+
}
31+
}

client/src/main/java/io/hstream/HStreamClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,6 @@ static HStreamClientBuilder builder() {
117117
* @param force the flag whether to enable force deletion
118118
*/
119119
void deleteSubscription(String subscriptionId, boolean force);
120+
121+
Cluster describeCluster();
120122
}

client/src/main/kotlin/io/hstream/impl/HStreamClientKtImpl.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.hstream.impl
33
import com.google.protobuf.Empty
44
import io.grpc.ChannelCredentials
55
import io.hstream.BufferedProducerBuilder
6+
import io.hstream.Cluster
67
import io.hstream.ConsumerBuilder
78
import io.hstream.HStreamClient
89
import io.hstream.ProducerBuilder
@@ -176,6 +177,13 @@ class HStreamClientKtImpl(bootstrapServerUrls: List<String>, credentials: Channe
176177
}
177178
}
178179

180+
override fun describeCluster(): Cluster {
181+
return unaryCallBlocked {
182+
val result = it.describeCluster(Empty.getDefaultInstance())
183+
return@unaryCallBlocked Cluster.newBuilder().uptime(result.clusterUpTime).build()
184+
}
185+
}
186+
179187
private final suspend fun lookupSubscriptionServerUrl(subscriptionId: String?): String {
180188
return unaryCallCoroutine {
181189
val req: LookupSubscriptionRequest =

client/src/main/proto

Submodule proto updated 1 file

0 commit comments

Comments
 (0)