// Path: src/main/java/com/thenetcircle/comsumerdispatcher/config/DispatcherConfig.java
// public class DispatcherConfig {
// 
// 	private static DispatcherConfig _self = null;
// 	private List<JobExecutor> allJobs = null;
// 	private Map<String, QueueConf> servers = null;
// 	private MonitorConf monitorConf = null;
// 
// 	public static synchronized DispatcherConfig getInstance() {
// 		if (null == _self) {
// 			_self = new DispatcherConfig();
// 		}
// 		return _self;
// 	}
// 	
// 	public void loadConfig(String configFilePath) throws Exception {
// 		ConfigLoader cLoader = null; 
// 		if (null == configFilePath) {
// 			cLoader = new DistributedConfigLoader(DistributionManager.getInstance().getZk());
// 		} else {
// 			cLoader = new FileConfigLoader(configFilePath);
// 		}
// 		
// 		setServers(cLoader.loadServers());// go first
// 		setAllJobs(cLoader.loadAllJobs());
// 		setMonitorConf(cLoader.loadJmxConfig());
// 	}
// 	
// 	public List<JobExecutor> getAllJobs() {
// 		return this.allJobs;
// 	}
// 	
// 	public Map<String, QueueConf> getServers() {
// 		return this.servers;
// 	}
// 	
// 	public MonitorConf getMonitorConf() {
// 		return monitorConf;
// 	}
// 	
// 	public void setAllJobs(List<JobExecutor> allJobs) {
// 		this.allJobs = allJobs;
// 	}
// 
// 	public void setServers(Map<String, QueueConf> servers) {
// 		this.servers = servers;
// 	}
// 
// 	public void setMonitorConf(MonitorConf monitorConf) {
// 		this.monitorConf = monitorConf;
// 	}
// 
// 	private DispatcherConfig() {
// 	}
// }
// 
// Path: src/main/java/com/thenetcircle/comsumerdispatcher/config/MonitorConf.java
// public class MonitorConf {
// 	// jmx config
// 	private String jmxRmiHost = null;
// 	private int jmxRmiPort;
// 	private String jmxHttpHost = null;
// 	private int jmxHttpPort;
// 	
// 	public String getJmxRmiHost() {
// 		return jmxRmiHost;
// 	}
// 
// 	public int getJmxRmiPort() {
// 		return jmxRmiPort;
// 	}
// 
// 	public String getJmxHttpHost() {
// 		return jmxHttpHost;
// 	}
// 
// 	public int getJmxHttpPort() {
// 		return jmxHttpPort;
// 	}
// 
// 	public void setJmxRmiHost(String jmxRmiHost) {
// 		this.jmxRmiHost = jmxRmiHost;
// 	}
// 
// 	public void setJmxRmiPort(int jmxRmiPort) {
// 		this.jmxRmiPort = jmxRmiPort;
// 	}
// 
// 	public void setJmxHttpHost(String jmxHttpHost) {
// 		this.jmxHttpHost = jmxHttpHost;
// 	}
// 
// 	public void setJmxHttpPort(int jmxHttpPort) {
// 		this.jmxHttpPort = jmxHttpPort;
// 	}
// 	
// 	
// }


import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.rmi.registry.LocateRegistry;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.thenetcircle.comsumerdispatcher.config.DispatcherConfig;
import com.thenetcircle.comsumerdispatcher.config.MonitorConf;
package com.thenetcircle.comsumerdispatcher.jmx;





public class ConsumerDispatcherMonitor {
	private static Log _logger = LogFactory.getLog(ConsumerDispatcherMonitor.class);
	
	private static final String fmtUrl = "service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi";
	
	public static void enableMonitor() {
		try {
			enableJMXRmi();
		} catch (IOException e) {
			e.printStackTrace();
		}
		maybeEnableJMXHttp();
	}
	
