当前位置: 首页>>代码示例>>Java>>正文


Java ClientCall类代码示例

本文整理汇总了Java中io.grpc.ClientCall的典型用法代码示例。如果您正苦于以下问题:Java ClientCall类的具体用法?Java ClientCall怎么用?Java ClientCall使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ClientCall类属于io.grpc包,在下文中一共展示了ClientCall类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: metadataInterceptor

import io.grpc.ClientCall; //导入依赖的package包/类
private ClientInterceptor metadataInterceptor() {
  ClientInterceptor interceptor = new ClientInterceptor() {
    @Override
    public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
        final io.grpc.MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, final Channel next) {
      return new ClientInterceptors.CheckedForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {
        @Override
        protected void checkedStart(Listener<RespT> responseListener, Metadata headers)
            throws StatusException {
          for (ConfigProto.CallMetadataEntry entry : callConfiguration.getMetadataList()) {
            Metadata.Key<String> key = Metadata.Key.of(entry.getName(), Metadata.ASCII_STRING_MARSHALLER);
            headers.put(key, entry.getValue());
          }
          delegate().start(responseListener, headers);
        }
      };
    }
  };

  return interceptor;
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:22,代码来源:ChannelFactory.java

示例2: subscribe

import io.grpc.ClientCall; //导入依赖的package包/类
@Override
public Subscription subscribe(@NonNull SubscriptionRequestTO req,
        @NonNull FactObserver observer) {
    SubscriptionImpl<Fact> subscription = SubscriptionImpl.on(observer);

    StreamObserver<FactStoreProto.MSG_Notification> responseObserver = new ClientStreamObserver(
            subscription);

    ClientCall<MSG_SubscriptionRequest, MSG_Notification> call = stub.getChannel().newCall(
            RemoteFactStoreGrpc.METHOD_SUBSCRIBE, stub.getCallOptions()
                    .withWaitForReady()
                    .withCompression("gzip"));

    asyncServerStreamingCall(call, converter.toProto(req), responseObserver);

    return subscription.onClose(() -> {
        cancel(call);
    });
}
 
开发者ID:uweschaefer,项目名称:factcast,代码行数:20,代码来源:GrpcFactStore.java

示例3: interceptCall

import io.grpc.ClientCall; //导入依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
        final MethodDescriptor<ReqT, RespT> method, CallOptions callOptions,
        final Channel next) {
    return new ClientInterceptors.CheckedForwardingClientCall<ReqT, RespT>(
            next.newCall(method, callOptions)) {
        @Override
        protected void checkedStart(Listener<RespT> responseListener, Metadata headers)
                throws StatusException {
            Metadata cachedSaved;
            URI uri = serviceUri(next, method);
            synchronized (this) {
                Map<String, List<String>> latestMetadata = getRequestMetadata(uri);
                if (mLastMetadata == null || mLastMetadata != latestMetadata) {
                    mLastMetadata = latestMetadata;
                    mCached = toHeaders(mLastMetadata);
                }
                cachedSaved = mCached;
            }
            headers.merge(cachedSaved);
            delegate().start(responseListener, headers);
        }
    };
}
 
开发者ID:hsavaliya,项目名称:GoogleAssistantSDK,代码行数:25,代码来源:SpeechService.java

示例4: interceptCall

import io.grpc.ClientCall; //导入依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(final MethodDescriptor<ReqT, RespT> method,
                                                           CallOptions callOptions, final Channel next) {
    return new ClientInterceptors.CheckedForwardingClientCall<ReqT, RespT>(
            next.newCall(method, callOptions)) {
        @Override
        protected void checkedStart(Listener<RespT> responseListener, Metadata headers)
                throws StatusException {

            Metadata cachedSaved;
            URI uri = serviceUri(next, method);
            synchronized (GoogleCredentialsInterceptor.this) {
                Map<String, List<String>> latestMetadata = getRequestMetadata(uri);
                if (mLastMetadata == null || mLastMetadata != latestMetadata) {
                    mLastMetadata = latestMetadata;
                    mCached = toHeaders(mLastMetadata);
                }
                cachedSaved = mCached;
            }
            headers.merge(cachedSaved);
            delegate().start(responseListener, headers);
        }
    };
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:25,代码来源:GoogleCredentialsInterceptor.java

示例5: interceptCall

import io.grpc.ClientCall; //导入依赖的package包/类
@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) {
      getToken(next).ifPresent(t -> headers.put(TOKEN, t));
      super.start(new SimpleForwardingClientCallListener<RespT>(responseListener) {
        @Override
        public void onClose(Status status, Metadata trailers) {
          if (isInvalidTokenError(status)) {
            try {
              refreshToken(next);
            } catch (Exception e) {
              // don't throw any error here.
              // rpc will retry on expired auth token.
            }
          }
          super.onClose(status, trailers);
        }
      }, headers);
    }
  };
}
 
