All client configurations work without any problems.
Election class in the Jetcd library has the following observe method,
void observe(ByteSequence electionName, Listener listener);
With this method you can know who the leader is.
But when I close etcd client, if I am observing, it throws exception.
public void disconnect() {
this.leaseKeepAliveClient.close();
this.lease.revoke(this.leaseId);
this.client.close();
}
io.etcd.jetcd.common.exception.EtcdException: Channel shutdownNow invoked
at io.etcd.jetcd.common.exception.EtcdExceptionFactory.newEtcdException(EtcdExceptionFactory.java:35)
at io.etcd.jetcd.common.exception.EtcdExceptionFactory.fromStatus(EtcdExceptionFactory.java:83)
at io.etcd.jetcd.common.exception.EtcdExceptionFactory.toEtcdException(EtcdExceptionFactory.java:79)
at io.etcd.jetcd.common.exception.EtcdExceptionFactory.toEtcdException(EtcdExceptionFactory.java:74)
at io.etcd.jetcd.impl.ElectionImpl.lambda$observe$6(ElectionImpl.java:144)
at io.vertx.grpc.stub.StreamObserverReadStream.onError(StreamObserverReadStream.java:44)
at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:481)
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:564).
....
....
....
Is there a sequence for closing?
import io.etcd.jetcd.Client;
import io.etcd.jetcd.election.Election;
import io.etcd.jetcd.election.ElectionClient;
public class JetcdElectionExample {
public static void main(String[] args) {
Client client = Client.builder().endpoints("http://localhost:2379").build();
Election election = client.getElectionClient();
try {
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
election.close();
} catch (Exception e) {
System.err.println("Error closing election client: " + e.getMessage());
}
client.close();
}
}
}
Always close the election client in a finally block .
New contributor
Mohit Mishra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1