本文整理匯總了Java中javax.management.ObjectInstance.getObjectName方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectInstance.getObjectName方法的具體用法?Java ObjectInstance.getObjectName怎麽用?Java ObjectInstance.getObjectName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.management.ObjectInstance
的用法示例。
在下文中一共展示了ObjectInstance.getObjectName方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readCPUUsage
import javax.management.ObjectInstance; //導入方法依賴的package包/類
public static Map<String, Object> readCPUUsage(ObjectInstance oi, MBeanServerConnection mbsc) {
Map<String, Object> m = new LinkedHashMap<String, Object>();
ObjectName on = oi.getObjectName();
Object procCPU = getMBeanAttrValue(mbsc, on, "ProcessCpuLoad");
Object systemCPU = getMBeanAttrValue(mbsc, on, "SystemCpuLoad");
if (procCPU == null) {
procCPU = new Long(-1);
systemCPU = new Long(-1);
}
else {
DecimalFormat formatter = new DecimalFormat("00.0");
procCPU = Double.valueOf(formatter.format((Double) procCPU * 100));
systemCPU = Double.valueOf(formatter.format((Double) systemCPU * 100));
}
m.put("cpu_p", procCPU);
m.put("cpu_s", systemCPU);
return m;
}
示例2: init
import javax.management.ObjectInstance; //導入方法依賴的package包/類
public void init(String host, int port) throws Exception {
int iport = 0;
String shost = null;
mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
String onStr = "*:type=ThreadPool,*";
ObjectName objectName = new ObjectName(onStr);
Set<ObjectInstance> set = mBeanServer.queryMBeans(objectName, null);
Iterator<ObjectInstance> iterator = set.iterator();
while (iterator.hasNext()) {
ObjectInstance oi = iterator.next();
objName = oi.getObjectName();
String name = objName.getKeyProperty("name");
/* Name are:
* http-8080
* jk-10.33.144.3-8009
* jk-jfcpc%2F10.33.144.3-8009
*/
String [] elenames = name.split("-");
String sport = elenames[elenames.length-1];
iport = Integer.parseInt(sport);
String [] shosts = elenames[1].split("%2F");
shost = shosts[0];
if (port==0 && host==null)
break; /* Take the first one */
if (host==null && iport==port)
break; /* Only port done */
if (shost.compareTo(host) == 0)
break; /* Done port and host are the expected ones */
}
if (objName == null)
throw(new Exception("Can't find connector for " + host + ":" + port));
this.port = iport;
this.host = shost;
}
示例3: main
import javax.management.ObjectInstance; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
for (Class<?> c : new Class<?>[] {
Spume.class, Thing.class, XSpume.class, XThing.class
}) {
for (ObjectName n : new ObjectName[] {null, new ObjectName("a:b=c")}) {
System.out.println("Class " + c.getName() + " with name " + n +
"...");
ObjectName realName = new ObjectName("a:type=" + c.getName());
Constructor<?> constr = c.getConstructor(ObjectName.class);
Object mbean = constr.newInstance(realName);
ObjectInstance oi;
String what =
"Registering MBean of type " + c.getName() + " under name " +
"<" + n + ">: ";
try {
oi = mbs.registerMBean(mbean, n);
} catch (Exception e) {
e.printStackTrace();
fail(what + " got " + e);
continue;
}
ObjectName registeredName = oi.getObjectName();
if (!registeredName.equals(realName))
fail(what + " registered as " + registeredName);
if (!mbs.isRegistered(realName)) {
fail(what + " not registered as expected");
}
mbs.unregisterMBean(registeredName);
}
}
System.err.flush();
if (failures == 0)
System.out.println("TEST PASSED");
else
throw new Exception("TEST FAILED: " + failure);
}
示例4: init
import javax.management.ObjectInstance; //導入方法依賴的package包/類
public void init(String host, int port) throws Exception {
int iport = 0;
String shost = null;
mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
String onStr = "*:type=ThreadPool,*";
ObjectName objectName = new ObjectName(onStr);
Set<ObjectInstance> set = mBeanServer.queryMBeans(objectName, null);
Iterator<ObjectInstance> iterator = set.iterator();
while (iterator.hasNext()) {
ObjectInstance oi = iterator.next();
objName = oi.getObjectName();
String name = objName.getKeyProperty("name");
/*
* Name are: http-8080 jk-10.33.144.3-8009
* jk-jfcpc%2F10.33.144.3-8009
*/
String[] elenames = name.split("-");
String sport = elenames[elenames.length - 1];
iport = Integer.parseInt(sport);
String[] shosts = elenames[1].split("%2F");
shost = shosts[0];
if (port == 0 && host == null)
break; /* Take the first one */
if (host == null && iport == port)
break; /* Only port done */
if (shost.compareTo(host) == 0)
break; /* Done port and host are the expected ones */
}
if (objName == null)
throw (new Exception("Can't find connector for " + host + ":" + port));
this.port = iport;
this.host = shost;
}
示例5: doRegister
import javax.management.ObjectInstance; //導入方法依賴的package包/類
/**
* Actually register the MBean with the server. The behavior when encountering
* an existing MBean can be configured using the {@link #setRegistrationBehavior(int)}
* and {@link #setRegistrationBehaviorName(String)} methods.
* @param mbean the MBean instance
* @param objectName the suggested ObjectName for the MBean
* @throws JMException if the registration failed
*/
protected void doRegister(Object mbean, ObjectName objectName) throws JMException {
ObjectName actualObjectName;
synchronized (this.registeredBeans) {
ObjectInstance registeredBean = null;
try {
registeredBean = this.server.registerMBean(mbean, objectName);
}
catch (InstanceAlreadyExistsException ex) {
if (this.registrationPolicy == RegistrationPolicy.IGNORE_EXISTING) {
if (logger.isDebugEnabled()) {
logger.debug("Ignoring existing MBean at [" + objectName + "]");
}
}
else if (this.registrationPolicy == RegistrationPolicy.REPLACE_EXISTING) {
try {
if (logger.isDebugEnabled()) {
logger.debug("Replacing existing MBean at [" + objectName + "]");
}
this.server.unregisterMBean(objectName);
registeredBean = this.server.registerMBean(mbean, objectName);
}
catch (InstanceNotFoundException ex2) {
logger.error("Unable to replace existing MBean at [" + objectName + "]", ex2);
throw ex;
}
}
else {
throw ex;
}
}
// Track registration and notify listeners.
actualObjectName = (registeredBean != null ? registeredBean.getObjectName() : null);
if (actualObjectName == null) {
actualObjectName = objectName;
}
this.registeredBeans.add(actualObjectName);
}
onRegister(actualObjectName, mbean);
}
示例6: registerEngine
import javax.management.ObjectInstance; //導入方法依賴的package包/類
private void registerEngine()
throws Exception
{
ObjectName engineName = new ObjectName
(domain + ":type=Engine");
if ( ! mBeanServer.isRegistered(engineName)) return;
String defaultHost =
(String) mBeanServer.getAttribute(engineName, "defaultHost");
ObjectName hostName = new ObjectName
(domain + ":type=Host," + "host=" + defaultHost);
if (!mBeanServer.isRegistered(hostName)) {
// Get the hosts' list
String onStr = domain + ":type=Host,*";
ObjectName objectName = new ObjectName(onStr);
Set set = mBeanServer.queryMBeans(objectName, null);
Iterator iterator = set.iterator();
String[] aliases;
boolean isRegisteredWithAlias = false;
while (iterator.hasNext()) {
if (isRegisteredWithAlias) break;
ObjectInstance oi = (ObjectInstance) iterator.next();
hostName = oi.getObjectName();
aliases = (String[])
mBeanServer.invoke(hostName, "findAliases", null, null);
for (int i=0; i < aliases.length; i++){
if (aliases[i].equalsIgnoreCase(defaultHost)){
isRegisteredWithAlias = true;
break;
}
}
}
if (!isRegisteredWithAlias)
log.warn(sm.getString("mapperListener.unknownDefaultHost", defaultHost));
}
// This should probably be called later
if( defaultHost != null ) {
mapper.setDefaultHostName(defaultHost);
}
}
示例7: readGCUsage
import javax.management.ObjectInstance; //導入方法依賴的package包/類
public static Map<String, Object> readGCUsage(ObjectInstance oi, MBeanServerConnection mbsc) {
Map<String, Object> m = new LinkedHashMap<String, Object>();
ObjectName on = oi.getObjectName();
String name = on.getKeyProperty("name");
String gcName = null;
if (minorGC.contains(name)) {
gcName = "mgc";
}
else if (fullGC.contains(name)) {
gcName = "fgc";
}
m.put(gcName + "_count", getMBeanAttrValue(mbsc, on, "CollectionCount"));
m.put(gcName + "_time", getMBeanAttrValue(mbsc, on, "CollectionTime"));
return m;
}
示例8: doCaptureMonitorData
import javax.management.ObjectInstance; //導入方法依賴的package包/類
/**
* doCaptureMonitorData
*
* @param mbsc
* @param timeFlag
* @return
* @throws IOException
*/
protected boolean doCaptureMonitorData(MBeanServerConnection mbsc, long timeFlag, MonitorDataFrame mdf)
throws IOException {
boolean needProcessCheck = true;
// get all monitors' MBean
Set<ObjectInstance> monitorMBeans = scanMonitorMBeans(mbsc);
// the monitorMBeans should not be null if connection is all right, still check that in case abnormal issues
if (doNoMBeanAction(monitorMBeans, "Monitor")) {
/**
* if the connection is not available, then the IOException will trigger process checking so if the
* connection is OK but there is no any MBean, we notify that but still return false that means we will not
* run process checking
*/
return false;
}
Iterator<ObjectInstance> iterator = monitorMBeans.iterator();
while (iterator.hasNext()) {
ObjectInstance oi = iterator.next();
try {
// catch monitor data
ObjectName monitorON = oi.getObjectName();
Object oData = mbsc.getAttribute(monitorON, "Data");
if (oData != null) {
needProcessCheck = false;
// add data to MonitorDataFrame
mdf.addData(monitorON.getKeyProperty("id"), oData.toString());
}
}
catch (Exception e) {
log.err(this, "MonitorMBean[" + oi.getObjectName().toString() + "] catch data FAILs", e);
}
}
// add appgroup
mdf.addExt("appgroup", this.getAppGroup());
return needProcessCheck;
}
示例9: readHeapPoolUsage
import javax.management.ObjectInstance; //導入方法依賴的package包/類
public static Map<String, Object> readHeapPoolUsage(ObjectInstance oi, MBeanServerConnection mbsc) {
Map<String, Object> m = new LinkedHashMap<String, Object>();
ObjectName on = oi.getObjectName();
String jvmMemPoolName = getHeapPoolName(on.getKeyProperty("name"));
m.put(jvmMemPoolName + "_use", getMBeanAttrValue(mbsc, on, "Usage", "used"));
m.put(jvmMemPoolName + "_commit", getMBeanAttrValue(mbsc, on, "Usage", "committed"));
m.put(jvmMemPoolName + "_max", getMBeanAttrValue(mbsc, on, "Usage", "max"));
m.put(jvmMemPoolName + "_init", getMBeanAttrValue(mbsc, on, "Usage", "init"));
return m;
}
示例10: readClassLoadUsage
import javax.management.ObjectInstance; //導入方法依賴的package包/類
public static Map<String, Object> readClassLoadUsage(ObjectInstance oi, MBeanServerConnection mbsc) {
Map<String, Object> m = new LinkedHashMap<String, Object>();
ObjectName on = oi.getObjectName();
m.put("class_total", getMBeanAttrValue(mbsc, on, "TotalLoadedClassCount"));
m.put("class_load", getMBeanAttrValue(mbsc, on, "LoadedClassCount"));
m.put("class_unload", getMBeanAttrValue(mbsc, on, "UnloadedClassCount"));
return m;
}
示例11: readHeapUsage
import javax.management.ObjectInstance; //導入方法依賴的package包/類
public static Map<String, Object> readHeapUsage(ObjectInstance oi, MBeanServerConnection mbsc) {
Map<String, Object> m = new LinkedHashMap<String, Object>();
ObjectName on = oi.getObjectName();
m.put("heap_use", getMBeanAttrValue(mbsc, on, "HeapMemoryUsage", "used"));
m.put("heap_commit", getMBeanAttrValue(mbsc, on, "HeapMemoryUsage", "committed"));
m.put("heap_max", getMBeanAttrValue(mbsc, on, "HeapMemoryUsage", "max"));
m.put("heap_init", getMBeanAttrValue(mbsc, on, "HeapMemoryUsage", "init"));
return m;
}
示例12: readNonHeapUsage
import javax.management.ObjectInstance; //導入方法依賴的package包/類
public static Map<String, Object> readNonHeapUsage(ObjectInstance oi, MBeanServerConnection mbsc) {
Map<String, Object> m = new LinkedHashMap<String, Object>();
ObjectName on = oi.getObjectName();
m.put("noheap_use", getMBeanAttrValue(mbsc, on, "NonHeapMemoryUsage", "used"));
m.put("noheap_commit", getMBeanAttrValue(mbsc, on, "NonHeapMemoryUsage", "committed"));
m.put("noheap_max", getMBeanAttrValue(mbsc, on, "NonHeapMemoryUsage", "max"));
m.put("noheap_init", getMBeanAttrValue(mbsc, on, "NonHeapMemoryUsage", "init"));
return m;
}
示例13: readThreadUsage
import javax.management.ObjectInstance; //導入方法依賴的package包/類
public static Map<String, Object> readThreadUsage(ObjectInstance oi, MBeanServerConnection mbsc) {
Map<String, Object> m = new LinkedHashMap<String, Object>();
ObjectName on = oi.getObjectName();
m.put("thread_live", getMBeanAttrValue(mbsc, on, "ThreadCount"));
m.put("thread_daemon", getMBeanAttrValue(mbsc, on, "DaemonThreadCount"));
m.put("thread_peak", getMBeanAttrValue(mbsc, on, "PeakThreadCount"));
m.put("thread_started", getMBeanAttrValue(mbsc, on, "TotalStartedThreadCount"));
return m;
}