Search in sources :

Example 1 with MBeanServer

use of javax.management.MBeanServer in project jetty.project by eclipse.

the class AttrEventTriggerTest method setUp.

@Before
public void setUp() throws Exception {
    File docRoot = new File("target/test-output/docroot/");
    docRoot.mkdirs();
    docRoot.deleteOnExit();
    System.setProperty("org.eclipse.jetty.util.log.DEBUG", "");
    _server = new Server();
    ServerConnector connector = new ServerConnector(_server);
    connector.setPort(0);
    _server.setConnectors(new Connector[] { connector });
    _handler = new TestHandler();
    _server.setHandler(_handler);
    MBeanContainer.resetUnique();
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    _mBeanContainer = new MBeanContainer(mBeanServer);
    _server.addBean(_mBeanContainer, true);
    _server.addBean(Log.getLog());
    _counter = _handler.getRequestCounter();
    _server.addBean(_counter);
    _server.start();
    startClient();
    _monitor = new JMXMonitor();
    int port = connector.getLocalPort();
    _requestUrl = "http://localhost:" + port + "/";
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) MBeanServer(javax.management.MBeanServer) Server(org.eclipse.jetty.server.Server) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) File(java.io.File) MBeanServer(javax.management.MBeanServer) Before(org.junit.Before)

Example 2 with MBeanServer

use of javax.management.MBeanServer in project tomcat by apache.

the class BaseGenericObjectPool method jmxRegister.

/**
     * Registers the pool with the platform MBean server.
     * The registered name will be
     * <code>jmxNameBase + jmxNamePrefix + i</code> where i is the least
     * integer greater than or equal to 1 such that the name is not already
     * registered. Swallows MBeanRegistrationException, NotCompliantMBeanException
     * returning null.
     *
     * @param config Pool configuration
     * @param jmxNameBase default base JMX name for this pool
     * @param jmxNamePrefix name prefix
     * @return registered ObjectName, null if registration fails
     */
private ObjectName jmxRegister(final BaseObjectPoolConfig config, final String jmxNameBase, String jmxNamePrefix) {
    ObjectName objectName = null;
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    int i = 1;
    boolean registered = false;
    String base = config.getJmxNameBase();
    if (base == null) {
        base = jmxNameBase;
    }
    while (!registered) {
        try {
            ObjectName objName;
            // only one so the names are cleaner.
            if (i == 1) {
                objName = new ObjectName(base + jmxNamePrefix);
            } else {
                objName = new ObjectName(base + jmxNamePrefix + i);
            }
            mbs.registerMBean(this, objName);
            objectName = objName;
            registered = true;
        } catch (final MalformedObjectNameException e) {
            if (BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX.equals(jmxNamePrefix) && jmxNameBase.equals(base)) {
                // Shouldn't happen. Skip registration if it does.
                registered = true;
            } else {
                // Must be an invalid name. Use the defaults instead.
                jmxNamePrefix = BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX;
                base = jmxNameBase;
            }
        } catch (final InstanceAlreadyExistsException e) {
            // Increment the index and try again
            i++;
        } catch (final MBeanRegistrationException e) {
            // Shouldn't happen. Skip registration if it does.
            registered = true;
        } catch (final NotCompliantMBeanException e) {
            // Shouldn't happen. Skip registration if it does.
            registered = true;
        }
    }
    return objectName;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Example 3 with MBeanServer

use of javax.management.MBeanServer in project jmxtrans by jmxtrans.

the class JmxTransformer method doMain.

/**
	 * The real main method.
	 */
private void doMain() throws Exception {
    MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
    ManagedJmxTransformerProcess mbean = new ManagedJmxTransformerProcess(this, configuration);
    platformMBeanServer.registerMBean(mbean, mbean.getObjectName());
    ManagedThreadPoolExecutor queryExecutorMBean = new ManagedThreadPoolExecutor(queryProcessorExecutor, "queryProcessorExecutor");
    platformMBeanServer.registerMBean(queryExecutorMBean, queryExecutorMBean.getObjectName());
    ManagedThreadPoolExecutor resultExecutorMBean = new ManagedThreadPoolExecutor(resultProcessorExecutor, "resultProcessorExecutor");
    platformMBeanServer.registerMBean(resultExecutorMBean, resultExecutorMBean.getObjectName());
    // Start the process
    this.start();
    while (true) {
        // TODO : Make something here, maybe watch for files?
        try {
            Thread.sleep(5);
        } catch (Exception e) {
            log.info("shutting down", e);
            break;
        }
    }
    platformMBeanServer.unregisterMBean(mbean.getObjectName());
    platformMBeanServer.unregisterMBean(queryExecutorMBean.getObjectName());
    platformMBeanServer.unregisterMBean(resultExecutorMBean.getObjectName());
}
Also used : ManagedThreadPoolExecutor(com.googlecode.jmxtrans.monitoring.ManagedThreadPoolExecutor) ValidationException(com.googlecode.jmxtrans.model.ValidationException) SchedulerException(org.quartz.SchedulerException) ParseException(java.text.ParseException) LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException) MBeanServer(javax.management.MBeanServer)

