List of usage examples for javax.management ObjectName ObjectName
public ObjectName(String name) throws MalformedObjectNameException
From source file:net.camelpe.examples.jboss7.loanbroker.queue.JBoss7CamelContextConfiguration.java
@PostConstruct public void createQueues() throws Exception { this.log.info("Creating queues ..."); final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); this.log.info("Found PlatformMBeanServer [{}]", mbeanServer); this.log.info("JMX Domains: {}", Arrays.toString(mbeanServer.getDomains())); for (final JmsResources.QueueDefinition queueDef : JmsResources.loanBrokerQueues()) { mbeanServer.invoke(new ObjectName("org.hornetq:module=JMS,type=Server"), "createQueue", new Object[] { queueDef.getName(), queueDef.getBinding() }, new String[] { "java.lang.String", "java.lang.String" }); this.log.info("Created queue [{}]", queueDef); }/*from w w w . j av a 2 s . co m*/ }
From source file:be.fgov.kszbcss.rhq.websphere.mbean.MBeanClientFactory.java
public MBeanClient getMBeanClient(String objectNamePattern) { try {/*from ww w. j ava2 s. c om*/ return getMBeanClient(new ObjectName(objectNamePattern)); } catch (MalformedObjectNameException ex) { throw new IllegalArgumentException(ex); } }
From source file:gr.cslab.Metric_test.java
static public void addMetric(String name, String attribute, String label, String units) { Metric m = null;/*from w w w.j a v a 2 s .c o m*/ try { ObjectName OName = new ObjectName(name); m = new Metric(OName, attribute, label, units); } catch (MalformedObjectNameException ex) { System.err.println("ERROR: Malformed MBean name: " + name); System.err.println(ex.getMessage()); } if (m != null) metrics.add(m); }
From source file:com.rackspacecloud.blueflood.tracker.Tracker.java
public synchronized void register() { if (isRegistered) return;// ww w . j ava2s . co m try { ObjectName objectName = new ObjectName(trackerName); // register TrackerMBean only if not already registered MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); if (!mBeanServer.isRegistered(objectName)) { ManagementFactory.getPlatformMBeanServer().registerMBean(instance, objectName); } isRegistered = true; log.info("MBean registered as " + trackerName); } catch (Exception exc) { log.error("Unable to register MBean " + trackerName, exc); } }
From source file:com.amazonaws.client.metrics.jmx.MBeans.java
/** * Returns true if an MBean identified by the specified object name is * already registered with the first MBean server, or the platform MBean * server if there is no explicitly registered MBean server; false * otherwise./*from w w w . ja va 2s.c o m*/ */ public static boolean isRegistered(String objectName) { MBeanServer server = getMBeanServer(); try { return server.isRegistered(new ObjectName(objectName)); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException(e); } }
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 {/* w w w.j a va2s . c om*/ // 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:com.fusesource.forge.jmstest.probe.jmx.JMXProbe.java
public void setObjectNameString(String objectName) { try {// w w w . ja va 2 s .c o m this.objectName = new ObjectName(objectName); } catch (Exception e) { log().error("Error seting ObjectName for Probe: " + objectName); setActive(false); lastException = Long.MAX_VALUE; } }
From source file:net.gcolin.simplerepo.test.AbstractRepoTest.java
protected Object executeOperationJmx(String name, String operation, Object[] arguments, String[] signature) throws Exception { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); ObjectName oname = server.queryNames(new ObjectName(name), null).iterator().next(); return server.invoke(oname, operation, arguments, signature); }
From source file:com.espertech.esper.example.servershellclient.ServerShellClientMain.java
public ServerShellClientMain() throws Exception { log.info("Loading properties"); Properties properties = new Properties(); InputStream propertiesIS = ServerShellClientMain.class.getClassLoader() .getResourceAsStream(ServerShellConstants.CONFIG_FILENAME); if (propertiesIS == null) { throw new RuntimeException( "Properties file '" + ServerShellConstants.CONFIG_FILENAME + "' not found in classpath"); }//from w ww .ja v a 2 s .c o m properties.load(propertiesIS); // Attached via JMX to running server log.info("Attach to server via JMX"); JMXServiceURL url = new JMXServiceURL(properties.getProperty(ServerShellConstants.MGMT_SERVICE_URL)); JMXConnector jmxc = JMXConnectorFactory.connect(url, null); MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); ObjectName mBeanName = new ObjectName(ServerShellConstants.MGMT_MBEAN_NAME); EPServiceProviderJMXMBean proxy = (EPServiceProviderJMXMBean) MBeanServerInvocationHandler .newProxyInstance(mbsc, mBeanName, EPServiceProviderJMXMBean.class, true); // Connect to JMS log.info("Connecting to JMS server"); String factory = properties.getProperty(ServerShellConstants.JMS_CONTEXT_FACTORY); String jmsurl = properties.getProperty(ServerShellConstants.JMS_PROVIDER_URL); String connFactoryName = properties.getProperty(ServerShellConstants.JMS_CONNECTION_FACTORY_NAME); String user = properties.getProperty(ServerShellConstants.JMS_USERNAME); String password = properties.getProperty(ServerShellConstants.JMS_PASSWORD); String destination = properties.getProperty(ServerShellConstants.JMS_INCOMING_DESTINATION); boolean isTopic = Boolean.parseBoolean(properties.getProperty(ServerShellConstants.JMS_IS_TOPIC)); JMSContext jmsCtx = JMSContextFactory.createContext(factory, jmsurl, connFactoryName, user, password, destination, isTopic); // Create statement via JMX log.info("Creating a statement via Java Management Extensions (JMX) MBean Proxy"); proxy.createEPL("select * from SampleEvent where duration > 9.9", "filterStatement", new ClientSideUpdateListener()); // Get producer jmsCtx.getConnection().start(); MessageProducer producer = jmsCtx.getSession().createProducer(jmsCtx.getDestination()); Random random = new Random(); String[] ipAddresses = { "127.0.1.0", "127.0.2.0", "127.0.3.0", "127.0.4.0" }; NumberFormat format = NumberFormat.getInstance(); // Send messages for (int i = 0; i < 1000; i++) { String ipAddress = ipAddresses[random.nextInt(ipAddresses.length)]; double duration = 10 * random.nextDouble(); String durationStr = format.format(duration); String payload = ipAddress + "," + durationStr; BytesMessage bytesMessage = jmsCtx.getSession().createBytesMessage(); bytesMessage.writeBytes(payload.getBytes()); bytesMessage.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT); producer.send(bytesMessage); if (i % 100 == 0) { log.info("Sent " + i + " messages"); } } // Create statement via JMX log.info("Destroing statement via Java Management Extensions (JMX) MBean Proxy"); proxy.destroy("filterStatement"); log.info("Shutting down JMS client connection"); jmsCtx.destroy(); log.info("Exiting"); System.exit(-1); }
From source file:org.ngrinder.monitor.service.MonitorClientSerivce.java
/** * Initialize the mbeanClient connection. * /*from w w w. jav a2 s . c o m*/ * @param ip * IP address of the monitor target * @param port * port of the monitor target * @param reportPath * report path * @param cache * cache for {@link SystemInfo} data. */ public void init(String ip, int port, File reportPath, Cache cache) { LOGGER.debug("Init MonitorClientSerivce for {}:{}", ip, port); this.ip = ip; this.cache = cache; try { mbeanClient = new MBeanClient(ip, port); String objNameStr = MonitorConstants.DEFAULT_MONITOR_DOMAIN + ":" + MonitorConstants.SYSTEM; ObjectName systemName = new ObjectName(objNameStr); sysInfoMBeanObj = new MonitorCollectionInfoDomain(systemName, "SystemInfo", SystemInfo.class); bw = new BufferedWriter( new FileWriter(new File(reportPath, Config.MONITOR_FILE_PREFIX + ip + ".data"), false)); // write header info bw.write(SystemInfo.HEADER); bw.newLine(); bw.flush(); } catch (Exception e) { LOGGER.error("Init Error while {} and {} {}", new Object[] { ip, port, reportPath }, e); } }