List of usage examples for javax.management ObjectName ObjectName
public ObjectName(String name) throws MalformedObjectNameException
From source file:fr.openfarm.jmx.service.JMXQuery.java
@Override public GetMultiObjectKeysResponse getWildcardJmxKeys(String name, String attributeName) throws MalformedObjectNameException, NullPointerException, AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, IOException { GetMultiObjectKeysResponse reponse = new GetMultiObjectKeysResponse(); ArrayList<MultiObjectKeys> multiObjectKeysList = new ArrayList<MultiObjectKeys>(); ObjectName objectName = new ObjectName(name); Set<ObjectName> objectNameList = connection.queryNames(objectName, null); for (ObjectName iterObject : objectNameList) { objectName = iterObject;/*from w w w . jav a 2 s . c o m*/ List<KeyResponse> keyList = new ArrayList<KeyResponse>(); Object attr = connection.getAttribute(objectName, attributeName); if (attr instanceof CompositeDataSupport) { CompositeDataSupport cds = (CompositeDataSupport) attr; CompositeType type = cds.getCompositeType(); Set<String> listKey = type.keySet(); for (Object key : listKey) { if (key instanceof String) { Object value = cds.get((String) key); KeyResponse keyResponse = new KeyResponse(); keyResponse.setKey(key.toString()); keyResponse.setValue(value.toString()); keyList.add(keyResponse); } } } else { KeyResponse keyResponse = new KeyResponse(); keyResponse.setValue(attr.toString()); keyList.add(keyResponse); } MultiObjectKeys multiObjectKeys = new MultiObjectKeys(); multiObjectKeys.setJmxKeys(keyList); multiObjectKeys.setObjectName(objectName.getCanonicalName()); multiObjectKeysList.add(multiObjectKeys); } reponse.setMultiObjectKeys(multiObjectKeysList); return reponse; }
From source file:net.sf.ehcache.management.ManagementServiceTest.java
/** * Can we register the CacheManager MBean? *///from ww w. j a va 2 s . c o m public void testRegisterCacheManager() throws Exception { //Set size so the second element overflows to disk. Ehcache ehcache = new net.sf.ehcache.Cache("testNoOverflowToDisk", 1, false, true, 500, 200); manager.addCache(ehcache); ehcache.put(new Element("key1", "value1")); ehcache.put(new Element("key2", "value1")); assertNull(ehcache.get("key1")); assertNotNull(ehcache.get("key2")); ObjectName name = new ObjectName("net.sf.ehcache:type=CacheManager,name=1"); CacheManager cacheManager = new CacheManager(manager); mBeanServer.registerMBean(cacheManager, name); mBeanServer.unregisterMBean(name); name = new ObjectName("net.sf.ehcache:type=CacheManager.Cache,CacheManager=1,name=testOverflowToDisk"); mBeanServer.registerMBean(new Cache(ehcache), name); mBeanServer.unregisterMBean(name); name = new ObjectName("net.sf.ehcache:type=CacheManager.Cache,CacheManager=1,name=sampleCache1"); mBeanServer.registerMBean(new Cache(manager.getCache("sampleCache1")), name); mBeanServer.unregisterMBean(name); }
From source file:net.tzolov.geode.jmx.JmxInfluxLoader.java
public void addNotificationListener(NotificationListener listener) { try {/*from www. j a v a 2s.c o m*/ this.jmxConnection.addNotificationListener(new ObjectName(GEM_FIRE_SERVICE_SYSTEM_TYPE_DISTRIBUTED), listener, null, null); } catch (Exception e) { log.error("Failed to register JMX notification listener: " + listener, e); } }
From source file:at.ac.tuwien.dsg.cloud.salsa.engine.utils.SystemFunctions.java
public static List<String> getEndPoints() throws MalformedObjectNameException, NullPointerException, UnknownHostException, AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); Set<ObjectName> objs = mbs.queryNames(new ObjectName("*:type=Connector,*"), Query.match(Query.attr("protocol"), Query.value("HTTP/1.1"))); String hostname = InetAddress.getLocalHost().getHostName(); InetAddress[] addresses = InetAddress.getAllByName(hostname); ArrayList<String> endPoints = new ArrayList<>(); for (Iterator<ObjectName> i = objs.iterator(); i.hasNext();) { ObjectName obj = i.next(); String scheme = mbs.getAttribute(obj, "scheme").toString(); String port = obj.getKeyProperty("port"); for (InetAddress addr : addresses) { String host = addr.getHostAddress(); String ep = scheme + "://" + host + ":" + port; endPoints.add(ep);//from ww w. ja va2s .com } } return endPoints; }
From source file:catalina.mbeans.MBeanFactory.java
/** * Create a new AccessLoggerValve.// www . ja v a2 s. c om * * @param parent MBean Name of the associated parent component * * @exception Exception if an MBean cannot be created or registered */ public String createAccessLoggerValve(String parent) throws Exception { // Create a new AccessLogValve instance AccessLogValve accessLogger = new AccessLogValve(); // Add the new instance to its parent component ObjectName pname = new ObjectName(parent); String type = pname.getKeyProperty("type"); Server server = ServerFactory.getServer(); Service service = server.findService(pname.getKeyProperty("service")); Engine engine = (Engine) service.getContainer(); if (type.equals("Context")) { Host host = (Host) engine.findChild(pname.getKeyProperty("host")); String pathStr = getPathStr(pname.getKeyProperty("path")); Context context = (Context) host.findChild(pathStr); ((StandardContext) context).addValve(accessLogger); } else if (type.equals("Engine")) { ((StandardEngine) engine).addValve(accessLogger); } else if (type.equals("Host")) { Host host = (Host) engine.findChild(pname.getKeyProperty("host")); ((StandardHost) host).addValve(accessLogger); } // Return the corresponding MBean name ManagedBean managed = registry.findManagedBean("AccessLogValve"); ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), accessLogger); return (oname.toString()); }
From source file:com.springsource.hq.plugin.tcserver.plugin.TomcatMeasurementPlugin.java
private long getTotalGarbageCollectionTime(MBeanServerConnection connection) throws MetricUnreachableException, MetricNotFoundException, PluginException { long totalGcTimeMillis = 0; try {/*from w ww . j a va2s . c o m*/ // Use of the MXBean replaced by plain old JMX query for TCS-71 // // Set<ObjectName> garbageCollectors = connection.queryNames( // new ObjectName("java.lang:type=GarbageCollector,*"), null); // for (ObjectName garbageCollectorName : garbageCollectors) { // GarbageCollectorMXBean garbageCollector = getGarbageCollectorMXBean( // connection, garbageCollectorName); // long collectionTime = garbageCollector.getCollectionTime(); ObjectName gcObjName = new ObjectName("java.lang:type=GarbageCollector,*"); Set<ObjectInstance> garbageCollectors = connection.queryMBeans(gcObjName, null); for (ObjectInstance instance : garbageCollectors) { ObjectName instanceName = instance.getObjectName(); Long l = (Long) connection.getAttribute(instance.getObjectName(), "CollectionTime"); long collectionTime = l.longValue(); LOGGER.debug(instanceName + "::CollectionTime=" + collectionTime); if (collectionTime > -1) { totalGcTimeMillis += collectionTime; } } } catch (MalformedObjectNameException e) { throw new MetricInvalidException("Error querying for GarbageCollector MBeans: " + e.getMessage(), e); } catch (IOException e) { throw new MetricUnreachableException("Error querying for GarbageCollector MBeans:" + e.getMessage(), e); } catch (AttributeNotFoundException e) { throw new MetricNotFoundException("Error querying for GarbageCollector MBeans:" + e.getMessage(), e); } catch (InstanceNotFoundException e) { throw new MetricNotFoundException("Error querying for GarbageCollector MBeans:" + e.getMessage(), e); } catch (MBeanException e) { throw new PluginException("Error querying for GarbageCollector MBeans:" + e.getMessage(), e); } catch (ReflectionException e) { throw new PluginException("Error querying for GarbageCollector MBeans:" + e.getMessage(), e); } catch (NullPointerException e) { throw new PluginException("Error querying for GarbageCollector MBeans:" + e.getMessage(), e); } return totalGcTimeMillis; }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.MMXPlugin.java
public void destroyPlugin() { XMPPServer server = XMPPServer.getInstance(); IQRouter iqRouter = server.getIQRouter(); iqRouter.removeHandler(mIQAppRegHandler); iqRouter.removeHandler(mIQDevRegHandler); iqRouter.removeHandler(mIQUserRegHandler); iqRouter.removeHandler(mIQMessageStateHandler); iqRouter.removeHandler(mIQPubSubHandler); iqRouter.removeHandler(mIQWakeupNSHandler); iqRouter.removeHandler(mIQPushNSHandler); iqRouter.removeHandler(mIQMsgAckNSHandler); InterceptorManager.getInstance().removeInterceptor(mmxPacketInterceptor); wakeupExecutionManager.stopWakeupExecution(); timeoutExecutionManager.stopTimeoutCheck(); // shutdown geo event dispatcher contextDispatcher.shutdown();/* w w w . j a v a 2s.co m*/ //Teardown the APNS Connection pool APNSConnectionPoolImpl.teardown(); adminAPIServer.stop(); publicAPIServer.stop(); try { ObjectName mbeanName = new ObjectName(MMXServerConstants.MMX_MBEAN_NAME); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); mbs.unregisterMBean(mbeanName); } catch (Exception e) { Log.error("destroyPlugin : error unregistering mbean={}", MMXServerConstants.MMX_MBEAN_NAME); } apnsFeedbackProcessExecutionManager.stop(); Log.info("App Management Plugin is destroyed"); }
From source file:io.fabric8.jolokia.assertions.JolokiaAssert.java
/** * Returns the attribute value of the given mbean and attribute name *//*from w w w . j a v a2s . co m*/ public Object attributeValue(String mbean, String attribute) throws MalformedObjectNameException, J4pException { ObjectName objectName = new ObjectName(mbean); J4pResponse<J4pReadRequest> results = client.execute(new J4pReadRequest(objectName, attribute)); return results.getValue(); }
From source file:hermes.ext.jbossmq.JBossMQAdmin.java
public QueueBrowser createDurableSubscriptionBrowser(final DestinationConfig dConfig) throws JMSException { try {/* ww w . ja va 2 s . c om*/ final ObjectName objectName = new ObjectName( "jboss.mq.destination:name=" + getRealDestinationName(dConfig) + ",service=Topic"); String[] params; String[] signature; if (dConfig.getSelector() == null) { params = new String[] { getHermes().getConnection().getClientID(), dConfig.getClientID() }; signature = new String[] { String.class.getName(), String.class.getName() }; } else { params = new String[] { getHermes().getConnection().getClientID(), dConfig.getClientID(), dConfig.getSelector() }; signature = new String[] { String.class.getName(), String.class.getName(), String.class.getName() }; } final Collection messages = (Collection) getRMIAdapter().invoke(objectName, "listDurableMessages", params, signature); return new QueueBrowser() { public void close() throws JMSException { // TODO Auto-generated method stub } public Enumeration getEnumeration() throws JMSException { return new IteratorEnumeration(messages.iterator()); } public String getMessageSelector() throws JMSException { return dConfig.getSelector(); } public Queue getQueue() throws JMSException { // TODO Auto-generated method stub return null; } }; } catch (Exception e) { log.error(e.getMessage(), e); throw new HermesException(e); } }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.util.MMXConfigurationTest.java
/** * Set the Configuration property via JMX and check whether the REST interface returns the same value * * @throws Exception/* ww w . j av a 2 s .co m*/ */ //TODO: Use the web target JAXRS API to execute these request possibly ? @Ignore @Test public void testSetMBeanLocalGetREST() throws Exception { ObjectName name = new ObjectName(MMX_MBEAN_OBJECT_NAME); ServletTester tester = new ServletTester(); tester.addServlet(LaxConfigServlet.class, "/config"); tester.start(); for (Triple<String, String, String> triple : mbeanAttributes) { String attrName = triple.getLeft(); String attrType = triple.getRight(); Object attrValue; if (attrType.equals("int")) { attrValue = RandomUtils.nextInt(30000, 65535); } else if (attrType.equals("long")) { attrValue = RandomUtils.nextLong(10, 1000); } else { attrValue = RandomStringUtils.randomAlphabetic(10); } Attribute attr1 = new Attribute(attrName, attrValue); server.setAttribute(name, attr1); Object attr2 = server.getAttribute(name, attrName); assertEquals("Attribute values do not match", attrValue, attr2); HttpTester request = new HttpTester(); // HttpTester.Request request = HttpTester.newRequest(); request.setMethod("GET"); request.setHeader("Host", "tester"); request.setURI("/config"); request.setContent(""); HttpTester response = new HttpTester(); response.parse(tester.getResponses(request.generate())); JsonElement jelement = new JsonParser().parse(response.getContent()); JsonObject jobject = jelement.getAsJsonObject(); jobject = jobject.getAsJsonObject("configs"); String attrValueRest = jobject.get(triple.getMiddle()).getAsString(); if (attrType.equals("int")) assertEquals("Values do not match", attrValue, Integer.parseInt(attrValueRest)); else if (attrType.equals("long")) assertEquals("Values do not match", attrValue, Long.parseLong(attrValueRest)); else assertEquals("Values do not match", attrValue, attrValueRest); } }