activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbert...@apache.org
Subject [1/2] activemq-artemis git commit: ARTEMIS-565 more tweaks on the JSON replacement
Date Tue, 26 Jul 2016 20:10:44 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/master 0d69b0e85 -> ec605e664


ARTEMIS-565 more tweaks on the JSON replacement


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/76938fe4
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/76938fe4
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/76938fe4

Branch: refs/heads/master
Commit: 76938fe44a98eb802a707ae630cc4f2d3008085e
Parents: 0d69b0e
Author: Clebert Suconic <clebertsuconic@apache.org>
Authored: Tue Jul 26 16:01:36 2016 -0400
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Tue Jul 26 16:05:17 2016 -0400

----------------------------------------------------------------------
 .../activemq/artemis/api/core/JsonUtil.java     | 38 ++++++++++++++++++++
 .../api/core/management/ManagementHelper.java   | 18 ++++++----
 .../management/impl/ManagementServiceImpl.java  |  4 +++
 .../ActiveMQServerControlUsingCoreTest.java     | 24 ++++++-------
 .../management/CoreMessagingProxy.java          | 11 +-----
 5 files changed, 66 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/76938fe4/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java
index dbfec9a..5a7a526 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java
@@ -260,6 +260,44 @@ public final class JsonUtil {
       return Json.createReader(new StringReader(jsonString)).readObject();
    }
 
+   public static Object convertJsonValue(Object jsonValue, Class desiredType) {
+      if (jsonValue instanceof JsonNumber) {
+         JsonNumber number = (JsonNumber) jsonValue;
+
+         if (desiredType == null || desiredType == Long.class || desiredType == Long.TYPE)
{
+            return number.longValue();
+         }
+         else if (desiredType == Integer.class || desiredType == Integer.TYPE) {
+            return number.intValue();
+         }
+         else if (desiredType == Double.class || desiredType == Double.TYPE) {
+            return number.doubleValue();
+         }
+         else {
+            return number.longValue();
+         }
+      }
+      else if (jsonValue instanceof JsonString) {
+         return ((JsonString) jsonValue).getString();
+      }
+      else if (jsonValue instanceof JsonValue) {
+         if (jsonValue == JsonValue.TRUE) {
+            return true;
+         }
+         else if (jsonValue == JsonValue.FALSE) {
+            return false;
+         }
+         else {
+            return jsonValue.toString();
+         }
+      }
+      else {
+         return jsonValue;
+      }
+   }
+
+
+
    private JsonUtil() {
    }
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/76938fe4/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ManagementHelper.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ManagementHelper.java
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ManagementHelper.java
index a4c0880..78405b0 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ManagementHelper.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ManagementHelper.java
@@ -21,7 +21,6 @@ import org.apache.activemq.artemis.api.core.Message;
 import org.apache.activemq.artemis.api.core.SimpleString;
 
 import javax.json.JsonArray;
