本文整理汇总了Java中com.google.protobuf.Descriptors.ServiceDescriptor.findMethodByName方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceDescriptor.findMethodByName方法的具体用法?Java ServiceDescriptor.findMethodByName怎么用?Java ServiceDescriptor.findMethodByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.Descriptors.ServiceDescriptor
的用法示例。
在下文中一共展示了ServiceDescriptor.findMethodByName方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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()));
}
}
示例6: create
import com.google.protobuf.Descriptors.ServiceDescriptor; //导入方法依赖的package包/类
public static <RequestT extends Message, ResponseT extends Message> RpcMethod<RequestT, ResponseT> create(
ServiceDescriptor descriptor, String methodName, RequestT requestDefaultInstance,
ResponseT responseDefaultInstance) {
MethodDescriptor method = descriptor.findMethodByName(methodName);
Preconditions.checkArgument(method != null);
Preconditions.checkArgument(requestDefaultInstance.getDescriptorForType() == method.getInputType());
Preconditions.checkArgument(responseDefaultInstance.getDescriptorForType() == method.getOutputType());
return new RpcMethod<RequestT, ResponseT>(method, responseDefaultInstance);
}
示例7: testCustomOptions
import com.google.protobuf.Descriptors.ServiceDescriptor; //导入方法依赖的package包/类
public void testCustomOptions() throws Exception {
Descriptor descriptor =
UnittestCustomOptions.TestMessageWithCustomOptions.getDescriptor();
assertTrue(
descriptor.getOptions().hasExtension(UnittestCustomOptions.messageOpt1));
assertEquals(Integer.valueOf(-56),
descriptor.getOptions().getExtension(UnittestCustomOptions.messageOpt1));
FieldDescriptor field = descriptor.findFieldByName("field1");
assertNotNull(field);
assertTrue(
field.getOptions().hasExtension(UnittestCustomOptions.fieldOpt1));
assertEquals(Long.valueOf(8765432109L),
field.getOptions().getExtension(UnittestCustomOptions.fieldOpt1));
EnumDescriptor enumType =
UnittestCustomOptions.TestMessageWithCustomOptions.AnEnum.getDescriptor();
assertTrue(
enumType.getOptions().hasExtension(UnittestCustomOptions.enumOpt1));
assertEquals(Integer.valueOf(-789),
enumType.getOptions().getExtension(UnittestCustomOptions.enumOpt1));
ServiceDescriptor service =
UnittestCustomOptions.TestServiceWithCustomOptions.getDescriptor();
assertTrue(
service.getOptions().hasExtension(UnittestCustomOptions.serviceOpt1));
assertEquals(Long.valueOf(-9876543210L),
service.getOptions().getExtension(UnittestCustomOptions.serviceOpt1));
MethodDescriptor method = service.findMethodByName("Foo");
assertNotNull(method);
assertTrue(
method.getOptions().hasExtension(UnittestCustomOptions.methodOpt1));
assertEquals(UnittestCustomOptions.MethodOpt1.METHODOPT1_VAL2,
method.getOptions().getExtension(UnittestCustomOptions.methodOpt1));
}
示例8: testCustomOptions
import com.google.protobuf.Descriptors.ServiceDescriptor; //导入方法依赖的package包/类
public void testCustomOptions() throws Exception {
// Get the descriptor indirectly from a dependent proto class. This is to
// ensure that when a proto class is loaded, custom options defined in its
// dependencies are also properly initialized.
Descriptor descriptor =
TestCustomOptions.TestMessageWithCustomOptionsContainer.getDescriptor()
.findFieldByName("field").getMessageType();
assertTrue(
descriptor.getOptions().hasExtension(UnittestCustomOptions.messageOpt1));
assertEquals(Integer.valueOf(-56),
descriptor.getOptions().getExtension(UnittestCustomOptions.messageOpt1));
FieldDescriptor field = descriptor.findFieldByName("field1");
assertNotNull(field);
assertTrue(
field.getOptions().hasExtension(UnittestCustomOptions.fieldOpt1));
assertEquals(Long.valueOf(8765432109L),
field.getOptions().getExtension(UnittestCustomOptions.fieldOpt1));
EnumDescriptor enumType =
UnittestCustomOptions.TestMessageWithCustomOptions.AnEnum.getDescriptor();
assertTrue(
enumType.getOptions().hasExtension(UnittestCustomOptions.enumOpt1));
assertEquals(Integer.valueOf(-789),
enumType.getOptions().getExtension(UnittestCustomOptions.enumOpt1));
ServiceDescriptor service =
UnittestCustomOptions.TestServiceWithCustomOptions.getDescriptor();
assertTrue(
service.getOptions().hasExtension(UnittestCustomOptions.serviceOpt1));
assertEquals(Long.valueOf(-9876543210L),
service.getOptions().getExtension(UnittestCustomOptions.serviceOpt1));
MethodDescriptor method = service.findMethodByName("Foo");
assertNotNull(method);
assertTrue(
method.getOptions().hasExtension(UnittestCustomOptions.methodOpt1));
assertEquals(UnittestCustomOptions.MethodOpt1.METHODOPT1_VAL2,
method.getOptions().getExtension(UnittestCustomOptions.methodOpt1));
}
示例9: messageReceived
import com.google.protobuf.Descriptors.ServiceDescriptor; //导入方法依赖的package包/类
/**
* Find the service and process the remote RPC.
*/
@SuppressWarnings("unchecked")
public void messageReceived(final IoSession session, Object message)
throws Exception {
RpcMessage request = (RpcMessage) message;
final int id = request.getId();
final String className = request.getClassName();
final String methodName = request.getMethod();
final String serviceName = request.getService();
Class reqClass = null;
try {
reqClass = Class.forName(className);
} catch (Exception e) {
logger.warn("Cannot find " + className);
sendResponse(session, id, Result.ERR, className, serviceName,
methodName, null);
return;
}
Method parseFromMethod = reqClass.getDeclaredMethod(PARSE_FROM_METHOD, PRASE_FROM_ARG);
Message reqMessage = null;
ByteString payload = request.getPayload();
if ( payload != null ) {
reqMessage = (Message)parseFromMethod.invoke(reqClass, payload.toByteArray());
}
if ( logger.isDebugEnabled() ) {
logger.debug("messageReceived id:{}, serviceName:{}, methodName:{}", new Object[]{id, serviceName, methodName});
}
SecureRpcCallback cb = new SecureRpcCallback(session, id, serviceName, methodName);
Service service = GameContext.getInstance().findRpcService(
serviceName, methodName);
if ( service != null ) {
ServiceDescriptor serviceDesc = service.getDescriptorForType();
MethodDescriptor methodDesc = serviceDesc.findMethodByName(methodName);
if ( methodDesc != null ) {
service.callMethod(methodDesc, rpcController, reqMessage, cb);
// if ( !cb.isCalled() ) {
// logger.warn("You may forgot to call RpcCallback.run method in {}", serviceName);
// sendResponse(session, id, Result.ERR, className, serviceName,
// methodName, null);
// }
} else {
logger.debug("Do not find the remote method: {}", methodName);
sendResponse(session, id, Result.ERR, className, serviceName,
methodName, null);
}
} else {
logger.debug("Do not find the remote service: {}", serviceName);
sendResponse(session, id, Result.ERR, className, serviceName,
methodName, null);
}
}
示例10: testCustomOptions
import com.google.protobuf.Descriptors.ServiceDescriptor; //导入方法依赖的package包/类
public void testCustomOptions() throws Exception {
// Get the descriptor indirectly from a dependent proto class. This is to
// ensure that when a proto class is loaded, custom options defined in its
// dependencies are also properly initialized.
Descriptor descriptor =
TestCustomOptions.TestMessageWithCustomOptionsContainer.getDescriptor()
.findFieldByName("field").getMessageType();
assertTrue(
descriptor.getOptions().hasExtension(UnittestCustomOptions.messageOpt1));
assertEquals(Integer.valueOf(-56),
descriptor.getOptions().getExtension(UnittestCustomOptions.messageOpt1));
FieldDescriptor field = descriptor.findFieldByName("field1");
assertNotNull(field);
assertTrue(
field.getOptions().hasExtension(UnittestCustomOptions.fieldOpt1));
assertEquals(Long.valueOf(8765432109L),
field.getOptions().getExtension(UnittestCustomOptions.fieldOpt1));
OneofDescriptor oneof = descriptor.getOneofs().get(0);
assertNotNull(oneof);
assertTrue(
oneof.getOptions().hasExtension(UnittestCustomOptions.oneofOpt1));
assertEquals(Integer.valueOf(-99),
oneof.getOptions().getExtension(UnittestCustomOptions.oneofOpt1));
EnumDescriptor enumType =
UnittestCustomOptions.TestMessageWithCustomOptions.AnEnum.getDescriptor();
assertTrue(
enumType.getOptions().hasExtension(UnittestCustomOptions.enumOpt1));
assertEquals(Integer.valueOf(-789),
enumType.getOptions().getExtension(UnittestCustomOptions.enumOpt1));
ServiceDescriptor service =
UnittestCustomOptions.TestServiceWithCustomOptions.getDescriptor();
assertTrue(
service.getOptions().hasExtension(UnittestCustomOptions.serviceOpt1));
assertEquals(Long.valueOf(-9876543210L),
service.getOptions().getExtension(UnittestCustomOptions.serviceOpt1));
MethodDescriptor method = service.findMethodByName("Foo");
assertNotNull(method);
assertTrue(
method.getOptions().hasExtension(UnittestCustomOptions.methodOpt1));
assertEquals(UnittestCustomOptions.MethodOpt1.METHODOPT1_VAL2,
method.getOptions().getExtension(UnittestCustomOptions.methodOpt1));
}