本文整理汇总了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);
}
}
}
示例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);
}
}
示例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);
}
}
示例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());
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
}
示例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;
}
示例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());
}
}
示例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();
}
示例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;
}
示例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()));
}
}
示例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;
}
}