Example 4 with MBeanServer

use of javax.management.MBeanServer in project hibernate-orm by hibernate.

the class EhcacheHibernateMBeanRegistrationImpl method registerBean.

private void registerBean(String name, CacheManager manager) throws Exception {
    ehcacheHibernate = new EhcacheHibernate(manager);
    int tries = 0;
    boolean success;
    Exception exception = null;
    final String cacheManagerClusterUUID = manager.getClusterUUID();
    String registeredCacheManagerName;
    do {
        registeredCacheManagerName = name;
        if (tries != 0) {
            registeredCacheManagerName += "_" + tries;
        }
        try {
            // register the CacheManager MBean
            final MBeanServer mBeanServer = getMBeanServer();
            cacheManagerObjectName = EhcacheHibernateMbeanNames.getCacheManagerObjectName(cacheManagerClusterUUID, registeredCacheManagerName);
            mBeanServer.registerMBean(ehcacheHibernate, cacheManagerObjectName);
            success = true;
            break;
        } catch (InstanceAlreadyExistsException e) {
            success = false;
            exception = e;
        }
        tries++;
    } while (tries < MAX_MBEAN_REGISTRATION_RETRIES);
    if (!success) {
        throw new Exception("Cannot register mbean for CacheManager with name" + manager.getName() + " afterQuery " + MAX_MBEAN_REGISTRATION_RETRIES + " retries. Last tried name=" + registeredCacheManagerName, exception);
    }
    status = Status.STATUS_ALIVE;
}
Also used : InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) CacheException(net.sf.ehcache.CacheException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanServer(javax.management.MBeanServer)

Example 5 with MBeanServer

use of javax.management.MBeanServer in project hbase by apache.

the class JSONBean method dumpRegionServerMetrics.

/**
   * Dump out a subset of regionserver mbeans only, not all of them, as json on System.out.
   * @throws MalformedObjectNameException
   * @throws IOException
   */
public static String dumpRegionServerMetrics() throws MalformedObjectNameException, IOException {
    // Guess this size
    StringWriter sw = new StringWriter(1024 * 100);
    try (PrintWriter writer = new PrintWriter(sw)) {
        JSONBean dumper = new JSONBean();
        try (JSONBean.Writer jsonBeanWriter = dumper.open(writer)) {
            MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
            jsonBeanWriter.write(mbeanServer, new ObjectName("java.lang:type=Memory"), null, false);
            jsonBeanWriter.write(mbeanServer, new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=IPC"), null, false);
            jsonBeanWriter.write(mbeanServer, new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=Replication"), null, false);
            jsonBeanWriter.write(mbeanServer, new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=Server"), null, false);
        }
    }
    sw.close();
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Aggregations

MBeanServer (javax.management.MBeanServer)1217 ObjectName (javax.management.ObjectName)938 Test (org.junit.Test)214 MalformedObjectNameException (javax.management.MalformedObjectNameException)122 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)94 InstanceNotFoundException (javax.management.InstanceNotFoundException)87 IOException (java.io.IOException)82 JMXServiceURL (javax.management.remote.JMXServiceURL)70 Attribute (javax.management.Attribute)66 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)65 HashMap (java.util.HashMap)63 MBeanRegistrationException (javax.management.MBeanRegistrationException)56 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)54 TabularData (javax.management.openmbean.TabularData)51 ArrayList (java.util.ArrayList)47 JMXConnectorServer (javax.management.remote.JMXConnectorServer)47 JMXConnector (javax.management.remote.JMXConnector)40 Map (java.util.Map)38 JMException (javax.management.JMException)38 Test (org.junit.jupiter.api.Test)36