This closes #670
This commit is contained in:
commit
ec605e6643
|
@ -260,6 +260,44 @@ public final class JsonUtil {
|
||||||
return Json.createReader(new StringReader(jsonString)).readObject();
|
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() {
|
private JsonUtil() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ import org.apache.activemq.artemis.api.core.Message;
|
||||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||||
|
|
||||||
import javax.json.JsonArray;
|
import javax.json.JsonArray;
|
||||||
import javax.json.JsonNumber;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to use ActiveMQ Artemis Core messages to manage server resources.
|
* 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.
|
* and the result will be a String corresponding to the server exception.
|
||||||
*/
|
*/
|
||||||
public static Object getResult(final Message message) throws 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);
|
Object[] res = ManagementHelper.getResults(message);
|
||||||
|
|
||||||
if (res != null) {
|
if (res != null) {
|
||||||
if (res[0] instanceof JsonNumber) {
|
return JsonUtil.convertJsonValue(res[0], desiredType);
|
||||||
return ((JsonNumber)res[0]).longValue();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return res[0];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -33,6 +33,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
|
||||||
import org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration;
|
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.SimpleString;
|
||||||
import org.apache.activemq.artemis.api.core.TransportConfiguration;
|
import org.apache.activemq.artemis.api.core.TransportConfiguration;
|
||||||
import org.apache.activemq.artemis.api.core.management.AcceptorControl;
|
import org.apache.activemq.artemis.api.core.management.AcceptorControl;
|
||||||
|
@ -721,6 +722,9 @@ public class ManagementServiceImpl implements ManagementService {
|
||||||
if (params[i] == null) {
|
if (params[i] == null) {
|
||||||
continue;
|
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 ||
|
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] == Double.TYPE && params[i].getClass() == Integer.class ||
|
||||||
paramTypes[i] == Long.TYPE && params[i].getClass() == Long.class ||
|
paramTypes[i] == Long.TYPE && params[i].getClass() == Long.class ||
|
||||||
|
|
|
@ -175,7 +175,7 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getConnectionCount() {
|
public int getConnectionCount() {
|
||||||
return (Integer) proxy.retrieveAttributeValue("connectionCount");
|
return (Integer) proxy.retrieveAttributeValue("connectionCount", Integer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -245,7 +245,7 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getIDCacheSize() {
|
public int getIDCacheSize() {
|
||||||
return (Integer) proxy.retrieveAttributeValue("IDCacheSize");
|
return (Integer) proxy.retrieveAttributeValue("IDCacheSize", Integer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getInterceptorClassNames() {
|
public String[] getInterceptorClassNames() {
|
||||||
|
@ -269,17 +269,17 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getJournalFileSize() {
|
public int getJournalFileSize() {
|
||||||
return (Integer) proxy.retrieveAttributeValue("journalFileSize");
|
return (Integer) proxy.retrieveAttributeValue("journalFileSize", Integer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getJournalMaxIO() {
|
public int getJournalMaxIO() {
|
||||||
return (Integer) proxy.retrieveAttributeValue("journalMaxIO");
|
return (Integer) proxy.retrieveAttributeValue("journalMaxIO", Integer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getJournalMinFiles() {
|
public int getJournalMinFiles() {
|
||||||
return (Integer) proxy.retrieveAttributeValue("journalMinFiles");
|
return (Integer) proxy.retrieveAttributeValue("journalMinFiles", Integer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -329,12 +329,12 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getScheduledThreadPoolMaxSize() {
|
public int getScheduledThreadPoolMaxSize() {
|
||||||
return (Integer) proxy.retrieveAttributeValue("scheduledThreadPoolMaxSize");
|
return (Integer) proxy.retrieveAttributeValue("scheduledThreadPoolMaxSize", Integer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getThreadPoolMaxSize() {
|
public int getThreadPoolMaxSize() {
|
||||||
return (Integer) proxy.retrieveAttributeValue("threadPoolMaxSize");
|
return (Integer) proxy.retrieveAttributeValue("threadPoolMaxSize", Integer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -354,7 +354,7 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getVersion() {
|
public String getVersion() {
|
||||||
return (String) proxy.retrieveAttributeValue("version");
|
return proxy.retrieveAttributeValue("version").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -517,22 +517,22 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getJournalBufferSize() {
|
public int getJournalBufferSize() {
|
||||||
return (Integer) proxy.retrieveAttributeValue("JournalBufferSize");
|
return (Integer) proxy.retrieveAttributeValue("JournalBufferSize", Integer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getJournalBufferTimeout() {
|
public int getJournalBufferTimeout() {
|
||||||
return (Integer) proxy.retrieveAttributeValue("JournalBufferTimeout");
|
return (Integer) proxy.retrieveAttributeValue("JournalBufferTimeout", Integer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getJournalCompactMinFiles() {
|
public int getJournalCompactMinFiles() {
|
||||||
return (Integer) proxy.retrieveAttributeValue("JournalCompactMinFiles");
|
return (Integer) proxy.retrieveAttributeValue("JournalCompactMinFiles", Integer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getJournalCompactPercentage() {
|
public int getJournalCompactPercentage() {
|
||||||
return (Integer) proxy.retrieveAttributeValue("JournalCompactPercentage");
|
return (Integer) proxy.retrieveAttributeValue("JournalCompactPercentage", Integer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -63,16 +63,7 @@ public class CoreMessagingProxy {
|
||||||
ClientMessage reply;
|
ClientMessage reply;
|
||||||
try {
|
try {
|
||||||
reply = requestor.request(m);
|
reply = requestor.request(m);
|
||||||
Object result = ManagementHelper.getResult(reply);
|
Object result = ManagementHelper.getResult(reply, desiredType);
|
||||||
|
|
||||||
if (desiredType != null && desiredType != result.getClass()) {
|
|
||||||
// Conversions
|
|
||||||
if (desiredType == Long.class && result.getClass() == Integer.class) {
|
|
||||||
Integer in = (Integer) result;
|
|
||||||
|
|
||||||
result = new Long(in.intValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue