@Override public Boolean call() { connect(timeoutMillis); beans.set(findMBeans(objectName)); return !beans.get().isEmpty(); }}) .rethrowException()
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 Void call() { getHelper().connect(getConfig(JMX_CONNECTION_TIMEOUT)); return null; } @Override public String toString() { return "Connect JMX "+getHelper().getUrl(); }
connect(); return true; } catch (Exception e) {
@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(); } }
@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); }
@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); } }
final AtomicInteger sequence = new AtomicInteger(0); jmxHelper.connect(TIMEOUT_MS); jmxHelper.addNotificationListener(jmxObjectName, new NotificationListener() { @Override