List of usage examples for javax.management MBeanServer queryNames
public Set<ObjectName> queryNames(ObjectName name, QueryExp query);
From source file:org.apache.camel.TestSupportJmxCleanup.java
public static void removeMBeans(String domain) throws Exception { MBeanServer mbsc = ManagementFactory.getPlatformMBeanServer(); Set<ObjectName> s = mbsc.queryNames(new ObjectName(getDomainName(domain) + ":*"), null); for (ObjectName on : s) { mbsc.unregisterMBean(on);//from ww w .jav a2 s . com } }
From source file:org.wso2.carbon.utils.MBeanRegistrar.java
public static void registerMBean(Object mbeanInstance, String objectName) throws Exception { MBeanServer mbs = ManagementFactory.getMBeanServer(); Set set = mbs.queryNames(new ObjectName(objectName), null); if (set.isEmpty()) { ObjectName name = new ObjectName(objectName); mbs.registerMBean(mbeanInstance, name); mbeans.add(name);/*from w ww .j a v a2 s.c o m*/ } else { log.debug("MBean " + objectName + " already exists"); throw new Exception("MBean " + objectName + " already exists"); } }
From source file:org.apache.camel.TestSupportJmxCleanup.java
public static void traceMBeans(String domain) throws Exception { MBeanServer mbsc = ManagementFactory.getPlatformMBeanServer(); String d = getDomainName(domain); Set<ObjectName> s = mbsc.queryNames(new ObjectName(d + ":*"), null); if (s.size() > 0) { LOG.warn(" + " + s.size() + " ObjectNames registered in domain \"" + d + "\""); for (ObjectName on : s) { LOG.warn(" | " + on); }/*from w w w. ja va 2 s.c o m*/ } }
From source file:org.apache.hadoop.hbase.util.JSONMetricUtil.java
public static Set<ObjectName> getRegistredMBeans(ObjectName name, MBeanServer mbs) { return mbs.queryNames(name, null); }
From source file:org.lobzik.home_sapiens.pi.AppData.java
public static List<String> getHTTPEndPoints() throws Exception { //tomcat-specific 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<String>(); for (Iterator<ObjectName> i = objs.iterator(); i.hasNext();) { ObjectName obj = i.next(); String scheme = mbs.getAttribute(obj, "scheme").toString(); if (!scheme.toLowerCase().equals("http")) { continue; }//from www . j a va2 s . c o m String port = obj.getKeyProperty("port"); for (InetAddress addr : addresses) { String host = addr.getHostAddress(); String ep = scheme + "://" + host + ":" + port; endPoints.add(ep); } } return endPoints; }
From source file:org.nuxeo.ecm.core.management.jtajca.JtajcaManagementFeature.java
public static <T> T getInstanceNamedWithPrefix(Class<T> type, String prefix) { MBeanServer mbs = Framework.getService(ServerLocator.class).lookupServer(); Set<String> names = new HashSet<>(); for (ObjectName objectName : mbs.queryNames(nameOf(type), null)) { String name = objectName.getKeyProperty("name"); names.add(name); // for error case if (name.startsWith(prefix)) { return JMX.newMXBeanProxy(mbs, objectName, type); }// www . j av a2 s . com } throw new RuntimeException("Found no bean with name prefix: " + prefix + " in available names: " + names); }
From source file:org.apache.streams.util.ComponentUtils.java
/** * Removes all mbeans registered undered a specific domain. Made specificly to clean up at unit tests * @param domain/* ww w. j a va 2 s. co m*/ */ public static void removeAllMBeansOfDomain(String domain) throws Exception { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); domain = domain.endsWith(":") ? domain : domain + ":"; ObjectName objectName = new ObjectName(domain + "*"); Set<ObjectName> mbeanNames = mbs.queryNames(objectName, null); for (ObjectName name : mbeanNames) { mbs.unregisterMBean(name); } }
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 w w w. j av a 2s . c o m*/ } } return endPoints; }
From source file:at.ac.tuwien.dsg.cloud.salsa.engine.utils.SystemFunctions.java
/** * This command try to get Port which the service is listening to. The port should be in the parameter -httpPort when running, or Tomcat port * * @return/*from ww w . ja va2 s .co m*/ */ public static String getPort() { try { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); Set<ObjectName> objs = mbs.queryNames(new ObjectName("*:type=Connector,*"), Query.match(Query.attr("protocol"), Query.value("HTTP/1.1"))); for (ObjectName obj : objs) { String port = obj.getKeyProperty("port"); return port; } } catch (MalformedObjectNameException e) { EngineLogger.logger .error("Cannot get listening port of salsa-engine service. return 8080 as default. Error: " + e.toString()); } EngineLogger.logger.error("Cannot find listening port of salsa-engine service. return 8080 as default"); return "8080"; }
From source file:org.onehippo.forge.camel.util.CamelContextUtils.java
/** * Finds the {@code ManagedCamelContextMBean} having {@code camelContextId} from the platform MBean server and invokes the {@code operation} * with {@code params} of which signature is like {@code signature} on the found {@code ManagedCamelContext} MBean. * If a blank {@code camelContextId} provided, then it invokes the operation on the first found {@code ManagedCamelContextMBean} MBean. * <p>Example code:</p>/* www. j av a2s .c om*/ * <pre> * CamelContextUtils.invokeManagedCamelContextMBean("camel-1", "sendBody", new Object [] { "direct:test", body }, new String {} { String.class.getName(), Object.class.getName() });; * </pre> * @param camelContextId camel context ID * @param operation operation name * @param params parameters array * @param signature signature of parameters * @return operation return */ public static Object invokeManagedCamelContextMBean(final String camelContextId, final String operation, Object[] params, String[] signature) { Object ret = null; try { QueryExp expr = Query.isInstanceOf(new StringValueExp(CAMEL_CONTEXT_MBEAN_INSTANCE_TYPE)); MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName objectName; if (StringUtils.isNotBlank(camelContextId)) { objectName = new ObjectName("org.apache.camel:name=" + camelContextId); } else { objectName = new ObjectName("org.apache.camel:*"); } Set<ObjectName> objectNames = mbeanServer.queryNames(objectName, expr); if (!objectNames.isEmpty()) { final ObjectName firstObjectName = objectNames.iterator().next(); ret = mbeanServer.invoke(firstObjectName, operation, params, signature); } else { throw new RuntimeException("No CamelContext found by name: " + objectName); } } catch (MalformedObjectNameException e) { throw new RuntimeException("MalformedObjectNameException: " + e, e); } catch (InstanceNotFoundException e) { throw new RuntimeException("InstanceNotFoundException: " + e, e); } catch (ReflectionException e) { throw new RuntimeException("ReflectionException: " + e, e); } catch (MBeanException e) { throw new RuntimeException("MBeanException: " + e, e); } return ret; }