use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Channel in project dubbo by alibaba.
the class GrpcProtocol method protocolBindingRefer.
@Override
protected <T> Invoker<T> protocolBindingRefer(final Class<T> type, final URL url) throws RpcException {
Class<?> enclosingClass = type.getEnclosingClass();
if (enclosingClass == null) {
throw new IllegalArgumentException(type.getName() + " must be declared inside protobuf generated classes, " + "should be something like ServiceNameGrpc.IServiceName.");
}
final Method dubboStubMethod;
try {
dubboStubMethod = enclosingClass.getDeclaredMethod("getDubboStub", Channel.class, CallOptions.class, URL.class, ReferenceConfigBase.class);
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException("Does not find getDubboStub in " + enclosingClass.getName() + ", please use the customized protoc-gen-dubbo-java to update the generated classes.");
}
// Channel
ReferenceCountManagedChannel channel = getSharedChannel(url);
// CallOptions
try {
@SuppressWarnings("unchecked") final T stub = (T) dubboStubMethod.invoke(null, channel, GrpcOptionsUtils.buildCallOptions(url), url, ApplicationModel.getConsumerModel(url.getServiceKey()).getReferenceConfig());
final Invoker<T> target = proxyFactory.getInvoker(stub, type, url);
GrpcInvoker<T> grpcInvoker = new GrpcInvoker<>(type, url, target, channel);
invokers.add(grpcInvoker);
return grpcInvoker;
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException("Could not create stub through reflection.", e);
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Channel in project toolkit by googleapis.
the class Pubsub method gapic.
private static void gapic(final Settings settings) throws Exception {
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
// In real clients, InstantiatingChannelProvider is responsible for adding interceptors.
// We can't use it here because InstantiatingChannelProvider doesn't have sslContext method.
// Instead, we imitate HeaderInterceptor.
ClientInterceptor headerInterceptor = new ClientInterceptor() {
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
ClientCall<ReqT, RespT> call = next.newCall(method, callOptions);
return new SimpleForwardingClientCall<ReqT, RespT>(call) {
@Override
public void start(ClientCall.Listener<RespT> responseListener, Metadata headers) {
headers.put(X_GOOG_HEADER_KEY, X_GOOG_HEADER_VALUE);
super.start(responseListener, headers);
}
};
}
};
ManagedChannel channel = NettyChannelBuilder.forTarget(settings.endpoint()).executor(executor).sslContext(GrpcSslContexts.forClient().trustManager(new File(settings.cert())).build()).intercept(headerInterceptor).build();
final Semaphore semaphore = new Semaphore(settings.numWorkers());
final TopicAdminClient client = TopicAdminClient.create(TopicAdminSettings.defaultBuilder().setChannelProvider(FixedChannelProvider.create(channel)).setExecutorProvider(FixedExecutorProvider.create(executor)).build());
final AtomicLong resetTime = new AtomicLong();
final AtomicLong numCalls = new AtomicLong();
final AtomicLong numErrs = new AtomicLong();
long endTime = System.nanoTime() + settings.warmDurNano() + settings.targetDurNano();
Thread resetter = new Thread(() -> {
try {
Thread.sleep(settings.warmDurNano() / MILLION);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
numCalls.set(0);
numErrs.set(0);
resetTime.set(System.nanoTime());
});
resetter.start();
while (System.nanoTime() < endTime) {
semaphore.acquire(1);
ApiFutures.addCallback(client.getTopicCallable().futureCall(GetTopicRequest.newBuilder().setTopicWithTopicName(TOPIC_NAME_RESOURCE).build()), new ApiFutureCallback<Topic>() {
@Override
public void onSuccess(Topic topic) {
if (!topic.getName().equals(TOPIC_NAME_STRING)) {
numErrs.incrementAndGet();
}
both();
}
@Override
public void onFailure(Throwable t) {
numErrs.incrementAndGet();
both();
}
void both() {
numCalls.incrementAndGet();
semaphore.release(1);
}
});
}
long nCalls = numCalls.get();
long nErrs = numErrs.get();
long runDurNano = System.nanoTime() - resetTime.get();
System.out.println("errors: " + nErrs);
System.out.println("calls: " + nCalls);
System.out.println("time per call (ns): " + (runDurNano / nCalls));
System.out.println("QPS: " + (nCalls * BILLION / runDurNano));
client.close();
channel.shutdown().awaitTermination(10, TimeUnit.SECONDS);
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Channel in project brave by openzipkin.
the class BaseITTracingClientInterceptor method initMessageTaggingClient.
void initMessageTaggingClient() {
SpanCustomizer customizer = CurrentSpanCustomizer.create(tracing);
AtomicInteger sends = new AtomicInteger(1);
AtomicInteger recvs = new AtomicInteger(1);
closeClient(client);
client = newClient(new ClientInterceptor() {
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
return new SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
super.start(new SimpleForwardingClientCallListener<RespT>(responseListener) {
@Override
public void onMessage(RespT message) {
customizer.tag("grpc.message_recv." + recvs.getAndIncrement(), message.toString());
delegate().onMessage(message);
}
}, headers);
}
@Override
public void sendMessage(ReqT message) {
customizer.tag("grpc.message_send." + sends.getAndIncrement(), message.toString());
delegate().sendMessage(message);
}
};
}
}, grpcTracing.newClientInterceptor());
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Channel in project incubator-skywalking by apache.
the class AppAndServiceRegisterClient method statusChanged.
@Override
public void statusChanged(GRPCChannelStatus status) {
if (GRPCChannelStatus.CONNECTED.equals(status)) {
Channel channel = ServiceManager.INSTANCE.findService(GRPCChannelManager.class).getChannel();
applicationRegisterServiceBlockingStub = ApplicationRegisterServiceGrpc.newBlockingStub(channel);
instanceDiscoveryServiceBlockingStub = InstanceDiscoveryServiceGrpc.newBlockingStub(channel);
serviceNameDiscoveryServiceBlockingStub = ServiceNameDiscoveryServiceGrpc.newBlockingStub(channel);
networkAddressRegisterServiceBlockingStub = NetworkAddressRegisterServiceGrpc.newBlockingStub(channel);
} else {
applicationRegisterServiceBlockingStub = null;
instanceDiscoveryServiceBlockingStub = null;
serviceNameDiscoveryServiceBlockingStub = null;
}
this.status = status;
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Channel in project incubator-skywalking by apache.
the class TraceSegmentServiceClient method statusChanged.
@Override
public void statusChanged(GRPCChannelStatus status) {
if (CONNECTED.equals(status)) {
Channel channel = ServiceManager.INSTANCE.findService(GRPCChannelManager.class).getChannel();
serviceStub = TraceSegmentServiceGrpc.newStub(channel);
}
this.status = status;
}
Aggregations