List of usage examples for javax.management MBeanServerFactory findMBeanServer
public synchronized static ArrayList<MBeanServer> findMBeanServer(String agentId)
Return a list of registered MBeanServer objects.
From source file:org.geoserver.wfs.notification.GMLNotificationSerializer.java
private final void registerMBean() { if (name == null) { return;// ww w. j a v a 2 s .co m } for (MBeanServer server : MBeanServerFactory.findMBeanServer(null)) { try { server.registerMBean(this, name); } catch (JMException e) { LOG.warn("Unable to register in JMX:", e); } } }
From source file:be.fedict.trust.service.snmp.SNMPInterceptor.java
private static Long getValue(String oid, String service) { LOG.debug("get value of counter oid=" + oid + " @ service=" + service); try {/*from w w w. j a va 2 s. c o m*/ for (MBeanServer mBeanServer : MBeanServerFactory.findMBeanServer(null)) { return (Long) mBeanServer.invoke(new ObjectName(service), "getValue", new Object[] { oid }, new String[] { "java.lang.String" }); } } catch (Exception e) { LOG.error("Failed to contact SNMP Mbean: " + e.getMessage(), e); } return 0L; }
From source file:org.alfresco.solr.servlet.Solr4X509ServletFilter.java
private int getHttpsPort() { try {/*from ww w. j ava2s. c om*/ MBeanServer mBeanServer = MBeanServerFactory.findMBeanServer(null).get(0); QueryExp query = Query.eq(Query.attr("Scheme"), Query.value("https")); Set<ObjectName> objectNames = mBeanServer.queryNames(null, query); if (objectNames != null && objectNames.size() > 0) { for (ObjectName objectName : objectNames) { String name = objectName.toString(); if (name.indexOf("port=") > -1) { String[] parts = name.split("port="); String port = parts[1]; try { int portNum = Integer.parseInt(port); return portNum; } catch (NumberFormatException e) { logger.error("Error parsing https port:" + port); return -1; } } } } } catch (Throwable t) { logger.error("Error getting https port:", t); } return -1; }
From source file:org.geoserver.wfs.notification.GMLNotificationSerializer.java
private final void unregisterMBean() { if (name == null) return;/*from w ww . ja v a2 s .c o m*/ for (MBeanServer server : MBeanServerFactory.findMBeanServer(null)) { try { server.unregisterMBean(name); } catch (JMException e) { LOG.warn("Unable to unregister from JMX:", e); } } }
From source file:org.apache.tomcat.util.mx.DynamicMBeanProxy.java
public static MBeanServer getMBeanServer() { if (mserver == null) { if (MBeanServerFactory.findMBeanServer(null).size() > 0) { mserver = (MBeanServer) MBeanServerFactory.findMBeanServer(null).get(0); } else {/*w w w . jav a 2 s .c o m*/ mserver = MBeanServerFactory.createMBeanServer(); } } return mserver; }
From source file:architecture.ee.web.spring.controller.SecureMoSKitoController.java
private List<URL> getClassPathUrlsForTomcat(final String context, final String contextPropertyName) { List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null); for (MBeanServer s : servers) { Set<ObjectInstance> instances = s.queryMBeans(null, new QueryExp() { public boolean apply(ObjectName name) throws BadStringOperationException, BadBinaryOpValueExpException, BadAttributeValueExpException, InvalidApplicationException { String type = name.getKeyProperty("type"); log.debug(name.getDomain() + " : " + name.getKeyPropertyList()); if (!type.equals("WebappClassLoader")) return false; if (!name.getDomain().equals("Catalina")) return false; if (!name.getKeyProperty(contextPropertyName).equals(context)) return false; return true; }//from ww w .ja va 2 s .c o m public void setMBeanServer(MBeanServer s) { } }); if (instances.size() > 0) { try { URL[] urls = (URL[]) s.getAttribute(instances.iterator().next().getObjectName(), "URLs"); return Arrays.asList(urls); } catch (Exception e) { } } } return null; }
From source file:be.fedict.trust.service.snmp.SNMPInterceptor.java
public static void setValue(String oid, String service, Long value) { LOG.debug("set value of counter oid=" + oid + " @ service=" + service + " to " + value); try {/*from www .j a v a 2 s .com*/ for (MBeanServer mBeanServer : MBeanServerFactory.findMBeanServer(null)) { mBeanServer.invoke(new ObjectName(service), "setValue", new Object[] { oid, value }, new String[] { "java.lang.String", "java.lang.Long" }); } } catch (Exception e) { LOG.error("Failed to contact SNMP Mbean: " + e.getMessage(), e); } }
From source file:be.fedict.trust.service.snmp.SNMPInterceptor.java
public static void increment(String oid, String service, Long increment) { LOG.debug("increment counter oid=" + oid + " @ service=" + service + " with " + increment); try {//from www.ja v a 2 s .com for (MBeanServer mBeanServer : MBeanServerFactory.findMBeanServer(null)) { mBeanServer.invoke(new ObjectName(service), "increment", new Object[] { oid, increment }, new String[] { "java.lang.String", "java.lang.Long" }); } } catch (Exception e) { LOG.error("Failed to contact SNMP Mbean: " + e.getMessage(), e); } }
From source file:org.apache.tinkerpop.gremlin.server.util.MetricManager.java
/** * Create a {@link JmxReporter} attached to the {@code MetricsRegistry}. * <p/>/*from w w w .j a va2 s . co m*/ * If {@code domain} or {@code agentId} is null, then Metrics's uses its own * internal default value(s). * <p/> * If {@code agentId} is non-null, then * MBeanServerFactory#findMBeanServer(agentId) must return exactly * one {@code MBeanServer}. The reporter will register with that server. If * the {@code findMBeanServer(agentId)} call returns no or multiple servers, * then this method logs an error and falls back on the Metrics default for * {@code agentId}. * * @param domain the JMX domain in which to continuously expose metrics * @param agentId the JMX agent ID */ public synchronized void addJmxReporter(final String domain, final String agentId) { if (null != jmxReporter) { log.debug("Metrics JmxReporter already active; not creating another"); return; } JmxReporter.Builder b = JmxReporter.forRegistry(getRegistry()); if (null != domain) { b.inDomain(domain); } if (null != agentId) { List<MBeanServer> servs = MBeanServerFactory.findMBeanServer(agentId); if (null != servs && 1 == servs.size()) { b.registerWith(servs.get(0)); } else { log.error("Metrics Slf4jReporter agentId {} does not resolve to a single MBeanServer", agentId); } } jmxReporter = b.build(); jmxReporter.start(); log.info("Configured Metrics JmxReporter configured with domain={} and agentId={}", Optional.ofNullable(domain).orElse(""), Optional.ofNullable(agentId).orElse("")); }
From source file:org.quartz.jobs.ee.jmx.JMXInvokerJob.java
private Object invoke(String objectName, String method, Object[] params, String[] types) throws Exception { MBeanServer server = (MBeanServer) MBeanServerFactory.findMBeanServer(null).get(0); ObjectName mbean = new ObjectName(objectName); if (server == null) { throw new Exception("Can't find mbean server"); }/*w w w . ja v a 2s . c om*/ getLog().info("invoking " + method); return server.invoke(mbean, method, params, types); }