1 26 27 package org.objectweb.jonas.ant.cluster; 28 29 import java.io.File ; 30 import java.util.ArrayList ; 31 import java.util.Iterator ; 32 import java.util.List ; 33 34 35 import org.objectweb.jonas.ant.jonasbase.JEcho; 36 import org.objectweb.jonas.ant.jonasbase.JMkdir; 37 import org.objectweb.jonas.ant.jonasbase.JTouch; 38 import org.objectweb.jonas.ant.jonasbase.Tasks; 39 40 44 public class Director extends Tasks { 45 46 49 private static final String INFO = "[Director] "; 50 51 54 private static final String DIRECTOR_FILE = "enhydra_director.conf"; 55 56 59 private File configurationFile = null; 60 61 64 private List appServerList = null; 65 66 69 private boolean stickySession = false; 70 71 74 public Director() { 75 super(); 76 appServerList = new ArrayList (); 77 } 78 79 83 public void createFile(String destDir) { 84 JMkdir mkdir = new JMkdir(); 85 mkdir.setDestDir(new File (destDir)); 86 addTask(mkdir); 87 88 JTouch touchWorker = new JTouch(); 89 configurationFile = new File (destDir + "/" + DIRECTOR_FILE); 90 touchWorker.setDestDir(configurationFile); 91 addTask(touchWorker); 92 93 } 94 95 100 public void addAppServer(String portNumber, String lbFactor) { 101 AppServer appServer = new AppServer(); 102 appServer.setPortNumber(portNumber); 103 appServer.setLbFactor(lbFactor); 104 appServerList.add(appServer); 105 } 106 107 112 private String getAppServerDef(AppServer appServer) { 113 String appServerDef = "\n" 114 + " <AppServer host= \"localhost\" port=\"" 115 + appServer.getPortNumber() 116 + "\" weight=\"" 117 + appServer.getLbFactor() 118 + "\" />"; 119 return appServerDef; 120 } 121 122 125 private void flushAppServerFile() { 126 JEcho echo = new JEcho(); 127 echo.setDestDir(configurationFile); 128 String appServersDefs = ""; 129 int ind = 1; 130 for (Iterator it = this.appServerList.iterator(); it.hasNext();) { 131 AppServer appServer = (AppServer) it.next(); 132 appServer.setName("appServer" + ind); 133 appServersDefs = appServersDefs + getAppServerDef(appServer); 134 ind++; 135 } 136 137 String contentFile = "\n" 138 + "<?xml version=\"1.0\"?>" + "\n" 139 + "<!DOCTYPE EnhydraDirectorConfig SYSTEM \"EnhydraDirectorConfig.dtd\">" + "\n" 140 + "<EnhydraDirectorConfig>" + "\n" 141 + " <Application prefix=\"/sampleCluster2/\">" 142 + appServersDefs + "\n" 143 + " </Application>" + "\n" 144 + " <Status prefix=\"/status\">" + "\n" 145 + " <Restrict server=\"127.0.0.1\" />" + "\n" 146 + " <Restrict client=\"127.0.0.1\" />" + "\n" 147 + " </Status>" + "\n" 148 + "</EnhydraDirectorConfig>"; 149 150 echo.setMessage(contentFile); 151 addTask(echo); 152 } 153 154 157 public void flushFile() { 158 flushAppServerFile(); 159 } 160 161 165 public void setStickySession(boolean stickySession) { 166 this.stickySession = stickySession; 167 } 168 169 173 public class AppServer { 174 175 178 private String portNumber = null; 179 180 183 private String lbFactor = null; 184 185 188 private String name = null; 189 190 194 public String getPortNumber() { 195 return portNumber; 196 } 197 198 202 public void setPortNumber(String portNumber) { 203 this.portNumber = portNumber; 204 } 205 206 210 public String getLbFactor() { 211 return lbFactor; 212 } 213 214 218 public void setLbFactor(String lbFactor) { 219 this.lbFactor = lbFactor; 220 } 221 222 226 public String getName() { 227 return name; 228 } 229 230 234 public void setName(String name) { 235 this.name = name; 236 } 237 } 238 } | Popular Tags |