1 26 27 package org.objectweb.jonas.ant.jonasbase; 28 29 import org.objectweb.jonas.ant.JOnASBaseTask; 30 31 35 public class Discovery extends Tasks { 36 37 40 private static final String INFO = "[Discovery] "; 41 42 45 private static final String DEFAULT_DISCOVERY_MCASTADDR = "224.224.224.224"; 46 47 50 private static final String DEFAULT_DISCOVERY_MCASTPORT = "9080"; 51 52 55 private static final String DEFAULT_DISCOVERY_GREETING_PORT = "9899"; 56 57 60 private static final String DEFAULT_DISCOVERY_SOURCE_PORT = "9888"; 61 62 65 private static final String DISCOVERY_MCASTADDR_PROPERTY = "jonas.service.discovery.multicast.address"; 66 67 70 private static final String DISCOVERY_MCASTPORT_PROPERTY = "jonas.service.discovery.multicast.port"; 71 72 75 private static final String DISCOVERY_MASTER_PROPERTY = "jonas.service.discovery.master"; 76 77 80 private static final String DISCOVERY_GREETING_PORT_PROPERTY = "jonas.service.discovery.greeting.port"; 81 82 85 private static final String DISCOVERY_GREETING_TIMEOUT_PROPERTY = "jonas.service.discovery.greeting.timeout"; 86 87 90 private static final String DISCOVERY_SOURCE_PORT_PROPERTY = "jonas.service.discovery.source.port"; 91 92 95 public Discovery() { 96 super(); 97 } 98 99 103 public void setSourcePort(String portNumber) { 104 enableMaster(); 105 106 String token = DISCOVERY_SOURCE_PORT_PROPERTY + "=" + DEFAULT_DISCOVERY_SOURCE_PORT; 108 String value = DISCOVERY_SOURCE_PORT_PROPERTY + "=" + portNumber; 109 JReplace propertyReplace = new JReplace(); 110 propertyReplace.setLogInfo(INFO + "Setting source port for discovery"); 111 propertyReplace.setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE); 112 propertyReplace.setToken(token); 113 propertyReplace.setValue(value); 114 addTask(propertyReplace); 115 } 116 117 120 private void enableMaster() { 121 String token1 = "#" + DISCOVERY_MASTER_PROPERTY; 123 String value1 = DISCOVERY_MASTER_PROPERTY; 124 JReplace propertyReplace1 = new JReplace(); 125 propertyReplace1.setLogInfo(INFO + "Enable master node for discovery"); 126 propertyReplace1.setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE); 127 propertyReplace1.setToken(token1); 128 propertyReplace1.setValue(value1); 129 addTask(propertyReplace1); 130 131 String token2 = "#" + DISCOVERY_SOURCE_PORT_PROPERTY; 133 String value2 = DISCOVERY_SOURCE_PORT_PROPERTY; 134 JReplace propertyReplace2 = new JReplace(); 135 propertyReplace2.setLogInfo(INFO + "Enable greeting timeout for discovery"); 136 propertyReplace2.setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE); 137 propertyReplace2.setToken(token2); 138 propertyReplace2.setValue(value2); 139 addTask(propertyReplace2); 140 } 141 142 145 private void enableGreeting() { 146 String token1 = "#" + DISCOVERY_GREETING_PORT_PROPERTY; 148 String value1 = DISCOVERY_GREETING_PORT_PROPERTY; 149 JReplace propertyReplace1 = new JReplace(); 150 propertyReplace1.setLogInfo(INFO + "Enable greeting port for discovery"); 151 propertyReplace1.setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE); 152 propertyReplace1.setToken(token1); 153 propertyReplace1.setValue(value1); 154 addTask(propertyReplace1); 155 156 String token2 = "#" + DISCOVERY_GREETING_TIMEOUT_PROPERTY; 158 String value2 = DISCOVERY_GREETING_TIMEOUT_PROPERTY; 159 JReplace propertyReplace2 = new JReplace(); 160 propertyReplace2.setLogInfo(INFO + "Enable greeting timeout for discovery"); 161 propertyReplace2.setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE); 162 propertyReplace2.setToken(token2); 163 propertyReplace2.setValue(value2); 164 addTask(propertyReplace2); 165 } 166 167 171 public void setGreetingPort(String portNumber) { 172 enableGreeting(); 173 String token = DISCOVERY_GREETING_PORT_PROPERTY + "=" + DEFAULT_DISCOVERY_GREETING_PORT; 175 String value = DISCOVERY_GREETING_PORT_PROPERTY + "=" + portNumber; 176 JReplace propertyReplace = new JReplace(); 177 propertyReplace.setLogInfo(INFO + "Setting greeting port for discovery"); 178 propertyReplace.setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE); 179 propertyReplace.setToken(token); 180 propertyReplace.setValue(value); 181 addTask(propertyReplace); 182 } 183 184 188 public void setMcastAddr(String mcastAddr) { 189 190 String token = DISCOVERY_MCASTADDR_PROPERTY + "=" + DEFAULT_DISCOVERY_MCASTADDR; 192 String value = DISCOVERY_MCASTADDR_PROPERTY + "=" + mcastAddr; 193 JReplace propertyReplace = new JReplace(); 194 propertyReplace.setLogInfo(INFO + "Setting mcastaddr for discovery"); 195 propertyReplace.setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE); 196 propertyReplace.setToken(token); 197 propertyReplace.setValue(value); 198 addTask(propertyReplace); 199 200 } 201 202 206 public void setMcastPort(String mcastPort) { 207 208 String token = DISCOVERY_MCASTPORT_PROPERTY + "=" + DEFAULT_DISCOVERY_MCASTPORT; 210 String value = DISCOVERY_MCASTPORT_PROPERTY + "=" + mcastPort; 211 JReplace propertyReplace = new JReplace(); 212 propertyReplace.setLogInfo(INFO + "Setting mcastport for discovery"); 213 propertyReplace.setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE); 214 propertyReplace.setToken(token); 215 propertyReplace.setValue(value); 216 addTask(propertyReplace); 217 218 } 219 } | Popular Tags |