List of usage examples for javax.management MBeanServer unregisterMBean
public void unregisterMBean(ObjectName name) throws InstanceNotFoundException, MBeanRegistrationException;
If this method successfully unregisters an MBean, a notification is sent as described above.
From source file:io.fabric8.test.smoke.JolokiaEndpointTestBase.java
@Test public void testJolokiaProxy() throws Exception { ContainerManager cntManager = ContainerManagerLocator.getContainerManager(); Container cnt = cntManager.getCurrentContainer(); ServiceEndpoint sep = cnt.getServiceEndpoint(URLServiceEndpoint.JOLOKIA_SERVICE_ENDPOINT_IDENTITY); URLServiceEndpoint urlsep = sep.adapt(URLServiceEndpoint.class); String serviceURL = urlsep.getServiceURL(); Assert.assertNotNull("Jolokia URL not null", serviceURL); // Get the local MBeanServer MBeanServer server = ServiceLocator.getRequiredService(MBeanServer.class); server.registerMBean(new Simple(), SimpleMXBean.OBJECT_NAME); try {/*from ww w.j ava 2 s .c o m*/ SimpleMXBean proxy = JolokiaMXBeanProxy.getMXBeanProxy(serviceURL, SimpleMXBean.OBJECT_NAME, SimpleMXBean.class); // Simple string echo Assert.assertEquals("Hello: Kermit", proxy.echo("Kermit")); // Set Bean attribute using JSONObject Bean bean = new Bean("Hello", "Foo"); proxy.setBean(bean); // Get Bean attribute using JSONObject Assert.assertEquals(bean, proxy.getBean()); // Simple Bean echo using JSONObject Assert.assertEquals(bean, proxy.echoBean(bean)); } finally { server.unregisterMBean(SimpleMXBean.OBJECT_NAME); } }
From source file:org.nuxeo.runtime.tomcat.NuxeoLauncher.java
protected void handleEvent(NuxeoWebappLoader loader, LifecycleEvent event) { String type = event.getType(); try {//ww w . j ava2 s . com MutableClassLoader cl = (MutableClassLoader) loader.getClassLoader(); boolean devMode = cl instanceof NuxeoDevWebappClassLoader; if (type == Lifecycle.CONFIGURE_START_EVENT) { File homeDir = resolveHomeDirectory(loader); if (devMode) { bootstrap = new DevFrameworkBootstrap(cl, homeDir); MBeanServer server = ManagementFactory.getPlatformMBeanServer(); server.registerMBean(bootstrap, new ObjectName(DEV_BUNDLES_NAME)); server.registerMBean(cl, new ObjectName(WEB_RESOURCES_NAME)); ((NuxeoDevWebappClassLoader) cl).setBootstrap((DevFrameworkBootstrap) bootstrap); } else { bootstrap = new FrameworkBootstrap(cl, homeDir); } bootstrap.setHostName("Tomcat"); bootstrap.setHostVersion(ServerInfo.getServerNumber()); bootstrap.initialize(); } else if (type == Lifecycle.START_EVENT) { bootstrap.start(); } else if (type == Lifecycle.STOP_EVENT) { bootstrap.stop(); if (devMode) { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); server.unregisterMBean(new ObjectName(DEV_BUNDLES_NAME)); server.unregisterMBean(new ObjectName(WEB_RESOURCES_NAME)); } } } catch (IOException | JMException | ReflectiveOperationException e) { log.error("Failed to handle event: " + type, e); } }
From source file:com.googlecode.arit.mbeans.MBeanScanner.java
public void clean(ClassLoader classLoader) { ArrayList<MBeanServer> mbeanServers = MBeanServerFactory.findMBeanServer(null); for (MBeanServer mbs : mbeanServers) { MBeanAccessor mbeanAccessor = mbsInspector.inspect(mbs); if (mbeanAccessor == null) { String errorMsg = "Unable to inspect MBeanServer of type " + mbs.getClass().getName(); LOG.error(errorMsg);// ww w. java 2 s. co m if (messages != null) { messages.addMessage(errorMsg); } } else { Set<ObjectName> mbeans; try { mbeans = mbs.queryNames(new ObjectName("*:*"), null); } catch (MalformedObjectNameException ex) { // We should never get here throw new Error(ex); } for (ObjectName name : mbeans) { Object mbean = mbeanAccessor.retrieve(name); if (mbean.getClass().getClassLoader().equals(classLoader)) { try { mbs.unregisterMBean(name); } catch (JMException ex) { String errorMsg = "Error during cleanup of mbean - unregistration of mbean " + name.toString() + " failed"; LOG.error(errorMsg, ex); if (messages != null) { messages.addMessage(errorMsg); } } } } } } }
From source file:org.apache.jk.common.ModJkMX.java
public void destroy() { try {//from w ww . java 2 s . c o m // We should keep track of loaded beans and call stop. // Modeler should do it... Iterator mbeansIt = mbeans.values().iterator(); MBeanServer mbserver = Registry.getRegistry().getMBeanServer(); while (mbeansIt.hasNext()) { MBeanProxy proxy = (MBeanProxy) mbeansIt.next(); Object ooname = proxy.getObjectName(); if (ooname != null) { ObjectName oname = null; if (ooname instanceof ObjectName) { oname = (ObjectName) ooname; } else if (ooname instanceof String) { oname = new ObjectName((String) ooname); } if (oname != null) { mbserver.unregisterMBean(oname); } } } } catch (Throwable t) { log.error("Destroy error", t); } }
From source file:org.wso2.carbon.caching.impl.CacheImpl.java
@Override public void stop() { Util.checkAccess(ownerTenantDomain, ownerTenantId); checkStatusStarted();/*from w w w.ja va 2 s.com*/ lastAccessed = System.currentTimeMillis(); localCache.clear(); if (!isLocalCache) { distributedCache.clear(); distributedTimestampMap.clear(); } // Unregister the cacheMXBean MBean MBeanServer mserver = getMBeanServer(); try { mserver.unregisterMBean(cacheMXBeanObjName); } catch (InstanceNotFoundException ignored) { } catch (MBeanRegistrationException e) { log.error("Cannot unregister CacheMXBean", e); } status = Status.STOPPED; cacheManager.removeCache(cacheName); }
From source file:com.web.server.SARDeployer.java
/** * This method undeployed the SAR// w ww. ja v a2s. c om * @param dir * @return */ public boolean deleteDir(File dir) { String fileName = dir.getName(); System.out.println("Dirname to be deleted" + fileName); Sar sar = null; try { sar = (Sar) sardigester.parse(new InputSource( new FileInputStream(deployDirectory + "/" + fileName + "/META-INF/" + "mbean-service.xml"))); } catch (IOException | SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } URLClassLoader sarClassLoader = (URLClassLoader) sarsMap.get(fileName); if (sarClassLoader != null) { ClassLoaderUtil.closeClassLoader(sarClassLoader); CopyOnWriteArrayList mbeans = sar.getMbean(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); System.out.println(mbs); ObjectName objName; try { for (int index = 0; index < mbeans.size(); index++) { Mbean mbean = (Mbean) mbeans.get(index); System.out.println(mbean.getObjectname()); System.out.println(mbean.getCls()); objName = new ObjectName(mbean.getObjectname()); if (mbs.isRegistered(objName)) { mbs.invoke(objName, "stopService", null, null); //mbs.invoke(objName, "destroy", null, null); mbs.unregisterMBean(objName); } } sarsMap.remove(fileName); } catch (MalformedObjectNameException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MBeanRegistrationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstanceNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ReflectionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MBeanException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return recursiveDelete(dir); }
From source file:com.fatwire.dta.sscrawler.URLReaderService.java
public void start(final ProgressMonitor monitor) { connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.getParams().setConnectionTimeout(30000); connectionManager.getParams().setDefaultMaxConnectionsPerHost(1500); connectionManager.getParams().setMaxTotalConnections(30000); final MBeanServer platform = java.lang.management.ManagementFactory.getPlatformMBeanServer(); try {/*from w w w . j a v a 2 s . c o m*/ platform.registerMBean(new ReaderService(scheduler, connectionManager), new ObjectName("com.fatwire.crawler:name=scheduler")); } catch (final Throwable t) { log.error(t.getMessage(), t); } monitor.beginTask("Crawling on " + hostConfig.toString(), maxPages == Integer.MAX_VALUE ? -1 : maxPages); scheduler.monitor = monitor; for (final QueryString thingToDo : startUrls) { scheduler.schedulePage(thingToDo); } scheduler.waitForlAllTasksToFinish(); try { connectionManager.shutdown(); } catch (final Throwable t) { log.error(t.getMessage(), t); } try { platform.unregisterMBean(new ObjectName("com.fatwire.crawler:name=scheduler")); } catch (final Throwable t) { log.error(t.getMessage(), t); } monitor.done(); }
From source file:com.fatwire.dta.sscrawler.App.java
protected void doWork(final CommandLine cmd) throws Exception { final Crawler crawler = new Crawler(); URI startUri = null;/* w ww. j a v a2 s . c om*/ startUri = URI.create(cmd.getArgs()[1]); if (cmd.hasOption('m')) { crawler.setMaxPages(Integer.parseInt(cmd.getOptionValue('m'))); } final int threads = Integer.parseInt(cmd.getOptionValue('t', "5")); if (startUri == null) { throw new IllegalArgumentException("startUri is not set"); } final int t = startUri.toASCIIString().indexOf("/ContentServer"); if (t == -1) { throw new IllegalArgumentException("/ContentServer is not found on the startUri."); } crawler.setStartUri(new URI(null, null, null, -1, startUri.getRawPath(), startUri.getRawQuery(), startUri.getFragment())); final HostConfig hc = createHostConfig(URI.create(startUri.toASCIIString().substring(0, t))); final String proxyUsername = cmd.getOptionValue("pu"); final String proxyPassword = cmd.getOptionValue("pw"); final String proxyHost = cmd.getOptionValue("ph"); final int proxyPort = Integer.parseInt(cmd.getOptionValue("", "8080")); if (StringUtils.isNotBlank(proxyUsername) && StringUtils.isNotBlank(proxyUsername)) { hc.setProxyCredentials(new UsernamePasswordCredentials(proxyUsername, proxyPassword)); } if (StringUtils.isNotBlank(proxyHost)) { hc.setProxyHost(new ProxyHost(proxyHost, proxyPort)); } else if (StringUtils.isNotBlank(System.getProperty("http.proxyhost")) && StringUtils.isNotBlank(System.getProperty("http.proxyport"))) { hc.setProxyHost(new ProxyHost(System.getProperty("http.proxyhost"), Integer.parseInt(System.getProperty("http.proxyport")))); } crawler.setHostConfig(hc); SSUriHelper helper = null; if (cmd.hasOption('f')) { final UriHelperFactory f = (UriHelperFactory) Class.forName(cmd.getOptionValue('f')).newInstance(); helper = f.create(crawler.getStartUri().getPath()); } else { helper = new SSUriHelper(crawler.getStartUri().getPath()); } final ThreadPoolExecutor readerPool = new RenderingThreadPool(threads); final MBeanServer platform = java.lang.management.ManagementFactory.getPlatformMBeanServer(); try { platform.registerMBean(readerPool, new ObjectName("com.fatwire.crawler:name=readerpool")); } catch (final Throwable x) { LogFactory.getLog(App.class).error(x.getMessage(), x); } crawler.setExecutor(readerPool); File path = null; if (cmd.hasOption('d')) { path = new File(cmd.getOptionValue("d")); } else { path = getOutputDir(); } if (path != null) { final SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HHmm"); path = new File(path, df.format(new Date())); path.mkdirs(); } crawler.setReporters(createReporters(path, helper)); crawler.setUriHelper(helper); try { crawler.work(); } finally { readerPool.shutdown(); try { platform.unregisterMBean(new ObjectName("com.fatwire.crawler:name=readerpool")); } catch (final Throwable x) { LogFactory.getLog(App.class).error(x.getMessage(), x); } } }
From source file:org.red5.server.stream.ClientBroadcastStream.java
protected void unregisterJMX() { if (registerJMX) { if (StringUtils.isNotEmpty(publishedName) && !"false".equals(publishedName)) { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try { ObjectName oName = new ObjectName( String.format("org.red5.server:type=ClientBroadcastStream,scope=%s,publishedName=%s", getScope().getName(), publishedName)); mbs.unregisterMBean(oName); } catch (Exception e) { log.warn("Exception unregistering", e); }/*from w w w. j a v a 2s. co m*/ } } }
From source file:org.codice.ddf.security.certificate.keystore.editor.KeystoreEditor.java
private void registerMbean() { ObjectName objectName = null; MBeanServer mBeanServer = null; try {/*from w w w.j a va 2 s .c o m*/ objectName = new ObjectName(KeystoreEditor.class.getName() + ":service=keystore"); mBeanServer = ManagementFactory.getPlatformMBeanServer(); } catch (MalformedObjectNameException e) { LOGGER.error("Unable to create Keystore Editor MBean.", e); } if (mBeanServer != null) { try { try { mBeanServer.registerMBean(this, objectName); LOGGER.info("Registered Keystore Editor MBean under object name: {}", objectName.toString()); } catch (InstanceAlreadyExistsException e) { // Try to remove and re-register mBeanServer.unregisterMBean(objectName); mBeanServer.registerMBean(this, objectName); LOGGER.info("Re-registered Keystore Editor MBean"); } } catch (Exception e) { LOGGER.error("Could not register MBean [{}].", objectName.toString(), e); } } }