public static void main(String[] args) throws Exception {
final Child child = new Child();
test(child,"Child[MBean]",false);
final ChildMix childx = new ChildMix();
test(childx,"ChildMix[MXBean]",true);
final ChildMixMix childmx = new ChildMixMix();
test(childmx,"ChildMixMix[MXBean]",false);
final StandardMBean schild = new StandardMBean(child,ChildMBean.class);
test(schild,"Child[StandarMBean(Child)]",false);
final StandardMBean schildx =
new StandardMBean(childx,ChildMXBean.class,true);
test(schildx,"ChildMix[StandarMXBean(ChildMix)]",true);
final StandardMBean schildmx =
new StandardMBean(childmx,ChildMixMXBean.class,true);
test(schildmx,"ChildMixMix[StandarMXBean(ChildMixMix)]",true);
}
java类javax.management.StandardMBean的实例源码
TooManyFooTest.java 文件源码
项目:openjdk-jdk7u-jdk
阅读 25
收藏 0
点赞 0
评论 0
Scope.java 文件源码
项目:red5-server-common
阅读 33
收藏 0
点赞 0
评论 0
protected void registerJMX() {
// register with jmx
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
try {
String cName = this.getClass().getName();
if (cName.indexOf('.') != -1) {
cName = cName.substring(cName.lastIndexOf('.')).replaceFirst("[\\.]", "");
}
oName = new ObjectName(String.format("org.red5.server:type=%s,name=%s", cName, name));
// don't reregister
if (!mbs.isRegistered(oName)) {
mbs.registerMBean(new StandardMBean(this, ScopeMXBean.class, true), oName);
}
} catch (Exception e) {
log.warn("Error on jmx registration", e);
}
}
RTMPMinaConnection.java 文件源码
项目:red5-server-common
阅读 14
收藏 0
点赞 0
评论 0
protected void registerJMX() {
// register with jmx
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
try {
String cName = this.getClass().getName();
if (cName.indexOf('.') != -1) {
cName = cName.substring(cName.lastIndexOf('.')).replaceFirst("[\\.]", "");
}
String hostStr = host;
int port = 1935;
if (host != null && host.indexOf(":") > -1) {
String[] arr = host.split(":");
hostStr = arr[0];
port = Integer.parseInt(arr[1]);
}
// Create a new mbean for this instance
oName = new ObjectName(String.format("org.red5.server:type=%s,connectionType=%s,host=%s,port=%d,clientId=%s", cName, type, hostStr, port, client.getId()));
if (!mbs.isRegistered(oName)) {
mbs.registerMBean(new StandardMBean(this, RTMPMinaConnectionMXBean.class, true), oName);
} else {
log.debug("Connection is already registered in JMX");
}
} catch (Exception e) {
log.warn("Error on jmx registration", e);
}
}
TooManyFooTest.java 文件源码
项目:openjdk-icedtea7
阅读 20
收藏 0
点赞 0
评论 0
public static void main(String[] args) throws Exception {
final Child child = new Child();
test(child,"Child[MBean]",false);
final ChildMix childx = new ChildMix();
test(childx,"ChildMix[MXBean]",true);
final ChildMixMix childmx = new ChildMixMix();
test(childmx,"ChildMixMix[MXBean]",false);
final StandardMBean schild = new StandardMBean(child,ChildMBean.class);
test(schild,"Child[StandarMBean(Child)]",false);
final StandardMBean schildx =
new StandardMBean(childx,ChildMXBean.class,true);
test(schildx,"ChildMix[StandarMXBean(ChildMix)]",true);
final StandardMBean schildmx =
new StandardMBean(childmx,ChildMixMXBean.class,true);
test(schildmx,"ChildMixMix[StandarMXBean(ChildMixMix)]",true);
}
MBeanUtilsTest.java 文件源码
项目:basis
阅读 16
收藏 0
点赞 0
评论 0
public void testProxy() throws Exception {
ObjectName n = new ObjectName("foo:id=" + UUID.randomUUID().toString());
Impl s = new Impl();
server.registerMBean(new StandardMBean(s, Ifc1.class), n);
Ifc1 s1 = MBeanUtils.createProxy(getClass().getClassLoader(), n, Ifc1.class);
assertNotNull(s1);
assertEquals(s.foo, s1.getfoo());
assertEquals(s.bar, s1.getBar());
assertEquals("ab", s1.cat("a", "b"));
Ifc1 s2 = MBeanUtils.createProxy(getClass().getClassLoader(), n, Ifc1.class);
assertNotNull(s2);
assertEquals(s.foo, s2.getfoo());
assertEquals(s.bar, s2.getBar());
assertEquals("ab", s2.cat("a", "b"));
}
JMXUtil.java 文件源码
项目:red5-server
阅读 19
收藏 0
点赞 0
评论 0
@SuppressWarnings({ "unchecked", "rawtypes" })
public static boolean registerNewMBean(Class clazz, Class interfaceClass) {
boolean status = false;
try {
String cName = clazz.getName();
if (cName.indexOf('.') != -1) {
cName = cName.substring(cName.lastIndexOf('.')).replaceFirst("[\\.]", "");
}
log.debug("Register name: {}", cName);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
mbs.registerMBean(new StandardMBean(Class.forName(clazz.getName()).newInstance(), interfaceClass), new ObjectName("org.red5.server:type=" + cName));
status = true;
} catch (Exception e) {
log.error("Could not register the {} MBean", clazz.getName(), e);
}
return status;
}
JMXUtil.java 文件源码
项目:red5-mobileconsole
阅读 40
收藏 0
点赞 0
评论 0
@SuppressWarnings({ "unchecked", "rawtypes" })
public static boolean registerNewMBean(Class clazz, Class interfaceClass) {
boolean status = false;
try {
String cName = clazz.getName();
if (cName.indexOf('.') != -1) {
cName = cName.substring(cName.lastIndexOf('.')).replaceFirst("[\\.]", "");
}
log.debug("Register name: {}", cName);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
mbs.registerMBean(new StandardMBean(Class.forName(clazz.getName()).newInstance(), interfaceClass), new ObjectName("org.red5.server:type=" + cName));
status = true;
} catch (Exception e) {
log.error("Could not register the {} MBean", clazz.getName(), e);
}
return status;
}
Scope.java 文件源码
项目:red5-mobileconsole
阅读 30
收藏 0
点赞 0
评论 0
protected void registerJMX() {
// register with jmx
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
try {
String cName = this.getClass().getName();
if (cName.indexOf('.') != -1) {
cName = cName.substring(cName.lastIndexOf('.')).replaceFirst("[\\.]", "");
}
oName = new ObjectName(String.format("org.red5.server:type=%s,name=%s", cName, name));
// don't reregister
if (!mbs.isRegistered(oName)) {
mbs.registerMBean(new StandardMBean(this, ScopeMXBean.class, true), oName);
}
} catch (Exception e) {
log.warn("Error on jmx registration", e);
}
}
RTMPMinaConnection.java 文件源码
项目:red5-mobileconsole
阅读 16
收藏 0
点赞 0
评论 0
protected void registerJMX() {
// register with jmx
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
try {
String cName = this.getClass().getName();
if (cName.indexOf('.') != -1) {
cName = cName.substring(cName.lastIndexOf('.')).replaceFirst("[\\.]", "");
}
String hostStr = host;
int port = 1935;
if (host != null && host.indexOf(":") > -1) {
String[] arr = host.split(":");
hostStr = arr[0];
port = Integer.parseInt(arr[1]);
}
// Create a new mbean for this instance
oName = new ObjectName(String.format("org.red5.server:type=%s,connectionType=%s,host=%s,port=%d,clientId=%s", cName, type, hostStr, port, client.getId()));
if (!mbs.isRegistered(oName)) {
mbs.registerMBean(new StandardMBean(this, RTMPMinaConnectionMXBean.class, true), oName);
} else {
log.debug("Connection is already registered in JMX");
}
} catch (Exception e) {
log.warn("Error on jmx registration", e);
}
}
RedisThrottler.java 文件源码
项目:log4j2-redis-appender
阅读 19
收藏 0
点赞 0
评论 0
private RedisThrottlerJmxBean registerOrGetJmxBean() {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
try {
synchronized (jmxBeanReferenceCountByName) {
// Get the reference count for the JMX bean.
Integer jmxBeanReferenceCount = jmxBeanReferenceCountByName.get(jmxBeanName);
if (jmxBeanReferenceCount == null) {
jmxBeanReferenceCount = 0;
}
// Create or get the JMX bean.
RedisThrottlerJmxBean jmxBean;
try {
jmxBean = new RedisThrottlerInternalJmxBean();
StandardMBean jmxBeanWrapper = new StandardMBean(jmxBean, RedisThrottlerJmxBean.class);
mbs.registerMBean(jmxBeanWrapper, jmxBeanName);
} catch (InstanceAlreadyExistsException ignored) {
jmxBean = JMX.newMBeanProxy(mbs, jmxBeanName, RedisThrottlerJmxBean.class);
}
// Increment the reference count and return the JMX bean.
jmxBeanReferenceCountByName.put(jmxBeanName, jmxBeanReferenceCount + 1);
return jmxBean;
}
} catch (Throwable error) {
String message = String.format("failed accessing the JMX bean (jmxBeanName=%s)", jmxBeanName);
throw new RuntimeException(message, error);
}
}