Java Code Examples for javax.management.MalformedObjectNameException#printStackTrace()

The following examples show how to use javax.management.MalformedObjectNameException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IPPortUtil.java    From Tbed with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @return
 * @throws MalformedObjectNameException
 * 获取当前机器的端口号
 */
public static String getLocalPort()  {//throws MalformedObjectNameException
    MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
    Set<ObjectName> objectNames = null;
    try {
        objectNames = beanServer.queryNames(new ObjectName("*:type=Connector,*"),
                Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
    } catch (MalformedObjectNameException e) {
        e.printStackTrace();
    }
    String port = objectNames.iterator().next().getKeyProperty("port");
    return port;
}
 
Example 2
Source File: PerfCounters.java    From java-svc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static ObjectName createObjectName(String name) {
	try {
		return new ObjectName(name);
	} catch (MalformedObjectNameException e) {
		// This will not happen – known to be well-formed.
		e.printStackTrace();
	}
	return null;
}
 
Example 3
Source File: VMLogger.java    From openjdk-systemtest with Apache License 2.0 5 votes vote down vote up
private void initialiseServerNames() {
    try {
    	srvRuntimeName  = new ObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME);
        srvOSName       = new ObjectName(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);
        srvClassName    = new ObjectName(ManagementFactory.CLASS_LOADING_MXBEAN_NAME);

        if (!(compiler.equals(""))) {	
            srvCompName = new ObjectName(ManagementFactory.COMPILATION_MXBEAN_NAME);
        }
                    
        srvThrdName     = new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME);
        srvMemName      = new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME);
        srvLogName      = new ObjectName("java.util.logging:type=Logging");
        srvMemMgrNames  = mbs.queryNames(new ObjectName(ManagementFactory.MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE + ",*"), null);
        srvMemPoolNames = mbs.queryNames(new ObjectName(ManagementFactory.MEMORY_POOL_MXBEAN_DOMAIN_TYPE + ",*"), null);
        srvGCNames      = mbs.queryNames(new ObjectName(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",*"), null);

    } catch ( MalformedObjectNameException me) {
        Message.logOut("Got a MalformedObjectNameException");
        me.printStackTrace();
        Assert.fail("Got a MalformedObjectNameException");
    } catch ( IOException ie ) {
        Message.logOut("Caught an IOException:");
        ie.printStackTrace();
        Assert.fail("Caught an IOException: \n" + ie.getMessage());
    }	
}
 
Example 4
Source File: BufferMonitorView.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public BufferMonitorViewSupport(JmxModel jmx, String title, String bufferName) {
    GlobalPreferences preferences = GlobalPreferences.sharedInstance();
    int chartCache = preferences.getMonitoredDataCache() * 60 /
                 preferences.getMonitoredDataPoll();
    conn = jmx.getMBeanServerConnection();
    try {
        bufferObjectName = new ObjectName(bufferName);
    } catch (MalformedObjectNameException ex) {
        ex.printStackTrace();
    }
    TITLE = title;
    initModels(chartCache);
    initComponents();
}
 
