1 28 29 package com.caucho.server.cluster; 30 31 import com.caucho.loader.EnvironmentLocal; 32 import com.caucho.log.Log; 33 import com.caucho.util.L10N; 34 35 import java.util.ArrayList ; 36 import java.util.logging.Logger ; 37 38 43 public class ClusterGroup { 44 private static final L10N L = new L10N(ClusterGroup.class); 45 private static final Logger log = Log.open(ClusterGroup.class); 46 47 static protected final EnvironmentLocal<ClusterGroup> _clusterGroupLocal 48 = new EnvironmentLocal<ClusterGroup>(); 49 50 private final ArrayList <Cluster> _clusterList 51 = new ArrayList <Cluster>(); 52 53 private ClusterGroup() 54 { 55 } 56 57 60 public static ClusterGroup getClusterGroup() 61 { 62 return _clusterGroupLocal.get(); 63 } 64 65 68 public static ClusterGroup createClusterGroup() 69 { 70 ClusterGroup group = _clusterGroupLocal.getLevel(); 71 72 if (group == null) { 73 group = new ClusterGroup(); 74 _clusterGroupLocal.set(group); 75 } 76 77 return group; 78 } 79 80 83 public void addCluster(Cluster cluster) 84 { 85 if (! _clusterList.contains(cluster)) 86 _clusterList.add(cluster); 87 } 88 89 92 public ArrayList <Cluster> getClusterList() 93 { 94 return _clusterList; 95 } 96 97 100 public Cluster findCluster(String id) 101 { 102 for (int i = _clusterList.size() - 1; i >= 0; i--) { 103 Cluster cluster = _clusterList.get(i); 104 105 if (cluster.getId().equals(id)) 106 return cluster; 107 } 108 109 return null; 110 } 111 112 115 public ClusterClient findClient(String host, int port) 116 { 117 for (int i = _clusterList.size() - 1; i >= 0; i--) { 118 Cluster cluster = _clusterList.get(i); 119 120 ClusterClient clusterClient = cluster.findClient(host, port); 121 122 if (clusterClient != null) 123 return clusterClient; 124 } 125 126 return null; 127 } 128 } 129 | Popular Tags |