本文整理了Java中javax.management.ObjectName.<init>()
方法的一些代码示例,展示了ObjectName.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ObjectName.<init>()
方法的具体详情如下:
包路径:javax.management.ObjectName
类名称:ObjectName
方法名:<init>
暂无
代码示例来源:origin: alibaba/druid
public static void unregister(String name) {
try {
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
mbeanServer.unregisterMBean(new ObjectName(name));
} catch (JMException e) {
throw new IllegalArgumentException(name, e);
}
}
代码示例来源:origin: alibaba/druid
public static ObjectName register(String name, Object mbean) {
try {
ObjectName objectName = new ObjectName(name);
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
try {
mbeanServer.registerMBean(mbean, objectName);
} catch (InstanceAlreadyExistsException ex) {
mbeanServer.unregisterMBean(objectName);
mbeanServer.registerMBean(mbean, objectName);
}
return objectName;
} catch (JMException e) {
throw new IllegalArgumentException(name, e);
}
}
代码示例来源:origin: alibaba/druid
public static void registerMBean() {
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
try {
ObjectName objectName = new ObjectName(MBEAN_NAME);
if (!mbeanServer.isRegistered(objectName)) {
mbeanServer.registerMBean(instance, objectName);
}
} catch (JMException ex) {
LOG.error("register mbean error", ex);
}
}
代码示例来源:origin: alibaba/nacos
public void init() {
try {
ObjectName oName = new ObjectName(this.name + ":type=" + TaskManager.class.getSimpleName());
ManagementFactory.getPlatformMBeanServer().registerMBean(this, oName);
} catch (Exception e) {
log.error("registerMBean_fail", "注册mbean出错", e);
}
}
}
代码示例来源:origin: jmxtrans/jmxtrans
public static void main(String[] args) throws MalformedObjectNameException, NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanRegistrationException, InstanceNotFoundException {
Counter mock = new Counter("myCounter");
ObjectName objectName = new ObjectName(MOCK_MBEAN_NAME);
MBeanServer mBeanServer = getPlatformMBeanServer();
// platform MBean server is global, mBean registration might persist between tests
if (mBeanServer.isRegistered(objectName)) {
mBeanServer.unregisterMBean(objectName);
}
mBeanServer.registerMBean(mock, objectName);
while (true) {
System.out.println("hello, it is: " + new Date());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
currentThread().interrupt();
break;
}
}
}
代码示例来源:origin: apache/geode
public static boolean isAttributeAvailable(String attributeName, String objectName) {
try {
ObjectName objName = new ObjectName(objectName);
mbeanServer.getAttribute(objName, attributeName);
} catch (MalformedObjectNameException | ReflectionException | MBeanException
| InstanceNotFoundException | AttributeNotFoundException | NullPointerException e) {
return false;
}
return true;
}
代码示例来源:origin: apache/kafka
public static synchronized void unregisterAppInfo(String prefix, String id, Metrics metrics) {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
try {
ObjectName name = new ObjectName(prefix + ":type=app-info,id=" + Sanitizer.jmxSanitize(id));
if (server.isRegistered(name))
server.unregisterMBean(name);
unregisterMetrics(metrics);
} catch (JMException e) {
log.warn("Error unregistering AppInfo mbean", e);
}
}
代码示例来源:origin: stackoverflow.com
List<String> getEndPoints() throws MalformedObjectNameException,
NullPointerException, UnknownHostException, AttributeNotFoundException,
InstanceNotFoundException, MBeanException, ReflectionException {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objs = mbs.queryNames(new ObjectName("*:type=Connector,*"),
Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
String hostname = InetAddress.getLocalHost().getHostName();
InetAddress[] addresses = InetAddress.getAllByName(hostname);
ArrayList<String> endPoints = new ArrayList<String>();
for (Iterator<ObjectName> i = objs.iterator(); i.hasNext();) {
ObjectName obj = i.next();
String scheme = mbs.getAttribute(obj, "scheme").toString();
String port = obj.getKeyProperty("port");
for (InetAddress addr : addresses) {
String host = addr.getHostAddress();
String ep = scheme + "://" + host + ":" + port;
endPoints.add(ep);
}
}
return endPoints;
}
代码示例来源:origin: mpusher/mpush
public HotSpotDiagnosticMXBean run() throws Exception {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> s = server.queryNames(new ObjectName(HOT_SPOT_BEAN_NAME), null);
Iterator<ObjectName> itr = s.iterator();
if (itr.hasNext()) {
ObjectName name = itr.next();
HotSpotDiagnosticMXBean bean = ManagementFactory.newPlatformMXBeanProxy(server,
name.toString(), HotSpotDiagnosticMXBean.class);
return bean;
} else {
return null;
}
}
});
代码示例来源:origin: wildfly/wildfly
/**
* Unregisters object_name and everything under it
* @param object_name
*/
public static void unregister(MBeanServer server, String object_name) throws Exception {
Set<ObjectName> mbeans = server.queryNames(new ObjectName(object_name), null);
if(mbeans != null)
for (ObjectName name: mbeans)
server.unregisterMBean(name);
}
代码示例来源:origin: aws/aws-sdk-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.
*/
public static boolean isRegistered(String objectName) {
MBeanServer server = getMBeanServer();
try {
return server.isRegistered(new ObjectName(objectName));
} catch (MalformedObjectNameException e) {
throw new IllegalArgumentException(e);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testRegisterIgnoreExisting() throws Exception {
ObjectName objectName = ObjectNameManager.getInstance(OBJECT_NAME);
Person preRegistered = new Person();
preRegistered.setName("Rob Harrop");
server.registerMBean(preRegistered, objectName);
Person springRegistered = new Person();
springRegistered.setName("Sally Greenwood");
String objectName2 = "spring:test=equalBean";
Map<String, Object> beans = new HashMap<>();
beans.put(objectName.toString(), springRegistered);
beans.put(objectName2, springRegistered);
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(server);
exporter.setBeans(beans);
exporter.setRegistrationPolicy(RegistrationPolicy.IGNORE_EXISTING);
start(exporter);
ObjectInstance instance = server.getObjectInstance(objectName);
assertNotNull(instance);
ObjectInstance instance2 = server.getObjectInstance(new ObjectName(objectName2));
assertNotNull(instance2);
// should still be the first bean with name Rob Harrop
assertEquals("Rob Harrop", server.getAttribute(objectName, "Name"));
}
代码示例来源:origin: apache/geode
private void registerFileUploaderMBean() {
try {
ObjectName mbeanON = new ObjectName(ManagementConstants.OBJECTNAME__FILEUPLOADER_MBEAN);
MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> names = platformMBeanServer.queryNames(mbeanON, null);
if (names.isEmpty()) {
platformMBeanServer.registerMBean(new FileUploader(getRemoteStreamExporter()), mbeanON);
logger.info("Registered FileUploaderMBean on " + mbeanON);
}
} catch (InstanceAlreadyExistsException | MBeanRegistrationException
| NotCompliantMBeanException | MalformedObjectNameException e) {
throw new GemFireConfigException("Error while configuring FileUploader MBean", e);
}
}
代码示例来源:origin: Netflix/servo
private static void fetchExecutorMetrics(long now, MBeanServer mbs, List<Metric> metrics)
throws JMException {
final ObjectName executorName = new ObjectName("Catalina:type=Executor,*");
final Set<ObjectName> names = mbs.queryNames(executorName, null);
if (names == null) {
return;
}
for (ObjectName name : names) {
AttributeList list = mbs.getAttributes(name, EXECUTOR_ATTRS);
for (Attribute a : list.asList()) {
addMetric(metrics, a.getName().equals("completedTaskCount")
? toCounter(now, name, a)
: toGauge(now, name, a));
}
}
}
代码示例来源:origin: apache/kafka
metrics.addReporter(reporter);
assertFalse(server.isRegistered(new ObjectName(":type=grp1")));
sensor.add(metrics.metricName("pack.bean2.total", "grp2"), new Total());
assertTrue(server.isRegistered(new ObjectName(":type=grp1")));
assertEquals(Double.NaN, server.getAttribute(new ObjectName(":type=grp1"), "pack.bean1.avg"));
assertTrue(server.isRegistered(new ObjectName(":type=grp2")));
assertEquals(0.0, server.getAttribute(new ObjectName(":type=grp2"), "pack.bean2.total"));
assertFalse(reporter.containsMbean(mBeanName));
assertFalse(server.isRegistered(new ObjectName(":type=grp1")));
assertTrue(server.isRegistered(new ObjectName(":type=grp2")));
assertEquals(0.0, server.getAttribute(new ObjectName(":type=grp2"), "pack.bean2.total"));
assertFalse(reporter.containsMbean(mBeanName));
assertFalse(server.isRegistered(new ObjectName(":type=grp1")));
assertFalse(server.isRegistered(new ObjectName(":type=grp2")));
} finally {
metrics.close();
代码示例来源:origin: hawtio/hawtio
void init() throws Exception {
if (objectName == null) {
objectName = new ObjectName("hawtio:type=OSGiTools");
}
if (mBeanServer == null) {
mBeanServer = ManagementFactory.getPlatformMBeanServer();
}
mBeanServer.registerMBean(this, objectName);
}
代码示例来源:origin: wildfly/wildfly
public static void unregisterChannel(MBeanServer server, String name) throws Exception {
if (server != null)
server.unregisterMBean(new ObjectName(name));
}
代码示例来源:origin: Red5/red5-server
protected void registerJMX() {
// register with jmx
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
try {
oName = new ObjectName("org.red5.server:name=contextLoader,type=ContextLoader");
// check for existing registration before registering
if (!mbs.isRegistered(oName)) {
mbs.registerMBean(new StandardMBean(this, ContextLoaderMXBean.class, true), oName);
} else {
log.debug("ContextLoader is already registered in JMX");
}
} catch (Exception e) {
log.warn("Error on jmx registration", e);
}
}
代码示例来源:origin: btraceio/btrace
public static void registerMBean(Class clazz) {
if (isMBean(clazz)) {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
BTraceMBean bean = new BTraceMBean(clazz);
try {
ObjectName on = new ObjectName("btrace:name=" + bean.beanName);
if (server.isRegistered(on)) {
server.unregisterMBean(on);
}
server.registerMBean(bean, on);
} catch (RuntimeException re) {
throw re;
} catch (Exception exp) {
throw new RuntimeException(exp);
}
}
}
代码示例来源:origin: alibaba/jstorm
public static Long getPhysicMemorySize() {
Object object;
try {
object = ManagementFactory.getPlatformMBeanServer().getAttribute(
new ObjectName("java.lang", "type", "OperatingSystem"), "TotalPhysicalMemorySize");
} catch (Exception e) {
LOG.warn("Failed to get system physical memory size,", e);
return null;
}
return (Long) object;
}
内容来源于网络,如有侵权,请联系作者删除!