List of usage examples for javax.management ObjectName getInstance
public static ObjectName getInstance(ObjectName name)
Return an instance of ObjectName that can be used anywhere the given object can be used.
From source file:org.apache.geode.admin.jmx.internal.SystemMemberCacheJmxImpl.java
/** * Creates a new cache server MBean and returns its <code>ObjectName</code>. * * @since GemFire 5.7/*from w ww.j ava2 s. com*/ */ public ObjectName manageCacheServer() throws AdminException, MalformedObjectNameException { try { SystemMemberBridgeServerJmxImpl bridge = (SystemMemberBridgeServerJmxImpl) addCacheServer(); return ObjectName.getInstance(bridge.getMBeanName()); } catch (AdminException e) { MBeanUtil.logStackTrace(Level.WARN, e); throw e; } catch (RuntimeException e) { MBeanUtil.logStackTrace(Level.WARN, e); throw e; } catch (VirtualMachineError err) { SystemFailure.initiateFailure(err); // If this ever returns, rethrow the error. We're poisoned // now, so don't let this thread continue. throw err; } catch (Error e) { // Whenever you catch Error or Throwable, you must also // catch VirtualMachineError (see above). However, there is // _still_ a possibility that you are dealing with a cascading // error condition, so you also need to check to see if the JVM // is still usable: SystemFailure.checkFailure(); MBeanUtil.logStackTrace(Level.ERROR, e); throw e; } }
From source file:org.mule.management.agents.JmxAgent.java
protected void registerConfigurationService() throws NotCompliantMBeanException, MBeanRegistrationException, InstanceAlreadyExistsException, MalformedObjectNameException { ObjectName on = ObjectName.getInstance(getDomainName() + ":type=control,name=ConfigurationService"); MuleConfigurationServiceMBean serviceMBean = new MuleConfigurationService(); logger.debug("Registering configuration with name: " + on); mBeanServer.registerMBean(serviceMBean, on); registeredMBeans.add(on);//from www. j av a2 s.c o m }
From source file:org.mule.management.agents.JmxAgent.java
protected void registerComponentServices() throws NotCompliantMBeanException, MBeanRegistrationException, InstanceAlreadyExistsException, MalformedObjectNameException { Iterator iter = MuleManager.getInstance().getModel().getComponentNames(); String name;/*from w w w.ja v a 2s . c o m*/ while (iter.hasNext()) { name = iter.next().toString(); ObjectName on = ObjectName .getInstance(getDomainName() + ":type=control,name=" + name + "ComponentService"); ComponentServiceMBean serviceMBean = new ComponentService(name); logger.debug("Registering component with name: " + on); mBeanServer.registerMBean(serviceMBean, on); registeredMBeans.add(on); } }
From source file:org.ofbiz.core.entity.transaction.DBCPConnectionFactory.java
private static BasicDataSource createDataSource(JdbcDatasourceInfo jdbcDatasource) throws Exception { final Properties dbcpProperties = loadDbcpProperties(); final BasicDataSource dataSource = BasicDataSourceFactory.createDataSource(dbcpProperties); dataSource.setDriverClassLoader(Thread.currentThread().getContextClassLoader()); dataSource.setDriverClassName(jdbcDatasource.getDriverClassName()); dataSource.setUrl(jdbcDatasource.getUri()); dataSource.setUsername(jdbcDatasource.getUsername()); dataSource.setPassword(jdbcDatasource.getPassword()); if (isNotEmpty(jdbcDatasource.getIsolationLevel())) { dataSource.setDefaultTransactionIsolation( TransactionIsolations.fromString(jdbcDatasource.getIsolationLevel())); }//from ww w . jav a 2s . com if (dbcpProperties.containsKey(PROP_JMX) && Boolean.valueOf(dbcpProperties.getProperty(PROP_JMX))) { dataSource.setJmxName( ObjectName.getInstance(dbcpProperties.getProperty(PROP_MBEANNAME)).getCanonicalName()); } return dataSource; }
From source file:org.cloudfoundry.identity.varz.VarzEndpoint.java
private Map<String, ?> getMBeans(String domain, String pattern) throws Exception { Set<ObjectName> names = server.queryNames(ObjectName.getInstance(domain + ":" + pattern), null); Map<String, Object> result = new LinkedHashMap<String, Object>(); for (ObjectName name : names) { Map<String, Object> map = new MBeanMap(server, name); Map<String, Object> objects = getMap((Map<String, Object>) result, domain); String type = name.getKeyProperty("type"); if (type != null) { type = VarzStringUtils.camelToUnderscore(type); objects = getMap(objects, type); }/*w w w.j a v a 2 s . c om*/ String key = name.getKeyProperty("name"); if (key != null) { key = VarzStringUtils.camelToUnderscore(key); objects = getMap(objects, key); } for (String property : name.getKeyPropertyList().keySet()) { if (property.equals("type") || property.equals("name")) { continue; } key = VarzStringUtils.camelToUnderscore(property); objects = getMap(objects, key); String value = name.getKeyProperty(property); objects = getMap(objects, value); } if (key == null) { key = type; } if (key == null) { key = domain; } objects.putAll(map); } return result; }
From source file:org.rhq.plugins.jbossas.util.DeploymentUtility.java
/** * Retrieves all the discovery information for a War resources. We are retrieving all the information * so that there is only ever one call to the MBeanServer to get the deployed mbeans, therefore saving * some performance if it did this for each and every war resource one at a time. * * @param connection EmsConnection to get the mbean information * @param jbossManMBeanNames Name of the main jboss.management mbeans for a collection of wars. * @return map holds all the war deployment information for the objects passed in the objectNames collection *//*from www. ja va 2 s . c om*/ public static Map<String, List<WarDeploymentInformation>> getWarDeploymentInformation(EmsConnection connection, List<String> jbossManMBeanNames) { // We need a list of informations, as one jsr77 deployment can end up in multiple web apps in different vhosts HashMap<String, List<WarDeploymentInformation>> retDeploymentInformationMap = new HashMap<String, List<WarDeploymentInformation>>(); // will contain information on all deployments Collection deploymentInfos; try { // NOTE: This is an expensive operation, since it returns a bunch of large objects. deploymentInfos = getDeploymentInformations(connection); } catch (Exception e) { return null; } String separator = System.getProperty("file.separator"); boolean isOnWin = separator.equals("\\"); // Loop through the deployment infos, and find the deployment infos corresponding to each of the // jboss.management/JSR77 MBean names that were passed into this method. From the deployment infos, // we can figure out the vhost(s) and context root for each WAR. for (Object deploymentInfo : deploymentInfos) { try { // NOTE: There may be more than one jboss.web MBean, // e.g. "jboss.web:J2EEApplication=none,J2EEServer=none,j2eeType=WebModule,name=//localhost/jmx-console", // associated with a given WAR deployment, in which case, the "deployedObject" field will be // arbitrarily set to the name of one of the jboss.web MBeans. ObjectName jbossWebObjectName = getFieldValue(deploymentInfo, "deployedObject", ObjectName.class); if (jbossWebObjectName != null) { // e.g. "jmx-console.war" String shortName = getFieldValue(deploymentInfo, "shortName", String.class); for (String jbossManMBeanName : jbossManMBeanNames) { ObjectName jbossManObjectName = new ObjectName(jbossManMBeanName); String jbossManWarName = jbossManObjectName.getKeyProperty("name"); if (shortName.equals(jbossManWarName)) { log.debug("Found DeploymentInfo for WAR " + shortName + "."); // The only reliable way to determine the vhosts associated with the WAR is to use // the "mbeans" field, whose value is a list of all the Servlet MBeans, // .e.g. "jboss.web:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/jmx-console,j2eeType=Servlet,name=default", // corresponding to the WAR (one per servlet per vhost). List servletObjectNames = getFieldValue(deploymentInfo, "mbeans", List.class); Set<String> webModuleNames = new HashSet(); for (Object servletObjectName : servletObjectNames) { // e.g. Figure out the web module name, e.g. "//localhost/jmx-console". // NOTE: We must use reflection when working with the returned ObjectNames, since EMS // loaded them using a different classloader. Attempting to access them directly // would cause ClassCastExceptions. Class<? extends Object> objectNameClass = servletObjectName.getClass(); Method getKeyPropertyMethod = objectNameClass.getMethod("getKeyProperty", String.class); String webModuleName = (String) getKeyPropertyMethod.invoke(servletObjectName, "WebModule"); webModuleNames.add(webModuleName); } log.debug("Found " + webModuleNames.size() + " Web modules for WAR " + shortName + ": " + webModuleNames); String path = getPath(isOnWin, deploymentInfo); List<WarDeploymentInformation> infos = new ArrayList<WarDeploymentInformation>(); for (String webModuleName : webModuleNames) { WebModule webModule = parseWebModuleName(webModuleName); WarDeploymentInformation deploymentInformation = new WarDeploymentInformation(); deploymentInformation.setVHost(webModule.vhost); deploymentInformation.setFileName(path); deploymentInformation.setContextRoot(webModule.contextRoot); String jbossWebMBeanName = String.format(JBOSS_WEB_MBEAN_NAME_TEMPLATE, webModuleName); jbossWebObjectName = ObjectName.getInstance(jbossWebMBeanName); jbossWebMBeanName = jbossWebObjectName.getCanonicalName(); deploymentInformation.setJbossWebModuleMBeanObjectName(jbossWebMBeanName); infos.add(deploymentInformation); } retDeploymentInformationMap.put(jbossManMBeanName, infos); } } } } catch (Exception evalError) { log.warn("Failed to determine if a deployment contains our MBean", evalError); } } return retDeploymentInformationMap; }
From source file:com.evolveum.midpoint.web.page.PageTemplate.java
protected void clearLessJsCache(AjaxRequestTarget target) { try {/* w w w . j a va2 s. c o m*/ ArrayList<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null); if (servers.size() > 1) { LOGGER.info("Too many mbean servers, cache won't be cleared."); for (MBeanServer server : servers) { LOGGER.info(server.getDefaultDomain()); } return; } MBeanServer server = servers.get(0); ObjectName objectName = ObjectName.getInstance("wro4j-idm:type=WroConfiguration"); server.invoke(objectName, "reloadCache", new Object[] {}, new String[] {}); if (target != null) { target.add(PageTemplate.this); } } catch (Exception ex) { LoggingUtils.logException(LOGGER, "Couldn't clear less/js cache", ex); error("Error occurred, reason: " + ex.getMessage()); if (target != null) { target.add(getFeedbackPanel()); } } }
From source file:org.apache.geode.admin.jmx.internal.SystemMemberCacheJmxImpl.java
/** * Returns the MBean <code>ObjectName</code>s for all cache servers that serve this cache to * clients./*from w w w .ja v a2 s. c om*/ * * @since GemFire 4.0 */ public ObjectName[] manageCacheServers() throws AdminException, MalformedObjectNameException { try { SystemMemberCacheServer[] bridges = getCacheServers(); ObjectName[] names = new ObjectName[bridges.length]; for (int i = 0; i < bridges.length; i++) { SystemMemberBridgeServerJmxImpl bridge = (SystemMemberBridgeServerJmxImpl) bridges[i]; names[i] = ObjectName.getInstance(bridge.getMBeanName()); } return names; } catch (AdminException e) { MBeanUtil.logStackTrace(Level.WARN, e); throw e; } catch (RuntimeException e) { MBeanUtil.logStackTrace(Level.WARN, e); throw e; } catch (VirtualMachineError err) { SystemFailure.initiateFailure(err); // If this ever returns, rethrow the error. We're poisoned // now, so don't let this thread continue. throw err; } catch (Error e) { // Whenever you catch Error or Throwable, you must also // catch VirtualMachineError (see above). However, there is // _still_ a possibility that you are dealing with a cascading // error condition, so you also need to check to see if the JVM // is still usable: SystemFailure.checkFailure(); MBeanUtil.logStackTrace(Level.ERROR, e); throw e; } }
From source file:org.mule.management.agents.JmxAgent.java
public void registerComponentService(String name) throws NotCompliantMBeanException, MBeanRegistrationException, InstanceAlreadyExistsException, MalformedObjectNameException { ObjectName on = ObjectName.getInstance(getDomainName() + ":type=control,name=" + name + "ComponentService"); ComponentServiceMBean serviceMBean = new ComponentService(name); logger.debug("Registering component with name: " + on); mBeanServer.registerMBean(serviceMBean, on); registeredMBeans.add(on);/* w w w .ja v a 2 s . co m*/ }