Example usage for javax.management JMX newMBeanProxy

List of usage examples for javax.management JMX newMBeanProxy

Introduction

In this page you can find the example usage for javax.management JMX newMBeanProxy.

Prototype

public static <T> T newMBeanProxy(MBeanServerConnection connection, ObjectName objectName,
        Class<T> interfaceClass) 

Source Link

Document

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:

  • proxy.getSomeAttribute() which will result in a call to mbs.

    Usage

    From source file:com.adaptris.core.runtime.AdapterRegistryTest.java

    public void testProxy_DestroyAdapter_ObjectName() throws Exception {
        AdapterRegistry myAdapterRegistry = (AdapterRegistry) AdapterRegistry
                .findInstance(new JunitBootstrapProperties(new Properties()));
        String adapterName = this.getClass().getSimpleName() + "." + getName();
        Adapter adapter = createAdapter(adapterName, 2, 2);
        String xml = DefaultMarshaller.getDefaultMarshaller().marshal(adapter);
        ObjectName objName = myAdapterRegistry.createAdapter(xml);
        assertTrue(mBeanServer.isRegistered(objName));
        assertEquals(1, myAdapterRegistry.getAdapters().size());
        AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, objName, AdapterManagerMBean.class);
        manager.requestStart();/*w w w  .j  ava 2 s  .  c o m*/
        myAdapterRegistry.destroyAdapter(objName);
        assertFalse(mBeanServer.isRegistered(objName));
        assertEquals(0, myAdapterRegistry.getAdapters().size());
    }
    

    From source file:com.adaptris.core.runtime.AdapterRegistryTest.java

    public void testStart() throws Exception {
        AdapterRegistry adapterRegistry = (AdapterRegistry) AdapterRegistry
                .findInstance(new JunitBootstrapProperties(new Properties()));
        String adapterName = this.getClass().getSimpleName() + "." + getName();
        Adapter adapter = createAdapter(adapterName, 2, 2);
        String xml = DefaultMarshaller.getDefaultMarshaller().marshal(adapter);
        ObjectName objName = adapterRegistry.createAdapter(xml);
        assertEquals(1, adapterRegistry.getAdapters().size());
        AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, objName, AdapterManagerMBean.class);
        AdapterRegistry.start(adapterRegistry.getAdapters());
        assertEquals(StartedState.getInstance(), manager.getComponentState());
    }
    

    From source file:com.adaptris.core.runtime.AdapterRegistryTest.java

    public void testStop() throws Exception {
        AdapterRegistry adapterRegistry = (AdapterRegistry) AdapterRegistry
                .findInstance(new JunitBootstrapProperties(new Properties()));
        String adapterName = this.getClass().getSimpleName() + "." + getName();
        Adapter adapter = createAdapter(adapterName, 2, 2);
        String xml = DefaultMarshaller.getDefaultMarshaller().marshal(adapter);
        ObjectName objName = adapterRegistry.createAdapter(xml);
        assertEquals(1, adapterRegistry.getAdapters().size());
        AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, objName, AdapterManagerMBean.class);
        manager.requestStart();//from  w w  w . ja  va 2 s.c  om
        AdapterRegistry.stop(adapterRegistry.getAdapters());
        assertEquals(StoppedState.getInstance(), manager.getComponentState());
    }
    

    From source file:com.adaptris.core.runtime.AdapterRegistryTest.java

    public void testClose() throws Exception {
        AdapterRegistry adapterRegistry = (AdapterRegistry) AdapterRegistry
                .findInstance(new JunitBootstrapProperties(new Properties()));
        String adapterName = this.getClass().getSimpleName() + "." + getName();
        Adapter adapter = createAdapter(adapterName, 2, 2);
        String xml = DefaultMarshaller.getDefaultMarshaller().marshal(adapter);
        ObjectName objName = adapterRegistry.createAdapter(xml);
        assertEquals(1, adapterRegistry.getAdapters().size());
        AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, objName, AdapterManagerMBean.class);
        manager.requestStart();/*from   ww  w.  j  a va2 s.co m*/
        AdapterRegistry.close(adapterRegistry.getAdapters());
        assertEquals(ClosedState.getInstance(), manager.getComponentState());
    }
    

    From source file:com.adaptris.core.runtime.AdapterRegistryTest.java

    public void testSendShutdownEvent() throws Exception {
        AdapterRegistry adapterRegistry = (AdapterRegistry) AdapterRegistry
                .findInstance(new JunitBootstrapProperties(new Properties()));
        String adapterName = this.getClass().getSimpleName() + "." + getName();
        Adapter adapter = createAdapter(adapterName, 2, 2);
        DefaultEventHandler evh = new DefaultEventHandler();
        StaticMockEventProducer producer = new StaticMockEventProducer(
                Arrays.asList(new Class[] { AdapterShutdownEvent.class }));
        producer.getMessages().clear();// w w w.j  a va 2s  . c  om
        evh.setProducer(producer);
        adapter.setEventHandler(evh);
        String xml = DefaultMarshaller.getDefaultMarshaller().marshal(adapter);
        ObjectName objName = adapterRegistry.createAdapter(xml);
        assertEquals(1, adapterRegistry.getAdapters().size());
        AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, objName, AdapterManagerMBean.class);
        manager.requestStart();
        assertEquals(0, producer.messageCount());
        // This should send an extra event.
        AdapterRegistry.sendShutdownEvent(adapterRegistry.getAdapters());
        waitForMessages(producer, 1);
        assertEquals(1, producer.messageCount());
        AdapterRegistry.close(adapterRegistry.getAdapters());
        producer.getMessages().clear();
    }
    

    From source file:com.spotify.reaper.cassandra.JmxProxy.java

    @Override
    public Map.Entry<String, ColumnFamilyStoreMBean> next() {
        ObjectName objectName = resIter.next();
        String keyspaceName = objectName.getKeyProperty("keyspace");
        ColumnFamilyStoreMBean cfsProxy = JMX.newMBeanProxy(mbeanServerConn, objectName,
                ColumnFamilyStoreMBean.class);
        return new AbstractMap.SimpleImmutableEntry<>(keyspaceName, cfsProxy);
    }
    

    From source file:com.adaptris.core.runtime.AdapterRegistryTest.java

    public void testSendShutdownEvent_AdapterAlreadyClosed() throws Exception {
        AdapterRegistry adapterRegistry = (AdapterRegistry) AdapterRegistry
                .findInstance(new JunitBootstrapProperties(new Properties()));
        String adapterName = this.getClass().getSimpleName() + "." + getName();
        Adapter adapter = createAdapter(adapterName, 2, 2);
        DefaultEventHandler evh = new DefaultEventHandler();
        StaticMockEventProducer producer = new StaticMockEventProducer(
                Arrays.asList(new Class[] { AdapterShutdownEvent.class }));
        producer.getMessages().clear();/*from   w  w  w .  j  ava  2  s  .  c  o  m*/
        evh.setProducer(producer);
        adapter.setEventHandler(evh);
        String xml = DefaultMarshaller.getDefaultMarshaller().marshal(adapter);
        ObjectName objName = adapterRegistry.createAdapter(xml);
        assertEquals(1, adapterRegistry.getAdapters().size());
        AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, objName, AdapterManagerMBean.class);
        manager.requestStart();
        manager.requestClose();
        assertEquals(0, producer.messageCount());
        // This shouldn't send an extra event because the adapter is already closed.
        AdapterRegistry.sendShutdownEvent(adapterRegistry.getAdapters());
        Thread.sleep(1000);
        assertEquals(0, producer.messageCount());
        AdapterRegistry.close(adapterRegistry.getAdapters());
        producer.getMessages().clear();
    }
    

    From source file:com.adaptris.core.runtime.AdapterRegistryTest.java

    public void testProxy_GetConfigurationURL() 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);
        URLString expectedURL = new URLString(filename);
        ObjectName objName = registry.createAdapter(expectedURL);
        assertNotNull(objName);//  w  ww .j  a v  a2s.  c o m
        assertTrue(mBeanServer.isRegistered(objName));
        assertEquals(expectedURL, registry.getConfigurationURL(objName));
    }
    

    From source file:com.adaptris.core.runtime.AdapterRegistryTest.java

    public void testProxy_GetConfigurationURL_NoURL() 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 w  w w.  j  av  a2  s.c  o  m*/
        assertTrue(mBeanServer.isRegistered(objName));
        assertNull(registry.getConfigurationURL(objName));
    }
    

    From source file:com.adaptris.core.runtime.AdapterRegistryTest.java

    public void testProxy_RemoveConfigurationURL() throws Exception {
        AdapterRegistry adapterRegistry = (AdapterRegistry) AdapterRegistry
                .findInstance(new JunitBootstrapProperties(new Properties()));
        AdapterRegistryMBean registry = JMX.newMBeanProxy(mBeanServer, adapterRegistry.createObjectName(),
                AdapterRegistryMBean.class);
        String adapterName = this.getClass().getSimpleName() + "." + getName();
        Adapter adapter = createAdapter(adapterName, 2, 2);
        File filename = deleteLater(adapter);
        DefaultMarshaller.getDefaultMarshaller().marshal(adapter, filename);
        URLString expectedURL = new URLString(filename);
        ObjectName objName = registry.createAdapter(expectedURL);
        assertNotNull(objName);//from  www.  ja v a 2s . c om
        assertTrue(mBeanServer.isRegistered(objName));
        assertEquals(expectedURL, registry.getConfigurationURL(objName));
        assertTrue(registry.removeConfigurationURL(objName));
        assertNull(registry.getConfigurationURL(objName));
        assertNull(adapterRegistry.getConfigurationURL(objName));
        assertFalse(registry.removeConfigurationURL(objName));
    }