1 29 30 package com.caucho.boot; 31 32 import com.caucho.config.BuilderProgram; 33 import com.caucho.config.types.InitProgram; 34 import com.caucho.loader.EnvironmentBean; 35 import com.caucho.loader.EnvironmentClassLoader; 36 import com.caucho.vfs.Path; 37 38 import javax.annotation.PostConstruct; 39 import java.util.ArrayList ; 40 41 public class ResinConfig implements EnvironmentBean { 42 private ArrayList <InitProgram> _clusterDefaultList 43 = new ArrayList <InitProgram>(); 44 45 private ArrayList <ClusterConfig> _clusterList 46 = new ArrayList <ClusterConfig>(); 47 48 private ClassLoader _classLoader; 49 50 private Path _resinHome; 51 private Path _rootDirectory; 52 53 ResinConfig(Path resinHome, Path serverRoot) 54 { 55 _resinHome = resinHome; 56 _rootDirectory = serverRoot; 57 58 _classLoader = new EnvironmentClassLoader(); 59 } 60 61 public Path getResinHome() 62 { 63 return _resinHome; 64 } 65 66 public Path getRootDirectory() 67 { 68 return _rootDirectory; 69 } 70 71 public void setRootDirectory(Path rootDirectory) 72 { 73 _rootDirectory = rootDirectory; 74 } 75 76 public ClassLoader getClassLoader() 77 { 78 return _classLoader; 79 } 80 81 84 public void addClusterDefault(InitProgram program) 85 throws Throwable  86 { 87 _clusterDefaultList.add(program); 88 } 89 90 public ClusterConfig createCluster() 91 { 92 ClusterConfig cluster = new ClusterConfig(this); 93 94 for (int i = 0; i < _clusterDefaultList.size(); i++) 95 _clusterDefaultList.get(i).configure(cluster); 96 97 _clusterList.add(cluster); 98 99 return cluster; 100 } 101 102 public ServerCompatConfig createServer() 103 { 104 return new ServerCompatConfig(); 105 } 106 107 110 public void addThreadPool(BuilderProgram program) 111 { 112 } 113 114 public void setGroupName(BuilderProgram program) 115 { 116 } 117 118 public void setUserName(BuilderProgram program) 119 { 120 } 121 122 public void setMinFreeMemory(BuilderProgram program) 123 { 124 } 125 126 129 public void setSecurityManager(BuilderProgram program) 130 { 131 } 132 133 136 public ClusterConfig findCluster(String id) 137 { 138 for (int i = 0; i < _clusterList.size(); i++) { 139 ClusterConfig cluster = _clusterList.get(i); 140 141 if (id.equals(cluster.getId())) 142 return cluster; 143 } 144 145 return null; 146 } 147 148 151 public ResinWatchdog findServer(String id) 152 { 153 for (int i = 0; i < _clusterList.size(); i++) { 154 ClusterConfig cluster = _clusterList.get(i); 155 156 ResinWatchdog server = cluster.findServer(id); 157 158 if (server != null) 159 return server; 160 } 161 162 return null; 163 } 164 165 public class ServerCompatConfig { 166 public ClusterCompatConfig createCluster() 167 { 168 return new ClusterCompatConfig(); 169 } 170 171 public SrunCompatConfig createHttp() 172 { 173 return new SrunCompatConfig(); 174 } 175 176 179 public void addBuilderProgram(BuilderProgram program) 180 { 181 } 182 } 183 184 public class ClusterCompatConfig { 185 public SrunCompatConfig createSrun() 186 { 187 return new SrunCompatConfig(); 188 } 189 190 193 public void addBuilderProgram(BuilderProgram program) 194 { 195 } 196 } 197 198 public class SrunCompatConfig { 199 private String _id = ""; 200 201 public void setId(String id) 202 { 203 _id = id; 204 } 205 206 public void setServerId(String id) 207 { 208 _id = id; 209 } 210 211 214 public void addBuilderProgram(BuilderProgram program) 215 { 216 } 217 218 @PostConstruct 219 public void init() 220 { 221 ResinWatchdog server = findServer(_id); 222 223 if (server != null) 224 return; 225 226 ClusterConfig cluster = findCluster(""); 227 228 if (cluster == null) 229 cluster = createCluster(); 230 231 server = cluster.createServer(); 232 server.setId(_id); 233 cluster.addServer(server); 234 } 235 } 236 } 237 | Popular Tags |