Skip to content

Commit

Permalink
Fixed #1903 by filtering out AMQ add/remove mbeans of client connecto…
Browse files Browse the repository at this point in the history
…rs that would cause the tree to be updated. Added JVM system property that can be used to turn on old behavior.
  • Loading branch information
davsclaus committed Nov 22, 2015
1 parent aea3ec9 commit 7c205fa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/Configuration.md
Expand Up @@ -387,6 +387,10 @@ The following table contains the various configuration settings for the various
<td>hawtio.sessionTimeout</td>
<td><strong>hawtio 1.2.2</strong> The maximum time interval, in seconds, that the servlet container will keep this session open between client accesses. If this option is not configured, then hawtio uses the default session timeout of the servlet container.</td>
</tr>
<tr>
<td>hawtio.activemq.verbose.tree</td>
<td><strong>hawtio 1.4.57</strong> Is default <tt>false</tt> to filter out verbose ActiveMQ details from the tree in hawtio. This ensures situations when ActiveMQ will constantly add/remove same set of mbeans for a client connection because the client is not using pooled connections or using XA transactions without caching the consumer. In situations like these ActiveMQ keeps changing the mbeans which would cause the hawtio web console to trigger an update in the tree, which makes using the web console more sluggish. Therefore this is filtered out by default. This option can be set to <tt>true</tt> to restore old behavior.</td>
</tr>
</tbody>
</table>

Expand Down
28 changes: 28 additions & 0 deletions hawtio-system/src/main/java/io/hawt/jmx/JmxTreeWatcher.java
Expand Up @@ -3,6 +3,7 @@
import java.lang.management.ManagementFactory;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Pattern;
import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanServer;
import javax.management.MBeanServerDelegate;
Expand All @@ -23,14 +24,23 @@ public class JmxTreeWatcher implements JmxTreeWatcherMBean {
private static final transient Logger LOG = LoggerFactory.getLogger(JmxTreeWatcher.class);
private static AtomicBoolean logged = new AtomicBoolean();

public static final String ACTIVEMQ_VERBOSE_TREE = "hawtio.activemq.verbose.tree";

private static final Pattern AMQ_CONSUMER_PATTERN = Pattern.compile(".*\\[mbeanName=org.apache.activemq:type=Broker.*endpoint=Consumer.*\\]");

// TODO: system property to turn this on|off

private ObjectName objectName;
private MBeanServer mBeanServer;
private AtomicLong counter = new AtomicLong(0);
private NotificationListener listener;
private NotificationFilter filter;
private String version;
private boolean activeMQVerbose;

public void init() throws Exception {
activeMQVerbose = "true".equals(System.getProperty(ACTIVEMQ_VERBOSE_TREE, "false"));

if (objectName == null) {
objectName = getObjectName();
}
Expand Down Expand Up @@ -73,6 +83,7 @@ public void destroy() throws Exception {
mBeanServer.unregisterMBean(objectName);
}
}
logged.set(false);
}

public String getVersion() {
Expand All @@ -97,6 +108,23 @@ protected NotificationListener getNotificationListener() {
return new NotificationListener() {
@Override
public void handleNotification(Notification notification, Object handback) {

// ActiveMQ can be verbose causing hawtio tree to be constantly updated
// and therefore cause the UI to keep updating the tree, making using hawtio sluggish

if (!activeMQVerbose) {
if (notification != null) {
String toString = notification.toString();
if (AMQ_CONSUMER_PATTERN.matcher(toString).matches()) {
return;
}
}
}

if (LOG.isTraceEnabled()) {
LOG.trace("Notification: {}", notification);
}

// TODO should we filter only types "JMX.mbean.registered" and "JMX.mbean.unregistered"?
counter.incrementAndGet();
}
Expand Down

0 comments on commit 7c205fa

Please sign in to comment.