@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); } }
@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(); } } }
@Override public void onManagementStarting() { super.onManagementStarting(); // TODO Would be nice to share the JmxHelper for all destinations, so just one connection. // But tricky for if brooklyn were distributed try { if (virtualHost == null) virtualHost = getConfig(QpidBroker.VIRTUAL_HOST_NAME); sensors().set(QpidBroker.VIRTUAL_HOST_NAME, virtualHost); virtualHostManager = new ObjectName(format("org.apache.qpid:type=VirtualHost.VirtualHostManager,VirtualHost=\"%s\"", virtualHost)); jmxHelper = new JmxHelper(getParent()); } catch (MalformedObjectNameException e) { throw Exceptions.propagate(e); } }
@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()); }
@Override public void waitForServiceUp(long duration, TimeUnit units) { super.waitForServiceUp(duration, units); if (((KafkaBrokerDriver)getDriver()).isJmxEnabled()) { // Wait for the MBean to exist JmxHelper helper = new JmxHelper(this); try { helper.assertMBeanExistsEventually(SOCKET_SERVER_STATS_MBEAN, units.toMillis(duration)); } finally { helper.terminate(); } } }
@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); }
@Override public void setEntity(EntityLocal entity) { if (getConfig(HELPER) == null) { JmxHelper helper = new JmxHelper(entity); setConfig(HELPER, helper); setConfig(OWN_HELPER, true); setConfig(JMX_URI, helper.getUrl()); } super.setEntity(entity); }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); jmxObjectName = new ObjectName(objectName); // Create an entity and configure it with the above JMX service entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).impl(TestEntityWithJmx.class).additionalInterfaces(UsesJmx.class)); app.start(ImmutableList.of(new SimulatedLocation())); jmxHelper = new JmxHelper(entity); jmxService = new JmxService(entity); }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); // Create an entity and configure it with the above JMX service entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).impl(TestEntityWithJmx.class).additionalInterfaces(UsesJmx.class)); app.start(ImmutableList.of(new SimulatedLocation())); jmxHelper = new JmxHelper(entity); jmxService = new JmxService(entity); }
@Override public JmxFeed call() throws Exception { JmxHelper helper = new JmxHelper(entity); JmxFeed feed = JmxFeed.builder() .entity(entity) .period(period) .helper(helper) .pollAttribute(new JmxAttributePollConfig<T>(sensor) .objectName(objectName) .attributeName(attribute) .suppressDuplicates(Boolean.TRUE.equals(suppressDuplicates)) .onFailureOrException(Functions.<T>constant((T) defaultValue))) .build(); entity.addFeed(feed); return feed; } })
@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); } }
jmxHelper = new JmxHelper(this);
@Override public void start(Collection<? extends Location> locs) { // TODO Auto-generated method stub super.start(locs); sensors().set(Attributes.HOSTNAME, "localhost"); sensors().set(UsesJmx.JMX_PORT, LocalhostMachineProvisioningLocation.obtainPort(PortRanges.fromString("40123+"))); // only supports no-agent, at the moment config().set(UsesJmx.JMX_AGENT_MODE, JmxAgentModes.NONE); sensors().set(UsesJmx.RMI_REGISTRY_PORT, -1); // -1 means to use the JMX_PORT only ConfigToAttributes.apply(this, UsesJmx.JMX_CONTEXT); JmxFeed.Builder feedBuilder = JmxFeed.builder() .entity(this) .pollAttribute(new JmxAttributePollConfig<String>(SENSOR_STRING) .objectName(OBJECT_NAME) .period(50) .attributeName(JMX_ATTRIBUTE_NAME)); if (getConfig(PRE_CREATE_JMX_HELPER)) { JmxHelper jmxHelper = new JmxHelper(this); feedBuilder.helper(jmxHelper); } addFeed(feedBuilder.build()); } }