NO-JIRA fix fieldname regression
Fix field name regression, but ensure predicate and sorting still works. Remove reflection introduced by new sorting, and rely on field mapping.
This commit is contained in:
parent
b39c556784
commit
f08da813a1
|
@ -53,8 +53,6 @@ public abstract class ActiveMQAbstractView<T> {
|
|||
|
||||
protected String options;
|
||||
|
||||
private Method getter;
|
||||
|
||||
public ActiveMQAbstractView() {
|
||||
this.sortColumn = getDefaultOrderColumn();
|
||||
this.sortOrder = "asc";
|
||||
|
@ -98,29 +96,18 @@ public abstract class ActiveMQAbstractView<T> {
|
|||
return predicate;
|
||||
}
|
||||
|
||||
private Method getGetter() {
|
||||
if (getter == null) {
|
||||
getter = findGetterMethod(getClassT(), sortColumn);
|
||||
}
|
||||
return getter;
|
||||
}
|
||||
|
||||
public Ordering<T> getOrdering() {
|
||||
return new Ordering<T>() {
|
||||
|
||||
@Override
|
||||
public int compare(T left, T right) {
|
||||
Method getter = getGetter();
|
||||
try {
|
||||
if (getter != null) {
|
||||
Object leftValue = getter.invoke(left);
|
||||
Object rightValue = getter.invoke(right);
|
||||
if (leftValue instanceof Comparable && rightValue instanceof Comparable) {
|
||||
if (sortOrder.equals("desc")) {
|
||||
return ((Comparable) rightValue).compareTo(leftValue);
|
||||
} else {
|
||||
return ((Comparable) leftValue).compareTo(rightValue);
|
||||
}
|
||||
Object leftValue = getField(left, sortColumn);;
|
||||
Object rightValue = getField(right, sortColumn);;
|
||||
if (leftValue instanceof Comparable && rightValue instanceof Comparable) {
|
||||
if (sortOrder.equals("desc")) {
|
||||
return ((Comparable) rightValue).compareTo(leftValue);
|
||||
} else {
|
||||
return ((Comparable) leftValue).compareTo(rightValue);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -132,17 +119,7 @@ public abstract class ActiveMQAbstractView<T> {
|
|||
};
|
||||
}
|
||||
|
||||
public static Method findGetterMethod(Class clazz, String sortColumn) {
|
||||
String name = "get" + Character.toUpperCase(sortColumn.charAt(0)) + sortColumn.substring(1);
|
||||
Method[] methods = clazz.getMethods();
|
||||
for (Method method : methods) {
|
||||
Class<?>[] params = method.getParameterTypes();
|
||||
if (method.getName().equals(name) && params.length == 0) {
|
||||
return method;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
abstract Object getField(T t, String fieldName);
|
||||
|
||||
public void setOptions(String options) {
|
||||
JsonObject json = JsonUtil.readJsonObject(options);
|
||||
|
|
|
@ -17,9 +17,16 @@
|
|||
package org.apache.activemq.artemis.core.management.impl.view;
|
||||
|
||||
import javax.json.JsonObjectBuilder;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.activemq.artemis.core.management.impl.view.predicate.AddressFilterPredicate;
|
||||
import org.apache.activemq.artemis.core.server.ActiveMQServer;
|
||||
import org.apache.activemq.artemis.core.server.ServerSession;
|
||||
import org.apache.activemq.artemis.core.server.impl.AddressInfo;
|
||||
import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
|
||||
import org.apache.activemq.artemis.utils.JsonLoader;
|
||||
|
||||
public class AddressView extends ActiveMQAbstractView<AddressInfo> {
|
||||
|
@ -56,6 +63,29 @@ public class AddressView extends ActiveMQAbstractView<AddressInfo> {
|
|||
return obj;
|
||||
}
|
||||
|
||||
public Object getField(AddressInfo address, String fieldName) {
|
||||
if (address == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (fieldName) {
|
||||
case "id":
|
||||
return address.getId();
|
||||
case "name":
|
||||
return address.getName();
|
||||
case "routingTypes":
|
||||
return address.getRoutingTypes();
|
||||
case "queueCount":
|
||||
try {
|
||||
return server.bindingQuery(address.getName()).getQueueNames().size();
|
||||
} catch (Exception e) {
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported field, " + fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultOrderColumn() {
|
||||
return defaultSortColumn;
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Set;
|
|||
|
||||
import org.apache.activemq.artemis.core.management.impl.view.predicate.ConnectionFilterPredicate;
|
||||
import org.apache.activemq.artemis.core.server.ActiveMQServer;
|
||||
import org.apache.activemq.artemis.core.server.ServerConsumer;
|
||||
import org.apache.activemq.artemis.core.server.ServerSession;
|
||||
import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
|
||||
import org.apache.activemq.artemis.utils.JsonLoader;
|
||||
|
@ -61,13 +62,45 @@ public class ConnectionView extends ActiveMQAbstractView<RemotingConnection> {
|
|||
.add("remoteAddress", toString(connection.getRemoteAddress()))
|
||||
.add("users", StringUtil.joinStringList(users, ","))
|
||||
.add("creationTime", new Date(connection.getCreationTime()).toString())
|
||||
.add("implementation", toString(toString(connection.getClass().getSimpleName())))
|
||||
.add("implementation", toString(connection.getClass().getSimpleName()))
|
||||
.add("protocol", toString(connection.getProtocolName()))
|
||||
.add("clientID", toString(connection.getClientID()))
|
||||
.add("localAddress", toString(connection.getTransportLocalAddress()))
|
||||
.add("sessionCount", server.getSessions(connection.getID().toString()).size());
|
||||
}
|
||||
|
||||
public Object getField(RemotingConnection connection, String fieldName) {
|
||||
List<ServerSession> sessions = server.getSessions(connection.getID().toString());
|
||||
|
||||
switch (fieldName) {
|
||||
case "connectionID":
|
||||
return connection.getID();
|
||||
case "remoteAddress":
|
||||
return connection.getRemoteAddress();
|
||||
case "users":
|
||||
Set<String> users = new HashSet<>();
|
||||
for (ServerSession session : sessions) {
|
||||
String username = session.getUsername() == null ? "" : session.getUsername();
|
||||
users.add(username);
|
||||
}
|
||||
return users;
|
||||
case "creationTime":
|
||||
return new Date(connection.getCreationTime());
|
||||
case "implementation":
|
||||
return connection.getClass().getSimpleName();
|
||||
case "protocol":
|
||||
return connection.getProtocolName();
|
||||
case "clientID":
|
||||
return connection.getClientID();
|
||||
case "localAddress":
|
||||
return connection.getTransportLocalAddress();
|
||||
case "sessionCount":
|
||||
return sessions.size();
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported field, " + fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultOrderColumn() {
|
||||
return defaultSortColumn;
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.Date;
|
|||
import org.apache.activemq.artemis.core.management.impl.view.predicate.ConsumerFilterPredicate;
|
||||
import org.apache.activemq.artemis.core.server.ActiveMQServer;
|
||||
import org.apache.activemq.artemis.core.server.ServerConsumer;
|
||||
import org.apache.activemq.artemis.core.server.ServerProducer;
|
||||
import org.apache.activemq.artemis.core.server.ServerSession;
|
||||
import org.apache.activemq.artemis.utils.JsonLoader;
|
||||
|
||||
|
@ -58,13 +59,47 @@ public class ConsumerView extends ActiveMQAbstractView<ServerConsumer> {
|
|||
.add("protocol", toString(consumer.getConnectionProtocolName()))
|
||||
.add("queue", toString(consumer.getQueueName()))
|
||||
.add("queueType", toString(consumer.getQueueType()).toLowerCase())
|
||||
.add("address", toString(consumer.getQueueAddress().toString()))
|
||||
.add("address", toString(consumer.getQueueAddress()))
|
||||
.add("localAddress", toString(consumer.getConnectionLocalAddress()))
|
||||
.add("remoteAddress", toString(consumer.getConnectionRemoteAddress()))
|
||||
.add("creationTime", new Date(consumer.getCreationTime()).toString());
|
||||
return obj;
|
||||
}
|
||||
|
||||
public Object getField(ServerConsumer consumer, String fieldName) {
|
||||
ServerSession session = server.getSessionByID(consumer.getSessionID());
|
||||
|
||||
//if session is not available then consumer is not in valid state - ignore
|
||||
if (session == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (fieldName) {
|
||||
case "id":
|
||||
return consumer.getSequentialID();
|
||||
case "session":
|
||||
return consumer.getSessionName();
|
||||
case "user":
|
||||
return session.getUsername();
|
||||
case "clientID":
|
||||
return consumer.getConnectionClientID();
|
||||
case "protocol":
|
||||
return consumer.getConnectionProtocolName();
|
||||
case "queue":
|
||||
return consumer.getQueueName();
|
||||
case "queueType":
|
||||
return consumer.getQueueType();
|
||||
case "localAddress":
|
||||
return consumer.getConnectionLocalAddress();
|
||||
case "remoteAddress":
|
||||
return consumer.getConnectionRemoteAddress();
|
||||
case "creationTime":
|
||||
return new Date(consumer.getCreationTime());
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported field, " + fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultOrderColumn() {
|
||||
return defaultSortColumn;
|
||||
|
|
|
@ -44,6 +44,12 @@ public class ProducerView extends ActiveMQAbstractView<ServerProducer> {
|
|||
@Override
|
||||
public JsonObjectBuilder toJson(ServerProducer producer) {
|
||||
ServerSession session = server.getSessionByID(producer.getSessionID());
|
||||
|
||||
//if session is not available then consumer is not in valid state - ignore
|
||||
if (session == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
JsonObjectBuilder obj = JsonLoader.createObjectBuilder().add("id", toString(producer.getID()))
|
||||
.add("session", toString(session.getName()))
|
||||
.add("clientID", toString(session.getRemotingConnection().getClientID()))
|
||||
|
@ -56,6 +62,38 @@ public class ProducerView extends ActiveMQAbstractView<ServerProducer> {
|
|||
return obj;
|
||||
}
|
||||
|
||||
public Object getField(ServerProducer producer, String fieldName) {
|
||||
ServerSession session = server.getSessionByID(producer.getSessionID());
|
||||
|
||||
//if session is not available then consumer is not in valid state - ignore
|
||||
if (session == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (fieldName) {
|
||||
case "id":
|
||||
return producer.getID();
|
||||
case "session":
|
||||
return session.getName();
|
||||
case "user":
|
||||
return session.getUsername();
|
||||
case "clientID":
|
||||
return session.getRemotingConnection().getClientID();
|
||||
case "protocol":
|
||||
return session.getRemotingConnection().getProtocolName();
|
||||
case "address":
|
||||
return producer.getAddress() != null ? producer.getAddress() : session.getDefaultAddress();
|
||||
case "localAddress":
|
||||
return session.getRemotingConnection().getTransportConnection().getLocalAddress();
|
||||
case "remoteAddress":
|
||||
return session.getRemotingConnection().getTransportConnection().getRemoteAddress();
|
||||
case "creationTime":
|
||||
return producer.getCreationTime();
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported field, " + fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultOrderColumn() {
|
||||
return defaultSortColumn;
|
||||
|
|
|
@ -18,11 +18,14 @@ package org.apache.activemq.artemis.core.management.impl.view;
|
|||
|
||||
import javax.json.JsonObjectBuilder;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
import org.apache.activemq.artemis.api.core.management.QueueControl;
|
||||
import org.apache.activemq.artemis.core.management.impl.view.predicate.QueueFilterPredicate;
|
||||
import org.apache.activemq.artemis.core.server.ActiveMQServer;
|
||||
import org.apache.activemq.artemis.core.server.Queue;
|
||||
import org.apache.activemq.artemis.core.server.ServerSession;
|
||||
import org.apache.activemq.artemis.utils.JsonLoader;
|
||||
|
||||
public class QueueView extends ActiveMQAbstractView<QueueControl> {
|
||||
|
@ -65,6 +68,54 @@ public class QueueView extends ActiveMQAbstractView<QueueControl> {
|
|||
return obj;
|
||||
}
|
||||
|
||||
public Object getField(QueueControl queue, String fieldName) {
|
||||
Queue q = server.locateQueue(new SimpleString(queue.getName()));
|
||||
switch (fieldName) {
|
||||
case "id":
|
||||
return queue.getID();
|
||||
case "name":
|
||||
return queue.getName();
|
||||
case "address":
|
||||
return queue.getAddress();
|
||||
case "filter":
|
||||
return queue.getFilter();
|
||||
case "rate":
|
||||
return q.getRate();
|
||||
case "durable":
|
||||
return queue.isDurable();
|
||||
case "paused":
|
||||
return q.isPaused();
|
||||
case "temporary":
|
||||
return queue.isTemporary();
|
||||
case "purgeOnNoConsumers":
|
||||
return queue.isPurgeOnNoConsumers();
|
||||
case "consumerCount":
|
||||
return queue.getConsumerCount();
|
||||
case "maxConsumers":
|
||||
return queue.getMaxConsumers();
|
||||
case "autoCreated":
|
||||
return q.isAutoCreated();
|
||||
case "user":
|
||||
return q.getUser();
|
||||
case "routingType":
|
||||
return queue.getRoutingType();
|
||||
case "messagesAdded":
|
||||
return queue.getMessagesAdded();
|
||||
case "messageCount":
|
||||
return queue.getMessageCount();
|
||||
case "messagesAcked":
|
||||
return queue.getMessagesAcknowledged();
|
||||
case "deliveringCount":
|
||||
return queue.getDeliveringCount();
|
||||
case "messagesKilled":
|
||||
return queue.getMessagesKilled();
|
||||
case "deliverDeliver":
|
||||
return q.isDirectDeliver();
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported field, " + fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultOrderColumn() {
|
||||
return defaultSortColumn;
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.util.Date;
|
|||
|
||||
import org.apache.activemq.artemis.core.management.impl.view.predicate.SessionFilterPredicate;
|
||||
import org.apache.activemq.artemis.core.server.ServerSession;
|
||||
import org.apache.activemq.artemis.core.server.impl.AddressInfo;
|
||||
import org.apache.activemq.artemis.utils.JsonLoader;
|
||||
|
||||
public class SessionView extends ActiveMQAbstractView<ServerSession> {
|
||||
|
@ -48,6 +49,25 @@ public class SessionView extends ActiveMQAbstractView<ServerSession> {
|
|||
return obj;
|
||||
}
|
||||
|
||||
public Object getField(ServerSession session, String fieldName) {
|
||||
switch (fieldName) {
|
||||
case "id":
|
||||
return session.getName();
|
||||
case "user":
|
||||
return session.getUsername();
|
||||
case "creationTime":
|
||||
return new Date(session.getCreationTime());
|
||||
case "consumerCount":
|
||||
return session.getConsumerCount();
|
||||
case "producerCount":
|
||||
return session.getProducerCount();
|
||||
case "connectionID":
|
||||
return session.getConnectionID();
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported field, " + fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultOrderColumn() {
|
||||
return defaultSortColumn;
|
||||
|
|
Loading…
Reference in New Issue