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


Java Channel.newCall方法代码示例

本文整理汇总了Java中io.grpc.Channel.newCall方法的典型用法代码示例。如果您正苦于以下问题:Java Channel.newCall方法的具体用法?Java Channel.newCall怎么用?Java Channel.newCall使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.grpc.Channel的用法示例。


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

示例1: metadataInterceptor

import io.grpc.Channel; //导入方法依赖的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: interceptCall

import io.grpc.Channel; //导入方法依赖的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

示例3: interceptCall

import io.grpc.Channel; //导入方法依赖的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

示例4: interceptCall

import io.grpc.Channel; //导入方法依赖的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

示例5: createCloseableChannel

import io.grpc.Channel; //导入方法依赖的package包/类
/**
 * Given a channel, create a CloseableChannel that invokces onClientClose when the close
 * method is invoked.
 */
private static CloseableChannel createCloseableChannel(
    final Channel channel, final ClientCloseHandler onClientClose) {
  return new CloseableChannel() {
    @Override
    public void close() throws IOException {
      onClientClose.close();
    }

    @Override
    public <ReqT, RespT> Call<ReqT, RespT> newCall(
        MethodDescriptor<ReqT, RespT> methodDescriptor) {
      return channel.newCall(methodDescriptor);
    }
  };
}
 
开发者ID:dmmcerlean,项目名称:cloud-bigtable-client,代码行数:20,代码来源:BigtableChannels.java

示例6: interceptCall

import io.grpc.Channel; //导入方法依赖的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

示例7: interceptCall

import io.grpc.Channel; //导入方法依赖的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

示例8: interceptCall

