@Override public void waitForServiceUp(long duration, TimeUnit units) { super.waitForServiceUp(duration, units); // Also wait for the MBean to exist (as used when creating queue/topic) JmxHelper helper = new JmxHelper(this); try { String virtualHost = getConfig(QpidBroker.VIRTUAL_HOST_NAME); ObjectName virtualHostManager = new ObjectName(format("org.apache.qpid:type=VirtualHost.VirtualHostManager,VirtualHost=\"%s\"", virtualHost)); helper.connect(); helper.assertMBeanExistsEventually(virtualHostManager, units.toMillis(duration)); } catch (MalformedObjectNameException e) { throw Exceptions.propagate(e); } catch (IOException e) { throw Exceptions.propagate(e); } finally { if (helper != null) helper.terminate(); } }
@Override public void create() { log.debug("{} adding queue {} to broker {}", new Object[] {this, getName(), jmxHelper.getAttribute(brokerMBeanName, "BrokerName")}); jmxHelper.operation(brokerMBeanName, "addQueue", getName()); connectSensors(); }
public void addNotificationListener(String objectName, NotificationListener listener) { addNotificationListener(createObjectName(objectName), listener, null); }
/** @see #operation(ObjectName, String, Object ...) */ public Object operation(String objectName, String method, Object... arguments) { return operation(createObjectName(objectName), method, arguments); }
@Override public Boolean call() { connect(timeoutMillis); beans.set(findMBeans(objectName)); return !beans.get().isEmpty(); }}) .rethrowException()
@Override public void waitForServiceUp(long duration, TimeUnit units) { super.waitForServiceUp(duration, units); if (((JavaSoftwareProcessDriver)getDriver()).isJmxEnabled()) { // Wait for the MBean to exist JmxHelper helper = new JmxHelper(this); try { helper.assertMBeanExistsEventually(ZOOKEEPER_MBEAN, units.toMillis(duration)); } finally { helper.terminate(); } } }
@Test public void testMBeanNotFoundLoggedOnlyOncePerUrl() throws Exception { ObjectName wrongObjectName = new ObjectName("DoesNotExist:type=DoesNotExist"); // Expect just one log message about: // JMX object DoesNotExist:type=DoesNotExist not found at service:jmx:rmi://localhost:1099/jndi/rmi://localhost:9001/jmxrmi" for (int i = 0; i < 10; i++) { jmxHelper.findMBean(wrongObjectName); } jmxService.shutdown(); jmxHelper.disconnect(); jmxService = newJmxServiceRetrying(LOCALHOST_NAME, 5); jmxHelper = new JmxHelper(jmxService.getUrl()); jmxHelper.connect(); // Expect just one log message about: // JMX object DoesNotExist:type=DoesNotExist not found at service:jmx:rmi://localhost:1099/jndi/rmi://localhost:9001/jmxrmi" for (int i = 0; i < 10; i++) { jmxHelper.findMBean(wrongObjectName); } }
@Override public Object call() throws Exception { if (log.isDebugEnabled()) log.debug("jmx operation polling for {} sensors at {} -> {}", new Object[] {getEntity(), getJmxUri(), operationName}); if (signature.size() == params.size()) { return getHelper().operation(objectName, operationName, signature, params); } else { return getHelper().operation(objectName, operationName, params.toArray()); } } },
@SuppressWarnings("unchecked") public AsserterForJmxConnection(VanillaJavaApp e) throws MalformedURLException { this.entity = e; JmxHelper jmxHelper = new JmxHelper(entity); this.url = new JMXServiceURL(jmxHelper.getUrl()); this.env = Maps.newLinkedHashMap(jmxHelper.getConnectionEnvVars()); }
@BeforeMethod(alwaysRun=true) public void setUp() throws Exception { jmxObjectName = new ObjectName(objectName); jmxObjectNameWithWildcard = new ObjectName(objectNameWithWildcard); jmxService = newJmxServiceRetrying(LOCALHOST_NAME, 5); jmxHelper = new JmxHelper(jmxService.getUrl()); jmxHelper.setMinTimeBetweenReconnectAttempts(0); jmxHelper.connect(TIMEOUT_MS); }
@Override public void onManagementStarting() { super.onManagementStarting(); String brokerName = getBrokerName(); Preconditions.checkArgument(brokerName != null && !brokerName.isEmpty(), "ActiveMQ brokerName attribute must be specified"); try { brokerMBeanName = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + brokerName); jmxHelper = new JmxHelper(getParent()); } catch (MalformedObjectNameException e) { throw Exceptions.propagate(e); } }
public void assertMBeanExistsEventually(ObjectName objectName, long timeoutMillis) { assertMBeanExistsEventually(objectName, timeoutMillis, TimeUnit.MILLISECONDS); }
@Test public void testSetAttributeUsingObjectNameWildcard() throws Exception { DynamicMBean mbean = jmxService.registerMBean(MutableMap.of("myattr", "myval"), objectName); jmxHelper.setAttribute(jmxObjectNameWithWildcard, "myattr", "abc"); Object actual = jmxHelper.getAttribute(jmxObjectName, "myattr"); assertEquals(actual, "abc"); }
public synchronized void reconnect() throws IOException { disconnect(); try { connect(); failedReconnecting = false; } catch (Exception e) { if (failedReconnecting) { if (LOG.isDebugEnabled()) LOG.debug("unable to re-connect to JMX url (repeated failure): {}: {}", url, e); } else { LOG.debug("unable to re-connect to JMX url {} (rethrowing): {}", url, e); failedReconnecting = true; } failedReconnectingTime = System.currentTimeMillis(); throw Throwables.propagate(e); } }
@Override public Object call() throws Exception { if (log.isTraceEnabled()) log.trace("jmx attribute polling for {} sensors at {} -> {}", new Object[] {getEntity(), getJmxUri(), jmxAttributeName}); return getHelper().getAttribute(objectName, jmxAttributeName); } },
while (currentTime <= endMs) { currentTime = System.currentTimeMillis(); if (attempt != 0) sleep(100); //sleep 100 to prevent thrashing and facilitate interruption if (LOG.isTraceEnabled()) LOG.trace("trying connection to {} at time {}", url, currentTime); connect(); return true; } catch (Exception e) { Exceptions.propagateIfFatal(e); if (!terminated.get() && shouldRetryOn(e)) { if (LOG.isDebugEnabled()) LOG.debug("Attempt {} failed connecting to {} ({})", new Object[] {attempt + 1, url, e.getMessage()}); lastError = e;
final AtomicInteger sequence = new AtomicInteger(0); jmxHelper.connect(TIMEOUT_MS); jmxHelper.addNotificationListener(jmxObjectName, new NotificationListener() { @Override public void handleNotification(Notification notif, Object callback) {
if (connector != null) connector.close(); JMXServiceURL serviceUrl = new JMXServiceURL(url); Map env = getConnectionEnvVars(); try { connector = newConnector(serviceUrl, env); } catch (NullPointerException npe) { disconnectNow(); throw new IllegalStateException("JMX Helper "+this+" already terminated");
@Override public Void call() { getHelper().connect(getConfig(JMX_CONNECTION_TIMEOUT)); return null; } @Override public String toString() { return "Connect JMX "+getHelper().getUrl(); }