1 29 30 package com.caucho.server.resin; 31 32 import com.caucho.server.cluster.Cluster; 33 import com.caucho.server.cluster.ClusterPort; 34 import com.caucho.server.cluster.ClusterServer; 35 import com.caucho.util.L10N; 36 import com.caucho.vfs.JsseSSLFactory; 37 38 import javax.annotation.PostConstruct; 39 import java.net.UnknownHostException ; 40 41 44 public class ClusterCompatConfig { 45 private static final L10N L = new L10N(ClusterCompatConfig.class); 46 47 private final Resin _resin; 48 49 private String _id = ""; 50 private Cluster _cluster; 51 52 55 public ClusterCompatConfig(Resin resin) 56 { 57 _resin = resin; 58 } 59 60 public void setId(String id) 61 { 62 _id = id; 63 } 64 65 Cluster getCluster() 66 { 67 if (_cluster != null) 68 return _cluster; 69 70 _cluster = _resin.findCluster(_id); 71 72 if (_cluster == null) { 73 try { 74 _cluster = _resin.createCluster(); 75 _cluster.setId(_id); 76 _resin.addCluster(_cluster); 77 } catch (Throwable e) { 78 throw new RuntimeException (e); 79 } 80 } 81 82 return _cluster; 83 } 84 85 public SrunCompatConfig createSrun() 86 { 87 return new SrunCompatConfig(); 88 } 89 90 public class SrunCompatConfig { 91 private String _id = ""; 92 private ClusterServer _server; 93 94 SrunCompatConfig() 95 { 96 Cluster cluster = getCluster(); 97 } 98 99 public void setId(String id) 100 { 101 _id = id; 102 } 103 104 public void setServerId(String id) 105 { 106 setId(id); 107 } 108 109 public void setHost(String host) 110 throws UnknownHostException 111 { 112 getClusterPort().setAddress(host); 113 } 114 115 public void setPort(int port) 116 { 117 getClusterPort().setPort(port); 118 } 119 120 public void setJsseSsl(JsseSSLFactory ssl) 121 { 122 getClusterPort().setJsseSsl(ssl); 123 } 124 125 public void setIndex(int index) 126 { 127 } 129 130 public void setBackup(boolean backup) 131 { 132 } 134 135 private ClusterPort getClusterPort() 136 { 137 return getClusterServer().getClusterPort(); 138 } 139 140 private ClusterServer getClusterServer() 141 { 142 if (_server == null) 143 _server = _cluster.findServer(_id); 144 145 if (_server == null) { 146 try { 147 _server = _cluster.createServer(); 148 _server.setId(_id); 149 _cluster.addServer(_server); 150 } catch (Throwable e) { 151 throw new RuntimeException (e); 152 } 153 } 154 155 return _server; 156 } 157 158 @PostConstruct 159 public void init() 160 throws Exception 161 { 162 _server.init(); 163 } 164 } 165 } 166 | Popular Tags |