import io.grpc.Channel; //导入方法依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
    MethodDescriptor<ReqT, RespT> method,
    CallOptions callOptions,
    Channel next) {
  ClientInterceptor binlogInterceptor = getClientInterceptor(method.getFullMethodName());
  if (binlogInterceptor == null) {
    return next.newCall(method, callOptions);
  } else {
    return InternalClientInterceptors
        .wrapClientInterceptor(
            binlogInterceptor,
            IDENTITY_MARSHALLER,
            IDENTITY_MARSHALLER)
        .interceptCall(method, callOptions, next);
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:18,代码来源:BinaryLogProvider.java

示例9: interceptCall

import io.grpc.Channel; //导入方法依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
    MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
  // New RPCs on client-side inherit the tag context from the current Context.
  TagContext parentCtx = tagger.getCurrentTagContext();
  final ClientCallTracer tracerFactory =
      newClientCallTracer(parentCtx, method.getFullMethodName(),
          recordStartedRpcs, recordFinishedRpcs);
  ClientCall<ReqT, RespT> call =
      next.newCall(method, callOptions.withStreamTracerFactory(tracerFactory));
  return new SimpleForwardingClientCall<ReqT, RespT>(call) {
    @Override
    public void start(Listener<RespT> responseListener, Metadata headers) {
      delegate().start(
          new SimpleForwardingClientCallListener<RespT>(responseListener) {
            @Override
            public void onClose(Status status, Metadata trailers) {
              tracerFactory.callEnded(status);
              super.onClose(status, trailers);
            }
          },
          headers);
    }
  };
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:26,代码来源:CensusStatsModule.java

示例10: interceptCall

import io.grpc.Channel; //导入方法依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
    MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
  // New RPCs on client-side inherit the tracing context from the current Context.
  // Safe usage of the unsafe trace API because CONTEXT_SPAN_KEY.get() returns the same value
  // as Tracer.getCurrentSpan() except when no value available when the return value is null
  // for the direct access and BlankSpan when Tracer API is used.
  final ClientCallTracer tracerFactory = newClientCallTracer(CONTEXT_SPAN_KEY.get(), method);
  ClientCall<ReqT, RespT> call =
      next.newCall(method, callOptions.withStreamTracerFactory(tracerFactory));
  return new SimpleForwardingClientCall<ReqT, RespT>(call) {
    @Override
    public void start(Listener<RespT> responseListener, Metadata headers) {
      delegate().start(
          new SimpleForwardingClientCallListener<RespT>(responseListener) {
            @Override
            public void onClose(io.grpc.Status status, Metadata trailers) {
              tracerFactory.callEnded(status);
              super.onClose(status, trailers);
            }
          },
          headers);
    }
  };
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:26,代码来源:CensusTracingModule.java

示例11: wrapChannel_methodDescriptor

import io.grpc.Channel; //导入方法依赖的package包/类
@Test
public void wrapChannel_methodDescriptor() throws Exception {
  final AtomicReference<MethodDescriptor<?, ?>> methodRef =
      new AtomicReference<MethodDescriptor<?, ?>>();
  Channel channel = new Channel() {
    @Override
    public <RequestT, ResponseT> ClientCall<RequestT, ResponseT> newCall(
        MethodDescriptor<RequestT, ResponseT> method, CallOptions callOptions) {
      methodRef.set(method);
      return new NoopClientCall<RequestT, ResponseT>();
    }

    @Override
    public String authority() {
      throw new UnsupportedOperationException();
    }
  };
  Channel wChannel = binlogProvider.wrapChannel(channel);
  ClientCall<String, Integer> ignoredClientCall = wChannel.newCall(method, CallOptions.DEFAULT);
  validateWrappedMethod(methodRef.get());
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:22,代码来源:BinaryLogProviderTest.java

示例12: interceptCall

import io.grpc.Channel; //导入方法依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method,
    CallOptions callOptions, Channel next) {
  Integer timeout = callOptions.getOption(DEADLINE_KEY);
  CallOptions callOptionsWithTimeout = null != timeout && timeout > 0 ? 
      callOptions.withDeadlineAfter(timeout, TimeUnit.MILLISECONDS) : callOptions;
  return next.newCall(method, callOptionsWithTimeout);
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:9,代码来源:StubDeadlineClientInterceptor.java

示例13: interceptCall

import io.grpc.Channel; //导入方法依赖的package包/类
@Override
public <R, S> ClientCall<R, S> interceptCall(
    MethodDescriptor<R, S> methodDescriptor, CallOptions callOptions, Channel channel) {
  ClientMetrics metrics = clientMetricsFactory.createMetricsForMethod(methodDescriptor);
  return new MonitoringClientCall<>(
      channel.newCall(methodDescriptor, callOptions),
      metrics,
      GrpcMethod.of(methodDescriptor),
      configuration,
      clock);
}
 
开发者ID:grpc-ecosystem,项目名称:java-grpc-prometheus,代码行数:12,代码来源:MonitoringClientInterceptor.java

示例14: listenableAsyncCall

import io.grpc.Channel; //导入方法依赖的package包/类
protected static <T, V> ListenableFuture<V> listenableAsyncCall(
    Channel channel,
    MethodDescriptor<T, V> method, T request) {
  Call<T, V> call = channel.newCall(method);
  AsyncUnaryOperationObserver<V> observer = new AsyncUnaryOperationObserver<>();
  Calls.asyncUnaryCall(call, request, observer);
  return observer.getCompletionFuture();
}
 
开发者ID:dmmcerlean,项目名称:cloud-bigtable-client,代码行数:9,代码来源:BigtableGrpcClient.java

示例15: interceptCall

import io.grpc.Channel; //导入方法依赖的package包/类
@Override
public <RequestT, ResponseT> ClientCall<RequestT, ResponseT> interceptCall(
    MethodDescriptor<RequestT, ResponseT> method, CallOptions callOptions, Channel next) {
  assertThat(callOptions.getCredentials()).isEqualTo(credentials);
  // Remove the call credentials to allow testing with dummy ones.
  return next.newCall(method, callOptions.withCallCredentials(null));
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:8,代码来源:GrpcRemoteCacheTest.java


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