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


Java AbstractStub类代码示例

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


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

示例1: buildProtoClient

import io.grpc.stub.AbstractStub; //导入依赖的package包/类
@SuppressWarnings({"rawtypes", "unchecked"})
private GrpcProtocolClient<Object> buildProtoClient(GrpcURL refUrl) {
  boolean isGeneric = refUrl.getParameter(Constants.GENERIC_KEY, Boolean.FALSE);
  boolean isGrpcStub = refUrl.getParameter(Constants.GRPC_STUB_KEY, Boolean.FALSE);
  if (isGeneric) {
    return new GenericProxyClient<Object>(refUrl);
  } else {
    if (isGrpcStub) {
      String stubClassName = refUrl.getParameter(Constants.INTERFACECLASS_KEY);
      try {
        Class<? extends AbstractStub> stubClass =
            (Class<? extends AbstractStub>) ReflectUtils.name2class(stubClassName);
        return new GrpcStubClient<Object>(stubClass, refUrl);
      } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException("grpc stub client the class must exist in classpath",
            e);
      }
    } else {
      return new DefaultProxyClient<Object>(refUrl);
    }
  }
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:23,代码来源:GrpcClientStrategy.java

示例2: withNewChannel

import io.grpc.stub.AbstractStub; //导入依赖的package包/类
<T extends AbstractStub<T>, R> CompletableFuture<R> withNewChannel(
    String endpoint,
    Function<ManagedChannel, T> stubCustomizer,
    Function<T, CompletableFuture<R>> stubConsumer) {

  final ManagedChannel channel = defaultChannelBuilder()
      .nameResolverFactory(
          forEndpoints(
              Optional.ofNullable(builder.authority()).orElse("etcd"),
              Collections.singleton(endpoint),
              Optional.ofNullable(builder.uriResolverLoader())
                  .orElseGet(URIResolverLoader::defaultLoader)
          )
      ).build();

  try {
    T stub = stubCustomizer.apply(channel);

    return stubConsumer.apply(stub).whenComplete(
        (r, t) -> channel.shutdown()
    );
  } catch (Exception e) {
    channel.shutdown();
    throw EtcdExceptionFactory.toEtcdException(e);
  }
}
 
开发者ID:coreos,项目名称:jetcd,代码行数:27,代码来源:ClientConnectionManager.java

示例3: addConnection

import io.grpc.stub.AbstractStub; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void addConnection(ServiceType serviceType, String host, int port) {
    ManagedChannel channel = NettyChannelBuilder.forAddress(host, port)
            .negotiationType(NegotiationType.PLAINTEXT) // TODO: gRPC encryption
            .keepAliveTime(1, TimeUnit.MINUTES)
            .keepAliveTimeout(5, TimeUnit.SECONDS)
            .directExecutor()
            .channelType(EpollSocketChannel.class)
            .eventLoopGroup(new EpollEventLoopGroup())
            .build();

    AbstractStub blocking;
    AbstractStub async;

    switch (serviceType) {
        case WORLD: {
            blocking = WorldServiceGrpc.newBlockingStub(channel);
            async = WorldServiceGrpc.newStub(channel);
            break;
        }
        case PLUGIN_MANAGER: {
            blocking = PluginManagerGrpc.newBlockingStub(channel);
            async = PluginManagerGrpc.newStub(channel);
            break;
        }
        default: {
            throw new RuntimeException("Service type not handled: " + serviceType.name());
        }
    }

    ServiceConnection connection = ServiceConnection.builder()
            .channel(channel)
            .blockingStub(blocking)
            .asyncStub(async)
            .build();

    this.connections.put(serviceType, connection);
}
 
开发者ID:JungleTree,项目名称:JungleTree,代码行数:40,代码来源:JungleConnectorGrpcClient.java

示例4: isGrpcStubClient

