List of usage examples for javax.management MBeanServerConnection getAttribute
public Object getAttribute(ObjectName name, String attribute) throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException, IOException;
From source file:com.cognifide.aet.runner.util.MessagesManager.java
protected Set<ObjectName> getAetQueuesObjects(MBeanServerConnection connection) throws AETException { ObjectName[] queues;/*from www . j a v a 2s. c om*/ try { ObjectName broker = new ObjectName(BROKER_OBJECT_NAME); connection.getMBeanInfo(broker); queues = (ObjectName[]) connection.getAttribute(broker, QUEUES_ATTRIBUTE); } catch (Exception e) { throw new AETException("Exception while getting AET Queues.", e); } return filter(queues); }
From source file:com.custardsource.maven.plugins.jmx.SetAttribute.java
@Override public Object execute(MBeanServerConnection connection) throws Exception { ObjectName name = new ObjectName(objectName); ConvertUtilsBean converter = new ConvertUtilsBean(); Object attributeValue = converter.convert(value, ClassUtils.getClass(type)); connection.setAttribute(name, new Attribute(attributeName, attributeValue)); return connection.getAttribute(name, attributeName); }
From source file:com.dsf.dbxtract.cdc.AppJournalWindowTest.java
@Test(dependsOnMethods = { "testAppWithJournalWindow" }) public void testInfoStatistics() throws Exception { JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:5000/jmxrmi"); JMXConnector jmxc = JMXConnectorFactory.connect(url, null); MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); ObjectName mbeanName = new ObjectName("com.dsf.dbxtract:type=InfoMBean"); TabularDataSupport info = (TabularDataSupport) mbsc.getAttribute(mbeanName, InfoMBean.ATTR_INFO); Collection<?> list = info.values(); boolean hasHandlerEntry = false; for (Iterator<?> it = list.iterator(); it.hasNext();) { CompositeDataSupport entry = (CompositeDataSupport) it.next(); if (entry.get("handler").equals(TestWindowHandler.class.getName())) { assert (((Long) entry.get("readCount")).longValue() == TEST_SIZE); hasHandlerEntry = true;//from w w w. j a va 2 s . c o m } } assert (hasHandlerEntry); jmxc.close(); }
From source file:com.clustercontrol.HinemosManagerCli.java
private void invoke() { System.setProperty("sun.rmi.transport.connectionTimeout", String.valueOf(connectTimeout)); System.setProperty("sun.rmi.transport.tcp.responseTimeout", String.valueOf(responseTimeout)); try {//from ww w . j a va 2s .c om JMXServiceURL url = new JMXServiceURL( String.format("service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi", ip, port)); Map<String, Object> env = new HashMap<String, Object>(); if (user != null && password != null) { env.put(JMXConnector.CREDENTIALS, new String[] { user, password }); } MBeanServerConnection mbsc = JMXConnectorFactory.connect(url, env).getMBeanServerConnection(); ObjectName mbeanName = new ObjectName("com.clustercontrol.mbean:type=" + name); if (doesOutputInfo) { printMBeanInfo(mbsc.getMBeanInfo(mbeanName)); return; } Object ret; if (attribute != null) { ret = mbsc.getAttribute(mbeanName, attribute); } else { String[] signature = new String[operationArgs.length]; for (int i = 0; i < signature.length; i++) { signature[i] = String.class.getName(); } ret = mbsc.invoke(mbeanName, operation, operationArgs, signature); } System.out.println(ret); } catch (Exception e) { e.printStackTrace(); System.exit(2); } }
From source file:com.tribloom.module.JmxClient.java
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { Map<String, Object> model = new HashMap<String, Object>(); model.put("connectionSuccess", true); model.put("time", System.currentTimeMillis()); try {/*from w w w .j a va 2 s. com*/ // Create an RMI connector client and // connect it to the RMI connector server // echo("\nCreate an RMI connector client and " + "connect it to the RMI connector server"); JMXServiceURL url = new JMXServiceURL( "service:jmx:rmi://ignored/jndi/rmi://localhost:50500/alfresco/jmxrmi"); Map<String, Object> env = new HashMap<String, Object>(); String[] creds = { "controlRole", "change_asap" }; env.put(JMXConnector.CREDENTIALS, creds); JMXConnector jmxc = JMXConnectorFactory.connect(url, env); // Get an MBeanServerConnection // echo("\nGet an MBeanServerConnection"); MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); ObjectName memory = new ObjectName("java.lang:type=Memory"); CompositeData heapMemUsage = (CompositeData) mbsc.getAttribute(memory, "HeapMemoryUsage"); addCompositeData(model, heapMemUsage, "heapMemoryUsage"); CompositeData nonHeapMemUsage = (CompositeData) mbsc.getAttribute(memory, "NonHeapMemoryUsage"); addCompositeData(model, nonHeapMemUsage, "nonHeapMemoryUsage"); ObjectName operatingSystem = new ObjectName("java.lang:type=OperatingSystem"); model.put("openFileDescriptorCount", mbsc.getAttribute(operatingSystem, "OpenFileDescriptorCount")); model.put("maxFileDescriptorCount", mbsc.getAttribute(operatingSystem, "MaxFileDescriptorCount")); model.put("committedVirtualMemorySize", mbsc.getAttribute(operatingSystem, "CommittedVirtualMemorySize")); model.put("totalSwapSpaceSize", mbsc.getAttribute(operatingSystem, "TotalSwapSpaceSize")); model.put("freeSwapSpaceSize", mbsc.getAttribute(operatingSystem, "FreeSwapSpaceSize")); model.put("processCpuTime", mbsc.getAttribute(operatingSystem, "ProcessCpuTime")); model.put("freePhysicalMemorySize", mbsc.getAttribute(operatingSystem, "FreePhysicalMemorySize")); model.put("totalPhysicalMemorySize", mbsc.getAttribute(operatingSystem, "TotalPhysicalMemorySize")); model.put("operatingSystemName", mbsc.getAttribute(operatingSystem, "Name")); model.put("operatingSystemVersion", mbsc.getAttribute(operatingSystem, "Version")); model.put("operatingSystemArch", mbsc.getAttribute(operatingSystem, "Arch")); model.put("availableProcessors", mbsc.getAttribute(operatingSystem, "AvailableProcessors")); model.put("systemLoadAverage", mbsc.getAttribute(operatingSystem, "SystemLoadAverage")); try { ObjectName parNewGarbageCollector = new ObjectName("java.lang:type=GarbageCollector,name=ParNew"); echo("\nparNewGarbageCollector = " + parNewGarbageCollector); CompositeData parNewLastGcInfo = (CompositeData) mbsc.getAttribute(parNewGarbageCollector, "LastGcInfo"); addCompositeData(model, parNewLastGcInfo, "parNewLastGcInfo"); } catch (InstanceNotFoundException ex) { // No Garbage Collection has occurred yet echo("No Garbage Collection found: " + ex.getMessage()); } try { ObjectName concurrentGarbageCollector = new ObjectName( "java.lang:type=GarbageCollector,name=ConcurrentMarkSweep"); echo("\nconcurrentGarbageCollector = " + concurrentGarbageCollector); CompositeData concurrentGarbageCollectorLastGcInfo = (CompositeData) mbsc .getAttribute(concurrentGarbageCollector, "LastGcInfo"); addCompositeData(model, concurrentGarbageCollectorLastGcInfo, "concurrentMarkSweepLastGcInfo"); } catch (InstanceNotFoundException ex) { // No Garbage Collection has occurred yet echo("No Garbage Collection found: " + ex.getMessage()); } ObjectName classLoading = new ObjectName("java.lang:type=ClassLoading"); model.put("classLoadingLoadedClassCount", mbsc.getAttribute(classLoading, "LoadedClassCount")); model.put("classLoadingUnloadedClassCount", mbsc.getAttribute(classLoading, "UnloadedClassCount")); model.put("classLoadingTotalLoadedClassCount", mbsc.getAttribute(classLoading, "TotalLoadedClassCount")); ObjectName runtime = new ObjectName("java.lang:type=Runtime"); model.put("runtimeName", mbsc.getAttribute(runtime, "Name")); model.put("runtimeClassPath", mbsc.getAttribute(runtime, "ClassPath")); // TODO: Tabular type... Object sysProps = mbsc.getAttribute(runtime, "SystemProperties"); echo("\nsysProps = " + sysProps); model.put("runtimeStartTime", mbsc.getAttribute(runtime, "StartTime")); model.put("runtimeVmName", mbsc.getAttribute(runtime, "VmName")); model.put("runtimeVmVendor", mbsc.getAttribute(runtime, "VmVendor")); model.put("runtimeVmVersion", mbsc.getAttribute(runtime, "VmVersion")); model.put("runtimeLibraryPath", mbsc.getAttribute(runtime, "LibraryPath")); model.put("runtimeBootClassPath", mbsc.getAttribute(runtime, "BootClassPath")); model.put("runtimeManagementSpecVersion", mbsc.getAttribute(runtime, "ManagementSpecVersion")); model.put("runtimeSpecName", mbsc.getAttribute(runtime, "SpecName")); model.put("runtimeSpecVendor", mbsc.getAttribute(runtime, "SpecVendor")); model.put("runtimeSpecVersion", mbsc.getAttribute(runtime, "SpecVersion")); model.put("runtimeInputArguments", mbsc.getAttribute(runtime, "InputArguments")); // TODO: Array... model.put("runtimeUptime", mbsc.getAttribute(runtime, "Uptime")); try { ObjectName memoryPool = new ObjectName("java.lang:type=MemoryPool"); model.put("memoryPoolName", mbsc.getAttribute(memoryPool, "Name")); model.put("memoryPoolType", mbsc.getAttribute(memoryPool, "Type")); CompositeData memoryPoolUsage = (CompositeData) mbsc.getAttribute(memoryPool, "Usage"); addCompositeData(model, memoryPoolUsage, "memoryPoolUsage"); CompositeData memoryPoolPeakUsage = (CompositeData) mbsc.getAttribute(memoryPool, "PeakUsage"); addCompositeData(model, memoryPoolPeakUsage, "memoryPoolPeakUsage"); model.put("memoryPoolMemoryManagerNames", mbsc.getAttribute(memoryPool, "MemoryManagerNames")); // Array of strings model.put("memoryPoolUsageThreshold", mbsc.getAttribute(memoryPool, "UsageThreshold")); model.put("memoryPoolUsageThresholdExceeded", mbsc.getAttribute(memoryPool, "UsageThresholdExceeded")); model.put("memoryPoolUsageThresholdCount", mbsc.getAttribute(memoryPool, "UsageThresholdCount")); model.put("memoryPoolUsageThresholdSupported", mbsc.getAttribute(memoryPool, "UsageThresholdSupported")); model.put("memoryPoolCollectionUsageThreshold", mbsc.getAttribute(memoryPool, "CollectionUsageThreshold")); model.put("memoryPoolCollectionUsageThresholdExceeded", mbsc.getAttribute(memoryPool, "CollectionUsageThresholdExceeded")); model.put("memoryPoolCollectionUsageThresholdCount", mbsc.getAttribute(memoryPool, "CollectionUsageThresholdCount")); CompositeData collectionUsage = (CompositeData) mbsc.getAttribute(memoryPool, "CollectionUsage"); addCompositeData(model, collectionUsage, "memoryPoolCollectionUsage"); model.put("memoryPoolCollectionUsageThresholdSupported", mbsc.getAttribute(memoryPool, "CollectionUsageThresholdSupported")); } catch (InstanceNotFoundException ex) { // Memory pool not initialized yet } echo("\nClose the connection to the server"); jmxc.close(); echo("\nBye! Bye!"); } catch (Exception ex) { ex.printStackTrace(); model.put("connectionSuccess", false); model.put("exception", ex.getMessage()); } return model; }
From source file:org.jboss.as.test.integration.domain.rbac.JmxRBACProviderHostScopedRolesTestCase.java
private void getAttribute(String userName, JmxManagementInterface jmx) throws Exception { boolean successExpected = isReadAllowed(userName); MBeanServerConnection connection = jmx.getConnection(); ObjectName domain = new ObjectName("java.lang:type=OperatingSystem"); try {/*from w ww. ja v a 2s.c om*/ Object attribute = connection.getAttribute(domain, "Name"); assertTrue("Failure was expected", successExpected); assertEquals(System.getProperty("os.name"), attribute.toString()); } catch (JMRuntimeException e) { if (e.getMessage().contains("WFLYJMX0037")) { assertFalse("Success was expected but failure happened: " + e, successExpected); } else { throw e; } } }
From source file:org.jminix.console.resource.AttributeResource.java
@Override protected Map<String, Object> getModel() { String domain = getRequest().getAttributes().get("domain").toString(); String mbean = new EncoderBean().decode(getRequest().getAttributes().get("mbean").toString()); String attribute = new EncoderBean().decode(getRequest().getAttributes().get("attribute").toString()); Map<String, Object> model = new HashMap<String, Object>(); try {// www .j a v a2s. c o m MBeanServerConnection server = getServer(); MBeanAttributeInfo info = null; for (MBeanAttributeInfo i : server.getMBeanInfo(new ObjectName(domain + ":" + mbean)).getAttributes()) { if (i.getName().equals(attribute)) { info = i; } } Object value = server.getAttribute(new ObjectName(domain + ":" + mbean), attribute); model.put("attribute", info); if (value == null) { model.put("value", "<null>"); } else if (value.getClass().isArray()) { templateName = "array-attribute"; model.put("items", value); } else if (value instanceof CompositeData) { templateName = "composite-attribute"; model.put("attribute", value); } else if (value instanceof TabularData) { templateName = "tabular-attribute"; model.put("attribute", value); } else { model.put("value", value); } return model; } catch (IOException e) { throw new RuntimeException(e); } catch (AttributeNotFoundException e) { throw new RuntimeException(e); } catch (InstanceNotFoundException e) { throw new RuntimeException(e); } catch (MalformedObjectNameException e) { throw new RuntimeException(e); } catch (MBeanException e) { Exception targetException = e.getTargetException(); if (targetException instanceof RuntimeErrorException) { throw new RuntimeException(targetException.getCause()); } log.warn("Error accessing attribute", e); model.put("value", e.getTargetException().getCause().getMessage()); return model; } catch (ReflectionException e) { throw new RuntimeException(e); } catch (IntrospectionException e) { throw new RuntimeException(e); } catch (RuntimeException e) { model.put("value", e.getMessage()); log.warn("Error accessing attribute", e); return model; } }
From source file:org.rhq.cassandra.ClusterInitService.java
private String getSchemaVersionForNode(String storageNode, int jmxPort) throws Exception { String url = this.getJMXConnectionURL(storageNode, jmxPort); JMXServiceURL serviceURL = new JMXServiceURL(url); Map<String, String> env = new HashMap<String, String>(); JMXConnector connector = null; try {//from ww w . ja v a 2s . c o m connector = JMXConnectorFactory.connect(serviceURL, env); MBeanServerConnection serverConnection = connector.getMBeanServerConnection(); ObjectName storageService = new ObjectName("org.apache.cassandra.db:type=StorageService"); String attribute = "SchemaVersion"; try { return (String) serverConnection.getAttribute(storageService, attribute); } catch (Exception e) { // It is ok to just catch and log exceptions here particularly in an integration // test environment where we could potentially try to do the JMX query before // Cassandra is fully initialized. We can query StorageService before the native // transport server is initialized which will result in Cassandra throwing a NPE. // We do not want propagate that exception because it is just a matter of waiting // for Cassandra to finish initializing. if (log.isDebugEnabled()) { log.debug("Failed to read attribute [" + attribute + "] from " + storageService, e); } else { log.info("Faied to read attribute [" + attribute + "] from " + storageService + ": " + e.getMessage()); } } } finally { if (connector != null) { connector.close(); } } return null; }
From source file:com.stumbleupon.hbaseadmin.JMXQuery.java
protected Object doAttributeOperation(MBeanServerConnection mbsc, ObjectInstance instance, String command, MBeanAttributeInfo[] infos) throws Exception { final CommandParse parse = new CommandParse(command); if ((parse.getArgs() == null) || (parse.getArgs().length == 0)) { return mbsc.getAttribute(instance.getObjectName(), parse.getCmd()); }// ww w .ja v a 2 s .co m if (parse.getArgs().length != 1) { throw new IllegalArgumentException("One only argument setting attribute values: " + parse.getArgs()); } final MBeanAttributeInfo info = (MBeanAttributeInfo) getFeatureInfo(infos, parse.getCmd()); final Constructor c = getResolvedClass(info.getType()).getConstructor(new Class[] { String.class }); final Attribute a = new Attribute(parse.getCmd(), c.newInstance(new Object[] { parse.getArgs()[0] })); mbsc.setAttribute(instance.getObjectName(), a); return null; }
From source file:org.rhq.plugins.jslee.JainSleeServerDiscoveryComponent.java
private DiscoveredResourceDetails createResourceDetails(ResourceDiscoveryContext discoveryContext, Configuration pluginConfig, ProcessInfo processInfo, JBossInstallationInfo installInfo) throws Exception { String serverHomeDir = pluginConfig.getSimple(MobicentsJSleeProperties.JSLEE_HOME_DIR).getStringValue(); File absoluteConfigPath = resolvePathRelativeToHomeDir(pluginConfig, serverHomeDir); // Canonicalize the config path, so it's consistent no matter how it's entered. // This prevents two servers with different forms of the same config path, but // that are actually the same server, from ending up in inventory. // JON: fix for JBNADM-2634 - do not resolve symlinks (ips, 12/18/07) String key = FileUtils.getCanonicalPath(absoluteConfigPath.getPath()); String bindAddress = pluginConfig.getSimple(ApplicationServerPluginConfigurationProperties.BIND_ADDRESS) .getStringValue();// w ww .ja v a2 s . c o m String namingUrl = pluginConfig.getSimple(ApplicationServerPluginConfigurationProperties.NAMING_URL) .getStringValue(); // Only include the JNP port in the Resource name if its value is not "***CHANGE_ME***". String namingPort = getNamingPort(namingUrl); ObjectName sleemanagement = new ObjectName(SleeManagementMBean.OBJECT_NAME); String principal = pluginConfig.getSimple("principal").getStringValue(); String credentials = pluginConfig.getSimple("credentials").getStringValue(); MBeanServerUtils mbeanUtils = new MBeanServerUtils(namingUrl, principal, credentials); MBeanServerConnection connection = mbeanUtils.getConnection(); try { mbeanUtils.login(); String sleeName = (String) connection.getAttribute(sleemanagement, "SleeName"); String sleeVersion = (String) connection.getAttribute(sleemanagement, "SleeVersion"); String sleeVendor = (String) connection.getAttribute(sleemanagement, "SleeVendor"); String description = sleeName + " v" + sleeVersion + " by " + sleeVendor; // TODO : DO we care if its RHQ Server? // File deployDir = new File(absoluteConfigPath, "deploy"); // File rhqInstallerWar = new File(deployDir, "rhq-installer.war"); // File rhqInstallerWarUndeployed = new File(deployDir, "rhq-installer.war.rej"); // boolean isRhqServer = rhqInstallerWar.exists() || rhqInstallerWarUndeployed.exists(); // if (isRhqServer) { // baseName += " RHQ Server, "; // description += " hosting the RHQ Server"; // // We know this is an RHQ Server. Let's add an event source for its server log file, but disable it by // // default. // configureEventSourceForServerLogFile(pluginConfig); // } String name = formatServerName(sleeName + " " + sleeVersion, bindAddress, namingPort); return new DiscoveredResourceDetails(discoveryContext.getResourceType(), key, name, sleeVersion, description, pluginConfig, processInfo); } finally { try { mbeanUtils.logout(); } catch (LoginException e) { if (log.isDebugEnabled()) { log.debug("Failed to logout from secured JMX", e); } } } }