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.StandardMessageErrorDigestTest.java

    public void testMBean_GetMessageDigest() throws Exception {
        String adapterName = this.getClass().getSimpleName() + "." + getName();
        Adapter adapter = createAdapter(adapterName);
        StandardMessageErrorDigester digester = createDigester();
        digester.setUniqueId(getName());//from  ww  w  .  ja  v a  2s .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());
        } finally {
            stop(adapter);
        }
    }
    

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

    public void testApplyService_WithConnections_Rewrite() throws Exception {
        String adapterName = this.getClass().getSimpleName() + "." + getName();
        Adapter adapter = createAdapter(adapterName, 2, 2);
        adapter.getSharedComponents().addConnection(new NullConnection(getName()));
        List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
        ObjectName objectName = createComponentCheckerObjectName(adapterName);
        LifecycleHelper.initAndStart(adapter);
        register(mBeans);/*from w  w  w . ja  v  a 2  s. c o m*/
        // Must init & start because of shared connections.
        LifecycleHelper.initAndStart(adapter);
        AdapterComponentCheckerMBean manager = JMX.newMBeanProxy(mBeanServer, objectName,
                AdapterComponentCheckerMBean.class);
        AdaptrisMessage msg = new DefaultSerializableMessageTranslator().translate(
                manager.applyService(createConnectedServices(getName()), createSerializableMessage(), true));
        assertTrue(msg.containsKey("key"));
        assertEquals("value", msg.getMetadataValue("key"));
    }
    

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

    public void testMBean_Retry_File() throws Exception {
        Adapter adapter = createAdapter(getName());
        Channel c = createChannel(getName());
        StandardWorkflow wf = createWorkflow(getName());
        MockMessageProducer mock = new MockMessageProducer();
        wf.setProducer(mock);//w  w  w .  java 2  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() + "@" + getName());
        File fileToRetry = writeFile(msg, new MimeEncoder());
    
        AdapterManager adapterManager = new AdapterManager(adapter);
        try {
            adapterManager.registerMBean();
            adapterManager.requestStart();
            ObjectName retrierObjName = createRetrierObjectName(adapterManager);
            DefaultFailedMessageRetrierJmxMBean jmxBean = JMX.newMBeanProxy(mBeanServer, retrierObjName,
                    DefaultFailedMessageRetrierJmxMBean.class);
            assertTrue(jmxBean.retryMessage(fileToRetry));
            waitForMessages(mock, 1);
            assertEquals(1, mock.messageCount());
        } finally {
            adapterManager.requestClose();
            adapterManager.unregisterMBean();
        }
    }
    

    From source file:co.runrightfast.vertx.core.application.RunRightFastVertxApplicationLauncherTest.java

    @Test
    public void testRunApp() throws Exception {
        ForkJoinPool.commonPool().execute(() -> RunRightFastVertxApplicationLauncher.run(() -> app));
    
        final RunRightFastVerticleId verticleManagerId = RunRightFastVerticleManager.VERTICLE_ID;
        final CompletableFuture future = new CompletableFuture();
        final String address = EventBusAddress.eventBusAddress(verticleManagerId, "get-verticle-deployments");
        final Vertx vertx = app.vertxService().getVertx();
        vertx.eventBus().send(address, GetVerticleDeployments.Request.newBuilder().build(),
                new DeliveryOptions().setSendTimeout(2000L), getVerticleDeploymentsResponseHandler(future));
        final Object result = future.get(2000L, TimeUnit.MILLISECONDS);
    
        final ApplicationMXBean appMXBean = JMX.newMBeanProxy(ManagementFactory.getPlatformMBeanServer(),
                applicationMBeanObjectName(JmxUtils.RUNRIGHTFAST_JMX_DOMAIN, ApplicationMXBean.class),
                ApplicationMXBean.class);
        assertThat(appMXBean.getApplicationGroup(), is("co.runrightfast"));
        assertThat(appMXBean.getApplicationName(), is("test-app"));
        assertThat(appMXBean.getApplicationVersion(), is("1.0.0"));
        log.logp(INFO, getClass().getName(), "testRunApp", "{0}:\n{1}",
                new Object[] { "configAsHConf", appMXBean.configAsHConf() });
        log.logp(INFO, getClass().getName(), "testRunApp", "{0}:\n{1}",
                new Object[] { "configAsHJson", appMXBean.configAsJson() });
        log.logp(INFO, getClass().getName(), "testRunApp", "{0}:\n{1}",
                new Object[] { "configWithCommentsAndSourceInfo", appMXBean.configWithCommentsAndSourceInfo() });
        appMXBean.shutdown();//from   ww w  . j a v a2s.  co  m
        app.vertxService().awaitTerminated();
    }
    

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

    public void testApplyService_WithConnections_NoRewrite() throws Exception {
        String adapterName = this.getClass().getSimpleName() + "." + getName();
        Adapter adapter = createAdapter(adapterName, 2, 2);
        adapter.getSharedComponents().addConnection(new NullConnection(getName()));
        List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
        ObjectName objectName = createComponentCheckerObjectName(adapterName);
        register(mBeans);//from   ww w . j a v a2  s.com
        AdapterComponentCheckerMBean manager = JMX.newMBeanProxy(mBeanServer, objectName,
                AdapterComponentCheckerMBean.class);
        AdaptrisMessage msg = new DefaultSerializableMessageTranslator()
                .translate(manager.applyService(createConnectedServices(null), createSerializableMessage(), false));
        assertTrue(msg.containsKey("key"));
        assertEquals("value", msg.getMetadataValue("key"));
    }
    

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

    public void testMBean_GetMessageDigestMultipleWorkflow() throws Exception {
        String adapterName = this.getClass().getSimpleName() + "." + getName();
        Adapter adapter = createAdapter(adapterName);
        adapter.setMessageErrorDigester(new StandardMessageErrorDigester(getName()));
        Channel channel1 = createChannel("channel1");
        StandardWorkflow workflow1 = createWorkflow("workflow1");
        StandardWorkflow workflow2 = createWorkflow("workflow2");
        workflow1.getServiceCollection().add(new ThrowExceptionService(new ConfiguredException("fail1")));
        workflow2.getServiceCollection().add(new ThrowExceptionService(new ConfiguredException("fail2")));
        channel1.getWorkflowList().add(workflow1);
        channel1.getWorkflowList().add(workflow2);
        adapter.getChannelList().add(channel1);
        List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    
        try {/* w  w w .  j  a v  a  2s.c  o  m*/
            start(adapter);
            register(mBeans);
            ObjectName adapterObj = createAdapterObjectName(adapterName);
            ObjectName digesterObj = createMessageErrorDigestObjectName(adapterName, getName());
            StandardMessageErrorDigesterJmxMBean errDigester = JMX.newMBeanProxy(mBeanServer, digesterObj,
                    StandardMessageErrorDigesterJmxMBean.class);
    
            workflow1.onAdaptrisMessage(new DefaultMessageFactory().newMessage("Hello Workflow1"));
            workflow2.onAdaptrisMessage(new DefaultMessageFactory().newMessage("Hello Workflow2"));
    
            // They should have failed.
            assertNotNull(errDigester.getDigest());
            assertEquals(2, errDigester.getDigest().size());
            assertEquals(2, errDigester.getTotalErrorCount());
            MessageDigestErrorEntry entry1 = errDigester.getDigest().get(0);
            MessageDigestErrorEntry entry2 = errDigester.getDigest().get(1);
            assertEquals("workflow1@channel1", entry1.getWorkflowId());
            assertEquals("workflow2@channel1", entry2.getWorkflowId());
        } finally {
            stop(adapter);
        }
    }
    

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

    public void testMBean_Retry_File_WorkflowNotFound() throws Exception {
        Adapter adapter = createAdapter(getName());
        Channel c = createChannel(getName());
        StandardWorkflow wf = createWorkflow(getName());
        MockMessageProducer mock = new MockMessageProducer();
        wf.setProducer(mock);/*  ww  w  .j  a  v  a 2s.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());
    
        AdapterManager adapterManager = new AdapterManager(adapter);
        try {
            adapterManager.registerMBean();
            adapterManager.requestStart();
            ObjectName retrierObjName = createRetrierObjectName(adapterManager);
            DefaultFailedMessageRetrierJmxMBean jmxBean = JMX.newMBeanProxy(mBeanServer, retrierObjName,
                    DefaultFailedMessageRetrierJmxMBean.class);
    
            assertFalse(jmxBean.retryMessage(fileToRetry));
            assertEquals(0, mock.messageCount());
        } finally {
            adapterManager.requestClose();
            adapterManager.unregisterMBean();
        }
    }
    

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

    /**
     * Convenience method for sending a shutdown event for every adapter.
     * //from  w w w . j  av a  2s .c  o m
     * @param adapterManagers set of managers.
     */
    public static void sendShutdownEvent(Set<ObjectName> adapterManagers) {
        for (ObjectName obj : adapterManagers) {
            AdapterManagerMBean mgr = JMX.newMBeanProxy(JmxHelper.findMBeanServer(), obj,
                    AdapterManagerMBean.class);
            try {
                mgr.sendLifecycleEvent(EventFactory.create(AdapterShutdownEvent.class));
            } catch (CoreException e) {
                log.warn("Failed to send ShutdownEvent for " + mgr.getUniqueId());
            }
        }
    }
    

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

    public void testMBean_getDigestSubset_FromIndex() 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  ava 2  s  .  c  o  m*/
            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);
            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.DefaultFailedMessageRetrierJmxTest.java

    public void testMBean_Retry_File_NotEncoded() throws Exception {
        Adapter adapter = createAdapter(getName());
        Channel c = createChannel(getName());
        StandardWorkflow wf = createWorkflow(getName());
        MockMessageProducer mock = new MockMessageProducer();
        wf.setProducer(mock);//from  w ww.j a v a 2  s  .  c om
        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, null);
    
        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 (CoreException expected) {
    
            }
        } finally {
            adapterManager.requestClose();
            adapterManager.unregisterMBean();
        }
    }