-import javax.json.JsonNumber;
 
 /**
  * Helper class to use ActiveMQ Artemis Core messages to manage server resources.
@@ -216,15 +215,20 @@ public final class ManagementHelper {
     * and the result will be a String corresponding to the server exception.
     */
    public static Object getResult(final Message message) throws Exception {
+      return getResult(message, null);
+   }
+
+      /**
+       * Returns the result of an operation invocation or an attribute value.
+       * <br>
+       * If an error occurred on the server, {@link #hasOperationSucceeded(Message)} will
return {@code false}.
+       * and the result will be a String corresponding to the server exception.
+       */
+   public static Object getResult(final Message message, Class desiredType) throws Exception
{
       Object[] res = ManagementHelper.getResults(message);
 
       if (res != null) {
-         if (res[0] instanceof JsonNumber) {
-            return ((JsonNumber)res[0]).longValue();
-         }
-         else {
-            return res[0];
-         }
+         return JsonUtil.convertJsonValue(res[0], desiredType);
       }
       else {
          return null;

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/76938fe4/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
index a43c666..22b4e50 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
@@ -33,6 +33,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ScheduledExecutorService;
 
 import org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration;
+import org.apache.activemq.artemis.api.core.JsonUtil;
 import org.apache.activemq.artemis.api.core.SimpleString;
 import org.apache.activemq.artemis.api.core.TransportConfiguration;
 import org.apache.activemq.artemis.api.core.management.AcceptorControl;
@@ -721,6 +722,9 @@ public class ManagementServiceImpl implements ManagementService {
                if (params[i] == null) {
                   continue;
                }
+
+               params[i] = JsonUtil.convertJsonValue(params[i], paramTypes[i]);
+
                if (paramTypes[i].isAssignableFrom(params[i].getClass()) || paramTypes[i]
== Long.TYPE && params[i].getClass() == Integer.class ||
                   paramTypes[i] == Double.TYPE && params[i].getClass() == Integer.class
||
                   paramTypes[i] == Long.TYPE && params[i].getClass() == Long.class
||

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/76938fe4/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java
index 498c31f..89debb6 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java
@@ -175,7 +175,7 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes
 
          @Override
          public int getConnectionCount() {
-            return (Integer) proxy.retrieveAttributeValue("connectionCount");
+            return (Integer) proxy.retrieveAttributeValue("connectionCount", Integer.class);
          }
 
          @Override
@@ -245,7 +245,7 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes
 
          @Override
          public int getIDCacheSize() {
-            return (Integer) proxy.retrieveAttributeValue("IDCacheSize");
+            return (Integer) proxy.retrieveAttributeValue("IDCacheSize", Integer.class);
          }
 
          public String[] getInterceptorClassNames() {
@@ -269,17 +269,17 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes
 
          @Override
          public int getJournalFileSize() {
-            return (Integer) proxy.retrieveAttributeValue("journalFileSize");
+            return (Integer) proxy.retrieveAttributeValue("journalFileSize", Integer.class);
          }
 
          @Override
          public int getJournalMaxIO() {
-            return (Integer) proxy.retrieveAttributeValue("journalMaxIO");
+            return (Integer) proxy.retrieveAttributeValue("journalMaxIO", Integer.class);
          }
 
          @Override
          public int getJournalMinFiles() {
-            return (Integer) proxy.retrieveAttributeValue("journalMinFiles");
+            return (Integer) proxy.retrieveAttributeValue("journalMinFiles", Integer.class);
          }
 
          @Override
@@ -329,12 +329,12 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes
 
          @Override
          public int getScheduledThreadPoolMaxSize() {
-            return (Integer) proxy.retrieveAttributeValue("scheduledThreadPoolMaxSize");
+            return (Integer) proxy.retrieveAttributeValue("scheduledThreadPoolMaxSize", Integer.class);
          }
 
          @Override
          public int getThreadPoolMaxSize() {
-            return (Integer) proxy.retrieveAttributeValue("threadPoolMaxSize");
+            return (Integer) proxy.retrieveAttributeValue("threadPoolMaxSize", Integer.class);
          }
 
          @Override
@@ -354,7 +354,7 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes
 
          @Override
          public String getVersion() {
-            return (String) proxy.retrieveAttributeValue("version");
+            return proxy.retrieveAttributeValue("version").toString();
          }
 
          @Override
@@ -517,22 +517,22 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes
 
          @Override
          public int getJournalBufferSize() {
-            return (Integer) proxy.retrieveAttributeValue("JournalBufferSize");
+            return (Integer) proxy.retrieveAttributeValue("JournalBufferSize", Integer.class);
          }
 
          @Override
          public int getJournalBufferTimeout() {
-            return (Integer) proxy.retrieveAttributeValue("JournalBufferTimeout");
+            return (Integer) proxy.retrieveAttributeValue("JournalBufferTimeout", Integer.class);
          }
 
          @Override
          public int getJournalCompactMinFiles() {
-            return (Integer) proxy.retrieveAttributeValue("JournalCompactMinFiles");
+            return (Integer) proxy.retrieveAttributeValue("JournalCompactMinFiles", Integer.class);
          }
 
          @Override
          public int getJournalCompactPercentage() {
-            return (Integer) proxy.retrieveAttributeValue("JournalCompactPercentage");
+            return (Integer) proxy.retrieveAttributeValue("JournalCompactPercentage", Integer.class);
          }
 
          @Override

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/76938fe4/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/CoreMessagingProxy.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/CoreMessagingProxy.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/CoreMessagingProxy.java
index fca1d1f..e9168a2 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/CoreMessagingProxy.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/CoreMessagingProxy.java
@@ -63,16 +63,7 @@ public class CoreMessagingProxy {
       ClientMessage reply;
       try {
          reply = requestor.request(m);
-         Object result = ManagementHelper.getResult(reply);
-
-         if (desiredType != null && desiredType != result.getClass()) {
-            // Conversions
-            if (desiredType == Long.class && result.getClass() == Integer.class)
{
-               Integer in = (Integer) result;
-
-               result = new Long(in.intValue());
-            }
-         }
+         Object result = ManagementHelper.getResult(reply, desiredType);
 
          return result;
       }


Mime
View raw message