1 29 30 package com.caucho.server.resin; 31 32 import com.caucho.config.BuilderProgram; 33 import com.caucho.config.BuilderProgramContainer; 34 import com.caucho.config.SchemaBean; 35 import com.caucho.server.cluster.Cluster; 36 import com.caucho.server.cluster.ClusterServer; 37 import com.caucho.server.port.Port; 38 import com.caucho.util.L10N; 39 40 import javax.annotation.PostConstruct; 41 import java.util.ArrayList ; 42 import java.util.logging.Logger ; 43 44 47 public class ServerCompatConfig implements SchemaBean { 48 private static final L10N L = new L10N(ServerCompatConfig.class); 49 private static final Logger log 50 = Logger.getLogger(ServerCompatConfig.class.getName()); 51 52 private final Resin _resin; 53 54 private ArrayList <HttpCompatConfig> _httpList 55 = new ArrayList <HttpCompatConfig>(); 56 57 private BuilderProgramContainer _program 58 = new BuilderProgramContainer(); 59 60 63 public ServerCompatConfig(Resin resin) 64 { 65 if (resin == null) 66 throw new NullPointerException (); 67 68 _resin = resin; 69 } 70 71 74 public String getSchema() 75 { 76 return "com/caucho/server/resin/server.rnc"; 77 } 78 79 public void addBuilderProgram(BuilderProgram program) 80 { 81 _program.addProgram(program); 82 } 83 84 87 public HttpCompatConfig createHttp() 88 { 89 HttpCompatConfig http = new HttpCompatConfig(); 90 91 return http; 92 } 93 94 97 public ClusterCompatConfig createCluster() 98 { 99 return new ClusterCompatConfig(_resin); 100 } 101 102 @PostConstruct 103 public void init() 104 { 105 try { 106 String serverId = _resin.getServerId(); 107 108 ClusterServer clusterServer = _resin.findClusterServer(serverId); 109 110 if (clusterServer != null) { 111 } 112 else { 113 if (_resin.getClusterList().size() > 0 || ! "".equals(serverId)) { 114 log.warning(L.l("-server '{0}' does not match any defined servers", 115 serverId)); 116 } 117 118 Cluster cluster = _resin.createCluster(); 119 _resin.addCluster(cluster); 120 121 clusterServer = cluster.createServer(); 122 123 clusterServer.setPort(0); 124 125 cluster.addServer(clusterServer); 126 } 127 128 _program.configure(clusterServer.getCluster()); 129 } catch (RuntimeException e) { 130 throw e; 131 } catch (Throwable e) { 132 throw new RuntimeException (e); 133 } 134 } 135 136 public class HttpCompatConfig { 137 private String _id = ""; 138 139 private BuilderProgramContainer _program 140 = new BuilderProgramContainer(); 141 142 HttpCompatConfig() 143 { 144 } 145 146 public void setId(String id) 147 { 148 _id = id; 149 } 150 151 public void setServerId(String id) 152 { 153 setId(id); 154 } 155 156 public void addBuilderProgram(BuilderProgram program) 157 { 158 _program.addProgram(program); 159 } 160 161 @PostConstruct 162 public void init() 163 throws Throwable 164 { 165 ClusterServer server = _resin.findClusterServer(_id); 166 167 if (server == null) { 168 Cluster cluster = _resin.findCluster(""); 169 170 if (cluster == null) { 171 cluster = _resin.createCluster(); 172 _resin.addCluster(cluster); 173 } 174 175 server = cluster.createServer(); 176 server.setId(_id); 177 server.getClusterPort().setPort(0); 178 cluster.addServer(server); 179 } 180 181 Port http = server.createHttp(); 182 _program.configure(http); 183 } 184 } 185 } 186 | Popular Tags |