List of usage examples for javax.management ObjectInstance getObjectName
public ObjectName getObjectName()
From source file:com.meltmedia.cadmium.deployer.JBossUtil.java
public static boolean isWarDeployed(String warName, Logger log) throws Exception { MBeanServer server = MBeanServerLocator.locateJBoss(); Set<ObjectInstance> foundInstances = server .queryMBeans(new ObjectName("jboss.deployment:type=Deployment,id=\"*" + warName + "*\""), null); boolean found = false; if (foundInstances != null && foundInstances.size() > 0) { log.debug("MBean query returned: {} results.", foundInstances.size()); for (ObjectInstance instance : foundInstances) { String simpleName = "" + server.getAttribute(instance.getObjectName(), "SimpleName"); log.debug("Checking {} is {}", simpleName, warName); if (simpleName.equals(warName)) { found = true;/*w w w .j av a 2 s .c o m*/ String state = server.getAttribute(instance.getObjectName(), "State") + ""; log.debug("Deployment state {}", state); if (state.equals("ERROR")) { Object error = server.getAttribute(instance.getObjectName(), "Problem"); log.debug("Found problem: {}", error); if (error instanceof Throwable) { throw new Exception((Throwable) error); } else { throw new Exception(error.toString()); } } else if (state.equals("DEPLOYED")) { return true; } else if (state.equals("UNDEPLOYED")) { found = false; } } } } if (!found) { throw new NoDeploymentFoundException(); } return false; }
From source file:gemlite.shell.converters.ServiceNameConverter.java
public boolean getAllPossibleValues(List<Completion> completions, Class<?> targetType, String existingData, String optionContext, MethodTarget target) { if ((String.class.equals(targetType)) && (StringUtils.contains(optionContext, "param.context.service.name"))) { Set<ObjectInstance> beans = jmxService.listMBeans(); for (ObjectInstance bean : beans) { String name = bean.getObjectName().getCanonicalName(); if (existingData != null) { if (name.startsWith(existingData)) { completions.add(new Completion(name)); }/*from ww w . j a va 2 s .co m*/ } else { completions.add(new Completion(name)); } } } return !completions.isEmpty(); }
From source file:com.linkedin.d2.balancer.util.LoadBalancerClientCli.java
public static void resetTogglingStores(String host, boolean enabled) throws Exception { MonitoredHost _host = MonitoredHost.getMonitoredHost(new HostIdentifier(host)); for (Object pidObj : _host.activeVms()) { int pid = (Integer) pidObj; System.out.println("checking pid: " + pid); JMXServiceURL jmxUrl = null; com.sun.tools.attach.VirtualMachine vm = com.sun.tools.attach.VirtualMachine.attach(pid + ""); try {/*from w ww . ja v a2 s .c o m*/ // get the connector address String connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS); // establish connection to connector server if (connectorAddress != null) { jmxUrl = new JMXServiceURL(connectorAddress); } } finally { vm.detach(); } if (jmxUrl != null) { System.out.println("got jmx url: " + jmxUrl); // connect to jmx JMXConnector connector = JMXConnectorFactory.connect(jmxUrl); connector.connect(); MBeanServerConnection mbeanServer = connector.getMBeanServerConnection(); // look for all beans in the d2 name space Set<ObjectInstance> objectInstances = mbeanServer.queryMBeans(new ObjectName("com.linkedin.d2:*"), null); for (ObjectInstance objectInstance : objectInstances) { System.err.println("checking object: " + objectInstance.getObjectName()); // if we've found a toggling store, then toggle it if (objectInstance.getObjectName().toString().endsWith("TogglingStore")) { System.out.println("found toggling zk store, so toggling to: " + enabled); mbeanServer.invoke(objectInstance.getObjectName(), "setEnabled", new Object[] { enabled }, new String[] { "boolean" }); } } } else { System.out.println("pid is not a jmx process: " + pid); } } }
From source file:org.trpr.platform.batch.impl.spring.jmx.JMXJobUtils.java
/** * Constructor for this class// w ww . ja v a 2 s .c o m */ public JMXJobUtils() { this.mbeanServer = ManagementFactory.getPlatformMBeanServer(); Set<ObjectInstance> mbeans = mbeanServer.queryMBeans(null, null); for (ObjectInstance mbean : mbeans) { if (mbean.getObjectName().toString().indexOf(JOB_ADMINISTRATOR) > -1) { this.jobAdministratorInstance = mbean; break; } } }
From source file:com.taobao.metamorphosis.tools.shell.StopBrokerTool.java
@Override public void doMain(String[] args) throws Exception { CommandLine commandLine = this.getCommandLine(args); String host = commandLine.getOptionValue("host", "127.0.0.1"); int port = Integer.parseInt(commandLine.getOptionValue("port", "9999")); JMXClient jmxClient = JMXClient.getJMXClient(host, port); this.println("connected to " + jmxClient.getAddressAsString()); ObjectInstance brokerInstance = jmxClient.queryMBeanForOne(METABROKER_NAME); if (brokerInstance != null) { jmxClient.invoke(brokerInstance.getObjectName(), "stop", new Object[0], new String[0]); jmxClient.close();//from ww w. ja v a 2 s . co m this.println("invoke " + brokerInstance.getClassName() + "#stop success"); } else { this.println(" " + METABROKER_NAME); } }
From source file:com.taobao.metamorphosis.tools.shell.SlaveStatus.java
@Override public void doMain(String[] args) throws Exception { CommandLine commandLine = CommandLineUtils.parseCmdLine(args, new Options().addOption("host", true, "host").addOption("port", true, "port")); String host = commandLine.getOptionValue("host", "127.0.0.1"); int port = Integer.parseInt(commandLine.getOptionValue("port", "9123")); JMXClient jmxClient = JMXClient.getJMXClient(host, port); this.println("connected to " + jmxClient.getAddressAsString()); ObjectInstance metaConfigInstance = jmxClient.queryMBeanForOne(HANDLE_NANE); if (metaConfigInstance != null) { Object result = jmxClient.getAttribute(metaConfigInstance.getObjectName(), "Status"); System.out.println(result); jmxClient.close();/*from ww w . ja v a2 s. co m*/ this.println("invoke " + metaConfigInstance.getClassName() + "#reload success"); } else { this.println(" " + METACONFIG_NAME); } }
From source file:com.googlecode.psiprobe.beans.JvmMemoryInfoAccessorBean.java
public List getPools() throws Exception { List memoryPools = new LinkedList(); MBeanServer mBeanServer = new Registry().getMBeanServer(); Set memoryOPools = mBeanServer.queryMBeans(new ObjectName("java.lang:type=MemoryPool,*"), null); ///*from w ww. j a v a 2s . c o m*/ // totals // long totalInit = 0; long totalMax = 0; long totalUsed = 0; long totalCommitted = 0; for (Iterator it = memoryOPools.iterator(); it.hasNext();) { ObjectInstance oi = (ObjectInstance) it.next(); ObjectName oName = oi.getObjectName(); MemoryPool memoryPool = new MemoryPool(); memoryPool.setName(JmxTools.getStringAttr(mBeanServer, oName, "Name")); memoryPool.setType(JmxTools.getStringAttr(mBeanServer, oName, "Type")); CompositeDataSupport cd = (CompositeDataSupport) mBeanServer.getAttribute(oName, "Usage"); // // It seems that "Usage" attribute of one of the pools may turn into null intermittently. We better have a // dip in the graph then an NPE though. // if (cd != null) { memoryPool.setMax(JmxTools.getLongAttr(cd, "max")); memoryPool.setUsed(JmxTools.getLongAttr(cd, "used")); memoryPool.setInit(JmxTools.getLongAttr(cd, "init")); memoryPool.setCommitted(JmxTools.getLongAttr(cd, "committed")); } else { logger.error("Oops, JVM problem? " + oName.toString() + " \"Usage\" attribute is NULL!"); } totalInit += memoryPool.getInit(); totalMax += memoryPool.getMax(); totalUsed += memoryPool.getUsed(); totalCommitted += memoryPool.getCommitted(); memoryPools.add(memoryPool); } if (!memoryPools.isEmpty()) { MemoryPool pool = new MemoryPool(); pool.setName("Total"); pool.setType("TOTAL"); pool.setInit(totalInit); pool.setUsed(totalUsed); pool.setMax(totalMax); pool.setCommitted(totalCommitted); memoryPools.add(pool); } return memoryPools; }
From source file:net.zcarioca.jmx.services.impl.MBeanObjectServiceImpl.java
/** * {@inheritDoc}/*from www . jav a 2 s . com*/ */ @Override public Set<MBeanDescriptor> findMBeansByType(final String domain, final String type) { return toMBeanObjectSet(getPlatformMBeanServer().queryMBeans(null, null), new Predicate() { @Override public boolean evaluate(Object object) { ObjectInstance objInst = (ObjectInstance) object; ObjectName name = objInst.getObjectName(); if (StringUtils.equalsIgnoreCase(domain, objInst.getObjectName().getDomain())) { String objectType = name.getKeyProperty("type"); return StringUtils.equalsIgnoreCase(type, objectType); } return false; } }); }
From source file:com.lmig.cf.metrics.opsmetrics.OpsMetrics.java
private boolean metricValueIsNumber(MBeanServerConnection connection, ObjectInstance object, String attribute) { try {/*ww w. j av a 2 s .c om*/ return connection.getAttribute(object.getObjectName(), attribute) instanceof Number; } catch (AttributeNotFoundException | InstanceNotFoundException | MBeanException | ReflectionException | IOException e) { return false; } }
From source file:net.zcarioca.jmx.services.impl.MBeanObjectServiceImpl.java
private MBeanDescriptor toMBeanObject(ObjectInstance objectInstance) { try {// w ww .j ava 2 s .com MBeanInfo info = mbeanServer.getMBeanInfo(objectInstance.getObjectName()); return new MBeanDescriptor(objectInstance.getObjectName(), info); } catch (Exception exc) { log.warn("Could not find information for MBean: " + objectInstance.getObjectName(), exc); } return null; }