	protected static void enableJMXRmi() throws IOException {
// Path: src/main/java/com/thenetcircle/comsumerdispatcher/config/DispatcherConfig.java
// public class DispatcherConfig {
// 
// 	private static DispatcherConfig _self = null;
// 	private List<JobExecutor> allJobs = null;
// 	private Map<String, QueueConf> servers = null;
// 	private MonitorConf monitorConf = null;
// 
// 	public static synchronized DispatcherConfig getInstance() {
// 		if (null == _self) {
// 			_self = new DispatcherConfig();
// 		}
// 		return _self;
// 	}
// 	
// 	public void loadConfig(String configFilePath) throws Exception {
// 		ConfigLoader cLoader = null; 
// 		if (null == configFilePath) {
// 			cLoader = new DistributedConfigLoader(DistributionManager.getInstance().getZk());
// 		} else {
// 			cLoader = new FileConfigLoader(configFilePath);
// 		}
// 		
// 		setServers(cLoader.loadServers());// go first
// 		setAllJobs(cLoader.loadAllJobs());
// 		setMonitorConf(cLoader.loadJmxConfig());
// 	}
// 	
// 	public List<JobExecutor> getAllJobs() {
// 		return this.allJobs;
// 	}
// 	
// 	public Map<String, QueueConf> getServers() {
// 		return this.servers;
// 	}
// 	
// 	public MonitorConf getMonitorConf() {
// 		return monitorConf;
// 	}
// 	
// 	public void setAllJobs(List<JobExecutor> allJobs) {
// 		this.allJobs = allJobs;
// 	}
// 
// 	public void setServers(Map<String, QueueConf> servers) {
// 		this.servers = servers;
// 	}
// 
// 	public void setMonitorConf(MonitorConf monitorConf) {
// 		this.monitorConf = monitorConf;
// 	}
// 
// 	private DispatcherConfig() {
// 	}
// }
// 
// Path: src/main/java/com/thenetcircle/comsumerdispatcher/config/MonitorConf.java
// public class MonitorConf {
// 	// jmx config
// 	private String jmxRmiHost = null;
// 	private int jmxRmiPort;
// 	private String jmxHttpHost = null;
// 	private int jmxHttpPort;
// 	
// 	public String getJmxRmiHost() {
// 		return jmxRmiHost;
// 	}
// 
// 	public int getJmxRmiPort() {
// 		return jmxRmiPort;
// 	}
// 
// 	public String getJmxHttpHost() {
// 		return jmxHttpHost;
// 	}
// 
// 	public int getJmxHttpPort() {
// 		return jmxHttpPort;
// 	}
// 
// 	public void setJmxRmiHost(String jmxRmiHost) {
// 		this.jmxRmiHost = jmxRmiHost;
// 	}
// 
// 	public void setJmxRmiPort(int jmxRmiPort) {
// 		this.jmxRmiPort = jmxRmiPort;
// 	}
// 
// 	public void setJmxHttpHost(String jmxHttpHost) {
// 		this.jmxHttpHost = jmxHttpHost;
// 	}
// 
// 	public void setJmxHttpPort(int jmxHttpPort) {
// 		this.jmxHttpPort = jmxHttpPort;
// 	}
// 	
// 	
// }


// Path: src/main/java/com/thenetcircle/comsumerdispatcher/jmx/ConsumerDispatcherMonitor.java
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.rmi.registry.LocateRegistry;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.thenetcircle.comsumerdispatcher.config.DispatcherConfig;
import com.thenetcircle.comsumerdispatcher.config.MonitorConf;

package com.thenetcircle.comsumerdispatcher.jmx;





public class ConsumerDispatcherMonitor {
	private static Log _logger = LogFactory.getLog(ConsumerDispatcherMonitor.class);
	
	private static final String fmtUrl = "service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi";
	
	public static void enableMonitor() {
		try {
			enableJMXRmi();
		} catch (IOException e) {
			e.printStackTrace();
		}
		maybeEnableJMXHttp();
	}
	
	protected static void enableJMXRmi() throws IOException {
		MonitorConf config = DispatcherConfig.getInstance().getMonitorConf();