List of usage examples for javax.management JMX newMBeanProxy
public static <T> T newMBeanProxy(MBeanServerConnection connection, ObjectName objectName, Class<T> interfaceClass)
Make a proxy for a Standard MBean in a local or remote MBean Server.
If you have an MBean Server mbs containing an MBean with ObjectName name , and if the MBean's management interface is described by the Java interface MyMBean , you can construct a proxy for the MBean like this:
MyMBean proxy = JMX.newMBeanProxy(mbs, name, MyMBean.class);
Suppose, for example, MyMBean looks like this:
public interface MyMBean { public String getSomeAttribute(); public void setSomeAttribute(String value); public void someOperation(String param1, int param2); }
Then you can execute:
From source file:io.mapzone.controller.um.launcher.ArenaLauncher.java
protected void configureInstance(ProjectInstanceRecord instance) throws MalformedURLException { // config via JMX String url = "service:jmx:rmi:///jndi/rmi://" + instance.host.get().inetAddress.get() + ":" + instance.process.get().jmxPort.get() + "/jmxrmi"; JMXServiceURL serviceUrl = new JMXServiceURL(url); try (JMXConnector connector = JMXConnectorFactory.connect(serviceUrl, null);) { MBeanServerConnection conn = connector.getMBeanServerConnection(); log.info(url);//ww w . j a va2 s.c om while (conn.queryNames(ArenaConfigMBean.NAME.get(), null).isEmpty()) { log.info("No such MBean: " + ArenaConfigMBean.NAME.get()); Thread.sleep(100); } String localHttpPort = ControllerPlugin.instance().httpPort(); ArenaConfigMBean arenaConfig = JMX.newMBeanProxy(conn, ArenaConfigMBean.NAME.get(), ArenaConfigMBean.class); checked(() -> arenaConfig.setAppTitle(instance.project.get())); checked(() -> arenaConfig.setServiceAuthToken(project().serviceAuthToken.get())); // send before URLs!!! checked(() -> arenaConfig.setCatalogServerUrl("http://localhost:" + localHttpPort + "/csw")); checked(() -> arenaConfig.setProxyUrl(ProxyServlet.projectUrlBase(project()))); checked(() -> arenaConfig.setProjectCatalogId(project().catalogId.get())); log.info("Instance process configured."); } catch (Throwable e) { log.warn("Error while configuring instance.", e); } }
From source file:com.adaptris.core.runtime.AdapterComponentCheckerTest.java
public void testCheckInitialised() throws Exception { String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName, 2, 2); List<BaseComponentMBean> mBeans = createJmxManagers(adapter); ObjectName objectName = createComponentCheckerObjectName(adapterName); register(mBeans);// w ww . jav a 2s . c o m AdapterComponentCheckerMBean manager = JMX.newMBeanProxy(mBeanServer, objectName, AdapterComponentCheckerMBean.class); manager.checkInitialise(createServiceForTests()); }
From source file:com.adaptris.core.runtime.DefaultFailedMessageRetrierJmxTest.java
public void testMBean_GetParentId() throws Exception { Adapter adapter = createAdapter(getName()); DefaultFailedMessageRetrier retrier = new DefaultFailedMessageRetrier(); adapter.setFailedMessageRetrier(retrier); AdapterManager adapterManager = new AdapterManager(adapter); ObjectName retrierObjName = createRetrierObjectName(adapterManager); try {// w w w .ja v a 2s . c om adapterManager.registerMBean(); DefaultFailedMessageRetrierJmxMBean proxy = JMX.newMBeanProxy(mBeanServer, retrierObjName, DefaultFailedMessageRetrierJmxMBean.class); assertNotNull(proxy); assertEquals(getName(), proxy.getParentId()); } finally { adapterManager.unregisterMBean(); } }
From source file:com.adaptris.core.runtime.AdapterRegistry.java
public static AdapterRegistryMBean findInstance(Properties cfg) throws MalformedObjectNameException, CoreException { MBeanServer mbs = JmxHelper.findMBeanServer(); AdapterRegistryMBean result = null;/*from w w w. j a v a 2 s .c o m*/ ObjectName objName = ObjectName.getInstance(STANDARD_REGISTRY_JMX_NAME); if (mbs.isRegistered(objName)) { result = JMX.newMBeanProxy(mbs, objName, AdapterRegistryMBean.class); result.addConfiguration(cfg); } else { result = new AdapterRegistry(); result.registerMBean(); result.addConfiguration(cfg); } return result; }
From source file:com.adaptris.core.runtime.FileLogHandlerJmxTest.java
public void testMBean_GetParentObjectName() throws Exception { Adapter adapter = createAdapter(getName()); FileLogHandler handler = createHandler(); adapter.setLogHandler(handler);/*w w w .j av a 2 s . com*/ AdapterManager adapterManager = new AdapterManager(adapter); ObjectName flhObjName = createFileHandlerObjectName(adapterManager); try { adapterManager.registerMBean(); FileLogHandlerJmxMBean fileLogHandlerProxy = JMX.newMBeanProxy(mBeanServer, flhObjName, FileLogHandlerJmxMBean.class); assertNotNull(fileLogHandlerProxy); assertEquals(adapterManager.createObjectName(), fileLogHandlerProxy.getParentObjectName()); } finally { adapterManager.unregisterMBean(); } }
From source file:com.adaptris.core.runtime.AdapterComponentCheckerTest.java
public void testCheckInitialised_NotComponent() throws Exception { String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName, 2, 2); List<BaseComponentMBean> mBeans = createJmxManagers(adapter); ObjectName objectName = createComponentCheckerObjectName(adapterName); register(mBeans);/*from w w w . ja va2s . c o m*/ AdapterComponentCheckerMBean manager = JMX.newMBeanProxy(mBeanServer, objectName, AdapterComponentCheckerMBean.class); try { manager.checkInitialise("<Document/>"); fail(); } catch (CoreException expected) { } }
From source file:com.adaptris.core.runtime.DefaultFailedMessageRetrierJmxTest.java
public void testMBean_GetParentObjectName() throws Exception { Adapter adapter = createAdapter(getName()); DefaultFailedMessageRetrier retrier = new DefaultFailedMessageRetrier(); adapter.setFailedMessageRetrier(retrier); AdapterManager adapterManager = new AdapterManager(adapter); ObjectName retrierObjName = createRetrierObjectName(adapterManager); try {/* ww w . j av a 2 s .c o m*/ adapterManager.registerMBean(); DefaultFailedMessageRetrierJmxMBean proxy = JMX.newMBeanProxy(mBeanServer, retrierObjName, DefaultFailedMessageRetrierJmxMBean.class); assertNotNull(proxy); assertEquals(adapterManager.createObjectName(), proxy.getParentObjectName()); } finally { adapterManager.unregisterMBean(); } }
From source file:com.adaptris.core.interceptor.MessageMetricsStatisticsTest.java
public void testGetTotalStringStats() throws Exception { String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName); List<BaseComponentMBean> mBeans = createJmxManagers(adapter); try {//w w w .j a v a2 s.co m start(adapter); register(mBeans); ObjectName workflowObj = createWorkflowObjectName(adapterName); ObjectName metricsObj = createMetricsObjectName(adapterName); MessageMetricsStatisticsMBean stats = JMX.newMBeanProxy(mBeanServer, metricsObj, MessageMetricsStatisticsMBean.class); WorkflowManagerMBean workflow = JMX.newMBeanProxy(mBeanServer, workflowObj, WorkflowManagerMBean.class); assertNotNull(stats.getTotalStringStats()); SerializableAdaptrisMessage msg = createMessageForInjection(null); workflow.processAsync(msg); assertNotNull(stats.getTotalStringStats()); } finally { stop(adapter); } }
From source file:com.adaptris.core.runtime.RetryMessageErrorHandlerMonitorTest.java
public void testMBean_FailMessageById() throws Exception { String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName); MockMessageProducer failProducer = new MockMessageProducer(); RetryMessageErrorHandler handler = new RetryMessageErrorHandler(getName(), new StandaloneProducer(failProducer)); adapter.setMessageErrorHandler(handler); AdapterManager adapterManager = new AdapterManager(adapter); try {//from w ww . j a va 2s. c om registerMBeans(adapterManager); adapterManager.requestStart(); ObjectName retryObjectName = ObjectName.getInstance( JMX_RETRY_MONITOR_TYPE + adapterManager.createObjectHierarchyString() + ID_PREFIX + getName()); RetryMessageErrorHandlerMonitorMBean mbean = JMX.newMBeanProxy(mBeanServer, retryObjectName, RetryMessageErrorHandlerMonitorMBean.class); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); // 10 retries 10 minutes apart, so it should be waiting. handler.handleProcessingException(msg); assertEquals(1, mbean.waitingForRetry().size()); assertTrue(mbean.waitingForRetry().contains(msg.getUniqueId())); mbean.failMessage("hello"); mbean.failMessage(msg.getUniqueId()); assertEquals(1, failProducer.messageCount()); } finally { adapterManager.requestClose(); } }
From source file:com.adaptris.core.runtime.AdapterComponentCheckerTest.java
public void testCheckInitialised_Connection() throws Exception { String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName, 2, 2); List<BaseComponentMBean> mBeans = createJmxManagers(adapter); ObjectName objectName = createComponentCheckerObjectName(adapterName); register(mBeans);/*from ww w . j av a 2s .co m*/ AdapterComponentCheckerMBean manager = JMX.newMBeanProxy(mBeanServer, objectName, AdapterComponentCheckerMBean.class); manager.checkInitialise(DefaultMarshaller.getDefaultMarshaller().marshal(new NullConnection())); }