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 + "/";
}
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;
}
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());
}
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;
}
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();
}
Aggregations