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


Java ServiceDescriptor类代码示例

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


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

示例1: listServices

import com.google.protobuf.Descriptors.ServiceDescriptor; //导入依赖的package包/类
/** Lists the GRPC services - filtered by service name (contains) or method name (contains) */
public static void listServices(
    Output output,
    FileDescriptorSet fileDescriptorSet,
    String protoDiscoveryRoot,
    Optional<String> serviceFilter,
    Optional<String> methodFilter,
    Optional<Boolean> withMessage) {

  ServiceResolver serviceResolver = ServiceResolver.fromFileDescriptorSet(fileDescriptorSet);

  // Add white-space before the rendered output
  output.newLine();

  for (ServiceDescriptor descriptor : serviceResolver.listServices()) {
    boolean matchingDescriptor =
        !serviceFilter.isPresent()
        || descriptor.getFullName().toLowerCase().contains(serviceFilter.get().toLowerCase());

    if (matchingDescriptor) {
      listMethods(output, protoDiscoveryRoot, descriptor, methodFilter, withMessage);
    }
  }
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:25,代码来源:ServiceList.java

示例2: registerGpbMsgDesc

import com.google.protobuf.Descriptors.ServiceDescriptor; //导入依赖的package包/类
public void registerGpbMsgDesc(FileDescriptor fileDescriptor) {
    if (fileDescriptor == null) return;
    //  service
    for (ServiceDescriptor service : fileDescriptor.getServices()) {
        for (MethodDescriptor method : service.getMethods()) {
            if (gpbMsgDescMap.containsKey(method.getName())) {
                LOG.error("[Gpb] the method [" + method.getName() + "] already registered.");
            }
            registerGpbMessage(method.getInputType());
            methodInputTypeMap.put(method.getName(), method.getInputType().getName());
        }
    }
    //  message
    for (Descriptor descriptor : fileDescriptor.getMessageTypes()) {
        registerGpbMessage(descriptor);
    }
}
 
开发者ID:ogcs,项目名称:Okra-Ax,代码行数:18,代码来源:GpbMessageContext.java

示例3: processService

import com.google.protobuf.Descriptors.ServiceDescriptor; //导入依赖的package包/类
private void processService(ServiceDescriptor service, FileDescriptor fd) {
  String serviceName = service.getFullName();
  checkState(
      !fileDescriptorsBySymbol.containsKey(serviceName),
      "Service already defined: %s",
      serviceName);
  fileDescriptorsBySymbol.put(serviceName, fd);
  for (MethodDescriptor method : service.getMethods()) {
    String methodName = method.getFullName();
    checkState(
        !fileDescriptorsBySymbol.containsKey(methodName),
        "Method already defined: %s",
        methodName);
    fileDescriptorsBySymbol.put(methodName, fd);
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:17,代码来源:ProtoReflectionService.java

示例4: testServiceDescriptor

import com.google.protobuf.Descriptors.ServiceDescriptor; //导入依赖的package包/类
public void testServiceDescriptor() throws Exception {
  ServiceDescriptor service = TestService.getDescriptor();

  assertEquals("TestService", service.getName());
  assertEquals("protobuf_unittest.TestService", service.getFullName());
  assertEquals(UnittestProto.getDescriptor(), service.getFile());

  assertEquals(2, service.getMethods().size());

  MethodDescriptor fooMethod = service.getMethods().get(0);
  assertEquals("Foo", fooMethod.getName());
  assertEquals(UnittestProto.FooRequest.getDescriptor(),
               fooMethod.getInputType());
  assertEquals(UnittestProto.FooResponse.getDescriptor(),
               fooMethod.getOutputType());
  assertEquals(fooMethod, service.findMethodByName("Foo"));

  MethodDescriptor barMethod = service.getMethods().get(1);
  assertEquals("Bar", barMethod.getName());
  assertEquals(UnittestProto.BarRequest.getDescriptor(),
               barMethod.getInputType());
  assertEquals(UnittestProto.BarResponse.getDescriptor(),
               barMethod.getOutputType());
  assertEquals(barMethod, service.findMethodByName("Bar"));

  assertNull(service.findMethodByName("NoSuchMethod"));

  for (int i = 0; i < service.getMethods().size(); i++) {
    assertEquals(i, service.getMethods().get(i).getIndex());
  }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:32,代码来源:DescriptorsTest.java

示例5: getMethod

import com.google.protobuf.Descriptors.ServiceDescriptor; //导入依赖的package包/类
/**
 * Get matching method.
 */
public MethodDescriptor getMethod(String methodName, ServiceDescriptor descriptor) throws MethodNotFoundException {
    MethodDescriptor method = descriptor.findMethodByName(methodName);
    if (method == null) {
        throw new MethodNotFoundException(
                String.format("Could not find method %s in service %s", methodName, descriptor.getFullName())
        );
    }
    return method;
}
 
开发者ID:kevin-xu-158,项目名称:JavaNRPC,代码行数:13,代码来源:NrpcServiceRegistry.java

示例6: listServices

import com.google.protobuf.Descriptors.ServiceDescriptor; //导入依赖的package包/类
/** Lists all of the services found in the file descriptors */
public Iterable<ServiceDescriptor> listServices() {
  ArrayList<ServiceDescriptor> serviceDescriptors = new ArrayList<ServiceDescriptor>(); 
  for (FileDescriptor fileDescriptor: fileDescriptors) {
    serviceDescriptors.addAll(fileDescriptor.getServices());
  }
  return serviceDescriptors;
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:9,代码来源:ServiceResolver.java

示例7: resolveServiceMethod

import com.google.protobuf.Descriptors.ServiceDescriptor; //导入依赖的package包/类
private MethodDescriptor resolveServiceMethod(
    String serviceName, String methodName, String packageName) {
  ServiceDescriptor service = findService(serviceName, packageName);
  MethodDescriptor method = service.findMethodByName(methodName);
  if (method == null) {
    throw new IllegalArgumentException(
        "Unable to find method " + methodName + " in service " + serviceName);
  }
  return method;
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:11,代码来源:ServiceResolver.java

示例8: findService

import com.google.protobuf.Descriptors.ServiceDescriptor; //导入依赖的package包/类
private ServiceDescriptor findService(String serviceName, String packageName) {
  // TODO(dino): Consider creating an index.
  for (FileDescriptor fileDescriptor : fileDescriptors) {
    if (!fileDescriptor.getPackage().equals(packageName)) {
      // Package does not match this file, ignore.
      continue;
    }

    ServiceDescriptor serviceDescriptor = fileDescriptor.findServiceByName(serviceName);
    if (serviceDescriptor != null) {
      return serviceDescriptor;
    }
  }
  throw new IllegalArgumentException("Unable to find service with name: " + serviceName);
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:16,代码来源:ServiceResolver.java

示例9: listMethods

import com.google.protobuf.Descriptors.ServiceDescriptor; //导入依赖的package包/类
/** Lists the methods on the service (the methodFilter will be applied if non-empty)  */
private static void listMethods(
    Output output,
    String protoDiscoveryRoot,
    ServiceDescriptor descriptor,
    Optional<String> methodFilter,
    Optional<Boolean> withMessage) {

  boolean printedService = false;

  // Due to the way the protos are discovered, the leaf directly of the  protoDiscoveryRoot
  // is the same as the root directory as the proto file
  File protoDiscoveryDir = new File(protoDiscoveryRoot).getParentFile();

  for (MethodDescriptor method : descriptor.getMethods()) {
    if (!methodFilter.isPresent() || method.getName().contains(methodFilter.get())) {

      // Only print the service name once - and only if a method is going to be printed
      if (!printedService) {
        File pFile = new File(protoDiscoveryDir, descriptor.getFile().getName());
        output.writeLine(descriptor.getFullName() + " -> " + pFile.getAbsolutePath());
        printedService = true;
      }

      output.writeLine("  " + descriptor.getFullName() + "/" + method.getName());

      // If requested, add the message definition
      if (withMessage.isPresent() && withMessage.get()) {
        output.writeLine(renderDescriptor(method.getInputType(), "  "));
        output.newLine();
      }
    }
  }

  if (printedService) {
    output.newLine();
  }
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:39,代码来源:ServiceList.java

示例10: getMethod

import com.google.protobuf.Descriptors.ServiceDescriptor; //导入依赖的package包/类
/**
 * Get matching method.
 */
private MethodDescriptor getMethod(SocketRpcProtos.Request rpcRequest,
    ServiceDescriptor descriptor) throws RpcException {
  MethodDescriptor method = descriptor.findMethodByName(
      rpcRequest.getMethodName());
  if (method == null) {
    throw new RpcException(
        ErrorReason.METHOD_NOT_FOUND,
        String.format("Could not find method %s in service %s",
            rpcRequest.getMethodName(), descriptor.getFullName()),
        null);
  }
  return method;
}
 
开发者ID:sdeo,项目名称:protobuf-socket-rpc,代码行数:17,代码来源:RpcForwarder.java

示例11: testServiceDescriptor

import com.google.protobuf.Descriptors.ServiceDescriptor; //导入依赖的package包/类
public void testServiceDescriptor() throws Exception {
  ServiceDescriptor service = TestService.getDescriptor();

  assertEquals("TestService", service.getName());
  assertEquals("protobuf_unittest.TestService", service.getFullName());
  assertEquals(UnittestProto.getDescriptor(), service.getFile());


  MethodDescriptor fooMethod = service.getMethods().get(0);
  assertEquals("Foo", fooMethod.getName());
  assertEquals(UnittestProto.FooRequest.getDescriptor(),
               fooMethod.getInputType());
  assertEquals(UnittestProto.FooResponse.getDescriptor(),
               fooMethod.getOutputType());
  assertEquals(fooMethod, service.findMethodByName("Foo"));

  MethodDescriptor barMethod = service.getMethods().get(1);
  assertEquals("Bar", barMethod.getName());
  assertEquals(UnittestProto.BarRequest.getDescriptor(),
               barMethod.getInputType());
  assertEquals(UnittestProto.BarResponse.getDescriptor(),
               barMethod.getOutputType());
  assertEquals(barMethod, service.findMethodByName("Bar"));

  assertNull(service.findMethodByName("NoSuchMethod"));

  for (int i = 0; i < service.getMethods().size(); i++) {
    assertEquals(i, service.getMethods().get(i).getIndex());
  }
}
 
开发者ID:Microsoft,项目名称:vsminecraft,代码行数:31,代码来源:DescriptorsTest.java

示例12: getServiceName

import com.google.protobuf.Descriptors.ServiceDescriptor; //导入依赖的package包/类
/**
 * Returns the name to use for coprocessor service calls.  For core HBase services
 * (in the hbase.pb protobuf package), this returns the unqualified name in order to provide
 * backward compatibility across the package name change.  For all other services,
 * the fully-qualified service name is used.
 */
public static String getServiceName(Descriptors.ServiceDescriptor service) {
  if (service.getFullName().startsWith(hbaseServicePackage)) {
    return service.getName();
  }
  return service.getFullName();
}
 
开发者ID:apache,项目名称:hbase,代码行数:13,代码来源:CoprocessorRpcUtils.java

示例13: getMethodDescriptor

import com.google.protobuf.Descriptors.ServiceDescriptor; //导入依赖的package包/类
public static MethodDescriptor getMethodDescriptor(final String methodName,
    final ServiceDescriptor serviceDesc)
throws UnknownProtocolException {
  Descriptors.MethodDescriptor methodDesc = serviceDesc.findMethodByName(methodName);
  if (methodDesc == null) {
    throw new UnknownProtocolException("Unknown method " + methodName + " called on service " +
        serviceDesc.getFullName());
  }
  return methodDesc;
}
 
开发者ID:apache,项目名称:hbase,代码行数:11,代码来源:CoprocessorRpcUtils.java

示例14: makeCanonicalService

import com.google.protobuf.Descriptors.ServiceDescriptor; //导入依赖的package包/类
private void makeCanonicalService(final ServiceDescriptorProto.Builder service,
    final ServiceDescriptor serviceDescriptor) {
  for (final MethodDescriptorProto.Builder method : service.getMethodBuilderList()) {
    final MethodDescriptor methodDescriptor =
        serviceDescriptor.findMethodByName(method.getName());
    method.setInputType(ensureLeadingDot(methodDescriptor.getInputType().getFullName()));
    method.setOutputType(ensureLeadingDot(methodDescriptor.getOutputType().getFullName()));
  }
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:10,代码来源:FileDescriptors.java

示例15: updateIndexIfNecessary

import com.google.protobuf.Descriptors.ServiceDescriptor; //导入依赖的package包/类
/**
 * Checks for updates to the server's mutable services and updates the index if any changes are
 * detected. A change is any addition or removal in the set of file descriptors attached to the
 * mutable services or a change in the service names.
 *
 * @return The (potentially updated) index.
 */
private ServerReflectionIndex updateIndexIfNecessary() {
  synchronized (lock) {
    if (serverReflectionIndex == null) {
      serverReflectionIndex =
          new ServerReflectionIndex(server.getImmutableServices(), server.getMutableServices());
      return serverReflectionIndex;
    }

    Set<FileDescriptor> serverFileDescriptors = new HashSet<FileDescriptor>();
    Set<String> serverServiceNames = new HashSet<String>();
    List<ServerServiceDefinition> serverMutableServices = server.getMutableServices();
    for (ServerServiceDefinition mutableService : serverMutableServices) {
      io.grpc.ServiceDescriptor serviceDescriptor = mutableService.getServiceDescriptor();
      if (serviceDescriptor.getSchemaDescriptor() instanceof ProtoFileDescriptorSupplier) {
        String serviceName = serviceDescriptor.getName();
        FileDescriptor fileDescriptor =
            ((ProtoFileDescriptorSupplier) serviceDescriptor.getSchemaDescriptor())
                .getFileDescriptor();
        serverFileDescriptors.add(fileDescriptor);
        serverServiceNames.add(serviceName);
      }
    }

    // Replace the index if the underlying mutable services have changed. Check both the file
    // descriptors and the service names, because one file descriptor can define multiple
    // services.
    FileDescriptorIndex mutableServicesIndex = serverReflectionIndex.getMutableServicesIndex();
    if (!mutableServicesIndex.getServiceFileDescriptors().equals(serverFileDescriptors)
        || !mutableServicesIndex.getServiceNames().equals(serverServiceNames)) {
      serverReflectionIndex =
          new ServerReflectionIndex(server.getImmutableServices(), serverMutableServices);
    }

    return serverReflectionIndex;
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:44,代码来源:ProtoReflectionService.java


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