Registry.java 991 Bytes
package se.lil.jm;

import java.net.MalformedURLException;
import java.util.ArrayList;

public class Registry {
	private static ArrayList<JmxMon> jmxList = null;
	public static boolean test = true;
	
	public static synchronized ArrayList<JmxMon> getList() {
		if (jmxList == null) {
			jmxList = new ArrayList<JmxMon>();
		}
		return jmxList;
	}
	
	public static synchronized JmxMon findOrCreate(String conStr) throws MalformedURLException {
		for (JmxMon item : getList()) {
			if(item.getConString().equals(conStr)) {
				return item;
			}
		}
		// Not found, create it
		JmxMon monitor = new JmxMon(conStr);
		jmxList.add(monitor);
		return monitor;
	}
	
	public static synchronized void remove(String conStr) {
		JmxMon mon = null;
		for (JmxMon item : getList()) {
			if(item.getConString().equals(conStr)) {
				mon = item;
			}
		}
		if(mon != null) {
			try {
				mon.close();
			} catch (Throwable t) {}
			getList().remove(mon);
		}
	}
}