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.interceptor.MessageMetricsStatisticsTest.java

    public void testNoCachesExists() throws Exception {
        String adapterName = this.getClass().getSimpleName() + "." + getName();
    
        Adapter adapter = createAdapter(adapterName);
        List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
        try {//  w ww .j  a  v a 2 s.co m
            start(adapter);
            register(mBeans);
            ObjectName adapterObj = createAdapterObjectName(adapterName);
            ObjectName metricsObj = createMetricsObjectName(adapterName);
            MessageMetricsStatisticsMBean metrics = JMX.newMBeanProxy(mBeanServer, metricsObj,
                    MessageMetricsStatisticsMBean.class);
            assertEquals(0, metrics.getNumberOfTimeSlices());
        } finally {
            stop(adapter);
        }
    }
    

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

    public void testInFlightMessageCount() throws Exception {
        PoolingWorkflow workflow = new PoolingWorkflow(getName());
        Adapter adapter = buildAdapter(workflow);
        AdapterManager adapterManager = new AdapterManager(adapter);
        try {//from ww  w . j  av a2s .c o  m
            adapterManager.registerMBean();
            ObjectName objName = createInFlightObjectName(adapterManager);
            MessageInFlightMBean mbean = JMX.newMBeanProxy(mBeanServer, objName, MessageInFlightMBean.class);
            assertNotNull(mbean);
            assertEquals(0, mbean.messagesInFlightCount());
            adapterManager.requestStart();
            workflow.onAdaptrisMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
            LifecycleHelper.waitQuietly(100L);
            assertEquals(1, mbean.messagesInFlightCount());
            assertTrue(mbean.messagesInFlight());
        } finally {
            adapterManager.requestClose();
            adapterManager.unregisterMBean();
        }
    }
    

    From source file:com.adaptris.core.interceptor.MessageMetricsStatisticsByMetadataTest.java

    @Override
    public void testGetMessageStatistics() throws Exception {
        String adapterName = this.getClass().getSimpleName() + "." + getName();
        String payload = "SomePayload";
        MessageMetricsInterceptorByMetadata interceptor = (MessageMetricsInterceptorByMetadata) createInterceptor();
        interceptor.setUniqueId(getName());/*  w w w. j av a2 s  .  c om*/
        Adapter adapter = createSingleChannelAdapter(adapterName, interceptor);
        List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
        try {
            start(adapter);
            register(mBeans);
            ObjectName workflowObj = createWorkflowObjectName(adapterName);
            ObjectName metricsObj = createMetricsObjectName(adapterName, getName());
            MessageMetricsStatisticsMBean stats = JMX.newMBeanProxy(mBeanServer, metricsObj,
                    MessageMetricsStatisticsMBean.class);
            MessageProcessor workflow = JMX.newMBeanProxy(mBeanServer, workflowObj, MessageProcessor.class);
            workflow.processAsync(createMessageForInjection(payload));
    
            assertEquals(1, stats.getStatistics().size());
            assertEquals(interceptor.getStats().size(), stats.getStatistics().size());
            MessageStatistic interceptorStat = (MessageStatistic) interceptor.getStats().get(0);
            MessageStatistic mbeanStat = stats.getStatistics().get(0);
    
            assertNotSame(interceptorStat, mbeanStat); // They're not objectively equals (not clones), and no equals method.
    
            assertEquals(interceptorStat.getEndMillis(), mbeanStat.getEndMillis());
            assertEquals(interceptorStat.getTotalMessageCount(), mbeanStat.getTotalMessageCount());
            assertEquals(interceptorStat.getTotalMessageErrorCount(), mbeanStat.getTotalMessageErrorCount());
            assertEquals(interceptorStat.getTotalMessageSize(), mbeanStat.getTotalMessageSize());
        } finally {
            stop(adapter);
        }
    }
    

    From source file:com.adaptris.core.interceptor.MetadataCountMBeanTest.java

    public void testGetMetadataStatistics() throws Exception {
        String adapterName = this.getClass().getSimpleName() + "." + getName();
        MetadataTotalsInterceptor interceptor = createInterceptor();
        interceptor.setUniqueId(getName());/*from w  w  w. j  ava2  s .  co  m*/
        Adapter adapter = createSingleChannelAdapter(adapterName, interceptor);
    
        List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
        try {
            start(adapter);
            register(mBeans);
            ObjectName workflowObj = createWorkflowObjectName(adapterName);
            ObjectName metricsObj = createMetricsObjectName(adapterName, getName());
            MetadataStatisticsMBean stats = JMX.newMBeanProxy(mBeanServer, metricsObj,
                    MetadataStatisticsMBean.class);
            WorkflowManagerMBean workflow = JMX.newMBeanProxy(mBeanServer, workflowObj, WorkflowManagerMBean.class);
            SerializableAdaptrisMessage msg = createMessageForInjection(null);
            workflow.processAsync(msg);
    
            assertEquals(1, stats.getStatistics().size());
            assertEquals(interceptor.getStats().size(), stats.getStatistics().size());
    
            MetadataStatistic interceptorStat = (MetadataStatistic) interceptor.getStats().get(0);
            MetadataStatistic mbeanStat = stats.getStatistics().get(0);
    
            assertNotSame(interceptorStat, mbeanStat); // They're not objectively equals (not clones), and no equals method.
            assertEquals(interceptorStat.getEndMillis(), mbeanStat.getEndMillis());
            assertEquals(interceptorStat.getMetadataStatistics(), mbeanStat.getMetadataStatistics());
        } finally {
            stop(adapter);
        }
    }
    

    From source file:com.adaptris.core.interceptor.MetadataTotalsMBeanTest.java

    public void testGetMetadataStatistics() throws Exception {
        String adapterName = this.getClass().getSimpleName() + "." + getName();
        MetadataCountInterceptor interceptor = createInterceptor();
        interceptor.setUniqueId(getName());//  w  w w .  j  a  v  a  2  s .  c o m
        Adapter adapter = createSingleChannelAdapter(adapterName, interceptor);
    
        List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
        try {
            start(adapter);
            register(mBeans);
            ObjectName workflowObj = createWorkflowObjectName(adapterName);
            ObjectName metricsObj = createMetricsObjectName(adapterName, getName());
            MetadataStatisticsMBean stats = JMX.newMBeanProxy(mBeanServer, metricsObj,
                    MetadataStatisticsMBean.class);
            WorkflowManagerMBean workflow = JMX.newMBeanProxy(mBeanServer, workflowObj, WorkflowManagerMBean.class);
            SerializableAdaptrisMessage msg = createMessageForInjection(null);
            workflow.processAsync(msg);
    
            assertEquals(1, stats.getStatistics().size());
            assertEquals(interceptor.getStats().size(), stats.getStatistics().size());
    
            MetadataStatistic interceptorStat = (MetadataStatistic) interceptor.getStats().get(0);
            MetadataStatistic mbeanStat = stats.getStatistics().get(0);
    
            assertNotSame(interceptorStat, mbeanStat); // They're not objectively equals (not clones), and no equals method.
            assertEquals(interceptorStat.getEndMillis(), mbeanStat.getEndMillis());
            assertEquals(interceptorStat.getMetadataStatistics(), mbeanStat.getMetadataStatistics());
        } finally {
            stop(adapter);
        }
    }
    

    From source file:com.adaptris.core.interceptor.MessageMetricsStatisticsTest.java

    public void testGetMessageStatistics() throws Exception {
        String adapterName = this.getClass().getSimpleName() + "." + getName();
        String payload = "SomePayload";
        MessageMetricsInterceptor interceptor = (MessageMetricsInterceptor) createInterceptor();
        interceptor.setUniqueId(getName());/*from   ww w. j a  v  a  2  s . c  om*/
        Adapter adapter = createSingleChannelAdapter(adapterName, interceptor);
        List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
        try {
            start(adapter);
            register(mBeans);
            ObjectName workflowObj = createWorkflowObjectName(adapterName);
            ObjectName metricsObj = createMetricsObjectName(adapterName, getName());
            MessageMetricsStatisticsMBean stats = JMX.newMBeanProxy(mBeanServer, metricsObj,
                    MessageMetricsStatisticsMBean.class);
            MessageProcessor workflow = JMX.newMBeanProxy(mBeanServer, workflowObj, MessageProcessor.class);
            workflow.processAsync(createMessageForInjection(payload));
    
            assertEquals(1, stats.getStatistics().size());
            assertEquals(interceptor.getStats().size(), stats.getStatistics().size());
            MessageStatistic interceptorStat = (MessageStatistic) interceptor.getStats().get(0);
            MessageStatistic mbeanStat = stats.getStatistics().get(0);
    
            assertNotSame(interceptorStat, mbeanStat); // They're not objectively equals (not clones), and no equals method.
    
            assertEquals(interceptorStat.getEndMillis(), mbeanStat.getEndMillis());
            assertEquals(interceptorStat.getTotalMessageCount(), mbeanStat.getTotalMessageCount());
            assertEquals(interceptorStat.getTotalMessageErrorCount(), mbeanStat.getTotalMessageErrorCount());
            assertEquals(interceptorStat.getTotalMessageSize(), mbeanStat.getTotalMessageSize());
        } finally {
            stop(adapter);
        }
    }
    

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

    public void testMBean_FailAllMessages() 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 v  a  2 s .  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.failAllMessages(true);
            assertEquals(1, failProducer.messageCount());
            handler.handleProcessingException(AdaptrisMessageFactory.getDefaultInstance().newMessage());
            // All msgs Fail.
            assertEquals(0, mbean.waitingForRetry().size());
            assertEquals(2, failProducer.messageCount());
        } finally {
            adapterManager.requestClose();
        }
    }
    

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

    public void testRegistered() 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 . j  a  v  a2 s. c o m*/
        ObjectName adapterObj = createAdapterObjectName(adapterName);
        AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
        Collection<ObjectName> names = manager.getChildRuntimeInfoComponents();
        assertTrue(names.contains(objectName));
    }
    

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

    public void testPendingMessageCount() throws Exception {
        final PoolingWorkflow workflow = new PoolingWorkflow(getName());
        Adapter adapter = buildAdapter(workflow);
        AdapterManager adapterManager = new AdapterManager(adapter);
        try {/*from  w w  w . j  av a2  s  .c  o  m*/
            adapterManager.registerMBean();
            ObjectName objName = createInFlightObjectName(adapterManager);
            MessageInFlightMBean mbean = JMX.newMBeanProxy(mBeanServer, objName, MessageInFlightMBean.class);
            assertNotNull(mbean);
            assertEquals(0, mbean.messagesInFlightCount());
            adapterManager.requestStart();
            workflow.onAdaptrisMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
            new Thread(new Runnable() {
    
                @Override
                public void run() {
                    workflow.onAdaptrisMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
                }
    
            }).start();
            LifecycleHelper.waitQuietly(200L);
            assertEquals(1, mbean.messagesInFlightCount());
            assertTrue(mbean.messagesInFlight());
            assertEquals(1, mbean.messagesPendingCount());
        } finally {
            adapterManager.requestClose();
            adapterManager.unregisterMBean();
        }
    }
    

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

    public void testMBean_GetParentId() throws Exception {
        Adapter adapter = createAdapter(getName());
        FileLogHandler handler = createHandler();
        adapter.setLogHandler(handler);//from  w  w  w.  j a v  a2s.c  om
        AdapterManager adapterManager = new AdapterManager(adapter);
        ObjectName flhObjName = createFileHandlerObjectName(adapterManager);
        try {
            adapterManager.registerMBean();
            FileLogHandlerJmxMBean fileLogHandlerProxy = JMX.newMBeanProxy(mBeanServer, flhObjName,
                    FileLogHandlerJmxMBean.class);
            assertNotNull(fileLogHandlerProxy);
            assertEquals(getName(), fileLogHandlerProxy.getParentId());
        } finally {
            adapterManager.unregisterMBean();
        }
    
    }