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 GetWildCardMultiDataResponse getWildCardJmxData(String name, String attributeName, String key) throws MalformedObjectNameException, NullPointerException, AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, IOException { ObjectName objectName = new ObjectName(name); Set<ObjectName> objectNameList = connection.queryNames(objectName, null); GetWildCardMultiDataResponse response = new GetWildCardMultiDataResponse(); List<ObjectNameAndKey> objectAndkeyList = new ArrayList<ObjectNameAndKey>(); for (ObjectName iterName : objectNameList) { objectName = iterName;// ww w.j a va 2 s . c o m ObjectNameAndKey objectAndKey = new ObjectNameAndKey(); objectAndKey.setObjectName(objectName.getCanonicalName()); Object attr = connection.getAttribute(objectName, attributeName); if (attr instanceof CompositeDataSupport) { CompositeDataSupport cds = (CompositeDataSupport) attr; if (key == null) { ErrorJmx error = new ErrorJmx(); error.setMessage("Key is null for composed data " + name); response.setError(error); return response; } KeyResponse keyResponse = new KeyResponse(); keyResponse.setKey(cds.get(key).toString()); objectAndKey.setKeyResponse(keyResponse); } else { KeyResponse keyResponse = new KeyResponse(); keyResponse.setKey(attr.toString()); objectAndKey.setKeyResponse(keyResponse); } objectAndkeyList.add(objectAndKey); } response.setResponse(objectAndkeyList); return response; }
From source file:com.googlecode.psiprobe.beans.ContainerListenerBean.java
/** * Load ObjectNames for the relevant MBeans so they can be queried at a later stage without searching MBean server * over and over again.//from w w w . j a v a2 s . c o m * * @throws Exception - this method does not handle any of the exceptions that may be thrown when querying MBean server. */ private synchronized void initialize() throws Exception { MBeanServer server = getContainerWrapper().getResourceResolver().getMBeanServer(); String serverName = getContainerWrapper().getTomcatContainer().getName(); Set threadPools = server.queryMBeans(new ObjectName(serverName + ":type=ThreadPool,*"), null); poolNames = new ArrayList(threadPools.size()); for (Iterator it = threadPools.iterator(); it.hasNext();) { ThreadPoolObjectName threadPoolObjectName = new ThreadPoolObjectName(); ObjectName threadPoolName = ((ObjectInstance) it.next()).getObjectName(); String name = threadPoolName.getKeyProperty("name"); threadPoolObjectName.setThreadPoolName(threadPoolName); ObjectName grpName = server .getObjectInstance(new ObjectName( threadPoolName.getDomain() + ":type=GlobalRequestProcessor,name=" + name)) .getObjectName(); threadPoolObjectName.setGlobalRequestProcessorName(grpName); // // unfortunately exact workers could not be found at the time of testing // so we filter out the relevant workers within the loop // Set workers = server .queryMBeans(new ObjectName(threadPoolName.getDomain() + ":type=RequestProcessor,*"), null); for (Iterator wrkIt = workers.iterator(); wrkIt.hasNext();) { ObjectName wrkName = ((ObjectInstance) wrkIt.next()).getObjectName(); if (name.equals(wrkName.getKeyProperty("worker"))) { threadPoolObjectName.getRequestProcessorNames().add(wrkName); } } poolNames.add(threadPoolObjectName); } Set executors = server.queryMBeans(new ObjectName(serverName + ":type=Executor,*"), null); executorNames = new ArrayList(executors.size()); for (Iterator it = executors.iterator(); it.hasNext();) { ObjectName executorName = ((ObjectInstance) it.next()).getObjectName(); executorNames.add(executorName); } // Register with MBean server server.addNotificationListener(new ObjectName("JMImplementation:type=MBeanServerDelegate"), this, null, null); }
From source file:io.fabric8.insight.metrics.service.MetricsCollector.java
@Activate private void activate(BundleContext bundleContext) throws Exception { this.bundleContext = bundleContext; this.executor = new ScheduledThreadPoolExecutor(threadPoolSize); this.executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); this.executor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); this.executor.scheduleWithFixedDelay(new Runnable() { @Override/*from w w w . ja v a 2 s. c o m*/ public void run() { process(); } }, 1, defaultDelay, TimeUnit.SECONDS); JMXUtils.registerMBean(this, mbeanServer, new ObjectName("io.fabric8.insight:type=MetricsCollector")); }
From source file:org.fishwife.jrugged.spring.CircuitBreakerBeanFactory.java
/** * Create a new {@link CircuitBreakerBean} and map it to the provided value. * If the {@link MBeanExportOperations} is set, then the CircuitBreakerBean will be * exported as a JMX MBean.// w w w . j a va 2 s . co m * If the CircuitBreaker already exists, then the existing instance is * returned. * @param name the value for the {@link org.fishwife.jrugged.CircuitBreaker} * @param config the {@link org.fishwife.jrugged.CircuitBreakerConfig} */ public synchronized CircuitBreaker createCircuitBreaker(String name, CircuitBreakerConfig config) { CircuitBreaker circuitBreaker = findCircuitBreaker(name); if (circuitBreaker == null) { circuitBreaker = new CircuitBreakerBean(name); configureCircuitBreaker(name, circuitBreaker, config); if (mBeanExportOperations != null) { ObjectName objectName; try { objectName = new ObjectName( "org.fishwife.jrugged.spring:type=CircuitBreakerBean," + "name=" + name); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException("Invalid MBean Name " + name, e); } mBeanExportOperations.registerManagedResource(circuitBreaker, objectName); } addCircuitBreakerToMap(name, circuitBreaker); } return circuitBreaker; }
From source file:fr.xebia.management.statistics.ServiceStatistics.java
/** * /*from www . j a v a2 s . co m*/ * @param name * identifier of the service * @param businessExceptionsTypes * types of exceptions that are categorized as business * exceptions * @param communicationExceptionsTypes * types of exceptions that are categorized as communication * exceptions * @throws MalformedObjectNameException */ public ServiceStatistics(String name, Class<?>[] businessExceptionsTypes, Class<?>[] communicationExceptionsTypes) throws MalformedObjectNameException { this(new ObjectName("fr.xebia:type=ServiceStatistics,name=" + name), businessExceptionsTypes, communicationExceptionsTypes); }
From source file:com.appleframework.jmx.connector.framework.ConnectorRegistry.java
@SuppressWarnings("deprecation") private static ConnectorRegistry create(ApplicationConfig config) throws Exception { Map<String, String> paramValues = config.getParamValues(); String appId = config.getApplicationId(); String connectorId = (String) paramValues.get("connectorId"); File file1 = new File(CoreUtils.getConnectorDir() + File.separatorChar + connectorId); URL[] urls = new URL[] { file1.toURL() }; ClassLoader cl = ClassLoaderRepository.getClassLoader(urls, true); //URLClassLoader cl = new URLClassLoader(urls, // ConnectorMBeanRegistry.class.getClassLoader()); Registry.MODELER_MANIFEST = MBEANS_DESCRIPTOR; URL res = cl.getResource(MBEANS_DESCRIPTOR); logger.info("Application ID : " + appId); logger.info("Connector Archive: " + file1.getAbsoluteFile()); logger.info("MBean Descriptor : " + res.toString()); //Thread.currentThread().setContextClassLoader(cl); //Registry.setUseContextClassLoader(true); ConnectorRegistry registry = new ConnectorRegistry(); registry.loadMetadata(cl);//w ww. j a v a 2s . c o m String[] mbeans = registry.findManagedBeans(); MBeanServer server = MBeanServerFactory.newMBeanServer(DOMAIN_CONNECTOR); for (int i = 0; i < mbeans.length; i++) { ManagedBean managed = registry.findManagedBean(mbeans[i]); String clsName = managed.getType(); String domain = managed.getDomain(); if (domain == null) { domain = DOMAIN_CONNECTOR; } Class<?> cls = Class.forName(clsName, true, cl); Object objMBean = null; // Use the factory method when it is defined. Method[] methods = cls.getMethods(); for (Method method : methods) { if (method.getName().equals(FACTORY_METHOD) && Modifier.isStatic(method.getModifiers())) { objMBean = method.invoke(null); logger.info("Create MBean using factory method."); break; } } if (objMBean == null) { objMBean = cls.newInstance(); } // Call the initialize method if the MBean extends ConnectorSupport class if (objMBean instanceof ConnectorSupport) { Method method = cls.getMethod("initialize", new Class[] { Map.class }); Map<String, String> props = config.getParamValues(); method.invoke(objMBean, new Object[] { props }); } ModelMBean mm = managed.createMBean(objMBean); String beanObjName = domain + ":name=" + mbeans[i]; server.registerMBean(mm, new ObjectName(beanObjName)); } registry.setMBeanServer(server); entries.put(appId, registry); return registry; }
From source file:com.zenoss.jmx.JmxClient.java
/** * Builds an ObjectName using the name provided * /*from w ww .jav a 2 s . c o m*/ * @param name * the MBean name * @throws JmxException * if the mbean name is not a properly formatted object name. */ private ObjectName buildObjectName(String name) throws JmxException { // construct the object name, making sure it is properly formatted ObjectName on = null; try { on = new ObjectName(name); } catch (MalformedObjectNameException e) { throw new JmxException("object name is malformed: " + name); } return on; }
From source file:io.fabric8.insight.metrics.service.MetricsCollector.java
@Deactivate private void deactivate() throws Exception { JMXUtils.unregisterMBean(mbeanServer, new ObjectName("io.fabric8.insight:type=MetricsCollector")); executor.shutdown();// w w w. j a v a 2 s. c om try { executor.awaitTermination(5, TimeUnit.SECONDS); } catch (InterruptedException e) { // Ignore } executor.shutdownNow(); try { executor.awaitTermination(5, TimeUnit.SECONDS); } catch (InterruptedException e) { // Ignore } for (QueryState q : queries.values()) { q.close(); } }
From source file:org.ff4j.jmx.FF4JMBeanTest.java
@Test public void should_get_feature_auth_roles() throws Exception { ObjectName objectName = new ObjectName(FF4J_OBJECT_NAME); @SuppressWarnings("unchecked") Set<String> featureAuthRoles = (Set<String>) mbServConn.invoke(objectName, "getPermissions", new Object[] { "jmxFeatureWithAuth" }, new String[] { "java.lang.String" }); Assert.assertTrue(featureAuthRoles.contains("ROLE_USER")); Assert.assertTrue(featureAuthRoles.contains("ROLE_ADMIN")); should_add_auth_role_to_feature();/*from w w w . ja v a 2 s .c o m*/ should_remove_auth_role_from_feature(); }
From source file:org.jolokia.client.request.J4pReadIntegrationTest.java
@Test public void multipleAttributes() throws MalformedObjectNameException, J4pException { for (J4pReadRequest req : readRequests(itSetup.getAttributeMBean(), "LongSeconds", "SmallMinutes")) { J4pReadResponse resp = j4pClient.execute(req); assertFalse(req.hasSingleAttribute()); assertEquals(2, req.getAttributes().size()); Map respVal = resp.getValue(); assertTrue(respVal.containsKey("LongSeconds")); assertTrue(respVal.containsKey("SmallMinutes")); Collection<String> attrs = resp.getAttributes(new ObjectName(itSetup.getAttributeMBean())); Set<String> attrSet = new HashSet<String>(attrs); assertTrue(attrSet.contains("LongSeconds")); assertTrue(attrSet.contains("SmallMinutes")); try {/* ww w . j av a 2s . c om*/ resp.getAttributes(new ObjectName("blub:type=bla")); fail(); } catch (IllegalArgumentException exp) { assertTrue(exp.getMessage().contains(itSetup.getAttributeMBean())); } Set<String> allAttrs = new HashSet<String>(resp.getAttributes()); assertEquals(2, allAttrs.size()); assertTrue(allAttrs.contains("LongSeconds")); assertTrue(allAttrs.contains("SmallMinutes")); Double val = resp.getValue(new ObjectName(itSetup.getAttributeMBean()), "SmallMinutes"); assertNotNull(val); try { resp.getValue(new ObjectName(itSetup.getAttributeMBean()), "Aufsteiger"); fail(); } catch (IllegalArgumentException exp) { assertTrue(exp.getMessage().contains("Aufsteiger")); } Double longVal = resp.getValue("LongSeconds"); assertNotNull(longVal); try { resp.getValue("Pinola bleibt"); fail(); } catch (IllegalArgumentException exp) { assertTrue(exp.getMessage().contains("Pinola")); } try { resp.getValue(null); fail(); } catch (IllegalArgumentException exp) { assertTrue(exp.getMessage().contains("null")); } try { req.getAttribute(); fail(); } catch (IllegalArgumentException exp) { assertTrue(exp.getMessage().contains("than one")); } } }