-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathGossipClient.java
More file actions
49 lines (38 loc) · 1.51 KB
/
GossipClient.java
File metadata and controls
49 lines (38 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.eventstore.dbclient;
import com.eventstore.dbclient.proto.gossip.GossipGrpc;
import com.eventstore.dbclient.proto.gossip.GossipOuterClass;
import com.eventstore.dbclient.proto.shared.Shared;
import io.grpc.ManagedChannel;
import io.grpc.stub.StreamObserver;
import java.util.concurrent.CompletableFuture;
public class GossipClient {
private final ManagedChannel channel;
private final GossipGrpc.GossipStub stub;
private final Timeouts timeouts;
public GossipClient(ManagedChannel channel, Timeouts timeouts) {
this.channel = channel;
this.timeouts = timeouts;
this.stub = GossipGrpc.newStub(channel);
}
public void shutdown() throws InterruptedException {
this.channel.shutdown().awaitTermination(timeouts.shutdownTimeout, timeouts.shutdownTimeoutUnit);
}
public CompletableFuture<ClusterInfo> readGossip() {
CompletableFuture<ClusterInfo> future = new CompletableFuture<>();
this.stub.read(Shared.Empty.getDefaultInstance(), new StreamObserver<GossipOuterClass.ClusterInfo>() {
@Override
public void onNext(GossipOuterClass.ClusterInfo value) {
ClusterInfo info = ClusterInfo.fromWire(value);
future.complete(info);
}
@Override
public void onError(Throwable t) {
future.completeExceptionally(t);
}
@Override
public void onCompleted() {
}
});
return future;
}
}