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.AdapterRegistry.java
@Override public void destroyAdapter(ObjectName adapterName) throws MalformedObjectNameException, CoreException { destroyAdapter(JMX.newMBeanProxy(mBeanServer, adapterName, AdapterManagerMBean.class)); }
From source file:com.adaptris.core.runtime.AdapterRegistryTest.java
public void testCreateAdapter_URL() throws Exception { String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName, 2, 2); File filename = deleteLater(adapter); DefaultMarshaller.getDefaultMarshaller().marshal(adapter, filename); AdapterRegistry myAdapterRegistry = (AdapterRegistry) AdapterRegistry .findInstance(new JunitBootstrapProperties(new Properties())); ObjectName objName = myAdapterRegistry.createAdapter(new URLString(filename)); assertNotNull(objName);/* ww w.ja v a2 s. 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()); }
From source file:com.adaptris.core.runtime.AdapterRegistry.java
/** * Convenience method to start a set of adapter managers that uses {@link AdapterManagerMBean#requestStart()} * * @param adapterManagers set of managers. *///from w ww. ja va 2s . c o m public static void start(Set<ObjectName> adapterManagers) throws CoreException { for (ObjectName obj : adapterManagers) { AdapterManagerMBean mgr = JMX.newMBeanProxy(JmxHelper.findMBeanServer(), obj, AdapterManagerMBean.class); mgr.requestStart(); } }
From source file:com.adaptris.core.runtime.AdapterRegistry.java
/** * Convenience method to close a set of adapter managers that uses * {@link AdapterManagerMBean#requestClose()} * * @param adapterManagers set of managers. * @throws CoreException wrapping other exceptions *///w w w . j a v a 2s .c o m public static void close(Set<ObjectName> adapterManagers) throws CoreException { for (ObjectName obj : adapterManagers) { AdapterManagerMBean mgr = JMX.newMBeanProxy(JmxHelper.findMBeanServer(), obj, AdapterManagerMBean.class); mgr.requestClose(); } }
From source file:com.adaptris.core.runtime.StandardMessageErrorDigestTest.java
public void testMBean_getDigestSubset_FromToIndex() throws Exception { String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName); StandardMessageErrorDigester digester = createDigester(getName()); adapter.setMessageErrorDigester(digester); List<BaseComponentMBean> mBeans = createJmxManagers(adapter); try {/*from w w w .j a va2 s .c om*/ start(adapter); register(mBeans); ObjectName adapterObj = createAdapterObjectName(adapterName); ObjectName digesterObj = createMessageErrorDigestObjectName(adapterName, getName()); StandardMessageErrorDigesterJmxMBean errDigesterBean = JMX.newMBeanProxy(mBeanServer, digesterObj, StandardMessageErrorDigesterJmxMBean.class); List<AdaptrisMessage> msgs = createListOfErrors(5, 1, getName(), null); for (AdaptrisMessage msg : msgs) { digester.digest(msg); } MessageErrorDigest digest = errDigesterBean.getDigestSubset(0, 5); assertEquals(5, digest.size()); for (MessageDigestErrorEntry e : digester.getDigest()) { assertTrue(e.getWorkflowId().startsWith("workflow")); assertNotNull(e.getStackTrace()); } } finally { stop(adapter); } }
From source file:com.adaptris.core.runtime.AdapterRegistry.java
/** * Convenience method to close a set of adapter managers that uses * {@link AdapterManagerMBean#requestStop()} * * @param adapterManagers set of managers. * @throws CoreException wrapping other exceptions *///w w w . j a v a 2 s . c om public static void stop(Set<ObjectName> adapterManagers) throws CoreException { for (ObjectName obj : adapterManagers) { AdapterManagerMBean mgr = JMX.newMBeanProxy(JmxHelper.findMBeanServer(), obj, AdapterManagerMBean.class); mgr.requestStop(); } }
From source file:com.adaptris.core.runtime.DefaultFailedMessageRetrierJmxTest.java
public void testMBean_Retry_File_NotFoundException() throws Exception { Adapter adapter = createAdapter(getName()); Channel c = createChannel(getName()); StandardWorkflow wf = createWorkflow(getName()); MockMessageProducer mock = new MockMessageProducer(); wf.setProducer(mock);/* www.ja va2 s. c o m*/ c.getWorkflowList().add(wf); adapter.getChannelList().add(c); DefaultFailedMessageRetrier retrier = new DefaultFailedMessageRetrier(); adapter.setFailedMessageRetrier(retrier); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); msg.addMetadata(Workflow.WORKFLOW_ID_KEY, getName() + "@BLAHBLAH"); File fileToRetry = writeFile(msg, new MimeEncoder()); fileToRetry.delete(); AdapterManager adapterManager = new AdapterManager(adapter); try { adapterManager.registerMBean(); adapterManager.requestStart(); ObjectName retrierObjName = createRetrierObjectName(adapterManager); DefaultFailedMessageRetrierJmxMBean jmxBean = JMX.newMBeanProxy(mBeanServer, retrierObjName, DefaultFailedMessageRetrierJmxMBean.class); try { jmxBean.retryMessage(fileToRetry); fail(); } catch (IOException expected) { } } finally { adapterManager.requestClose(); adapterManager.unregisterMBean(); } }
From source file:com.adaptris.core.runtime.AdapterRegistryTest.java
public void testCreateAdapterFromUrl_String() throws Exception { String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName, 2, 2); File filename = deleteLater(adapter); DefaultMarshaller.getDefaultMarshaller().marshal(adapter, filename); AdapterRegistry myAdapterRegistry = (AdapterRegistry) AdapterRegistry .findInstance(new JunitBootstrapProperties(new Properties())); ObjectName objName = myAdapterRegistry.createAdapterFromUrl(filename.toURI().toString()); assertNotNull(objName);//from w w w . j a v a2 s.co m 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.AdapterRegistry.java
/** * Convenience method to close a set of adapter managers that uses * {@link AdapterManagerMBean#unregisterMBean()} * * @param adapterManagers set of managers. * @throws CoreException wrapping other exceptions *///from www . ja v a2s . c om public static void unregister(Set<ObjectName> adapterManagers) throws CoreException { for (ObjectName obj : adapterManagers) { AdapterManagerMBean mgr = JMX.newMBeanProxy(JmxHelper.findMBeanServer(), obj, AdapterManagerMBean.class); mgr.unregisterMBean(); } }
From source file:com.adaptris.core.runtime.StandardMessageErrorDigestTest.java
public void testGetParentRuntimeInfo() throws Exception { String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName); adapter.setMessageErrorDigester(new StandardMessageErrorDigester(getName())); AdapterManager adapterManager = new AdapterManager(adapter); List<BaseComponentMBean> mBeans = new ArrayList<BaseComponentMBean>(); mBeans.add(adapterManager);/*ww w .j a va2s.c o m*/ mBeans.addAll(adapterManager.getAllDescendants()); try { register(mBeans); ObjectName adapterObj = adapterManager.createObjectName(); ObjectName digesterObj = createMessageErrorDigestObjectName(adapterName, getName()); StandardMessageErrorDigesterJmxMBean errDigester = JMX.newMBeanProxy(mBeanServer, digesterObj, StandardMessageErrorDigesterJmxMBean.class); assertEquals(adapterObj, errDigester.getParentObjectName()); assertEquals(adapterName, errDigester.getParentId()); } finally { } }