List of usage examples for javax.management ObjectName ObjectName
public ObjectName(String name) throws MalformedObjectNameException
From source file:com.all.services.ServiceConsole.java
@SuppressWarnings("unchecked") public static void main(String[] args) { try {/*from ww w.j av a 2 s . c o m*/ LOG.info("Connecting to JMX service..."); if (args.length < 2) { LOG.error("Incorrect usage of Ultrapeer console.\n\n Args should be 'command password [host]'"); throw new IllegalArgumentException("Not enough agrugments to run."); } HashMap env = new HashMap(); env.put("jmx.remote.credentials", new String[] { "controlRole", args[1] }); String hostname = args.length > 2 ? args[2] : ""; JMXConnector jmxc = JMXConnectorFactory .connect(new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + hostname + ":9999/jmxrmi"), env); ServiceMonitorMBean mbeanProxy = JMX.newMBeanProxy(jmxc.getMBeanServerConnection(), new ObjectName("com.all.services:type=ServiceMonitor"), ServiceMonitorMBean.class, true); handleCommand(mbeanProxy, args[0]); jmxc.close(); LOG.info("Done."); } catch (Exception e) { LOG.error(e, e); } }
From source file:co.paralleluniverse.common.monitoring.Monitor.java
public void registerMBean() { try {//from w ww.ja va 2 s.c o m LOG.info("Registering MBean {}", name); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName mxbeanName = new ObjectName(name); mbs.registerMBean(this, mxbeanName); this.registered = true; } catch (InstanceAlreadyExistsException ex) { throw new RuntimeException(ex); } catch (MBeanRegistrationException ex) { throw new RuntimeException(ex); } catch (NotCompliantMBeanException ex) { throw new AssertionError(ex); } catch (MalformedObjectNameException ex) { throw new AssertionError(ex); } }
From source file:org.apache.camel.component.zookeeper.ZooKeeperEndpointTest.java
public synchronized void testEnpointConfigurationCanBeSetViaJMX() throws Exception { Set s = mbsc.queryNames(new ObjectName(domainName + ":type=endpoints,*"), null); assertEquals("Could not find endpoints: " + s, 2, s.size()); ObjectName zepName = new ArrayList<ObjectName>(s).get(0); verifyManagedAttribute(zepName, "Path", "/someotherpath"); verifyManagedAttribute(zepName, "Create", true); verifyManagedAttribute(zepName, "Repeat", true); verifyManagedAttribute(zepName, "ListChildren", true); verifyManagedAttribute(zepName, "AwaitExistence", true); verifyManagedAttribute(zepName, "Timeout", 12345); verifyManagedAttribute(zepName, "Backoff", 12345L); mbsc.invoke(zepName, "clearServers", null, JmxUtils.getMethodSignature(ZooKeeperEndpoint.class.getMethod("clearServers", null))); mbsc.invoke(zepName, "addServer", new Object[] { "someserver:12345" }, JmxUtils .getMethodSignature(ZooKeeperEndpoint.class.getMethod("addServer", new Class[] { String.class }))); }
From source file:com.amazonaws.client.metrics.jmx.MBeans.java
/** * Unregisters the MBean under the given object name to the first MBean * server, or the platform MBean server if there is no explicitly registered * MBean server.// www. j a v a2s .co m * * @return true if the unregistration succeeded, or false if the MBean * doesn't exist under the given object name. * @throws MBeanRegistrationException * Wraps exceptions thrown by the preRegister(), preDeregister() * methods of the MBeanRegistration interface. */ public static <T> boolean unregisterMBean(String objectName) throws MBeanRegistrationException { MBeanServer server = getMBeanServer(); try { server.unregisterMBean(new ObjectName(objectName)); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException(e); } catch (InstanceNotFoundException e) { LogFactory.getLog(MBeans.class).debug("Failed to unregister mbean " + objectName, e); return false; } return true; }
From source file:be.fgov.kszbcss.rhq.websphere.mbean.MBeanObjectNamePatternLocator.java
public final Set<ObjectName> queryNames(WebSphereServer server) throws JMException, ConnectorException, InterruptedException { ObjectName pattern = getPattern(server); ObjectName actualPattern;/*from www. j av a 2 s.c o m*/ if (recursive || server.getProcessType().equals("ManagedProcess")) { actualPattern = pattern; } else { actualPattern = new ObjectName(pattern + ",cell=" + server.getCell() + ",node=" + server.getNode() + ",process=" + server.getServer()); } if (log.isDebugEnabled()) { log.debug("Query names for pattern " + actualPattern); } return server.getAdminClient().queryNames(actualPattern, null); }
From source file:org.apache.streams.jackson.ThroughputQueueDeserializer.java
@Override public ThroughputQueueBroadcast deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { try {//from w w w .j a va2 s . c om MBeanServer server = ManagementFactory.getPlatformMBeanServer(); ThroughputQueueBroadcast throughputQueueBroadcast = new ThroughputQueueBroadcast(); JsonNode attributes = jsonParser.getCodec().readTree(jsonParser); ObjectName name = new ObjectName(attributes.get("canonicalName").asText()); MBeanInfo info = server.getMBeanInfo(name); throughputQueueBroadcast.setName(name.toString()); for (MBeanAttributeInfo attribute : Arrays.asList(info.getAttributes())) { try { switch (attribute.getName()) { case "CurrentSize": throughputQueueBroadcast .setCurrentSize((long) server.getAttribute(name, attribute.getName())); break; case "AvgWait": throughputQueueBroadcast .setAvgWait((double) server.getAttribute(name, attribute.getName())); break; case "MaxWait": throughputQueueBroadcast.setMaxWait((long) server.getAttribute(name, attribute.getName())); break; case "Removed": throughputQueueBroadcast.setRemoved((long) server.getAttribute(name, attribute.getName())); break; case "Added": throughputQueueBroadcast.setAdded((long) server.getAttribute(name, attribute.getName())); break; case "Throughput": throughputQueueBroadcast .setThroughput((double) server.getAttribute(name, attribute.getName())); break; } } catch (Exception e) { LOGGER.error("Exception while trying to deserialize ThroughputQueueBroadcast object: {}", e); } } return throughputQueueBroadcast; } catch (Exception e) { return null; } }
From source file:org.apache.streams.jackson.DatumStatusCounterDeserializer.java
@Override public DatumStatusCounterBroadcast deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { try {//from ww w . j av a 2 s . c o m MBeanServer server = ManagementFactory.getPlatformMBeanServer(); DatumStatusCounterBroadcast datumStatusCounterBroadcast = new DatumStatusCounterBroadcast(); JsonNode attributes = jsonParser.getCodec().readTree(jsonParser); ObjectName name = new ObjectName(attributes.get("canonicalName").asText()); MBeanInfo info = server.getMBeanInfo(name); datumStatusCounterBroadcast.setName(name.toString()); for (MBeanAttributeInfo attribute : Arrays.asList(info.getAttributes())) { try { switch (attribute.getName()) { case "Failed": datumStatusCounterBroadcast .setFailed((boolean) server.getAttribute(name, attribute.getName())); break; case "Passed": datumStatusCounterBroadcast .setPassed((boolean) server.getAttribute(name, attribute.getName())); break; } } catch (Exception e) { LOGGER.error("Exception trying to deserialize DatumStatusCounterBroadcast object: {}", e); } } return datumStatusCounterBroadcast; } catch (Exception e) { LOGGER.error("Exception trying to deserialize DatumStatusCounterBroadcast object: {}", e); return null; } }
From source file:org.apache.streams.jackson.MemoryUsageDeserializer.java
@Override public MemoryUsageBroadcast deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { try {/*w w w.j a v a2 s . c o m*/ MBeanServer server = ManagementFactory.getPlatformMBeanServer(); MemoryUsageBroadcast memoryUsageBroadcast = new MemoryUsageBroadcast(); JsonNode attributes = jsonParser.getCodec().readTree(jsonParser); ObjectName name = new ObjectName(attributes.get("canonicalName").asText()); MBeanInfo info = server.getMBeanInfo(name); memoryUsageBroadcast.setName(name.toString()); for (MBeanAttributeInfo attribute : Arrays.asList(info.getAttributes())) { switch (attribute.getName()) { case "Verbose": memoryUsageBroadcast.setVerbose((boolean) server.getAttribute(name, attribute.getName())); break; case "ObjectPendingFinalizationCount": memoryUsageBroadcast.setObjectPendingFinalizationCount( Long.parseLong(server.getAttribute(name, attribute.getName()).toString())); break; case "HeapMemoryUsage": memoryUsageBroadcast.setHeapMemoryUsage( (Long) ((CompositeDataSupport) server.getAttribute(name, attribute.getName())) .get("used")); break; case "NonHeapMemoryUsage": memoryUsageBroadcast.setNonHeapMemoryUsage( (Long) ((CompositeDataSupport) server.getAttribute(name, attribute.getName())) .get("used")); break; } } return memoryUsageBroadcast; } catch (Exception e) { LOGGER.error("Exception trying to deserialize MemoryUsageDeserializer object: {}", e); return null; } }
From source file:psiprobe.controllers.threads.ThreadStackController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { long threadId = ServletRequestUtils.getLongParameter(request, "id", -1); String threadName = ServletRequestUtils.getStringParameter(request, "name", null); List<ThreadStackElement> stack = null; MBeanServer mbeanServer = new Registry().getMBeanServer(); ObjectName threadingOName = new ObjectName("java.lang:type=Threading"); if (threadId == -1 && threadName != null) { // find thread by name for (long id : (long[]) mbeanServer.getAttribute(threadingOName, "AllThreadIds")) { CompositeData cd = (CompositeData) mbeanServer.invoke(threadingOName, "getThreadInfo", new Object[] { id }, new String[] { "long" }); String name = JmxTools.getStringAttr(cd, "threadName"); if (threadName.equals(name)) { threadId = id;/*from w ww.ja v a 2 s . c o m*/ break; } } } if (mbeanServer.queryMBeans(threadingOName, null) != null && threadId != -1) { CompositeData cd = (CompositeData) mbeanServer.invoke(threadingOName, "getThreadInfo", new Object[] { threadId, stackElementCount }, new String[] { "long", "int" }); if (cd != null) { CompositeData[] elements = (CompositeData[]) cd.get("stackTrace"); threadName = JmxTools.getStringAttr(cd, "threadName"); stack = new ArrayList<>(elements.length); for (CompositeData cd2 : elements) { ThreadStackElement tse = new ThreadStackElement(); tse.setClassName(JmxTools.getStringAttr(cd2, "className")); tse.setFileName(JmxTools.getStringAttr(cd2, "fileName")); tse.setMethodName(JmxTools.getStringAttr(cd2, "methodName")); tse.setLineNumber(JmxTools.getIntAttr(cd2, "lineNumber", -1)); tse.setNativeMethod(JmxTools.getBooleanAttr(cd2, "nativeMethod")); stack.add(tse); } } } return new ModelAndView(getViewName(), "stack", stack).addObject("threadName", threadName); }
From source file:org.apache.streams.jackson.StreamsTaskCounterDeserializer.java
@Override public StreamsTaskCounterBroadcast deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { try {// w w w . j ava2s . c o m MBeanServer server = ManagementFactory.getPlatformMBeanServer(); StreamsTaskCounterBroadcast streamsTaskCounterBroadcast = new StreamsTaskCounterBroadcast(); JsonNode attributes = jsonParser.getCodec().readTree(jsonParser); ObjectName name = new ObjectName(attributes.get("canonicalName").asText()); MBeanInfo info = server.getMBeanInfo(name); streamsTaskCounterBroadcast.setName(name.toString()); for (MBeanAttributeInfo attribute : Arrays.asList(info.getAttributes())) { try { switch (attribute.getName()) { case "ErrorRate": streamsTaskCounterBroadcast .setErrorRate((double) server.getAttribute(name, attribute.getName())); break; case "NumEmitted": streamsTaskCounterBroadcast .setNumEmitted((long) server.getAttribute(name, attribute.getName())); break; case "NumReceived": streamsTaskCounterBroadcast .setNumReceived((long) server.getAttribute(name, attribute.getName())); break; case "NumUnhandledErrors": streamsTaskCounterBroadcast .setNumUnhandledErrors((long) server.getAttribute(name, attribute.getName())); break; case "AvgTime": streamsTaskCounterBroadcast .setAvgTime((double) server.getAttribute(name, attribute.getName())); break; case "MaxTime": streamsTaskCounterBroadcast .setMaxTime((long) server.getAttribute(name, attribute.getName())); break; } } catch (Exception e) { LOGGER.error("Exception while trying to deserialize StreamsTaskCounterBroadcast object: {}", e); } } return streamsTaskCounterBroadcast; } catch (Exception e) { LOGGER.error("Exception while trying to deserialize StreamsTaskCounterBroadcast object: {}", e); return null; } }