javax.management.MBeanServerInvocationHandler Java Examples
The following examples show how to use
javax.management.MBeanServerInvocationHandler.
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: BasicJMXWriterReaderTest.java From kieker with Apache License 2.0 | 6 votes |
private void checkControllerStateAfterRecordsPassedToController(final IMonitoringController monitoringController) throws Exception { // Test the JMX Controller final JMXServiceURL serviceURL = new JMXServiceURL( "service:jmx:rmi:///jndi/rmi://localhost:" + BasicJMXWriterReaderTest.PORT + "/jmxrmi"); final ObjectName controllerObjectName = new ObjectName(BasicJMXWriterReaderTest.DOMAIN, "type", BasicJMXWriterReaderTest.CONTROLLER); final JMXConnector jmx = JMXConnectorFactory.connect(serviceURL); final MBeanServerConnection mbServer = jmx.getMBeanServerConnection(); final Object tmpObj = MBeanServerInvocationHandler.newProxyInstance(mbServer, controllerObjectName, IMonitoringController.class, false); final IMonitoringController ctrlJMX = (IMonitoringController) tmpObj; Assert.assertTrue(monitoringController.isMonitoringEnabled()); Assert.assertTrue(ctrlJMX.isMonitoringEnabled()); Assert.assertTrue(ctrlJMX.disableMonitoring()); Assert.assertFalse(monitoringController.isMonitoringEnabled()); Assert.assertFalse(ctrlJMX.isMonitoringEnabled()); jmx.close(); }
Example #2
Source File: TestUtils.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #3
Source File: TestUtils.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #4
Source File: MBeanClientInterceptor.java From spring-analysis-note with MIT License | 6 votes |
/** * Ensures that an {@code MBeanServerConnection} is configured and attempts * to detect a local connection if one is not supplied. */ public void prepare() { synchronized (this.preparationMonitor) { if (this.server != null) { this.serverToUse = this.server; } else { this.serverToUse = null; this.serverToUse = this.connector.connect(this.serviceUrl, this.environment, this.agentId); } this.invocationHandler = null; if (this.useStrictCasing) { Assert.state(this.objectName != null, "No ObjectName set"); // Use the JDK's own MBeanServerInvocationHandler, in particular for native MXBean support. this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName, (this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface))); } else { // Non-strict casing can only be achieved through custom invocation handling. // Only partial MXBean support available! retrieveMBeanInfo(this.serverToUse); } } }
Example #5
Source File: PurgeCommandTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * This test ensures that the queueViewMbean will work. * * @throws Exception */ public void testQueueViewMbean() throws Exception { try { addMessages(); validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2); List<String> tokens = Arrays.asList(new String[]{"*"}); for (String token : tokens) { List<ObjectInstance> queueList = JmxMBeansUtil.queryMBeans(createJmxConnection(), "type=Broker,brokerName=localbroker,destinationType=Queue,destinationName=" + token); for (ObjectInstance queue : queueList) { ObjectName queueName = queue.getObjectName(); QueueViewMBean proxy = MBeanServerInvocationHandler.newProxyInstance(createJmxConnection(), queueName, QueueViewMBean.class, true); int removed = proxy.removeMatchingMessages(MSG_SEL_WITH_PROPERTY); LOG.info("Removed: " + removed); } } validateCounts(0, MESSAGE_COUNT, MESSAGE_COUNT); } finally { purgeAllMessages(); } }
Example #6
Source File: TestUtils.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #7
Source File: TestJMX.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private void registerAndVerifyMBean(MBeanServer mbs) { try { ObjectName myInfoObj = new ObjectName("com.alibaba.tenant.mxbean:type=MyTest"); MXBeanImpl myMXBean = new MXBeanImpl(); StandardMBean smb = new StandardMBean(myMXBean, MXBean.class); mbs.registerMBean(smb, myInfoObj); assertTrue(mbs.isRegistered(myInfoObj)); //call the method of MXBean MXBean mbean = (MXBean)MBeanServerInvocationHandler.newProxyInstance( mbs,new ObjectName("com.alibaba.tenant.mxbean:type=MyTest"), MXBean.class, true); assertTrue("test".equals(mbean.getName())); Set<ObjectInstance> instances = mbs.queryMBeans(new ObjectName("com.alibaba.tenant.mxbean:type=MyTest"), null); ObjectInstance instance = (ObjectInstance) instances.toArray()[0]; assertTrue(myMXBean.getClass().getName().equals(instance.getClassName())); MBeanInfo info = mbs.getMBeanInfo(myInfoObj); assertTrue(myMXBean.getClass().getName().equals(info.getClassName())); } catch (Exception e) { e.printStackTrace(); fail(); } }
Example #8
Source File: BasicJMXWriterReaderTest.java From kieker with Apache License 2.0 | 6 votes |
private void checkControllerStateBeforeRecordsPassedToController(final IMonitoringController monitoringController) throws Exception { // Test the JMX Controller final JMXServiceURL serviceURL = new JMXServiceURL( "service:jmx:rmi:///jndi/rmi://localhost:" + BasicJMXWriterReaderTest.PORT + "/jmxrmi"); final ObjectName controllerObjectName = new ObjectName(BasicJMXWriterReaderTest.DOMAIN, "type", BasicJMXWriterReaderTest.CONTROLLER); final JMXConnector jmx = JMXConnectorFactory.connect(serviceURL); final MBeanServerConnection mbServer = jmx.getMBeanServerConnection(); final Object tmpObj = MBeanServerInvocationHandler.newProxyInstance(mbServer, controllerObjectName, IMonitoringController.class, false); final IMonitoringController ctrlJMX = (IMonitoringController) tmpObj; Assert.assertTrue(monitoringController.isMonitoringEnabled()); Assert.assertTrue(ctrlJMX.isMonitoringEnabled()); jmx.close(); }
Example #9
Source File: TestUtils.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #10
Source File: MBeanClientInterceptor.java From java-technology-stack with MIT License | 6 votes |
/** * Ensures that an {@code MBeanServerConnection} is configured and attempts * to detect a local connection if one is not supplied. */ public void prepare() { synchronized (this.preparationMonitor) { if (this.server != null) { this.serverToUse = this.server; } else { this.serverToUse = null; this.serverToUse = this.connector.connect(this.serviceUrl, this.environment, this.agentId); } this.invocationHandler = null; if (this.useStrictCasing) { Assert.state(this.objectName != null, "No ObjectName set"); // Use the JDK's own MBeanServerInvocationHandler, in particular for native MXBean support. this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName, (this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface))); } else { // Non-strict casing can only be achieved through custom invocation handling. // Only partial MXBean support available! retrieveMBeanInfo(this.serverToUse); } } }
Example #11
Source File: MBeanClientInterceptor.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Ensures that an {@code MBeanServerConnection} is configured and attempts * to detect a local connection if one is not supplied. */ public void prepare() { synchronized (this.preparationMonitor) { if (this.server != null) { this.serverToUse = this.server; } else { this.serverToUse = null; this.serverToUse = this.connector.connect(this.serviceUrl, this.environment, this.agentId); } this.invocationHandler = null; if (this.useStrictCasing) { // Use the JDK's own MBeanServerInvocationHandler, in particular for native MXBean support. this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName, (this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface))); } else { // Non-strict casing can only be achieved through custom invocation handling. // Only partial MXBean support available! retrieveMBeanInfo(); } } }
Example #12
Source File: TestUtils.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #13
Source File: TestUtils.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #14
Source File: JBossWorkManagerUtils.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Obtain the default JBoss JCA WorkManager through a JMX lookup * for the JBossWorkManagerMBean. * @param mbeanName the JMX object name to use * @see org.jboss.resource.work.JBossWorkManagerMBean */ public static WorkManager getWorkManager(String mbeanName) { Assert.hasLength(mbeanName, "JBossWorkManagerMBean name must not be empty"); try { Class<?> mbeanClass = JBossWorkManagerUtils.class.getClassLoader().loadClass(JBOSS_WORK_MANAGER_MBEAN_CLASS_NAME); InitialContext jndiContext = new InitialContext(); MBeanServerConnection mconn = (MBeanServerConnection) jndiContext.lookup(MBEAN_SERVER_CONNECTION_JNDI_NAME); ObjectName objectName = ObjectName.getInstance(mbeanName); Object workManagerMBean = MBeanServerInvocationHandler.newProxyInstance(mconn, objectName, mbeanClass, false); Method getInstanceMethod = workManagerMBean.getClass().getMethod("getInstance"); return (WorkManager) getInstanceMethod.invoke(workManagerMBean); } catch (Exception ex) { throw new IllegalStateException( "Could not initialize JBossWorkManagerTaskExecutor because JBoss API is not available", ex); } }
Example #15
Source File: TestUtils.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #16
Source File: MBeanClientInterceptor.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Ensures that an {@code MBeanServerConnection} is configured and attempts * to detect a local connection if one is not supplied. */ public void prepare() { synchronized (this.preparationMonitor) { if (this.server != null) { this.serverToUse = this.server; } else { this.serverToUse = null; this.serverToUse = this.connector.connect(this.serviceUrl, this.environment, this.agentId); } this.invocationHandler = null; if (this.useStrictCasing) { // Use the JDK's own MBeanServerInvocationHandler, in particular for native MXBean support. this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName, (this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface))); } else { // Non-strict casing can only be achieved through custom invocation handling. // Only partial MXBean support available! retrieveMBeanInfo(); } } }
Example #17
Source File: JBossWorkManagerUtils.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Obtain the default JBoss JCA WorkManager through a JMX lookup * for the JBossWorkManagerMBean. * @param mbeanName the JMX object name to use * @see org.jboss.resource.work.JBossWorkManagerMBean */ public static WorkManager getWorkManager(String mbeanName) { Assert.hasLength(mbeanName, "JBossWorkManagerMBean name must not be empty"); try { Class<?> mbeanClass = JBossWorkManagerUtils.class.getClassLoader().loadClass(JBOSS_WORK_MANAGER_MBEAN_CLASS_NAME); InitialContext jndiContext = new InitialContext(); MBeanServerConnection mconn = (MBeanServerConnection) jndiContext.lookup(MBEAN_SERVER_CONNECTION_JNDI_NAME); ObjectName objectName = ObjectName.getInstance(mbeanName); Object workManagerMBean = MBeanServerInvocationHandler.newProxyInstance(mconn, objectName, mbeanClass, false); Method getInstanceMethod = workManagerMBean.getClass().getMethod("getInstance"); return (WorkManager) getInstanceMethod.invoke(workManagerMBean); } catch (Exception ex) { throw new IllegalStateException( "Could not initialize JBossWorkManagerTaskExecutor because JBoss API is not available", ex); } }
Example #18
Source File: TestUtils.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #19
Source File: TestUtils.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #20
Source File: CarbonMetricsTestCase.java From product-cep with Apache License 2.0 | 6 votes |
/** * This method will force metric manager to collect metrics by invoking report() method * using remote jmx * @throws IOException * @throws MalformedObjectNameException */ private void invokeJMXReportOperation() throws IOException, MalformedObjectNameException, XPathExpressionException { int JMXServicePort = Integer.parseInt(cepServer.getInstance().getPorts().get("jmxserver")); int RMIRegistryPort = Integer.parseInt(cepServer.getInstance().getPorts().get("rmiregistry")); JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost:" + JMXServicePort + "/jndi/rmi://localhost:" + RMIRegistryPort + "/jmxrmi"); Map<String, String[]> env = new HashMap<>(); String[] credentials = {"admin", "admin"}; env.put(JMXConnector.CREDENTIALS, credentials); JMXConnector jmxConnector = JMXConnectorFactory.connect(url, env); MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection(); ObjectName mbeanName = new ObjectName("org.wso2.carbon:type=MetricManager"); MetricManagerMXBean mbeanProxy = MBeanServerInvocationHandler.newProxyInstance( mbeanServerConnection, mbeanName, MetricManagerMXBean.class, true); mbeanProxy.report(); jmxConnector.close(); }
Example #21
Source File: TestUtils.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #22
Source File: GridAbstractTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Return JMX bean. * * @param igniteInstanceName Ignite instance name. * @param grp Name of the group. * @param name Name of the bean. * @param clazz Class of the mbean. * @return MX bean. * @throws Exception If failed. */ public static <T> T getMxBean(String igniteInstanceName, String grp, String name, Class<T> clazz) { ObjectName mbeanName = null; try { mbeanName = U.makeMBeanName(igniteInstanceName, grp, name); } catch (MalformedObjectNameException e) { fail("Failed to register MBean."); } MBeanServer mbeanSrv = ManagementFactory.getPlatformMBeanServer(); if (!mbeanSrv.isRegistered(mbeanName)) throw new IgniteException("MBean not registered."); return MBeanServerInvocationHandler.newProxyInstance(mbeanSrv, mbeanName, clazz, false); }
Example #23
Source File: TestUtils.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #24
Source File: Client.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public static void main(String[] args) throws Exception { // The RMI server's host: this is actually ignored by JSR 160 // since this information is stored in the RMI stub. String serverHost = "localhost"; // The host where the rmiregistry runs. String namingHost = "localhost"; String jndiPath = "/ssljmxconnector"; JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + serverHost + "/jndi/rmi://" + namingHost + jndiPath); JMXConnector connector = JMXConnectorFactory.connect(url); MBeanServerConnection connection = connector.getMBeanServerConnection(); // Call the server side ObjectName delegateName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate"); Object proxy = MBeanServerInvocationHandler.newProxyInstance(connection, delegateName, MBeanServerDelegateMBean.class, true); MBeanServerDelegateMBean delegate = (MBeanServerDelegateMBean)proxy; System.out.println(delegate.getImplementationVendor() + " is cool !"); }
Example #25
Source File: Client.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public static void main(String[] args) throws Exception { // The JMXConnectorServer protocol, in this case is IIOP String serverProtocol = "iiop"; // The RMI server's host: this is actually ignored by JSR 160 // since this information is stored in the RMI stub. String serverHost = "host"; // The host and port where the COSNaming service runs and the path under which the stub is registered. String namingHost = "localhost"; int namingPort = 1199; String jndiPath = "/jmxconnector"; // The address of the connector server JMXServiceURL url = new JMXServiceURL("service:jmx:" + serverProtocol + "://" + serverHost + "/jndi/iiop://" + namingHost + ":" + namingPort + jndiPath); // Connect a JSR 160 JMXConnector to the server side JMXConnector connector = JMXConnectorFactory.connect(url); // Retrieve an MBeanServerConnection that represent the MBeanServer the remote // connector server is bound to MBeanServerConnection connection = connector.getMBeanServerConnection(); // Call the server side as if it is a local MBeanServer ObjectName delegateName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate"); Object proxy = MBeanServerInvocationHandler.newProxyInstance(connection, delegateName, MBeanServerDelegateMBean.class, true); MBeanServerDelegateMBean delegate = (MBeanServerDelegateMBean)proxy; // The magic of JDK 1.3 dynamic proxy and JSR 160: // delegate.getImplementationVendor() is actually a remote JMX call, // but it looks like a local, old-style, java call. System.out.println(delegate.getImplementationVendor() + " is cool !"); }
Example #26
Source File: TestUtils.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Returns the ObjectName of the MBean that a proxy object * is proxying. **/ public static ObjectName getObjectName(Object proxy) { 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) return ((MBeanServerInvocationHandler)handler).getObjectName(); throw new IllegalArgumentException("not a JMX Proxy"); }
Example #27
Source File: MXBeanTest.java From hottub with GNU General Public License v2.0 | 5 votes |
static boolean equal(Object o1, Object o2, NamedMXBeans namedMXBeans) { if (o1 == o2) return true; if (o1 == null || o2 == null) return false; if (o1.getClass().isArray()) { if (!o2.getClass().isArray()) return false; return deepEqual(o1, o2, namedMXBeans); } if (o1 instanceof Map) { if (!(o2 instanceof Map)) return false; return equalMap((Map) o1, (Map) o2, namedMXBeans); } if (o1 instanceof CompositeData && o2 instanceof CompositeData) { return compositeDataEqual((CompositeData) o1, (CompositeData) o2, namedMXBeans); } if (Proxy.isProxyClass(o1.getClass())) { if (Proxy.isProxyClass(o2.getClass())) return proxyEqual(o1, o2, namedMXBeans); InvocationHandler ih = Proxy.getInvocationHandler(o1); // if (ih instanceof MXBeanInvocationHandler) { // return proxyEqualsObject((MXBeanInvocationHandler) ih, // o2, namedMXBeans); if (ih instanceof MBeanServerInvocationHandler) { return true; } else if (ih instanceof CompositeDataInvocationHandler) { return o2.equals(o1); // We assume the other object has a reasonable equals method } } else if (Proxy.isProxyClass(o2.getClass())) return equal(o2, o1, namedMXBeans); return o1.equals(o2); }
Example #28
Source File: MXBeanLookup.java From hottub with GNU General Public License v2.0 | 5 votes |
synchronized ObjectName mxbeanToObjectName(Object mxbean) throws OpenDataException { String wrong; if (mxbean instanceof Proxy) { InvocationHandler ih = Proxy.getInvocationHandler(mxbean); if (ih instanceof MBeanServerInvocationHandler) { MBeanServerInvocationHandler mbsih = (MBeanServerInvocationHandler) ih; if (mbsih.getMBeanServerConnection().equals(mbsc)) return mbsih.getObjectName(); else wrong = "proxy for a different MBeanServer"; } else wrong = "not a JMX proxy"; } else { ObjectName name = mxbeanToObjectName.get(mxbean); if (name != null) return name; wrong = "not an MXBean registered in this MBeanServer"; } String s = (mxbean == null) ? "null" : "object of type " + mxbean.getClass().getName(); throw new OpenDataException( "Could not convert " + s + " to an ObjectName: " + wrong); // Message will be strange if mxbean is null but it is not // supposed to be. }
Example #29
Source File: MXBeanLookup.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
synchronized ObjectName mxbeanToObjectName(Object mxbean) throws OpenDataException { String wrong; if (mxbean instanceof Proxy) { InvocationHandler ih = Proxy.getInvocationHandler(mxbean); if (ih instanceof MBeanServerInvocationHandler) { MBeanServerInvocationHandler mbsih = (MBeanServerInvocationHandler) ih; if (mbsih.getMBeanServerConnection().equals(mbsc)) return mbsih.getObjectName(); else wrong = "proxy for a different MBeanServer"; } else wrong = "not a JMX proxy"; } else { ObjectName name = mxbeanToObjectName.get(mxbean); if (name != null) return name; wrong = "not an MXBean registered in this MBeanServer"; } String s = (mxbean == null) ? "null" : "object of type " + mxbean.getClass().getName(); throw new OpenDataException( "Could not convert " + s + " to an ObjectName: " + wrong); // Message will be strange if mxbean is null but it is not // supposed to be. }
Example #30
Source File: MXBeanTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
static boolean equal(Object o1, Object o2, NamedMXBeans namedMXBeans) { if (o1 == o2) return true; if (o1 == null || o2 == null) return false; if (o1.getClass().isArray()) { if (!o2.getClass().isArray()) return false; return deepEqual(o1, o2, namedMXBeans); } if (o1 instanceof Map) { if (!(o2 instanceof Map)) return false; return equalMap((Map) o1, (Map) o2, namedMXBeans); } if (o1 instanceof CompositeData && o2 instanceof CompositeData) { return compositeDataEqual((CompositeData) o1, (CompositeData) o2, namedMXBeans); } if (Proxy.isProxyClass(o1.getClass())) { if (Proxy.isProxyClass(o2.getClass())) return proxyEqual(o1, o2, namedMXBeans); InvocationHandler ih = Proxy.getInvocationHandler(o1); // if (ih instanceof MXBeanInvocationHandler) { // return proxyEqualsObject((MXBeanInvocationHandler) ih, // o2, namedMXBeans); if (ih instanceof MBeanServerInvocationHandler) { return true; } else if (ih instanceof CompositeDataInvocationHandler) { return o2.equals(o1); // We assume the other object has a reasonable equals method } } else if (Proxy.isProxyClass(o2.getClass())) return equal(o2, o1, namedMXBeans); return o1.equals(o2); }