1 28 29 package com.caucho.server.cluster; 30 31 import com.caucho.loader.EnvironmentLocal; 32 import com.caucho.log.Log; 33 34 import java.util.ArrayList ; 35 import java.util.logging.Logger ; 36 37 40 public class ClusterContainer { 41 static protected final Logger log = Log.open(ClusterContainer.class); 42 43 static final EnvironmentLocal<ClusterContainer> _clusterContainerLocal = 44 new EnvironmentLocal<ClusterContainer>("caucho.cluster.container"); 45 46 private ClusterContainer _parent; 47 48 private ArrayList <Cluster> _clusterList = new ArrayList <Cluster>(); 49 50 private ClusterContainer() 51 { 52 } 53 54 57 public static ClusterContainer create() 58 { 59 ClusterContainer container = _clusterContainerLocal.getLevel(); 60 61 if (container == null) { 62 container = new ClusterContainer(); 63 ClusterContainer parent = _clusterContainerLocal.get(); 64 65 container.setParent(parent); 66 _clusterContainerLocal.set(container); 67 } 68 69 return container; 70 } 71 72 75 public static ClusterContainer getLocal() 76 { 77 return _clusterContainerLocal.get(); 78 } 79 80 83 public static ClusterContainer getLocal(ClassLoader loader) 84 { 85 return _clusterContainerLocal.get(loader); 86 } 87 88 91 private void setParent(ClusterContainer parent) 92 { 93 _parent = parent; 94 } 95 96 99 private ClusterContainer getParent() 100 { 101 return _parent; 102 } 103 104 107 public void addCluster(Cluster cluster) 108 { 109 _clusterList.add(cluster); 110 } 111 112 115 public ArrayList <Cluster> getClusterList() 116 { 117 return _clusterList; 118 } 119 120 123 public Cluster findCluster(String id) 124 { 125 for (int i = 0; i < _clusterList.size(); i++) { 126 Cluster cluster = _clusterList.get(i); 127 128 if (id.equals(cluster.getId())) 129 return cluster; 130 } 131 132 if (_parent != null) 133 return _parent.findCluster(id); 134 else 135 return null; 136 } 137 138 141 public ArrayList <ClusterPort> getServerPorts(String serverId) 142 { 143 ArrayList <ClusterPort> ports = new ArrayList <ClusterPort>(); 144 145 for (int i = 0; i < _clusterList.size(); i++) { 146 Cluster cluster = _clusterList.get(i); 147 148 ports.addAll(cluster.getServerPorts(serverId)); 149 } 150 151 return ports; 152 } 153 154 public String toString() 155 { 156 return ("ClusterContainer[]"); 157 } 158 } 159 | Popular Tags |