ARTEMIS-565 more tweaks on the JSON replacement
This commit is contained in:
parent
0d69b0e857
commit
76938fe44a
|
@ -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() {
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 ||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue