Refine search
/** * Starts a JMX connector that allows (un)registering MBeans with the MBean server and RMI invocations. * * @param port jmx port to use * @throws IOException */ private void startJmxService(int port) throws IOException { String serviceUrl = "service:jmx:rmi://localhost:" + port + "/jndi/rmi://localhost:" + port + "/jmxrmi"; JMXServiceURL url; try { url = new JMXServiceURL(serviceUrl); } catch (MalformedURLException e) { throw new IllegalArgumentException("Malformed service url created " + serviceUrl, e); } connector = JMXConnectorServerFactory.newJMXConnectorServer(url, null, ManagementFactory.getPlatformMBeanServer()); connector.start(); }
protected void assertJmxEquals(String attributeName, Object attributeValue) throws Exception { JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(new JMXServiceURL("service:jmx:rmi://"), null, ManagementFactory.getPlatformMBeanServer()); cs.start(); JMXConnector cc = null; try { cc = JMXConnectorFactory.connect(cs.getAddress()); MBeanServerConnection mbsc = cc.getMBeanServerConnection(); ObjectName objectName = JmxUtils.createObjectName(JmxUtils.getPackageName(failureDetector.getClass()), failureDetector.getClass() .getSimpleName()); Object availableNodes = mbsc.getAttribute(objectName, attributeName); assertEquals(attributeValue, availableNodes); } finally { if(cc != null) cc.close(); cs.stop(); } }
cs = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs); cs.setMBeanServerForwarder(new MBeanServerWrapper(securityService)); cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); cs.start(); await() .until(() -> cs.isActive());
JMXServiceURL url = new JMXServiceURL(this.serviceUrl); this.connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, this.environment, this.server); this.connectorServer.setMBeanServerForwarder(this.forwarder); this.connectorServer.start();
@Override public void run() { // ensure we use MDC logging with the broker name, so people can see the logs if MDC was in use if (brokerName != null) { MDC.put("activemq.broker", brokerName); } try { JMXConnectorServer server = connectorServer; if (started.get() && server != null) { LOG.debug("Starting JMXConnectorServer..."); try { // need to remove MDC as we must not inherit MDC in child threads causing leaks MDC.remove("activemq.broker"); server.start(); } finally { if (brokerName != null) { MDC.put("activemq.broker", brokerName); } connectorStarted.countDown(); } LOG.info("JMX consoles can connect to {}", server.getAddress()); } } catch (IOException e) { LOG.warn("Failed to start JMX connector {}. Will restart management to re-create JMX connector, trying to remedy this issue.", e.getMessage()); LOG.debug("Reason for failed JMX connector start", e); } finally { MDC.remove("activemq.broker"); } } };
public static void setUp() throws IOException { MBeanServer mbs = MBeanRegistry.getInstance().getPlatformMBeanServer(); JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://127.0.0.1"); cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); cs.start(); JMXServiceURL addr = cs.getAddress(); cc = JMXConnectorFactory.connect(addr); }
JMXServiceURL url = new JMXServiceURL("service:jmx:jmxmp://localhost:" + port); JMXConnectorServer connector = JMXConnectorServerFactory.newJMXConnectorServer(url, null, getServer()); factory.setServiceUrl(url.toString()); factory.setProxyInterface(IJmxTestBean.class); factory.setObjectName(OBJECT_NAME); connector.start(); connector.stop(); connector = JMXConnectorServerFactory.newJMXConnectorServer(url, null, getServer()); connector.start(); connector.stop();
String host = containerConfiguration.getHost(); if (cs != null && cs.isActive() && cs.getAddress().getPort() == port) { return; cs.stop(); JMXServiceURL jmxUrl = new JMXServiceURL(sJmxURL); .newJMXConnectorServer(jmxUrl, null, adminAttributes .getRawMBeanServer()); cs = connectorServer; cs.start(); + cs.getAddress().getURLPath()); } catch (Exception e) { log.error(
final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + hostname + ":" + port + "/jndi/rmi://" + hostname + ":" + port + "/jmxrmi"); new RMIConnectorServer(new JMXServiceURL("rmi", hostname, port), env, stub, mbs) { @Override public JMXServiceURL getAddress() { shiroAuthenticator = new JMXShiroAuthenticator(this.securityService); env.put(JMXConnectorServer.AUTHENTICATOR, shiroAuthenticator); jmxConnectorServer.addNotificationListener(shiroAuthenticator, null, jmxConnectorServer.getAttributes()); jmxConnectorServer.setMBeanServerForwarder(mBeanServerWrapper); } else { registerFileUploaderMBean(); jmxConnectorServer.start(); if (logger.isDebugEnabled()) { logger.debug("Finished starting jmx manager agent.");
public static void main(String[] args) { try { log("Creating Connector Server"); final JMXConnectorServer jcs = JMXConnectorServerFactory.newJMXConnectorServer(new JMXServiceURL("rmi", "localhost", 12387), null, ManagementFactory.getPlatformMBeanServer()); Thread jcsStopper = new Thread("JCS-Stopper") { public void run() { if(jcs.isActive()) { try { jcs.stop(); log("Connector Server Stopped"); } catch (Exception e) { log("Failed to stop JCS"); e.printStackTrace(); } } } }; jcsStopper.setDaemon(false); Runtime.getRuntime().addShutdownHook(jcsStopper); log("Registered Server Stop Task"); jcs.start(); log("Server Started"); Thread.sleep(3000); System.exit(0); } catch (Exception ex) { ex.printStackTrace(System.err); } }
sb.append("'\n"); if ((this.server != null) && this.server.isActive()) { sb.append("\tJMX remote access available:\n\t\tService URL: '"); final JMXServiceURL url = this.server.getAddress(); switch (this.usedJMXImplementation) { // NOPMD (extend in the future) case Sun: try { sb.append(new JMXServiceURL(url.getProtocol(), url.getHost(), url.getPort(), "/jndi/rmi://" + url.getHost() + ":" + this.port + "/" + "jmxrmi") .toString()); } catch (final MalformedURLException ignoreErrors) { final String[] connections = this.server.getConnectionIds(); if (connections.length == 0) { sb.append("\t\tNo current remote connections\n");
private void createJmxConnectorServer() throws IOException { LocateRegistry.createRegistry(1234); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost/jndi/rmi://localhost:1234/jmxrmi"); JMXConnectorServer svr = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); svr.start(); }
/** * Stop the {@code JMXConnectorServer} managed by an instance of this class. * Automatically called on {@code ApplicationContext} shutdown. * @throws IOException if there is an error stopping the connector server */ @Override public void destroy() throws IOException { try { if (this.connectorServer != null) { if (logger.isInfoEnabled()) { logger.info("Stopping JMX connector server: " + this.connectorServer); } this.connectorServer.stop(); } } finally { unregisterBeans(); } }
throw new RuntimeException("Started by another thread?"); JMX_CS = JMXConnectorServerFactory.newJMXConnectorServer(serviceUrl, jmxEnv, mbs); JMX_CS.start();
/** * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart() */ @Override public void doStart() throws Exception { _connectorServer.start(); ShutdownThread.register(0, this); LOG.info("JMX Remote URL: {}", _connectorServer.getAddress().toString()); }
@Test public void testTestValidConnection() throws Exception { Assume.group(TestGroup.JMXMP); JMXConnectorServer connectorServer = getConnectorServer(); connectorServer.start(); try { MBeanServerConnectionFactoryBean bean = new MBeanServerConnectionFactoryBean(); bean.setServiceUrl(serviceUrl); bean.afterPropertiesSet(); try { MBeanServerConnection connection = bean.getObject(); assertNotNull("Connection should not be null", connection); // perform simple MBean count test assertEquals("MBean count should be the same", getServer().getMBeanCount(), connection.getMBeanCount()); } finally { bean.destroy(); } } finally { connectorServer.stop(); } }
@Override public void run() { try { serverToStart.start(); } catch (IOException ex) { throw new JmxException("Could not start JMX connector server after delay", ex); } } };
private void closeConnectorServer() { if (_cs != null) { // Stopping the JMX ConnectorServer try { getEventLogger().message(ManagementConsoleMessages.SHUTTING_DOWN("JMX RMIConnectorServer", _cs.getAddress().getPort())); _cs.stop(); } catch (IOException e) { _log.error("Exception while closing the JMX ConnectorServer: ", e); } finally { _cs = null; } } }
void shutdown() { if (starter != null && starter instanceof RMIConnectorStarter) { ((RMIConnectorStarter) starter).stopAndUnexport(); } try { if (connObjectName != null) { mMBeanServer.unregisterMBean(connObjectName); connObjectName = null; } } catch (MBeanRegistrationException ex) { JMX_LOGGER.log(Level.SEVERE, JMX_MBEAN_REG_EXCEPTION, ex); } catch (InstanceNotFoundException ex) { JMX_LOGGER.log(Level.SEVERE, JMX_INSTANCE_NOT_FOUND_EXCEPTION, ex); } synchronized (service.lock) { for (final JMXConnectorServer connector : mConnectorServers) { try { final JMXServiceURL address = connector.getAddress(); connector.stop(); JMX_LOGGER.log(Level.INFO, JMX_STARTUPSERVICE_STOPPED_JMX_CONNECTOR, address); } catch (final Exception e) { e.printStackTrace(); } } service.jmxConnectorstatus = JMXConnectorStatus.STOPPED; } mConnectorServers.clear(); }