import io.grpc.stub.AbstractStub; //导入依赖的package包/类
private boolean isGrpcStubClient(Class<?> referenceClass) {
  if (AbstractStub.class.isAssignableFrom(referenceClass)) {
    return true;
  } else {
    return false;
  }
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:8,代码来源:GrpcReferenceRunner.java

示例5: getRemotingService

import io.grpc.stub.AbstractStub; //导入依赖的package包/类
/**
 * Get remoting service instance for client invocation.
 * @param <T> T
 * @param type the type of expected service instance
 * @return the instance of AbstractStub.
 */
public <T extends AbstractStub<T>> T getRemotingService(Class<T> type) {
  checkArgument(type != null, "Param cannot be null!");
  checkState(channel != null, "Channel has not been initialized.");
  T service = null;
  try {
    Constructor<T> constructor = type.getDeclaredConstructor(Channel.class);
    constructor.setAccessible(true);
    service = constructor.newInstance(getChannel()).withDeadlineAfter(defaultTimeout, TimeUnit.MILLISECONDS);     
  } catch (Exception ex) {
    throw new RpcClientException("Get remoting service '" + type.getName() + "' error happend", ex);
  }
  return service;
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:20,代码来源:GrpcTestClient.java

示例6: clientBuilderParams

import io.grpc.stub.AbstractStub; //导入依赖的package包/类
@Override
public <T> Optional<ClientBuilderParams> clientBuilderParams(T client) {
    if (!(client instanceof AbstractStub)) {
        return Optional.empty();
    }
    AbstractStub<?> stub = (AbstractStub<?>) client;
    if (!(stub.getChannel() instanceof ArmeriaChannel)) {
        return Optional.empty();
    }
    return Optional.of((ClientBuilderParams) stub.getChannel());
}
 
开发者ID:line,项目名称:armeria,代码行数:12,代码来源:GrpcClientFactory.java

示例7: getRemotingService

import io.grpc.stub.AbstractStub; //导入依赖的package包/类
/**
 * Get remoting service instance for client invocation.
 * 
 * @param type the type of expected service instance
 * @param timeout (millisecond) specify the remoting call will be expired at the specified offset 
 * @return T the instance of T.
 */
@Override
public AbstractStub<?> getRemotingService(Class<? extends AbstractStub<?>> type, String preferredZone, boolean usedTls, int timeout) {
  checkArgument(type != null, "The type of service interface cannot be null!");
  checkState(state.get() == State.STARTED, "Grpc client is not started!");
  AbstractStub<?> service;
  Method stubInitializationMethod;
  try {
    //The basic idea of instantiating grpc client stub:
    //  Class stubClazz = ***Stub.class (parameter pass in - Class<? extends AbstractStub<?>> type);
    //  Class grpcClazz = stubClazz.getEnclosingClass();
    //  Field serviceNameFiled = grpcClazz.getDeclaredField("SERVICE_NAME");
    //  String value = (String) serviceNameFiled.get(null);
    
    //E.g. public static final String SERVICE_NAME = "routeguide.RouteGuide";
    String serviceName = type.getEnclosingClass().getDeclaredField(GrpcConstants.SERVICE_NAME).get(null).toString();      
    if (!STUBS.containsKey(type.getName())) {
      // Instantiate the generated gRPC class.
      if (type.getName().endsWith(GrpcConstants.CLIENT_STUB_SUFFIX_BLOCKING)) {
        stubInitializationMethod = type.getEnclosingClass().getMethod(GrpcConstants.NEW_CLIENT_BLOCKING_STUB, Channel.class);
      } else if (type.getName().endsWith(GrpcConstants.CLIENT_STUB_SUFFIX_FUTURE)) {
        stubInitializationMethod = type.getEnclosingClass().getMethod(GrpcConstants.NEW_CLIENT_FUTURE_STUB, Channel.class);
      } else {
        stubInitializationMethod = type.getEnclosingClass().getMethod(GrpcConstants.NEW_CLIENT_ASYN_STUB, Channel.class);
      }
      STUBS.putIfAbsent(type.getName(), stubInitializationMethod);
    } else {
      stubInitializationMethod = STUBS.get(type.getName());
    }
    // instantiate the client stub according to the stub type
    service = (AbstractStub<?>) stubInitializationMethod.invoke(null, initializer.getChannelPool().getChannel(serviceName, preferredZone, usedTls));
    //Customizes the CallOptions passed the deadline to interceptor
    if (timeout > 0) {
       service.withOption(StubDeadlineClientInterceptor.DEADLINE_KEY, Integer.valueOf(timeout));
    }

  } catch (Exception ex) {
    log.error("Get remoting service '{}' error happend", type.getName(), ex);
    throw new RpcClientException(ex);
  }
  return service;
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:49,代码来源:GrpcClient.java

示例8: getRpcClient

import io.grpc.stub.AbstractStub; //导入依赖的package包/类
@Override
public RpcClient<? extends AbstractStub<?>> getRpcClient() {

  return GrpcClient.getInstance();
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:6,代码来源:GrpcClientProvider.java

示例9: withCallCredentials

import io.grpc.stub.AbstractStub; //导入依赖的package包/类
private static <T extends AbstractStub<T>> T withCallCredentials(
    T stub, @Nullable CallCredentials callCredentials) {
  stub = callCredentials != null ? stub.withCallCredentials(callCredentials) : stub;
  return stub;
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:6,代码来源:BuildEventServiceGrpcClient.java

示例10: newStub

import io.grpc.stub.AbstractStub; //导入依赖的package包/类
/**
 * create stub with saved channel.
 *
 * @param supplier the stub supplier
 * @param <T> the type of stub
 * @return the attached stub
 */
<T extends AbstractStub<T>> T newStub(Function<ManagedChannel, T> supplier) {
  return supplier.apply(getChannel());
}
 
开发者ID:coreos,项目名称:jetcd,代码行数:11,代码来源:ClientConnectionManager.java

示例11: getRemotingService

import io.grpc.stub.AbstractStub; //导入依赖的package包/类
/**
 * Get remoting service instance for client invocation.
 * @param <T> T
 * @param type the type of expected service instance
 * @return the instance of AbstractStub.
 */
public <T extends AbstractStub<T>> T getRemotingService(Class<T> type) {

  return ServiceTestResource.client.getRemotingService(type);
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:11,代码来源:BaseServiceApiTest.java


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