cn.nextop.gadget.etcd.impl.ClientStub Maven / Gradle / Ivy
The newest version!
package cn.nextop.gadget.etcd.impl;
import static cn.nextop.gadget.etcd.support.util.Objects.cast;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import cn.nextop.gadget.etcd.support.util.Strings;
import com.google.protobuf.AbstractMessage;
import cn.nextop.gadget.etcd.Client;
import cn.nextop.gadget.etcd.support.observer.PluralStreamObserver;
import cn.nextop.gadget.etcd.support.observer.SingleStreamObserver;
import io.grpc.ManagedChannel;
import io.grpc.stub.StreamObserver;
/**
* @author Baoyi Chen
*/
public abstract class ClientStub implements Client.Stub {
//
protected final String name;
protected final ClientImpl client;
/**
*
*/
public ClientStub(String name, ClientImpl client) {
this.name = name; this.client = client;
}
/**
*
*/
@Override
public String getName() {
return this.name;
}
@Override
public ClientImpl getClient() {
return this.client;
}
@Override
public String toString() {
return Strings.build(this)
.append("name", name).toString();
}
/**
*
*/
protected T create(Function factory) {
final T r = factory.apply(client.getChannel()); return r;
}
/**
*
*/
protected final SingleStreamObserver single(AbstractMessage request) {
StreamObserver> r = new SingleStreamObserver