
com.app.common.cluster.ClusterManager Maven / Gradle / Ivy
package com.app.common.cluster;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
/**
* 集群管理
*
* @author deshuai.kong
*
*/
public class ClusterManager {
private static ConcurrentHashMap chm = new ConcurrentHashMap();
static {
addCluster(new ZkCluster());
addCluster(new DbCluster());
}
public static void addCluster(ICluster cluster) {
chm.put(cluster.getClusterName(), cluster);
}
public static void removeServerListener(String clusterName, IClusterServerListener clusterListener) {
ICluster c = chm.get(clusterName);
if (c != null) {
c.removeServerListener(clusterListener);
}
}
public static void addServerListener(String clusterName, IClusterServerListener clusterListener) throws Exception {
ICluster c = chm.get(clusterName);
if (c != null) {
c.addServerListener(clusterListener);
} else {
throw new Exception(clusterName + " is not exist.");
}
};
public static void startServer(String clusterName, ServerInfo serverInfo) throws Exception {
ICluster c = chm.get(clusterName);
if (c != null) {
c.startServer(serverInfo);
} else {
throw new Exception(clusterName + " is not exist.");
}
};
// client
public static void startClient(String clusterName, ServerInfo serverInfo, IClusterClientListener clusterListener) throws Exception{
ICluster c = chm.get(clusterName);
if (c != null) {
c.startClient(serverInfo,clusterListener);
} else {
throw new Exception(clusterName + " is not exist.");
}
}
public static List getServerInfo(String clusterName, ServerInfo serverInfo) throws Exception {
ICluster c = chm.get(clusterName);
if (c != null) {
return c.getServerInfo(serverInfo);
} else {
throw new Exception(clusterName + " is not exist.");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy