Mule ESB 学习笔记(17)Mule和JMX的整合

阅读更多

Agent的实现:

package com.easyway.esb.mule.mbean;

import org.mule.api.MuleException;
import org.mule.api.agent.Agent;
import org.mule.api.lifecycle.InitialisationException;

import java.util.Collections;
import java.util.List;

/**
必须继承自org.mule.api.agent.Agent接口.
 * Mock agent
 */
public class AutoTaskAgent implements Agent
{

    private String frobbit;

    public String getName()
    {
        return "Test Agent";
    }

    public void setName(String name)
    {
        // nothing to do
    }

    public String getDescription()
    {
        return "Test JMX Agent";
    }

    public void initialise() throws InitialisationException
    {
        // nothing to do
    }

    public void start() throws MuleException
    {
        // nothing to do
    }

    public void stop() throws MuleException
    {
        // nothing to do
    }

    public void dispose()
    {
        // nothing to do
    }

    public List> getDependentAgents()
    {
        return Collections.emptyList();
    }

    public String getFrobbit()
    {
        return frobbit;
    }

    public void setFrobbit(String frobbit)
    {
        this.frobbit = frobbit;
    }
}

 

 

 

mule-mbean-config.xml的配置



    
        
        
            
            
        
    

    

    

    
        
    

    

    

    

 

 

 

jmx测试代码:

public class MuleAgentMain {
    public static void main(String[] args) throws Exception, ConfigurationException {
        String configFile = "mule-mbean-config.xml";
        String[] configFileArr = new String[] {configFile };
        MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
        MuleContext muleContext = muleContextFactory
                .createMuleContext(new SpringXmlConfigurationBuilder(configFileArr));
        muleContext.start();
        
        Agent agent = muleContext.getRegistry().lookupObject(JmxAgent.class);
        System.out.println(agent.getClass());
        JmxAgent jmxAgent = (JmxAgent) agent;
        System.out.println(jmxAgent.isCreateServer());
        System.out.println(jmxAgent.isLocateServer());
        System.out.println(jmxAgent.isEnableStatistics());
        System.out.println(jmxAgent.getConnectorServerUrl());

        agent = muleContext.getRegistry().lookupAgent("jmx-log4j");
        System.out.println(agent.getClass());

        agent = muleContext.getRegistry().lookupAgent("jmx-mx4j-adaptor");
        System.out.println( agent.getClass());
        Mx4jAgent mx4jAgent = (Mx4jAgent) agent;
        System.out.println(mx4jAgent.getJmxAdaptorUrl());

        agent = muleContext.getRegistry().lookupAgent("jmx-notifications");
        System.out.println(agent.getClass());

        agent = muleContext.getRegistry().lookupAgent("log4j-notifications");
        System.out.println(agent.getClass());

        agent = muleContext.getRegistry().lookupAgent("chainsaw-notifications");
        System.out.println(agent.getClass());
        Log4jNotificationLoggerAgent lnlAgent = (Log4jNotificationLoggerAgent) agent;
        System.out.println(lnlAgent.getChainsawPort()+" "+lnlAgent.getChainsawHost());

        agent = muleContext.getRegistry().lookupAgent("test-custom-agent");
        AutoTaskAgent autoTaskAgent=(AutoTaskAgent) agent;
        System.out.println( autoTaskAgent.getFrobbit());
        autoTaskAgent.setFrobbit("aaa");
        agent = muleContext.getRegistry().lookupAgent("test-custom-agent");
        System.out.println(((AutoTaskAgent)agent).getFrobbit());
    }
}

 

你可能感兴趣的:(mule,ESB,SOA,JMX)