开发者ID:coreos,项目名称:jetcd,代码行数:25,代码来源:ClientConnectionManager.java

示例6: newCall

import io.grpc.ClientCall; //导入依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT>
    newCall(MethodDescriptor<ReqT, RespT> methodDescriptor, CallOptions callOptions) {
  final Context timerContext = timer.time();
  final AtomicBoolean decremented = new AtomicBoolean(false);
  return new CheckedForwardingClientCall<ReqT, RespT>(delegate.newCall(methodDescriptor, callOptions)) {
    @Override
    protected void checkedStart(ClientCall.Listener<RespT> responseListener, Metadata headers)
        throws Exception {
      ClientCall.Listener<RespT> timingListener = wrap(responseListener, timerContext, decremented);
      getStats().ACTIVE_RPC_COUNTER.inc();
      getStats().RPC_METER.mark();
      delegate().start(timingListener, headers);
    }

    @Override
    public void cancel(String message, Throwable cause) {
      if (!decremented.getAndSet(true)) {
        getStats().ACTIVE_RPC_COUNTER.dec();
      }
      super.cancel(message, cause);
    }
  };
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:25,代码来源:ChannelPool.java

示例7: unaryCall

import io.grpc.ClientCall; //导入依赖的package包/类
/**
 * Executes a unary call with a response {@link SingleObserver}.
 */
public static <ReqT, RespT> Single<RespT> unaryCall(
    final ClientCall<ReqT, RespT> call,
    final ReqT request) {
  final SingleRequestSender<ReqT> requestSender = new SingleRequestSender<ReqT>(call, request);
  SingleResponseReceiver<RespT> responseReceiver = new SingleResponseReceiver<RespT>(call) {
    @Override
    public void startCall() {
      requestSender.startCall();
      super.startCall();
    }
  };

  call.start(responseReceiver, new Metadata());

  return Single.wrap(responseReceiver.singleSource());
}
 
开发者ID:xiaodongw,项目名称:grpc-rx,代码行数:20,代码来源:ClientCallsRx.java

示例8: serverStreamingCall

import io.grpc.ClientCall; //导入依赖的package包/类
/**
 * Executes a server-streaming call with a response {@link Subscriber}.
 */
public static <ReqT, RespT> Flowable<RespT> serverStreamingCall(
    final ClientCall<ReqT, RespT> call,
    ReqT request) {
  final SingleRequestSender<ReqT> requestSender = new SingleRequestSender<ReqT>(call, request);
  StreamingResponseReceiver<RespT> responseReceiver = new StreamingResponseReceiver<RespT>(call) {
    @Override
    public void startCall() {
      requestSender.startCall();
      super.startCall();
    }
  };

  call.start(responseReceiver, new Metadata());

  return Flowable.fromPublisher(responseReceiver.publisher());
}
 
开发者ID:xiaodongw,项目名称:grpc-rx,代码行数:20,代码来源:ClientCallsRx.java

示例9: clientStreamingCall

import io.grpc.ClientCall; //导入依赖的package包/类
/**
 * Executes a client-streaming call returning a {@link StreamObserver} for the requestMore messages.
 *
 * @return requestMore stream observer.
 */
public static <ReqT, RespT> Single<RespT> clientStreamingCall(
    ClientCall<ReqT, RespT> call,
    Flowable<ReqT> requests,
    CallOptions options) {
  final StreamRequestSender<ReqT> requestSender = new StreamRequestSender<ReqT>(call, getLowWatermark(options), getHighWatermark(options));
  SingleResponseReceiver<RespT> responseReceiver = new SingleResponseReceiver<RespT>(call) {
    @Override
    public void startCall() {
      requestSender.startCall();
      super.startCall();
    }
  };

  ClientCall.Listener<RespT> delegate = new DelegateClientCallListener<RespT>(requestSender, responseReceiver);
  call.start(delegate, new Metadata());

  requests.subscribe(requestSender.subscriber());

  return Single.wrap(responseReceiver.singleSource());
}
 
开发者ID:xiaodongw,项目名称:grpc-rx,代码行数:26,代码来源:ClientCallsRx.java

示例10: bidiStreamingCall

import io.grpc.ClientCall; //导入依赖的package包/类
/**
 * Executes a bidi-streaming call.
 *
 * @return requestMore stream observer.
 */
public static <ReqT, RespT> Flowable<RespT> bidiStreamingCall(
    ClientCall<ReqT, RespT> call,
    Flowable<ReqT> requests,
    CallOptions options) {
  final StreamRequestSender<ReqT> requestSender = new StreamRequestSender<ReqT>(call, getLowWatermark(options), getHighWatermark(options));
  StreamingResponseReceiver<RespT> responseReceiver = new StreamingResponseReceiver<RespT>(call) {
    @Override
    public void startCall() {
      requestSender.startCall();
      super.startCall();
    }
  };

  ClientCall.Listener<RespT> delegate = new DelegateClientCallListener<RespT>(requestSender, responseReceiver);
  call.start(delegate, new Metadata());

  requests.subscribe(requestSender.subscriber());

  return Flowable.fromPublisher(responseReceiver.publisher());
}
 
开发者ID:xiaodongw,项目名称:grpc-rx,代码行数:26,代码来源:ClientCallsRx.java

示例11: SingleResponseReceiver

import io.grpc.ClientCall; //导入依赖的package包/类
public SingleResponseReceiver(ClientCall<?, RespT> call) {
  this.call = call;

  this.source = new SingleSource<RespT>() {
    @Override
    public void subscribe(SingleObserver<? super RespT> observer) {
      responseObserver = observer;

      // todo which disposable should be used here
      observer.onSubscribe(Disposables.disposed());

      // start call until response gets subscribed
      startCall();

      if (error != null) {
        responseObserver.onError(error);
        error = null;
      }
    }
  };
}
 
开发者ID:xiaodongw,项目名称:grpc-rx,代码行数:22,代码来源:ClientCallsRx.java

示例12: StreamRequestSender

import io.grpc.ClientCall; //导入依赖的package包/类
public StreamRequestSender(ClientCall<ReqT, ?> call, int lowWatermark, int highWatermark) {
  this.call = call;

  grpcSubscriber  = new GrpcSubscriber<ReqT>(lowWatermark, highWatermark) {
    @Override
    protected boolean isReady() {
      return StreamRequestSender.this.call.isReady();
    }

    @Override
    protected void sendMessage(ReqT req) {
      StreamRequestSender.this.call.sendMessage(req);
    }

    @Override
    protected void error(Throwable t) {
      StreamRequestSender.this.call.cancel("Upstream error", t);
    }

    @Override
    protected void complete() {
      StreamRequestSender.this.call.halfClose();
    }
  };
}
 
开发者ID:xiaodongw,项目名称:grpc-rx,代码行数:26,代码来源:ClientCallsRx.java

示例13: interceptCall

import io.grpc.ClientCall; //导入依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
    MethodDescriptor<ReqT,RespT> method, CallOptions callOptions, Channel next) {
  LOGGER.info("Intercepted " + method.getFullMethodName());
  ClientCall<ReqT, RespT> call = next.newCall(method, callOptions);

  call = new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(call) {
    @Override
    public void start(Listener<RespT> responseListener, Metadata headers) {
      if (apiKey != null && !apiKey.isEmpty()) {
        LOGGER.info("Attaching API Key: " + apiKey);
        headers.put(API_KEY_HEADER, apiKey);
      }
      super.start(responseListener, headers);
    }
  };
  return call;
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:19,代码来源:HelloWorldClient.java

示例14: interceptCall

import io.grpc.ClientCall; //导入依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
    MethodDescriptor<ReqT,RespT> method, CallOptions callOptions, Channel next) {
  LOGGER.info("Intercepted " + method.getFullMethodName());
  ClientCall<ReqT, RespT> call = next.newCall(method, callOptions);

  call = new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(call) {
    @Override
    public void start(Listener<RespT> responseListener, Metadata headers) {
      if (apiKey != null && !apiKey.isEmpty()) {
        LOGGER.info("Attaching API Key: " + apiKey);
        headers.put(API_KEY_HEADER, apiKey);
      }
      if (authToken != null && !authToken.isEmpty()) {
        System.out.println("Attaching auth token");
        headers.put(AUTHORIZATION_HEADER, "Bearer " + authToken);
      }
      super.start(responseListener, headers);
    }
  };
  return call;
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:23,代码来源:BookstoreClient.java

示例15: advancedAsyncCall

import io.grpc.ClientCall; //导入依赖的package包/类
/**
 * This is more advanced and does not make use of the stub.  You should not normally need to do
 * this, but here is how you would.
 */
void advancedAsyncCall() {
  ClientCall<HelloRequest, HelloReply> call =
      channel.newCall(GreeterGrpc.getSayHelloMethod(), CallOptions.DEFAULT);

  final CountDownLatch latch = new CountDownLatch(1);

  call.start(new ClientCall.Listener<HelloReply>() {

    @Override
    public void onClose(Status status, Metadata trailers) {
      Verify.verify(status.getCode() == Status.Code.INTERNAL);
      Verify.verify(status.getDescription().contains("Narwhal"));
      // Cause is not transmitted over the wire.
      latch.countDown();
    }
  }, new Metadata());

  call.sendMessage(HelloRequest.newBuilder().setName("Marge").build());
  call.halfClose();

  if (!Uninterruptibles.awaitUninterruptibly(latch, 1, TimeUnit.SECONDS)) {
    throw new RuntimeException("timeout!");
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:29,代码来源:ErrorHandlingClient.java


注:本文中的io.grpc.ClientCall类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。