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


Java MethodDescriptor类代码示例

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


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

示例1: startServer

import io.grpc.MethodDescriptor; //导入依赖的package包/类
@BeforeClass
public static void startServer() throws IOException {
    AfricasTalking.initialize(Fixtures.USERNAME, Fixtures.API_KEY);
    server = new Server(new Authenticator() {
        @Override
        public boolean authenticate(String client) {
            return client.compareToIgnoreCase(TEST_CLIENT_ID) == 0;
        }
    });
    server.addSipCredentials("test", "secret", "sip://at.dev");
    server.start(certFile, privateKeyFile, TEST_PORT);
    
    ManagedChannel ch = NettyChannelBuilder.forAddress("localhost", TEST_PORT)
        .sslContext(GrpcSslContexts.forClient().trustManager(certFile).build())
        .build();

        
    client = SdkServerServiceGrpc.newBlockingStub(ch)
        .withCallCredentials(new CallCredentials(){
            @Override
            public void applyRequestMetadata(MethodDescriptor<?, ?> method, Attributes attrs, Executor appExecutor,
                    final MetadataApplier applier) {
                        appExecutor.execute(new Runnable(){
                            @Override
                            public void run() {
                                try {
                                    Metadata headers = new Metadata();
                                    Metadata.Key<String> clientIdKey = Metadata.Key.of("X-Client-Id", Metadata.ASCII_STRING_MARSHALLER);
                                    headers.put(clientIdKey, TEST_CLIENT_ID);
                                    applier.apply(headers);
                                } catch(Throwable ex) {
                                    applier.fail(Status.UNAUTHENTICATED.withCause(ex));
                                }
                            }
                        });
                
            }
        });
}
 
开发者ID:aksalj,项目名称:africastalking-java,代码行数:40,代码来源:ATServerTest.java

示例2: interceptCall

import io.grpc.MethodDescriptor; //导入依赖的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: callWithRetry

import io.grpc.MethodDescriptor; //导入依赖的package包/类
protected <ReqT, RespT> RespT callWithRetry(MethodDescriptor<ReqT, RespT> method,
                                            Supplier<ReqT> requestFactory,
                                            ErrorHandler<RespT> handler) {
  if (logger.isTraceEnabled()) {
    logger.trace(String.format("Calling %s...", method.getFullMethodName()));
  }
  RetryPolicy.Builder<RespT> builder = new Builder<>(conf.getRetryTimes(), conf.getBackOffClass());
  RespT resp =
      builder.create(handler)
          .callWithRetry(
              () -> {
                BlockingStubT stub = getBlockingStub();
                return ClientCalls.blockingUnaryCall(
                    stub.getChannel(), method, stub.getCallOptions(), requestFactory.get());
              },
              method.getFullMethodName());
  if (logger.isTraceEnabled()) {
    logger.trace(String.format("leaving %s...", method.getFullMethodName()));
  }
  return resp;
}
 
开发者ID:pingcap,项目名称:tikv-client-lib-java,代码行数:22,代码来源:AbstractGRPCClient.java

示例4: callAsyncWithRetry

import io.grpc.MethodDescriptor; //导入依赖的package包/类
protected <ReqT, RespT> void callAsyncWithRetry(
    MethodDescriptor<ReqT, RespT> method,
    Supplier<ReqT> requestFactory,
    StreamObserver<RespT> responseObserver,
    ErrorHandler<RespT> handler) {
  logger.debug(String.format("Calling %s...", method.getFullMethodName()));

  RetryPolicy.Builder<RespT> builder = new Builder<>(conf.getRetryTimes(), conf.getBackOffClass());
  builder.create(handler)
      .callWithRetry(
          () -> {
            StubT stub = getAsyncStub();
            ClientCalls.asyncUnaryCall(
                stub.getChannel().newCall(method, stub.getCallOptions()),
                requestFactory.get(),
                responseObserver);
            return null;
          },
          method.getFullMethodName());
  logger.debug(String.format("leaving %s...", method.getFullMethodName()));
}
 
开发者ID:pingcap,项目名称:tikv-client-lib-java,代码行数:22,代码来源:AbstractGRPCClient.java

示例5: callBidiStreamingWithRetry

import io.grpc.MethodDescriptor; //导入依赖的package包/类
<ReqT, RespT> StreamObserver<ReqT> callBidiStreamingWithRetry(
    MethodDescriptor<ReqT, RespT> method,
    StreamObserver<RespT> responseObserver,
    ErrorHandler<StreamObserver<ReqT>> handler) {
  logger.debug(String.format("Calling %s...", method.getFullMethodName()));

  RetryPolicy.Builder<StreamObserver<ReqT>> builder = new Builder<>(conf.getRetryTimes(), conf.getBackOffClass());
  StreamObserver<ReqT> observer =
      builder.create(handler)
          .callWithRetry(
              () -> {
                StubT stub = getAsyncStub();
                return asyncBidiStreamingCall(
                    stub.getChannel().newCall(method, stub.getCallOptions()), responseObserver);
              },
              method.getFullMethodName());
  logger.debug(String.format("leaving %s...", method.getFullMethodName()));
  return observer;
}
 
开发者ID:pingcap,项目名称:tikv-client-lib-java,代码行数:20,代码来源:AbstractGRPCClient.java

示例6: callServerStreamingWithRetry

