[ 
https://issues.apache.org/jira/browse/GEODE-4054?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16284108#comment-16284108
 ] 

ASF GitHub Bot commented on GEODE-4054:
---------------------------------------

WireBaron commented on a change in pull request #1141: GEODE-4054: Create 
module for Protobuf message-based client
URL: https://github.com/apache/geode/pull/1141#discussion_r155845793
 
 

 ##########
 File path: 
geode-protobuf-client/src/main/java/org/apache/geode/internal/cache/client/protobuf/MethodInvoker.java
 ##########
 @@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache.client.protobuf;
+
+import java.io.BufferedReader;
+import java.io.Reader;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.LinkedList;
+import java.util.Queue;
+
+import org.apache.geode.annotations.Experimental;
+
+@Experimental
+public class MethodInvoker {
+  public interface Prompter {
+    void prompt();
+  }
+
+  public interface Transcriber {
+    void transcribe(String str);
+  }
+
+  private static void invoke(Queue<String> tokens, Object object, String name) 
throws Throwable {
+    final Method method = findMethod(object.getClass(), name);
+    if (method == null) {
+      throw new NoSuchMethodException("Method " + name + " does not exist in " 
+ object.getClass());
+    }
+
+    if (0 < method.getParameterCount()) {
+      Object[] parameters = new Object[method.getParameterCount()];
+      int index = 0;
+      for (Type type : method.getParameterTypes()) {
+        // Adjust the type to box primitive types.
+        if (boolean.class == type) {
+          type = Boolean.class;
+        } else if (byte.class == type) {
+          type = Byte.class;
+        } else if (short.class == type) {
+          type = Short.class;
+        } else if (int.class == type) {
+          type = Integer.class;
+        } else if (long.class == type) {
+          type = Long.class;
+        } else if (float.class == type) {
+          type = Float.class;
+        } else if (double.class == type) {
+          type = Double.class;
+        }
+
+        if (!tokens.isEmpty()) {
+          final String parameter = tokens.remove();
+          try {
+            Constructor constructor = ((Class) 
type).getConstructor(String.class);
+            parameters[index++] = constructor.newInstance(parameter);
+          } catch (IllegalAccessException | InstantiationException | 
NoSuchMethodException e) {
+            e.printStackTrace(System.err);
+            parameters[index++] = parameter;
+          } catch (InvocationTargetException e) {
+            throw e.getTargetException();
+          }
+        } else {
+          parameters[index++] = null;
+        }
+      }
+      try {
+        method.invoke(object, parameters);
+      } catch (IllegalAccessException e) {
+        e.printStackTrace(System.err);
+      } catch (InvocationTargetException e) {
+        throw e.getTargetException();
+      }
+    } else {
+      try {
+        method.invoke(object);
+      } catch (IllegalAccessException e) {
+        e.printStackTrace(System.err);
+      } catch (InvocationTargetException e) {
+        throw e.getTargetException();
+      }
+    }
+  }
+
+  private static Method findMethod(Class clazz, String name) {
 
 Review comment:
   This seems a bit flimsy as it's valid (and not uncommon) for multiple 
methods to have the same name.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Create module for Protobuf message-based client
> -----------------------------------------------
>
>                 Key: GEODE-4054
>                 URL: https://issues.apache.org/jira/browse/GEODE-4054
>             Project: Geode
>          Issue Type: Improvement
>          Components: client/server
>            Reporter: Michael Dodge
>             Fix For: 1.4.0
>
>
> Create a module, geode-protobuf-client, that contains a simple Java client 
> that exercises the Protobuf messages and the new protocol. This client should 
> allow the interaction with a locator and cache server based on command-line 
> arguments, a file of commands, or an interactive shell.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to