Example 5
Source File: MBeanRegistration.java    From development with Apache License 2.0 5 votes vote down vote up
Set<ObjectName> queryRegisteredMBeans(String registrationName) {
    try {
        ObjectName query = new ObjectName(registrationName + ":*");
        return mbeanServer.queryNames(query, null);
    } catch (MalformedObjectNameException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 6
Source File: MemoryProfiler.java    From openjdk-systemtest with Apache License 2.0 4 votes vote down vote up
private void getStatsViaProxy() {
	RuntimeMXBean runtimeBean = null;
	OperatingSystemMXBean osBean = null;
	LoggingMXBean logBean = null;
	MemoryMXBean memoryBean = null;
	List<MemoryPoolMXBean> memPoolBeans = new ArrayList<MemoryPoolMXBean>();
	List<MemoryManagerMXBean> memMgrBeans = new ArrayList<MemoryManagerMXBean>();
	List<GarbageCollectorMXBean> gcBeans = new ArrayList<GarbageCollectorMXBean>();

	// Get the proxies for the runtime, os, log, memory MXBeans
	try {
		runtimeBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, ManagementFactory.RUNTIME_MXBEAN_NAME,
				RuntimeMXBean.class);
		osBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME,
				OperatingSystemMXBean.class);
		logBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, LogManager.LOGGING_MXBEAN_NAME,
				LoggingMXBean.class);
		memoryBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, ManagementFactory.MEMORY_MXBEAN_NAME,
				MemoryMXBean.class);

		Set<?> memPoolNames  = this.mbs.queryNames(new ObjectName(ManagementFactory.MEMORY_POOL_MXBEAN_DOMAIN_TYPE + ",*"), null);

		// Get a MXBean Proxy for each of the names returned, use the proxy to access the MXBeanS
		for (Object memPoolName : memPoolNames){
			ObjectName memPool = (ObjectName) memPoolName;
			MemoryPoolMXBean memPoolBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, memPool.toString(),
					MemoryPoolMXBean.class);
			memPoolBeans.add(memPoolBean);
		}

		Set<?> memMgrNames  = this.mbs.queryNames(new ObjectName(ManagementFactory.MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE + ",*"), null);

		// Get a MXBean Proxy for each of the names returned, use the proxy to access the MXBeanS
		for (Object memMgrName : memMgrNames){
			ObjectName memMgr = (ObjectName) memMgrName;
			MemoryManagerMXBean memMgrBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, memMgr.toString(),
					MemoryManagerMXBean.class);
			memMgrBeans.add(memMgrBean);
		}

		Set<?> gcNames  = this.mbs.queryNames(new ObjectName(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",*"), null);

		// Get a MXBean Proxy for each of the names returned, use the proxy to access the MXBeanS
		for (Object gcName : gcNames){
			ObjectName gc = (ObjectName) gcName;
			GarbageCollectorMXBean gcBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, gc.toString(),
					GarbageCollectorMXBean.class);
			gcBeans.add(gcBean);
		}
	} catch (IOException ioe) {
		ioe.printStackTrace();
		Assert.fail("A communication problem occurred when accessing the MBeanServerConnection");
	} catch (MalformedObjectNameException mone) {
		mone.printStackTrace();
		Assert.fail("Problem with creating the ObjectName for a MXBean");
	}

	try {
		Message.logOut("Starting to write data");
		this.envData.writeData (runtimeBean, osBean, logBean, false);

		int secondsCnt = 0;
		int writesCnt = 0;
		while (writesCnt < 30) {
			// Write out the methodData every 10 seconds
			if (secondsCnt == 10) {
				System.out.print(".");
				this.memoryData.writeData(memoryBean, memMgrBeans, memPoolBeans, gcBeans, true);
				secondsCnt = 0;
				writesCnt++;
			}
			this.recordMemoryStats(runtimeBean, memoryBean, writesCnt);
			Thread.sleep(1000);
			secondsCnt++;
		}
	} catch (InterruptedException ie) {
		ie.printStackTrace();
		Assert.fail("The sleeping profiler was interrupted");
	} catch (UndeclaredThrowableException ue) {
		// If the exception was caused by a Connect or Unmarshal Exception, assume the 
		// monitored JVM has finished.
		Throwable cause = ue.getCause();
		Class<ConnectException>     connectExcept = ConnectException.class;
		Class<UnmarshalException>     unmarshalExcept = UnmarshalException.class;

		if (connectExcept.isInstance(cause) || unmarshalExcept.isInstance(cause)) {
			this.closeCSVFile();
			Message.logOut("Exiting as JVM we are connected to has finished");
		}
		else { 
			Message.logOut("Rethrowing UndeclaredThrowableException");
		}
		Assert.fail();
	} finally {
		this.closeCSVFile();
	}
}