import io.grpc.MethodDescriptor; //导入依赖的package包/类
protected <ReqT, RespT> StreamingResponse callServerStreamingWithRetry(
    MethodDescriptor<ReqT, RespT> method,
    Supplier<ReqT> requestFactory,
    ErrorHandler<StreamingResponse> handler) {
  logger.debug(String.format("Calling %s...", method.getFullMethodName()));

  RetryPolicy.Builder<StreamingResponse> builder =
      new Builder<>(conf.getRetryTimes(), conf.getBackOffClass());
  StreamingResponse response =
      builder.create(handler)
          .callWithRetry(
              () -> {
                BlockingStubT stub = getBlockingStub();
                return new StreamingResponse(
                    blockingServerStreamingCall(
                        stub.getChannel(),
                        method,
                        stub.getCallOptions(),
                        requestFactory.get()
                    )
                );
              },
              method.getFullMethodName());
  logger.debug(String.format("leaving %s...", method.getFullMethodName()));
  return response;
}
 
开发者ID:pingcap,项目名称:tikv-client-lib-java,代码行数:27,代码来源:AbstractGRPCClient.java

示例7: interceptCall

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

示例8: interceptCall

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

示例9: newCall

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

示例10: UnaryCallRetryInterceptor

import io.grpc.MethodDescriptor; //导入依赖的package包/类
public UnaryCallRetryInterceptor(
    Channel delegate,
    ScheduledExecutorService executorService,
    Set<MethodDescriptor<?, ?>> retriableMethods,
    int initialBackoffMillis,
    double backoffMultiplier,
    int maxElapsedBackoffMillis) {
  this(
      delegate,
      executorService,
      Maps.asMap(retriableMethods, new Function<MethodDescriptor<?, ?>, Predicate<?>>() {
        @Override
        public Predicate<Object> apply(MethodDescriptor<?, ?> methodDescriptor) {
          return Predicates.alwaysTrue();
        }
      }),
      initialBackoffMillis,
      backoffMultiplier,
      maxElapsedBackoffMillis);
}
 
开发者ID:dmmcerlean,项目名称:cloud-bigtable-client,代码行数:21,代码来源:UnaryCallRetryInterceptor.java

示例11: newCall

import io.grpc.MethodDescriptor; //导入依赖的package包/类
@Override
public <ReqT, RespT> Call<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> methodDescriptor) {
  if (methodCanBeRetried(methodDescriptor)) {
    ExponentialBackOff.Builder backOffBuilder = new ExponentialBackOff.Builder();
    backOffBuilder.setInitialIntervalMillis(initialBackoffMillis);
    backOffBuilder.setMultiplier(backoffMultiplier);
    backOffBuilder.setMaxElapsedTimeMillis(maxElapsedBackoffMillis);
    Predicate<ReqT> isPayloadRetriablePredicate = getUncheckedPredicate(methodDescriptor);
    return new RetryingCall<>(
        delegate,
        methodDescriptor,
        isPayloadRetriablePredicate,
        executorService,
        backOffBuilder.build());
  }
  return delegate.newCall(methodDescriptor);
}
 
开发者ID:dmmcerlean,项目名称:cloud-bigtable-client,代码行数:18,代码来源:UnaryCallRetryInterceptor.java

示例12: createCloseableChannel

import io.grpc.MethodDescriptor; //导入依赖的package包/类
private static CloseableChannel createCloseableChannel(TransportOptions transportOptions,
    ExecutorService executor){
  final ChannelImpl channelImpl = createChannel(transportOptions, executor);
  return new CloseableChannel() {
    @Override
    public <RequestT, ResponseT> Call<RequestT, ResponseT> newCall(
        MethodDescriptor<RequestT, ResponseT> methodDescriptor) {
      return channelImpl.newCall(methodDescriptor);
    }
    
    @Override
    public void close() throws IOException {
      channelImpl.shutdown();
      while (!channelImpl.isTerminated()) {
        try {
          channelImpl.awaitTerminated(CHANNEL_TERMINATE_WAIT_SECONDS, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
          Thread.interrupted();
          throw new IOException("Interrupted while sleeping for close", e);
        }
      }
    }
  }; 
}
 
开发者ID:dmmcerlean,项目名称:cloud-bigtable-client,代码行数:25,代码来源:BigtableChannels.java

示例13: interceptCall

import io.grpc.MethodDescriptor; //导入依赖的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.MethodDescriptor; //导入依赖的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: beforeMethod

import io.grpc.MethodDescriptor; //导入依赖的package包/类
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    GRPCDynamicFields cachedObjects = (GRPCDynamicFields)objInst.getSkyWalkingDynamicField();
    Metadata headers = cachedObjects.getMetadata();
    Map<String, String> headerMap = new HashMap<String, String>();
    for (String key : headers.keys()) {
        if (!key.endsWith(Metadata.BINARY_HEADER_SUFFIX)) {
            String value = headers.get(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER));
            headerMap.put(key, value);
        }
    }

    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        String contextValue = headerMap.get(next.getHeadKey());
        if (!StringUtil.isEmpty(contextValue)) {
            next.setHeadValue(contextValue);
        }
    }

    final AbstractSpan span = ContextManager.createEntrySpan(cachedObjects.getRequestMethodName() + (cachedObjects.getMethodType() != MethodDescriptor.MethodType.UNARY ? STREAM_CALL_OPERATION_NAME_SUFFIX : BLOCK_CALL_OPERATION_NAME_SUFFIX), contextCarrier);
    span.setComponent(ComponentsDefine.GRPC);
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:27,代码来源:ServerCallOnReadyInterceptor.java


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