List of usage examples for java.lang.management ManagementFactory getPlatformMBeanServer
public static synchronized MBeanServer getPlatformMBeanServer()
From source file:be.fgov.kszbcss.rhq.websphere.config.ConfigQueryServiceImpl.java
public ConfigQueryServiceImpl(String cacheName, File persistentFile, WebSphereServer server, String cell) { this.cell = cell; config = new CellConfiguration(server, cell); queryCache = new ConfigQueryCache(cacheName, config, persistentFile); epochPollExecutorService = Executors.newScheduledThreadPool(1, new NamedThreadFactory(cacheName + "-epoch-poll")); future = epochPollExecutorService.scheduleWithFixedDelay(this, 0, 30, TimeUnit.SECONDS); queryCache.start(2);//from w w w. j av a 2s. c om try { mbean = ManagementFactory.getPlatformMBeanServer().registerMBean(this, ObjectName .getInstance("rhq.websphere:type=ConfigQueryService,cell=" + cell + ",cacheName=" + cacheName)); } catch (Throwable ex) { log.error("MBean registration failed", ex); } }
From source file:org.springframework.boot.context.SpringApplicationLifecycleRegistrar.java
@Override public void destroy() throws Exception { ManagementFactory.getPlatformMBeanServer().unregisterMBean(objectName); }
From source file:com.github.stephanarts.cas.ticket.registry.ZMQTicketRegistry.java
/** * Creates a new TicketRegistry Backend. * * An instance of the ZMQTicketRegistry stores * CAS Tickets in a cluster of Registry-Providers. * * @param providers Array of providers to connect to * @param address Address to bind the RegistryProvider on * @param port TCP port to bind the RegistryProvider on * @param requestTimeout Timeout//ww w. ja va 2s .c om * @param heartbeatTimeout Timeout * @param heartbeatInterval Interval * * @throws Exception if localProvider could not be found */ public ZMQTicketRegistry(final String[] providers, final String address, final int port, final int requestTimeout, final int heartbeatTimeout, final int heartbeatInterval) throws Exception { this.provider = new ZMQProvider("tcp://" + address + ":" + port, this.providerId); this.provider.start(); this.pacemaker = new PaceMaker(); pacemaker.setHeartbeatInterval(heartbeatInterval); pacemaker.setHeartbeatTimeout(heartbeatTimeout); this.registryBroker = new RegistryBroker(providers, requestTimeout, this.pacemaker, this.providerId); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); this.mbeanName = new ObjectName("CAS:type=TicketRegistry,provider='" + port + "'"); mbs.registerMBean(this.provider, this.mbeanName); try { this.registryBroker.bootstrap(); int nTickets = this.registryBroker.getTickets().size(); logger.info("Bootstrapping complete, got " + nTickets + " tickets."); } catch (final BootstrapException e) { logger.warn(e.getMessage()); } }
From source file:org.jolokia.jmx.JolokiaMBeanServerTest.java
@Test public void withConstraint() throws MalformedObjectNameException, NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanException, AttributeNotFoundException, ReflectionException, InstanceNotFoundException, ParseException, InvalidTargetObjectTypeException, NoSuchMethodException, IntrospectionException { JolokiaMBeanServer server = new JolokiaMBeanServer(); ObjectName oName = new ObjectName("test:type=jsonMBean"); server.registerMBean(new JsonAnnoPlainTest(), oName); MBeanServer plattformServer = ManagementFactory.getPlatformMBeanServer(); String deepDive = (String) plattformServer.getAttribute(oName, "DeepDive"); JSONObject deepDiveS = (JSONObject) new JSONParser().parse(deepDive); assertEquals(deepDiveS.size(), 1);//from w w w. j a v a2s . c o m // Serialization is truncated because of maxDepth = 1 assertTrue(deepDiveS.get("map") instanceof String); assertTrue(deepDiveS.get("map").toString().matches(".*hot=.*Chili.*")); server.unregisterMBean(oName); Assert.assertFalse(plattformServer.isRegistered(oName)); Assert.assertFalse(server.isRegistered(oName)); }
From source file:com.all.services.ServiceMonitor.java
public static void main(String[] args) { try {/*from w w w . ja v a2 s. c o m*/ LOG.info("Starting JMX..."); runMonitor(ManagementFactory.getPlatformMBeanServer(), "com.all.services:type=ServiceMonitor", new ServiceMonitor(Thread.currentThread())); while (!Thread.interrupted()) { try { Thread.sleep(1000); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } } catch (Exception e) { LOG.error(e, e); } finally { LOG.info("JMX has stopped."); System.exit(0); } }
From source file:io.hawt.osgi.jmx.RBACDecorator.java
void init() throws Exception { if (objectName == null) { objectName = new ObjectName("hawtio:type=security,area=jolokia,name=RBACDecorator"); }//from www . j av a 2s . c o m if (mBeanServer == null) { mBeanServer = ManagementFactory.getPlatformMBeanServer(); } mBeanServer.registerMBean(this, objectName); }
From source file:com.fatwire.gst.web.status.StatusRequestListener.java
public void contextInitialized(ServletContextEvent sce) { String n = sce.getServletContext().getContextPath(); if (n == null || n.length() == 0) { n = "/";//from www. j a v a2 s .co m } requestCounter = new RequestCounter(n); ConcurrencyCounter<?, ?> old = ConcurrencyCounterLocator.getInstance().register(requestCounter); if (old != null) { requestCounter = (RequestCounter) old; } try { name = new ObjectName("com.fatwire.gst.web:type=RequestCounter,name=" + ObjectName.quote(n)); ManagementFactory.getPlatformMBeanServer().registerMBean(new StatusCounter(requestCounter), name); } catch (Throwable e) { log.warn(e.getMessage(), e); } }
From source file:org.apache.helix.ipc.benchmark.BenchmarkDriver.java
@Override public void run() { try {/* w w w . j av a2s. co m*/ // Register controller MBean final BenchmarkDriver driver = this; ManagementFactory.getPlatformMBeanServer().registerMBean(new Controller() { @Override public void startTraffic(String remoteHost, int remotePort) { driver.startTraffic(remoteHost, remotePort); } @Override public void stopTraffic() { driver.stopTraffic(); } }, new ObjectName("org.apache.helix:type=BenchmarkDriver")); // The local server localhost = InetAddress.getLocalHost().getCanonicalHostName(); ipcService = new NettyHelixIPCService(new NettyHelixIPCService.Config() .setInstanceName(localhost + "_" + port).setPort(port).setNumConnections(numConnections)); // Counts number of messages received, and ack them ipcService.registerCallback(MESSAGE_TYPE, new HelixIPCCallback() { @Override public void onMessage(HelixMessageScope scope, UUID messageId, ByteBuf message) { // Do nothing } }); ipcService.start(); System.out.println( "Started IPC service on " + InetAddress.getLocalHost().getCanonicalHostName() + ":" + port); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.app.server.node.NodeServer.java
/** * This method implements the node server request *///from ww w. j a v a2s. c o m public void run() { //deployer.start(); try { ObjectName objName = new ObjectName("com.app.server:type=deployer,service=RMIDeployer"); MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); mbeanServer.createMBean("com.app.server.node.RMIDeployer", objName); mbeanServer.invoke(objName, "init", new Object[] { deployerList }, new String[] { Vector.class.getName() }); ServerConfig serverConfig = new ServerConfig(); serverConfig.setRmiregistryport(port + ""); serverConfig.setCachedir("d:/AppServer/cache"); mbeanServer.invoke(objName, "init", new Object[] { serviceList, serverConfig, mbeanServer }, new String[] { Vector.class.getName(), ServerConfig.class.getName(), MBeanServer.class.getName() }); InetAddress inet = null; inet = InetAddress.getLocalHost(); mbeanServer.invoke(objName, "deploy", new Object[] { new URL("file:///D:/AppServer/deploy/rmitest.rmi"), false, null, inet.getHostName() + ":" + port }, new String[] { URL.class.getName(), boolean.class.getName(), ClassLoader.class.getName(), String.class.getName() }); //deployer.deploy(new URL("file:///D:/AppServer/deploy/rmitest.rmi"),false,null,inet.getHostName()+":"+port); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:net.gcolin.simplerepo.test.AbstractRepoTest.java
protected void setAttributeJmx(String name, String attribute, Object arguments) throws Exception { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); ObjectName oname = server.queryNames(new ObjectName(name), null).iterator().next(); server.setAttribute(oname, new Attribute(attribute, arguments)); }