private void registerMBeanWithServer(Object obj, ObjectName name, boolean forceRegistration) throws JMException { // have we already registered the bean, there can be shared instances in the camel routes boolean exists = isRegistered(name); if (exists) { if (forceRegistration) { LOG.info( "ForceRegistration enabled, unregistering existing MBean with ObjectName: {}", name); server.unregisterMBean(name); } else { // okay ignore we do not want to force it and it could be a shared instance LOG.debug("MBean already registered with ObjectName: {}", name); } } // register bean if by force or not exists ObjectInstance instance = null; if (forceRegistration || !exists) { LOG.trace("Registering MBean with ObjectName: {}", name); instance = server.registerMBean(obj, name); } // need to use the name returned from the server as some JEE servers may modify the name if (instance != null) { ObjectName registeredName = instance.getObjectName(); LOG.debug("Registered MBean with ObjectName: {}", registeredName); mbeansRegistered.put(name, registeredName); } }
public HashMap<String, ArrayList<ObjectName>> getDomains( final MBeanServer mBeanServer, String mbeanDomain, String mBean) throws ReflectionException, InstanceNotFoundException, IntrospectionException, MalformedObjectNameException, NullPointerException { final HashMap<String, ArrayList<ObjectName>> result = new HashMap<String, ArrayList<ObjectName>>(); ObjectName queryObjectName = null; if (mbeanDomain != null && !mbeanDomain.isEmpty()) queryObjectName = new ObjectName(mbeanDomain + (mBean != null ? ":" + mBean : ":*")); final Set mbeans = mBeanServer.queryMBeans(queryObjectName, null); final Iterator iter = mbeans.iterator(); while (iter.hasNext()) { final ObjectInstance objectInstance = (ObjectInstance) iter.next(); final ObjectName objectName = objectInstance.getObjectName(); final String domain = objectName.getDomain(); // if (result.containsKey(domain)) { final ArrayList<ObjectName> list = result.get(domain); list.add(objectName); result.put(domain, list); } else { final ArrayList<ObjectName> list = new ArrayList<ObjectName>(); list.add(objectName); result.put(domain, list); } } return result; }
@Test(groups = "wso2.esb", description = "JMS Consumer Test after resume") public void testJMSResume() throws Exception { // redeploy proxy service addProxyService(AXIOMUtil.stringToOM(getJMSProxy())); // give it max time to deploy Thread.sleep(16000); // JMS should still be paused. assertTrue(!stringExistsInLog(msgAfter)); // resume JMS Listener from JMXClient Set<ObjectInstance> objSet = mbsc.queryMBeans( new ObjectName("org.apache.axis2:Type=Transport,ConnectorName=jms-listener-*"), null); Iterator i = objSet.iterator(); while (i.hasNext()) { ObjectInstance obj = (ObjectInstance) i.next(); mbsc.invoke(obj.getObjectName(), "resume", null, null); } Thread.sleep(10000); assertTrue(stringExistsInLog("Listener resumed")); assertTrue(stringExistsInLog(msgAfter)); }
public static List<MBeanPooledResource> of( String objectName, String poolTypeName, String mbeanKeyPropertyName, String mbeanActiveAttribute, String mbeanCountAttribute, String mbeanMaxAttribute, String mbeanQueueAttribute) { try { final Set<ObjectInstance> objectInstances = server.queryMBeans(new ObjectName(objectName), null); List<MBeanPooledResource> pools = new ArrayList<MBeanPooledResource>(objectInstances.size()); for (final ObjectInstance objectInstance : objectInstances) { pools.add( new MBeanPooledResource( poolTypeName, objectInstance.getObjectName(), mbeanKeyPropertyName, mbeanActiveAttribute, mbeanCountAttribute, mbeanMaxAttribute, mbeanQueueAttribute)); } return pools; } catch (Exception e) { logger.warn(e.getMessage() + " (this exception is ignored)", e); return new LinkedList<MBeanPooledResource>(); } }
public void unregisterAvailableMBeans(@Observes final AfterShutdownProccess event) { MBeanManager manager = Beans.getReference(MBeanManager.class); for (ObjectInstance instance : manager.listRegisteredMBeans()) { MBeanHelper.unregister(instance.getObjectName()); } manager.cleanRegisteredMBeans(); }
public static void main(String[] args) throws Exception { DevelopmentProvider dtp = new DevelopmentProvider(); Topology t = dtp.newTopology("DevelopmentSampleJobMXBean"); Random r = new Random(); TStream<Double> d = t.poll(() -> r.nextGaussian(), 100, TimeUnit.MILLISECONDS); d.sink(tuple -> System.out.print(".")); dtp.submit(t); System.out.println(dtp.getServices().getService(HttpServer.class).getConsoleUrl()); MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); StringBuffer sbuf = new StringBuffer(); sbuf.append(DevelopmentProvider.JMX_DOMAIN); sbuf.append(":interface="); sbuf.append(ObjectName.quote("quarks.execution.mbeans.JobMXBean")); sbuf.append(",type="); sbuf.append(ObjectName.quote("job")); sbuf.append(",*"); System.out.println("Looking for MBeans of type job: " + sbuf.toString()); ObjectName jobObjName = new ObjectName(sbuf.toString()); Set<ObjectInstance> jobInstances = mBeanServer.queryMBeans(jobObjName, null); Iterator<ObjectInstance> jobIterator = jobInstances.iterator(); while (jobIterator.hasNext()) { ObjectInstance jobInstance = jobIterator.next(); ObjectName objectName = jobInstance.getObjectName(); String jobId = (String) mBeanServer.getAttribute(objectName, "Id"); String jobName = (String) mBeanServer.getAttribute(objectName, "Name"); String jobCurState = (String) mBeanServer.getAttribute(objectName, "CurrentState"); String jobNextState = (String) mBeanServer.getAttribute(objectName, "NextState"); String jobHealth = (String) mBeanServer.getAttribute(objectName, "Health"); String jobLastError = (String) mBeanServer.getAttribute(objectName, "LastError"); System.out.println( "Found a job with JobId: " + jobId + " Name: " + jobName + " CurrentState: " + jobCurState + " NextState: " + jobNextState + " Health: " + jobHealth + " LastError: \"" + jobLastError + "\""); } }
/** Registers the Dynamic Mbean. */ public void start() { // create the corresponding MBean if (m_registerCallbacks) { m_MBean = new DynamicMBeanWRegisterImpl( m_jmxConfigFieldMap, m_instanceManager, m_preRegisterMeth, m_postRegisterMeth, m_preDeregisterMeth, m_postDeregisterMeth); } else { m_MBean = new DynamicMBeanImpl(m_jmxConfigFieldMap, m_instanceManager); } if (m_usesMOSGi) { // use whiteboard pattern to register MBean if (m_serviceRegistration != null) { m_serviceRegistration.unregister(); } // Register the ManagedService BundleContext bundleContext = m_instanceManager.getContext(); Properties properties = new Properties(); try { m_objectName = new ObjectName(getObjectNameString()); properties.put("jmxagent.objectName", m_objectName.toString()); m_serviceRegistration = bundleContext.registerService( javax.management.DynamicMBean.class.getName(), m_MBean, properties); m_registered = true; } catch (Exception e) { e.printStackTrace(); } } else { try { m_objectName = new ObjectName(getObjectNameString()); ObjectInstance instance = ManagementFactory.getPlatformMBeanServer().registerMBean(m_MBean, m_objectName); // we must retrieve object name used to register the MBean. // It can have been changed by preRegister method of // MBeanRegistration interface. if (m_registerCallbacks) { m_objectName = instance.getObjectName(); } m_registered = true; } catch (Exception e) { error("Registration of MBean failed.", e); } } }
/** Unregister all log4j MBeans if there are any left over the old deployment */ protected void unregisterMBeansIfNecessary() throws MalformedObjectNameException, InstanceNotFoundException, MBeanRegistrationException { if (mBeanServer.isRegistered(jmxSupport.getObjectName(JMX_OBJECT_NAME))) { // unregister all log4jMBeans and loggers Set log4jMBeans = mBeanServer.queryMBeans(jmxSupport.getObjectName("log4j*:*"), null); for (Iterator it = log4jMBeans.iterator(); it.hasNext(); ) { ObjectInstance objectInstance = (ObjectInstance) it.next(); ObjectName theName = objectInstance.getObjectName(); mBeanServer.unregisterMBean(theName); } } }
void init() { try { Set<ObjectInstance> existingInstances = _server.queryMBeans(new ObjectName(_domain + ":Cluster=cluster,*"), null); for (ObjectInstance instance : existingInstances) { String mbeanName = instance.getObjectName().toString(); // System.out.println("mbeanName: " + mbeanName); addMBean(instance.getObjectName()); } } catch (Exception e) { _logger.warn("fail to get all existing mbeans in " + _domain, e); } }
@Override public List<CamelProcessorMBean> getProcessors(String managementName) throws Exception { String id = managementName != null ? managementName : camelContextManagementName; ObjectName query = ObjectName.getInstance("org.apache.camel:context=" + id + ",type=processors,*"); Set<ObjectInstance> names = queryNames(query, null); List<CamelProcessorMBean> answer = new ArrayList<CamelProcessorMBean>(); for (ObjectInstance on : names) { CamelProcessorMBean processor; if (ManagedSendProcessor.class.getName().equals(on.getClassName())) { processor = (CamelProcessorMBean) newProxyInstance(on.getObjectName(), CamelSendProcessorMBean.class, true); } else if (ManagedDelayer.class.getName().equals(on.getClassName())) { processor = (CamelProcessorMBean) newProxyInstance(on.getObjectName(), CamelDelayProcessorMBean.class, true); } else if (ManagedThrottler.class.getName().equals(on.getClassName())) { processor = (CamelProcessorMBean) newProxyInstance(on.getObjectName(), CamelThrottleProcessorMBean.class, true); } else { processor = (CamelProcessorMBean) newProxyInstance(on.getObjectName(), CamelProcessorMBean.class, true); } answer.add(processor); } return answer; }
public static JSONObject loadMemoryInfo(String app) { try { MemoryMXBean mBean = JMConnManager.getMemoryMBean(app); MemoryUsage nonHeap = mBean.getNonHeapMemoryUsage(); MemoryUsage heap = mBean.getHeapMemoryUsage(); JSONObject map = new JSONObject(true); buildMemoryJSon(heap, "heap", map); buildMemoryJSon(nonHeap, "nonheap", map); JSONObject heapChild = new JSONObject(); JSONObject nonheapChild = new JSONObject(); JSONObject heapUsed = new JSONObject(); JSONObject heapMax = new JSONObject(); heapUsed.put("used", heap.getUsed()); heapMax.put("used", heap.getCommitted()); heapChild.put("HeapUsed", heapUsed); heapChild.put("HeapCommit", heapMax); JSONObject nonheapUsed = new JSONObject(); JSONObject noheapMax = new JSONObject(); nonheapUsed.put("used", nonHeap.getUsed()); noheapMax.put("used", nonHeap.getCommitted()); nonheapChild.put("NonheapUsed", nonheapUsed); nonheapChild.put("NonheapCommit", noheapMax); ObjectName obj = new ObjectName("java.lang:type=MemoryPool,*"); MBeanServerConnection conn = JMConnManager.getConn(app); Set<ObjectInstance> MBeanset = conn.queryMBeans(obj, null); for (ObjectInstance objx : MBeanset) { String name = objx.getObjectName().getCanonicalName(); String keyName = objx.getObjectName().getKeyProperty("name"); MemoryPoolMXBean bean = JMConnManager.getServer(app, name, MemoryPoolMXBean.class); JSONObject item = toJson(bean.getUsage()); if (JMConnManager.HEAP_ITEM.contains(keyName)) { heapChild.put(keyName, item); } else { nonheapChild.put(keyName, item); } } map.getJSONObject("heap").put("childs", heapChild); map.getJSONObject("nonheap").put("childs", nonheapChild); return map; } catch (Exception e) { throw new RuntimeException(e); } }
static String getJobGraph(ObjectName jobObjName) { Set<ObjectInstance> jobInstances = mBeanServer.queryMBeans(jobObjName, null); Iterator<ObjectInstance> jobIterator = jobInstances.iterator(); ObjectInstance jobInstance = null; if (jobIterator.hasNext()) { jobInstance = jobIterator.next(); } String gSnapshot = ""; if (jobInstance != null) { ObjectName jobObjectName = jobInstance.getObjectName(); MBeanInfo mBeanInfo = null; try { mBeanInfo = mBeanServer.getMBeanInfo(jobObjectName); } catch (IntrospectionException 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(); } /* * Now get the graph for the job */ Set<String> operations = new HashSet<String>(); for (MBeanOperationInfo operationInfo : mBeanInfo.getOperations()) { operations.add(operationInfo.getName()); if (operationInfo.getName().equals("graphSnapshot")) { try { gSnapshot = (String) mBeanServer.invoke(jobObjectName, "graphSnapshot", null, null); // System.out.println(gSnapshot); } 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 gSnapshot; }
public static JSONObject geGCInfo(String app) throws Exception { ObjectName obj = new ObjectName("java.lang:type=GarbageCollector,*"); MBeanServer conn = ManagementFactory.getPlatformMBeanServer(); Set<ObjectInstance> MBeanset = conn.queryMBeans(obj, null); Class<GarbageCollectorMXBean> cls = GarbageCollectorMXBean.class; JSONObject data = new JSONObject(); for (ObjectInstance objx : MBeanset) { String name = objx.getObjectName().getCanonicalName(); String keyName = objx.getObjectName().getKeyProperty("name"); GarbageCollectorMXBean gc = ManagementFactory.newPlatformMXBeanProxy(conn, name, cls); data.put(keyName + "-time", gc.getCollectionTime() / 1000.0); data.put(keyName + "-count", gc.getCollectionCount()); } return data; }
/** * Unregister all mbeans whose object names match a given filter. * * @param filter ObjectName-style formatted filter * @param mBeanServer mbean server from which to unregister mbeans * @return number of mbeans unregistered */ public static int unregisterMBeans(String filter, MBeanServer mBeanServer) { try { ObjectName filterObjName = new ObjectName(filter); Set<ObjectInstance> mbeans = mBeanServer.queryMBeans(filterObjName, null); for (ObjectInstance mbean : mbeans) { ObjectName name = mbean.getObjectName(); if (log.isTraceEnabled()) log.trace("Unregistering mbean with name: " + name); mBeanServer.unregisterMBean(name); } return mbeans.size(); } catch (Exception e) { throw new CacheException("Unable to register mbeans with filter=" + filter, e); } }
private void start(ObjectInstance instance) { try { factory.startQBean(this, instance.getObjectName()); } catch (Exception e) { getLog().warn("start", e); } }
private ObjectName findCacheBean( MBeanServer mbeanServer, String domain, String managerName, String cacheName) throws MalformedObjectNameException { Set<ObjectInstance> beanObjs = mbeanServer.queryMBeans( new ObjectName( String.format( "%s:type=Cache,name=*,manager=\"%s\",component=Cache", domain, managerName)), null); for (ObjectInstance beanObj : beanObjs) { String name = beanObj.getObjectName().getKeyProperty("name"); if (name != null && (name.startsWith(cacheName) || name.startsWith("\"" + cacheName))) { return beanObj.getObjectName(); } } return null; }
public void stop() { try { ObjectName objectName = new ObjectName(resourceAdapterObjectName); Set<ObjectInstance> mbeanSet = mBeanServer.queryMBeans(objectName, null); for (ObjectInstance mbean : mbeanSet) { String stateString = (String) mBeanServer.getAttribute(mbean.getObjectName(), "StateString"); if ("Started".equalsIgnoreCase(stateString) || "Starting".equalsIgnoreCase(stateString)) { mBeanServer.invoke(mbean.getObjectName(), "stop", new Object[0], new String[0]); } } } catch (Exception e) { log.error("Unable to stop HornetQ resource adapter.", e); } }
@Override public List<CamelThreadPoolMBean> getThreadPools(String managementName) throws Exception { String id = managementName != null ? managementName : camelContextManagementName; ObjectName query = ObjectName.getInstance("org.apache.camel:context=" + id + ",type=threadpools,*"); Set<ObjectInstance> names = queryNames(query, null); List<CamelThreadPoolMBean> answer = new ArrayList<CamelThreadPoolMBean>(); for (ObjectInstance on : names) { CamelThreadPoolMBean pool = (CamelThreadPoolMBean) newProxyInstance(on.getObjectName(), CamelThreadPoolMBean.class, true); answer.add(pool); } return answer; }
@SuppressWarnings("unchecked") @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String file = req.getParameter("file"); String id = req.getParameter("id"); log.fine("file: " + file); log.fine("id: " + id); if (StringUtils.isEmpty(file)) { req.setAttribute("message", "File not added (empty name)"); } else { MBeanServer server = InitServlet.getMBeanServer(); Set mbeans = server.queryMBeans(LogFileManager.getObjectName(), null); if (mbeans != null && mbeans.size() == 1) { ObjectInstance oi = (ObjectInstance) mbeans.iterator().next(); try { if (StringUtils.isEmpty(id)) { log.fine("invoking addLogFile(\"" + file + "\")"); server.invoke( oi.getObjectName(), "addLogFile", new Object[] {file}, new String[] {String.class.getName()}); } else { // explicit id log.fine("invoking addLogFile(\"" + id + "\", \"" + file + "\")"); server.invoke( oi.getObjectName(), "addLogFile", new Object[] {id, file}, new String[] {String.class.getName(), String.class.getName()}); } } catch (Exception e) { log.severe("Caught exception in class AddServlet, method doPost: " + e); req.setAttribute("message", "Error: " + e); } } else { log.warning( "MBean query did not return exactly one result, returned: " + mbeans == null ? "" + 0 : "" + mbeans.size()); } } req.getRequestDispatcher("/add.jsp").forward(req, resp); }
@Override public List<CamelEndpointMBean> getEndpoints(String managementName) throws Exception { String id = managementName != null ? managementName : camelContextManagementName; ObjectName query = ObjectName.getInstance("org.apache.camel:context=" + id + ",type=endpoints,*"); Set<ObjectInstance> names = queryNames(query, null); List<CamelEndpointMBean> answer = new ArrayList<CamelEndpointMBean>(); for (ObjectInstance on : names) { CamelEndpointMBean endpoint; if (ManagedBrowsableEndpoint.class.getName().equals(on.getClassName()) || SedaEndpoint.class.getName().equals(on.getClassName())) { endpoint = (CamelEndpointMBean) newProxyInstance(on.getObjectName(), CamelBrowsableEndpointMBean.class, true); } else if (on.getClassName().startsWith("org.apache.camel.component.jms")) { // special for JMS endpoints as they are browsable as well endpoint = (CamelEndpointMBean) newProxyInstance(on.getObjectName(), CamelBrowsableEndpointMBean.class, true); } else { endpoint = (CamelEndpointMBean) newProxyInstance(on.getObjectName(), CamelEndpointMBean.class, true); } answer.add(endpoint); } return answer; }
@Override public ManagedBacklogTracerMBean getCamelTracer(String managementName) throws Exception { String id = managementName != null ? managementName : camelContextManagementName; ObjectName query = ObjectName.getInstance("org.apache.camel:context=" + id + ",type=tracer,*"); Set<ObjectInstance> names = queryNames(query, null); for (ObjectInstance on : names) { if (on.getClassName().equals("org.apache.camel.management.mbean.ManagedBacklogTracer")) { ManagedBacklogTracerMBean tracer = (ManagedBacklogTracerMBean) newProxyInstance(on.getObjectName(), ManagedBacklogTracerMBean.class, true); return tracer; } } // tracer not found return null; }
/** * Unregisters all MBeans where the type matches given {@code type}. * * <p>Object name is created using {@link #createObjectName(String, String)} * * <p><i>In case of exception, a warn log will be written </i> * * @return the count of unregistered MBeans * @param mbeanIfc */ public int unregisterAll(String type) { int count = 0; String canonicalName = createObjectName(type, null).getCanonicalName(); Set<ObjectInstance> objectInstances = getMBeanServer().queryMBeans(null, null); for (ObjectInstance objectInstance : objectInstances) { ObjectName objectName = objectInstance.getObjectName(); if (objectName.getCanonicalName().startsWith(canonicalName)) { try { getMBeanServer().unregisterMBean(objectName); count++; } catch (Exception e) { log.warn( "Could not un-register MBean '" + objectName.getCanonicalName() + "'.", e.getMessage()); } } } return count; }
@Override public void destroy() { if (mbean != null) try { ManagementFactory.getPlatformMBeanServer().unregisterMBean(mbean.getObjectName()); } catch (Exception e) { e.printStackTrace(); } if (proxy != null) proxy.stop(); if (dicomConfig != null) dicomConfig.close(); }
@Override public List<CamelRouteMBean> getRoutes(String managementName) throws Exception { String id = managementName != null ? managementName : camelContextManagementName; ObjectName query = ObjectName.getInstance("org.apache.camel:context=" + id + ",type=routes,*"); Set<ObjectInstance> names = queryNames(query, null); List<CamelRouteMBean> answer = new ArrayList<CamelRouteMBean>(); for (ObjectInstance on : names) { CamelRouteMBean route; if (ManagedSuspendableRoute.class.getName().equals(on.getClassName())) { route = (CamelRouteMBean) newProxyInstance(on.getObjectName(), CamelSuspendableRouteMBean.class, true); } else { route = (CamelRouteMBean) newProxyInstance(on.getObjectName(), CamelRouteMBean.class, true); } answer.add(route); } return answer; }
@Test(groups = "wso2.esb", description = "JMS Consumer Test after pause") public void testJMSPause() throws Exception { // pause JMS Listener from JMXClient Set<ObjectInstance> objSet = mbsc.queryMBeans( new ObjectName("org.apache.axis2:Type=Transport,ConnectorName=jms-listener-*"), null); Iterator i = objSet.iterator(); while (i.hasNext()) { ObjectInstance obj = (ObjectInstance) i.next(); mbsc.invoke(obj.getObjectName(), "pause", null, null); } Thread.sleep(10000); assertTrue(stringExistsInLog("Listener paused")); // Put message in queue. sendMessage(msgAfter); Thread.sleep(10000); assertTrue(!stringExistsInLog(msgAfter)); }
@Override public List<CamelConsumerMBean> getConsumers(String managementName) throws Exception { String id = managementName != null ? managementName : camelContextManagementName; ObjectName query = ObjectName.getInstance("org.apache.camel:context=" + id + ",type=consumers,*"); Set<ObjectInstance> names = queryNames(query, null); List<CamelConsumerMBean> answer = new ArrayList<CamelConsumerMBean>(); for (ObjectInstance on : names) { CamelConsumerMBean consumer; if (ManagedScheduledPollConsumer.class.getName().equals(on.getClassName())) { consumer = (CamelConsumerMBean) newProxyInstance(on.getObjectName(), CamelScheduledPollConsumerMBean.class, true); } else { consumer = (CamelConsumerMBean) newProxyInstance(on.getObjectName(), CamelConsumerMBean.class, true); } answer.add(consumer); } return answer; }
static String getJobsInfo(ObjectName jobObjName) { Set<ObjectInstance> jobInstances = mBeanServer.queryMBeans(jobObjName, null); Iterator<ObjectInstance> jobIterator = jobInstances.iterator(); StringBuffer json = new StringBuffer("["); int counter = 0; while (jobIterator.hasNext()) { if (counter > 0) { json.append(","); } ObjectInstance jobInstance = jobIterator.next(); ObjectName jobObjectName = jobInstance.getObjectName(); MBeanInfo mBeanInfo = null; try { mBeanInfo = mBeanServer.getMBeanInfo(jobObjectName); } catch (IntrospectionException 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(); } /* * Get the names of all the attributes */ Set<String> names = new HashSet<String>(); for (MBeanAttributeInfo attributeInfo : mBeanInfo.getAttributes()) { names.add(attributeInfo.getName()); } // now construct the job json and add it to the string buffer StringBuffer s = new StringBuffer(); s.append("{\""); Iterator<String> it = names.iterator(); while (it.hasNext()) { String attr = it.next(); s.append(attr); s.append("\":\""); try { s.append((String) mBeanServer.getAttribute(jobObjectName, attr)); } catch (AttributeNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstanceNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MBeanException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ReflectionException e) { // TODO Auto-generated catch block e.printStackTrace(); } s.append("\",\""); } // remove the trailing ,\ s.deleteCharAt(s.length() - 1); s.deleteCharAt(s.length() - 1); json.append(s.toString() + "}"); counter++; } json.append("]"); String jsonString = json.toString(); return jsonString; }
public ObjectName getObjectName() { return instance != null ? instance.getObjectName() : null; }
public void stopService() throws Exception { MBeanServer mbserver = getServer(); mbserver.unregisterMBean(tckPluginMBean.getObjectName()); }