本文整理汇总了Java中javax.management.JMX.newMBeanProxy方法的典型用法代码示例。如果您正苦于以下问题:Java JMX.newMBeanProxy方法的具体用法?Java JMX.newMBeanProxy怎么用?Java JMX.newMBeanProxy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.management.JMX
的用法示例。
在下文中一共展示了JMX.newMBeanProxy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReadAttributes
import javax.management.JMX; //导入方法依赖的package包/类
@Test
public void testReadAttributes() throws Exception {
DynamicMBean proxy = JMX.newMBeanProxy(platformMBeanServer, threadPoolDynamicWrapperON, DynamicMBean.class);
assertEquals(threadCount, proxy.getAttribute(THREAD_COUNT));
assertEquals(threadPoolConfigBean.isTriggerNewInstanceCreation(),
proxy.getAttribute(TRIGGER_NEW_INSTANCE_CREATION));
AttributeList attributes = proxy.getAttributes(new String[] { THREAD_COUNT, TRIGGER_NEW_INSTANCE_CREATION });
assertEquals(2, attributes.size());
Attribute threadCountAttr = (Attribute) attributes.get(0);
assertEquals(THREAD_COUNT, threadCountAttr.getName());
assertEquals(threadCount, threadCountAttr.getValue());
Attribute boolTestAttr = (Attribute) attributes.get(1);
assertEquals(TRIGGER_NEW_INSTANCE_CREATION, boolTestAttr.getName());
assertEquals(threadPoolConfigBean.isTriggerNewInstanceCreation(), boolTestAttr.getValue());
MBeanInfo beanInfo = proxy.getMBeanInfo();
assertEquals(2, beanInfo.getAttributes().length);
}
示例2: makeNotificationEmitter
import javax.management.JMX; //导入方法依赖的package包/类
/**
* Transfroms a proxy implementing T in a proxy implementing T plus
* NotificationEmitter
*
**/
public static <T> T makeNotificationEmitter(T proxy,
Class<T> mbeanInterface) {
if (proxy instanceof NotificationEmitter)
return proxy;
if (proxy == null) return null;
if (!(proxy instanceof Proxy))
throw new IllegalArgumentException("not a "+Proxy.class.getName());
final Proxy p = (Proxy) proxy;
final InvocationHandler handler =
Proxy.getInvocationHandler(proxy);
if (!(handler instanceof MBeanServerInvocationHandler))
throw new IllegalArgumentException("not a JMX Proxy");
final MBeanServerInvocationHandler h =
(MBeanServerInvocationHandler)handler;
final ObjectName name = h.getObjectName();
final MBeanServerConnection mbs = h.getMBeanServerConnection();
final boolean isMXBean = h.isMXBean();
final T newProxy;
if (isMXBean)
newProxy = JMX.newMXBeanProxy(mbs,name,mbeanInterface,true);
else
newProxy = JMX.newMBeanProxy(mbs,name,mbeanInterface,true);
return newProxy;
}
示例3: testObjectNameSetterWithONContainingTransaction_shouldBeTranslatedToReadOnlyON
import javax.management.JMX; //导入方法依赖的package包/类
@Test
public void testObjectNameSetterWithONContainingTransaction_shouldBeTranslatedToReadOnlyON() throws Exception {
TestingParallelAPSPModuleFactory testingParallelAPSPConfigBeanFactory = new TestingParallelAPSPModuleFactory();
TestingParallelAPSPModule apspConfigBean = testingParallelAPSPConfigBeanFactory.createModule("", null, null);
ModuleIdentifier moduleIdentifier2 = new ModuleIdentifier("apsp", "parallel");
ObjectName dynON2 = ObjectNameUtil.createReadOnlyModuleON(moduleIdentifier2);
AbstractDynamicWrapper dyn = getDynamicWrapper(apspConfigBean, moduleIdentifier2);
platformMBeanServer.registerMBean(dyn, dynON2);
try {
TestingParallelAPSPConfigMXBean proxy = JMX.newMBeanProxy(platformMBeanServer, dynON2,
TestingParallelAPSPConfigMXBean.class);
ObjectName withTransactionName = ObjectNameUtil.createTransactionModuleON("transaction1", "moduleName",
"instanceName");
proxy.setThreadPool(withTransactionName);
ObjectName withoutTransactionName = ObjectNameUtil.withoutTransactionName(withTransactionName);
assertEquals(withoutTransactionName, proxy.getThreadPool());
} finally {
platformMBeanServer.unregisterMBean(dynON2);
}
}
示例4: testPrivate
import javax.management.JMX; //导入方法依赖的package包/类
private static void testPrivate(Class<?> iface) throws Exception {
try {
System.out.println("Creating a proxy for private M(X)Bean " +
iface.getName() + " ...");
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
ObjectName on = new ObjectName("test:type=Proxy");
JMX.newMBeanProxy(mbs, on, iface);
success("Created a proxy for private M(X)Bean - " + iface.getName());
} catch (Exception e) {
Throwable t = e;
while (t != null && !(t instanceof NotCompliantMBeanException)) {
t = t.getCause();
}
if (t != null) {
fail("Proxy not created");
} else {
throw e;
}
}
}
示例5: registerOrGetJmxBean
import javax.management.JMX; //导入方法依赖的package包/类
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);
}
}
示例6: testPassword
import javax.management.JMX; //导入方法依赖的package包/类
@Test
public void testPassword() throws Exception {
Assert.assertEquals("Passwords should match when not using JMX.",password,datasource.getPoolProperties().getPassword());
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ConnectionPoolMBean mbean = JMX.newMBeanProxy(mbs, oname, ConnectionPoolMBean.class);
String jmxPassword = mbean.getPassword();
Properties jmxProperties = mbean.getDbProperties();
Assert.assertFalse("Passwords should not match.", password.equals(jmxPassword));
Assert.assertFalse("Password property should be missing", jmxProperties.containsKey(PoolUtilities.PROP_PASSWORD));
}
示例7: connectAndValidateAsJmxClient
import javax.management.JMX; //导入方法依赖的package包/类
private void connectAndValidateAsJmxClient(final int jmxPort, final String serverHostName,
final boolean useSSL, final boolean useMulti) throws Exception {
// JMX RMI
Map<String, Object> environment = new HashMap();
if (useSSL) {
System.setProperty("javax.net.ssl.keyStore",
useMulti ? getMultiKeyKeystore() : getSimpleSingleKeyKeystore());
System.setProperty("javax.net.ssl.keyStoreType", "JKS");
System.setProperty("javax.net.ssl.keyStorePassword", "password");
System.setProperty("javax.net.ssl.trustStore",
useMulti ? getMultiKeyTruststore() : getSimpleSingleKeyKeystore());
System.setProperty("javax.net.ssl.trustStoreType", "JKS");
System.setProperty("javax.net.ssl.trustStorePassword", "password");
environment.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory());
}
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + serverHostName + ":" + jmxPort
+ "/jndi/rmi://" + serverHostName + ":" + jmxPort + "/jmxrmi");
JMXConnector jmxConnector = JMXConnectorFactory.connect(url, environment);
try {
MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection();
ObjectName mbeanName = new ObjectName("GemFire:service=System,type=Distributed");
// Get MBean proxy instance that will be used to make calls to registered MBean
DistributedSystemMXBean distributedSystemMXBean =
JMX.newMBeanProxy(mbeanServerConnection, mbeanName, DistributedSystemMXBean.class, true);
assertEquals(1, distributedSystemMXBean.getMemberCount());
assertEquals(1, distributedSystemMXBean.getLocatorCount());
} finally {
jmxConnector.close();
}
}
示例8: testNonCompliant
import javax.management.JMX; //导入方法依赖的package包/类
private static void testNonCompliant(Class<?> iface, boolean isMx) throws Exception {
try {
System.out.println("Creating a proxy for non-compliant " +
(isMx ? "MXBean" : "MBean") + " " +
iface.getName() + " ...");
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
ObjectName on = new ObjectName("test:type=Proxy");
if (isMx) {
JMX.newMXBeanProxy(mbs, on, iface);
} else {
JMX.newMBeanProxy(mbs, on, iface);
}
fail("Created a proxy for non-compliant " +
(isMx ? "MXBean" : "MBean") + " - " + iface.getName());
} catch (Exception e) {
Throwable t = e;
while (t != null && !(t instanceof NotCompliantMBeanException)) {
t = t.getCause();
}
if (t != null) {
success("Proxy not created");
} else {
throw e;
}
}
}
示例9: testCompliant
import javax.management.JMX; //导入方法依赖的package包/类
private static void testCompliant(Class<?> iface, boolean isMx) throws Exception {
try {
System.out.println("Creating a proxy for compliant " +
(isMx ? "MXBean" : "MBean") + " " +
iface.getName() + " ...");
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
ObjectName on = new ObjectName("test:type=Proxy");
if (isMx) {
JMX.newMXBeanProxy(mbs, on, iface);
} else {
JMX.newMBeanProxy(mbs, on, iface);
}
success("Created a proxy for compliant " +
(isMx ? "MXBean" : "MBean") + " - " + iface.getName());
} catch (Exception e) {
Throwable t = e;
while (t != null && !(t instanceof NotCompliantMBeanException)) {
t = t.getCause();
}
if (t != null) {
fail("Proxy not created");
} else {
throw e;
}
}
}
示例10: main
import javax.management.JMX; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
// 如果执行的JavaScript脚本内容过长
// 则可以把脚本写在一个文件里,然后使用jmx client 动态调用mbean接口方法
String user = "root";
String pwd = "root";
// 如果生产环境需要账号验证的话
String[] account = new String[] { user, pwd };
Map<String, String[]> props = new HashMap<String, String[]>();
props.put("jmx.remote.credentials", account);
// 10086参数,具体见启动脚本的vm参数,@see -Dcom.sun.management.jmxremote.port=10086
JMXServiceURL address =
new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:10086/jmxrmi");
JMXConnector connector = JMXConnectorFactory.connect(address, props);
MBeanServerConnection mBeanConnection = connector.getMBeanServerConnection();
connector.connect();
ObjectName objectName=new ObjectName("GameMXBean:name=GameMonitor");
System.out.println("\nMBean count = " + mBeanConnection.getMBeanCount());
for (ObjectInstance object : mBeanConnection.queryMBeans(null, null)) {
// System.out.println("object.getObjectName="+object.getObjectName());
}
final GameMonitorMXBean mBean = JMX.newMBeanProxy(mBeanConnection, objectName,
GameMonitorMXBean.class);
String script = readScript("script.js");
System.err.println(script);
System.err.println(mBean.execJavascript(script));
}
示例11: run
import javax.management.JMX; //导入方法依赖的package包/类
void run() throws Exception {
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
final ObjectName observedName = new ObjectName("a:b=c");
final ObjectName monitorName = new ObjectName("a:type=Monitor");
mbs.registerMBean(new StringMonitor(), monitorName);
final StringMonitorMBean monitorProxy =
JMX.newMBeanProxy(mbs, monitorName, StringMonitorMBean.class);
final TestMBean observedProxy =
JMX.newMBeanProxy(mbs, observedName, TestMBean.class);
final Runnable sensitiveThing = new Runnable() {
public void run() {
doSensitiveThing(monitorProxy, observedName);
}
};
final Runnable nothing = new Runnable() {
public void run() {}
};
final Runnable withinGetAttribute =
(when == When.IN_GET_ATTRIBUTE) ? sensitiveThing : nothing;
mbs.registerMBean(new Test(withinGetAttribute), observedName);
monitorProxy.addObservedObject(observedName);
monitorProxy.setObservedAttribute("Thing");
monitorProxy.setStringToCompare("old");
monitorProxy.setGranularityPeriod(10L); // 10 ms
monitorProxy.setNotifyDiffer(true);
final int initGetCount = observedProxy.getGetCount();
monitorProxy.start();
int getCount = initGetCount;
for (int i = 0; i < 500; i++) { // 500 * 10 = 5 seconds
getCount = observedProxy.getGetCount();
if (getCount != initGetCount)
break;
Thread.sleep(10);
}
if (getCount <= initGetCount)
throw new Exception("Test failed: presumable deadlock");
// This won't show up as a deadlock in CTRL-\ or in
// ThreadMXBean.findDeadlockedThreads(), because they don't
// see that thread A is waiting for thread B (B.join()), and
// thread B is waiting for a lock held by thread A
// Now we know the monitor has observed the initial value,
// so if we want to test notify behaviour we can trigger by
// exceeding the threshold.
if (when == When.IN_NOTIFY) {
final AtomicInteger notifCount = new AtomicInteger();
final NotificationListener listener = new NotificationListener() {
public void handleNotification(Notification n, Object h) {
Thread t = new Thread(sensitiveThing);
t.start();
try {
t.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
notifCount.incrementAndGet();
}
};
mbs.addNotificationListener(monitorName, listener, null, null);
observedProxy.setThing("new");
for (int i = 0; i < 500 && notifCount.get() == 0; i++)
Thread.sleep(10);
if (notifCount.get() == 0)
throw new Exception("Test failed: presumable deadlock");
}
}
示例12: main
import javax.management.JMX; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
ObjectName relSvcName = new ObjectName("a:type=relationService");
RelationServiceMBean relSvc =
JMX.newMBeanProxy(mbs, relSvcName, RelationServiceMBean.class);
mbs.createMBean("javax.management.relation.RelationService",
relSvcName,
new Object[] {Boolean.TRUE},
new String[] {"boolean"});
final BlockingQueue<Notification> q =
new ArrayBlockingQueue<Notification>(100);
NotificationListener qListener = new NotificationListener() {
public void handleNotification(Notification notification,
Object handback) {
q.add(notification);
}
};
mbs.addNotificationListener(relSvcName, qListener, null, null);
RoleInfo leftInfo =
new RoleInfo("left", "javax.management.timer.TimerMBean");
RoleInfo rightInfo =
new RoleInfo("right", "javax.management.timer.Timer");
relSvc.createRelationType("typeName", new RoleInfo[] {leftInfo, rightInfo});
ObjectName timer1 = new ObjectName("a:type=timer,number=1");
ObjectName timer2 = new ObjectName("a:type=timer,number=2");
mbs.createMBean("javax.management.timer.Timer", timer1);
mbs.createMBean("javax.management.timer.Timer", timer2);
Role leftRole =
new Role("left", Arrays.asList(new ObjectName[] {timer1}));
Role rightRole =
new Role("right", Arrays.asList(new ObjectName[] {timer2}));
RoleList roles =
new RoleList(Arrays.asList(new Role[] {leftRole, rightRole}));
final int NREPEAT = 10;
for (int i = 0; i < NREPEAT; i++) {
relSvc.createRelation("relationName", "typeName", roles);
relSvc.removeRelation("relationName");
}
Notification firstNotif = q.remove();
long seqNo = firstNotif.getSequenceNumber();
for (int i = 0; i < NREPEAT * 2 - 1; i++) {
Notification n = q.remove();
long nSeqNo = n.getSequenceNumber();
if (nSeqNo != seqNo + 1) {
throw new Exception(
"TEST FAILED: expected seqNo " + (seqNo + 1) + "; got " +
nSeqNo);
}
seqNo++;
}
System.out.println("TEST PASSED: got " + (NREPEAT * 2) + " notifications " +
"with contiguous sequence numbers");
}
示例13: newMBeanProxy
import javax.management.JMX; //导入方法依赖的package包/类
public final <T> T newMBeanProxy(final ObjectName objectName, final Class<T> interfaceClass,
final boolean notificationBroadcaster) {
return JMX.newMBeanProxy(getMBeanServer(), objectName, interfaceClass, notificationBroadcaster);
}
示例14: run
import javax.management.JMX; //导入方法依赖的package包/类
void run() throws Exception {
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
final ObjectName observedName = new ObjectName("a:b=c");
final ObjectName monitorName = new ObjectName("a:type=Monitor");
mbs.registerMBean(new CounterMonitor(), monitorName);
final CounterMonitorMBean monitorProxy =
JMX.newMBeanProxy(mbs, monitorName, CounterMonitorMBean.class);
final TestMBean observedProxy =
JMX.newMBeanProxy(mbs, observedName, TestMBean.class);
final Runnable sensitiveThing = new Runnable() {
public void run() {
doSensitiveThing(monitorProxy, observedName);
}
};
final Runnable nothing = new Runnable() {
public void run() {}
};
final Runnable withinGetAttribute =
(when == When.IN_GET_ATTRIBUTE) ? sensitiveThing : nothing;
mbs.registerMBean(new Test(withinGetAttribute), observedName);
monitorProxy.addObservedObject(observedName);
monitorProxy.setObservedAttribute("Thing");
monitorProxy.setInitThreshold(100);
monitorProxy.setGranularityPeriod(10L); // 10 ms
monitorProxy.setNotify(true);
final int initGetCount = observedProxy.getGetCount();
monitorProxy.start();
System.out.println("Checking GetCount, possible deadlock if timeout.");
do { // 8038322. Until timeout of testing harness
Thread.sleep(200);
} while ((observedProxy.getGetCount()) == initGetCount);
System.out.println("Done!");
// This won't show up as a deadlock in CTRL-\ or in
// ThreadMXBean.findDeadlockedThreads(), because they don't
// see that thread A is waiting for thread B (B.join()), and
// thread B is waiting for a lock held by thread A
// Now we know the monitor has observed the initial value,
// so if we want to test notify behaviour we can trigger by
// exceeding the threshold.
if (when == When.IN_NOTIFY) {
final AtomicInteger notifCount = new AtomicInteger();
final NotificationListener listener = new NotificationListener() {
public void handleNotification(Notification n, Object h) {
Thread t = new Thread(sensitiveThing);
t.start();
try {
t.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
notifCount.incrementAndGet();
}
};
mbs.addNotificationListener(monitorName, listener, null, null);
observedProxy.setThing(1000);
System.out.println("Waiting notifCount.get() != 0, possible deadlock if timeout.");
do {
Thread.sleep(200);
} while(notifCount.get() == 0); // 8038322. Until timeout of testing harness
System.out.println("Done");
}
}
示例15: newMBeanProxy
import javax.management.JMX; //导入方法依赖的package包/类
/**
* Usage of this method indicates error as config JMX uses solely MXBeans.
* Use {@link #newMXBeanProxy(javax.management.ObjectName, Class)}
* or {@link JMX#newMBeanProxy(javax.management.MBeanServerConnection, javax.management.ObjectName, Class)}
* This method will be removed soon.
*/
@Deprecated
public <T> T newMBeanProxy(final ObjectName on, final Class<T> clazz) {
ObjectName onObj = translateServiceRefIfPossible(on, clazz, configMBeanServer);
return JMX.newMBeanProxy(configMBeanServer, onObj, clazz);
}