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:com.adaptris.core.runtime.AdapterRegistryTest.java
public void testProxy_CreateAdapter_URL() throws Exception { AdapterRegistry myAdapterRegistry = (AdapterRegistry) AdapterRegistry .findInstance(new JunitBootstrapProperties(new Properties())); AdapterRegistryMBean registry = JMX.newMBeanProxy(mBeanServer, myAdapterRegistry.createObjectName(), AdapterRegistryMBean.class); String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName, 2, 2); File filename = deleteLater(adapter); DefaultMarshaller.getDefaultMarshaller().marshal(adapter, filename); ObjectName objName = registry.createAdapter(new URLString(filename)); assertNotNull(objName);// ww w. j a v a 2s .c om assertTrue(mBeanServer.isRegistered(objName)); AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, objName, AdapterManagerMBean.class); assertNotNull(manager); assertEquals(ClosedState.getInstance(), manager.getComponentState()); assertEquals(1, myAdapterRegistry.getAdapters().size()); assertEquals(1, registry.getAdapters().size()); }
From source file:com.adaptris.core.runtime.DefaultFailedMessageRetrierJmxTest.java
public void testMBean_Retry_WorkflowNotStarted() throws Exception { Adapter adapter = createAdapter(getName()); Channel channel = createChannel(getName()); StandardWorkflow wf = createWorkflow(getName()); MockMessageProducer mock = new MockMessageProducer(); wf.setProducer(mock);/*from w w w. ja v a 2 s. com*/ channel.getWorkflowList().add(wf); adapter.getChannelList().add(channel); DefaultFailedMessageRetrier retrier = new DefaultFailedMessageRetrier(); retrier.setShutdownWaitTime(new TimeInterval(10L, TimeUnit.SECONDS)); adapter.setFailedMessageRetrier(retrier); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); msg.addMetadata(Workflow.WORKFLOW_ID_KEY, getName() + "@" + getName()); SerializableAdaptrisMessage serialized = new DefaultSerializableMessageTranslator().translate(msg); AdapterManager adapterManager = new AdapterManager(adapter); try { adapterManager.registerMBean(); adapterManager.requestStart(); // Close the workflow directly wf.requestClose(); ObjectName retrierObjName = createRetrierObjectName(adapterManager); DefaultFailedMessageRetrierJmxMBean jmxBean = JMX.newMBeanProxy(mBeanServer, retrierObjName, DefaultFailedMessageRetrierJmxMBean.class); assertFalse(jmxBean.retryMessage(serialized)); assertEquals(0, mock.messageCount()); } finally { adapterManager.requestClose(); adapterManager.unregisterMBean(); } }
From source file:com.adaptris.core.runtime.StandardMessageErrorDigestTest.java
public void testMBean_RemoveDigestEntry_ByEntry() throws Exception { String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName); StandardMessageErrorDigester digester = createDigester(); digester.setUniqueId(getName());// www . j a v a2s .c o m adapter.setMessageErrorDigester(digester); List<BaseComponentMBean> mBeans = createJmxManagers(adapter); try { start(adapter); register(mBeans); ObjectName adapterObj = createAdapterObjectName(adapterName); ObjectName digesterObj = createMessageErrorDigestObjectName(adapterName, getName()); StandardMessageErrorDigesterJmxMBean errDigester = JMX.newMBeanProxy(mBeanServer, digesterObj, StandardMessageErrorDigesterJmxMBean.class); List<AdaptrisMessage> msgs = createMessages(5, 1); for (AdaptrisMessage msg : msgs) { digester.digest(msg); } assertNotNull(errDigester.getDigest()); assertEquals(5, errDigester.getDigest().size()); assertEquals(5, errDigester.getTotalErrorCount()); errDigester.remove(new MessageDigestErrorEntry(msgs.get(0).getUniqueId(), null)); assertEquals(4, errDigester.getDigest().size()); assertEquals(5, errDigester.getTotalErrorCount()); } finally { stop(adapter); } }
From source file:com.adaptris.core.runtime.AdapterRegistryTest.java
public void testCreateAdapter_String() throws Exception { String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName, 2, 2); String xml = DefaultMarshaller.getDefaultMarshaller().marshal(adapter); AdapterRegistry myAdapterRegistry = (AdapterRegistry) AdapterRegistry .findInstance(new JunitBootstrapProperties(new Properties())); ObjectName objName = myAdapterRegistry.createAdapter(xml); assertNotNull(objName);/*from ww w .j a va 2s . c o m*/ assertNotNull(myAdapterRegistry.getBuilder(objName)); assertNotNull(myAdapterRegistry.getBuilderMBean(objName)); assertTrue(mBeanServer.isRegistered(objName)); AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, objName, AdapterManagerMBean.class); assertNotNull(manager); assertEquals(ClosedState.getInstance(), manager.getComponentState()); assertEquals(1, myAdapterRegistry.getAdapters().size()); }
From source file:com.adaptris.core.runtime.DefaultFailedMessageRetrierJmxTest.java
public void testMBean_RetryWhen_Retrier_Closed() throws Exception { Adapter adapter = createAdapter(getName()); Channel channel = createChannel(getName()); StandardWorkflow wf = createWorkflow(getName()); MockMessageProducer mock = new MockMessageProducer(); wf.setProducer(mock);/*w ww . j a va 2 s .c o m*/ channel.getWorkflowList().add(wf); adapter.getChannelList().add(channel); DefaultFailedMessageRetrier retrier = new DefaultFailedMessageRetrier(); retrier.setShutdownWaitTime(new TimeInterval(10L, TimeUnit.SECONDS)); adapter.setFailedMessageRetrier(retrier); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); msg.addMetadata(Workflow.WORKFLOW_ID_KEY, getName() + "@" + getName()); SerializableAdaptrisMessage serialized = new DefaultSerializableMessageTranslator().translate(msg); AdapterManager adapterManager = new AdapterManager(adapter); try { adapterManager.registerMBean(); adapterManager.requestStart(); // Close the workflow directly LifecycleHelper.stop(retrier); LifecycleHelper.close(retrier); ObjectName retrierObjName = createRetrierObjectName(adapterManager); DefaultFailedMessageRetrierJmxMBean jmxBean = JMX.newMBeanProxy(mBeanServer, retrierObjName, DefaultFailedMessageRetrierJmxMBean.class); assertFalse(jmxBean.retryMessage(serialized)); assertEquals(0, mock.messageCount()); } finally { adapterManager.requestClose(); adapterManager.unregisterMBean(); } }
From source file:com.adaptris.core.runtime.StandardMessageErrorDigestTest.java
public void testMBean_RemoveDigestEntry_ByEntry_WithDelete() throws Exception { String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName); StandardMessageErrorDigester digester = createDigester(); digester.setUniqueId(getName());/* w w w. j a v a2 s. c o m*/ adapter.setMessageErrorDigester(digester); List<BaseComponentMBean> mBeans = createJmxManagers(adapter); File tempDir = Files.createTempDirectory(this.getClass().getSimpleName()).toFile(); tempDir.deleteOnExit(); cleaner.track(tempDir, digester, FileDeleteStrategy.FORCE); try { start(adapter); register(mBeans); ObjectName adapterObj = createAdapterObjectName(adapterName); ObjectName digesterObj = createMessageErrorDigestObjectName(adapterName, getName()); StandardMessageErrorDigesterJmxMBean errDigester = JMX.newMBeanProxy(mBeanServer, digesterObj, StandardMessageErrorDigesterJmxMBean.class); // The files don't actually exist; so they won't be deleted; List<AdaptrisMessage> msgs = createAndDigest(digester, "testDigest", tempDir.getCanonicalPath()); assertNotNull(errDigester.getDigest()); assertEquals(5, errDigester.getDigest().size()); assertEquals(5, errDigester.getTotalErrorCount()); errDigester.remove(new MessageDigestErrorEntry(msgs.get(0).getUniqueId(), null), true); assertEquals(4, errDigester.getDigest().size()); assertEquals(5, errDigester.getTotalErrorCount()); } finally { stop(adapter); } }
From source file:com.adaptris.core.runtime.AdapterRegistryTest.java
public void testProxy_CreateAdapter_String() throws Exception { AdapterRegistry myAdapterRegistry = (AdapterRegistry) AdapterRegistry .findInstance(new JunitBootstrapProperties(new Properties())); AdapterRegistryMBean registry = JMX.newMBeanProxy(mBeanServer, myAdapterRegistry.createObjectName(), AdapterRegistryMBean.class); String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName, 2, 2); String xml = DefaultMarshaller.getDefaultMarshaller().marshal(adapter); ObjectName objName = registry.createAdapter(xml); assertNotNull(objName);/*from www .ja v a 2s .c o m*/ assertNotNull(registry.getBuilder(objName)); assertTrue(mBeanServer.isRegistered(objName)); AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, objName, AdapterManagerMBean.class); assertNotNull(manager); assertEquals(ClosedState.getInstance(), manager.getComponentState()); assertEquals(1, registry.getAdapters().size()); }
From source file:com.adaptris.core.runtime.StandardMessageErrorDigestTest.java
public void testMBean_RemoveDigestEntry_ByMessageId() throws Exception { String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName); StandardMessageErrorDigester digester = createDigester(); digester.setUniqueId(getName());/* w w w . j av a2 s . c o m*/ adapter.setMessageErrorDigester(digester); List<BaseComponentMBean> mBeans = createJmxManagers(adapter); try { start(adapter); register(mBeans); ObjectName adapterObj = createAdapterObjectName(adapterName); ObjectName digesterObj = createMessageErrorDigestObjectName(adapterName, getName()); StandardMessageErrorDigesterJmxMBean errDigester = JMX.newMBeanProxy(mBeanServer, digesterObj, StandardMessageErrorDigesterJmxMBean.class); List<AdaptrisMessage> msgs = createMessages(5, 1); for (AdaptrisMessage msg : msgs) { digester.digest(msg); } assertNotNull(errDigester.getDigest()); assertEquals(5, errDigester.getDigest().size()); assertEquals(5, errDigester.getTotalErrorCount()); errDigester.remove(msgs.get(0).getUniqueId()); assertEquals(4, errDigester.getDigest().size()); assertEquals(5, errDigester.getTotalErrorCount()); } finally { stop(adapter); } }
From source file:com.spotify.reaper.cassandra.JmxProxy.java
/** * Checks if table exists in the cluster by instantiating a MBean for that table. *///from w w w. jav a 2 s.co m public boolean tableExists(String ks, String cf) { try { String type = cf.contains(".") ? "IndexColumnFamilies" : "ColumnFamilies"; String nameStr = String.format("org.apache.cassandra.db:type=*%s,keyspace=%s,columnfamily=%s", type, ks, cf); Set<ObjectName> beans = mbeanServer.queryNames(new ObjectName(nameStr), null); if (beans.isEmpty() || beans.size() != 1) { return false; } ObjectName bean = beans.iterator().next(); JMX.newMBeanProxy(mbeanServer, bean, ColumnFamilyStoreMBean.class); } catch (MalformedObjectNameException | IOException e) { String errMsg = String.format("ColumnFamilyStore for %s/%s not found: %s", ks, cf, e.getMessage()); LOG.warn(errMsg, e); return false; } return true; }
From source file:com.adaptris.core.runtime.AdapterRegistryTest.java
public void testPersistAdapter_MBean_to_URL() throws Exception { AdapterRegistry myAdapterRegistry = (AdapterRegistry) AdapterRegistry .findInstance(new JunitBootstrapProperties(new Properties())); String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName, 2, 2); File filename = deleteLater(adapter); String xml = DefaultMarshaller.getDefaultMarshaller().marshal(adapter); ObjectName objName = myAdapterRegistry.createAdapter(xml); assertNotNull(objName);// w w w . java2s . com AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, objName, AdapterManagerMBean.class); myAdapterRegistry.persistAdapter(manager, new URLString(filename)); Adapter marshalledAdapter = (Adapter) DefaultMarshaller.getDefaultMarshaller().unmarshal(filename); assertRoundtripEquality(adapter, marshalledAdapter); }