001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer: Florent BENOIT
022: * --------------------------------------------------------------------------
023: * $Id: Carol.java 7895 2006-01-18 06:53:55Z pelletib $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas.ant.jonasbase;
026:
027: import org.objectweb.jonas.ant.JOnASBaseTask;
028:
029: /**
030: * Defines properties for carol.properties
031: * @author Florent Benoit
032: */
033: public class Carol extends Tasks {
034:
035: /**
036: * Info for the logger
037: */
038: private static final String INFO = "[Carol] ";
039:
040: /**
041: * Protocols property
042: */
043: private static final String PROTOCOLS_PROPERTY = "carol.protocols";
044:
045: /**
046: * Default protocols
047: */
048: private static final String DEFAULT_PROTOCOLS = "jrmp";
049:
050: /**
051: * Default Host
052: */
053: private static final String DEFAULT_HOST = "localhost";
054:
055: /**
056: * Default protocol header
057: */
058: private static final String PROTOCOL_HEADER = "://";
059:
060: /**
061: * Default jrmp port number
062: */
063: private static final String DEFAULT_JRMP_PORT = "1099";
064:
065: /**
066: * Default jeremie port number
067: */
068: private static final String DEFAULT_JEREMIE_PORT = "2000";
069:
070: /**
071: * Default iiop port number
072: */
073: private static final String DEFAULT_IIOP_PORT = "2001";
074:
075: /**
076: * Default cmi port number
077: */
078: private static final String DEFAULT_CMI_PORT = "2002";
079:
080: /**
081: * Default irmi port number
082: */
083: private static final String DEFAULT_IRMI_PORT = "1098";
084:
085: /**
086: * Default cmi mcast addr
087: */
088: private static final String DEFAULT_CMI_MCASTADDR = "224.0.0.35";
089:
090: /**
091: * Default cmi mcast port
092: */
093: private static final String DEFAULT_CMI_MCASTPORT = "35467";
094:
095: /**
096: * Optimization
097: */
098: private static final String OPTIMIZATION_PROPERTY = "carol.jvm.rmi.local.call=";
099:
100: /**
101: * Optimization (off)
102: */
103: private static final String OPTIMIZATION_OFF = OPTIMIZATION_PROPERTY
104: + "false";
105:
106: /**
107: * Optimization (on)
108: */
109: private static final String OPTIMIZATION_ON = OPTIMIZATION_PROPERTY
110: + "true";
111:
112: /**
113: * CMI mcast addr attribut
114: */
115: private static final String CMI_MCASTADDR_ATTR = "mcast_addr";
116:
117: /**
118: * CMI mcast port attribut
119: */
120: private static final String CMI_MCASTPORT_ATTR = "mcast_port";
121:
122: /**
123: * Default constructor
124: */
125: public Carol() {
126: super ();
127: }
128:
129: /**
130: * Set the port for a protocol
131: * @param protocolName name of the protocol
132: * @param hostName for the protocol
133: * @param portNumber port for a given protocol
134: * @param protocolUrl URL for the protocol (if any)
135: * @param token of the protocol to replace
136: */
137: private void setURL(String protocolName, String hostName,
138: String portNumber, String protocolUrl, String token) {
139: String url = null;
140:
141: // Token to replace
142: token = protocolName + PROTOCOL_HEADER + DEFAULT_HOST + ":"
143: + token;
144:
145: if (protocolUrl != null) {
146: url = protocolUrl;
147: } else {
148: url = protocolName + PROTOCOL_HEADER + hostName + ":"
149: + portNumber;
150: }
151: JReplace propertyReplace = new JReplace();
152: propertyReplace.setLogInfo(INFO + "Setting URL for protocol '"
153: + protocolName + "' to : " + url);
154: propertyReplace
155: .setConfigurationFile(JOnASBaseTask.CAROL_CONF_FILE);
156: propertyReplace.setToken(token);
157: propertyReplace.setValue(url);
158: addTask(propertyReplace);
159: }
160:
161: /**
162: * Set the port for JRMP
163: * @param portNumber port for JRMP
164: */
165: public void setJrmpPort(String portNumber) {
166: setURL("rmi", DEFAULT_HOST, portNumber, null, DEFAULT_JRMP_PORT);
167: }
168:
169: /**
170: * Set the port for JEREMIE
171: * @param portNumber port for JEREMIE
172: */
173: public void setJeremiePort(String portNumber) {
174: setURL("jrmi", DEFAULT_HOST, portNumber, null,
175: DEFAULT_JEREMIE_PORT);
176: }
177:
178: /**
179: * Set the port for IIOP
180: * @param portNumber port for IIOP
181: */
182: public void setIiopPort(String portNumber) {
183: setURL("iiop", DEFAULT_HOST, portNumber, null,
184: DEFAULT_IIOP_PORT);
185: }
186:
187: /**
188: * Set the port for CMI
189: * @param portNumber port for CMI
190: */
191: public void setCmiPort(String portNumber) {
192: setURL("cmi", DEFAULT_HOST, portNumber, null, DEFAULT_CMI_PORT);
193: }
194:
195: /**
196: * Set the port for IRMI
197: * @param portNumber port for IRMI
198: */
199: public void setIrmiPort(String portNumber) {
200: setURL("rmi", DEFAULT_HOST, portNumber, null, DEFAULT_IRMI_PORT);
201: }
202:
203: /**
204: * Set mcastAddr for CMI
205: * @param mcastAddr multicast address
206: */
207: public void setCmiMcastAddr(String mcastAddr) {
208:
209: // Token to replace the multicast addr
210: String token = CMI_MCASTADDR_ATTR + "=" + "\""
211: + DEFAULT_CMI_MCASTADDR + "\"";
212: String value = CMI_MCASTADDR_ATTR + "=" + "\"" + mcastAddr
213: + "\"";
214: JReplace mcastAddrReplace = new JReplace();
215: mcastAddrReplace.setLogInfo(INFO
216: + "Setting mcastaddr for protocol cmi");
217: mcastAddrReplace
218: .setConfigurationFile(JOnASBaseTask.JGROUPS_CMI_CONF_FILE);
219: mcastAddrReplace.setToken(token);
220: mcastAddrReplace.setValue(value);
221: addTask(mcastAddrReplace);
222: }
223:
224: /**
225: * Set mcastPort for CMI
226: * @param mcastPort multicast port
227: */
228: public void setCmiMcastPort(String mcastPort) {
229:
230: // Token to replace the multicast port
231: String token = CMI_MCASTPORT_ATTR + "=" + "\""
232: + DEFAULT_CMI_MCASTPORT + "\"";
233: String value = CMI_MCASTPORT_ATTR + "=" + "\"" + mcastPort
234: + "\"";
235: JReplace mcastPortReplace = new JReplace();
236: mcastPortReplace.setLogInfo(INFO
237: + "Setting mcastport for protocol cmi");
238: mcastPortReplace
239: .setConfigurationFile(JOnASBaseTask.JGROUPS_CMI_CONF_FILE);
240: mcastPortReplace.setToken(token);
241: mcastPortReplace.setValue(value);
242: addTask(mcastPortReplace);
243:
244: }
245:
246: /**
247: * Set the port for all protocols
248: * @param portNumber port for all protocols
249: */
250: public void setDefaultPort(String portNumber) {
251: setJrmpPort(portNumber);
252: setJeremiePort(portNumber);
253: setIiopPort(portNumber);
254: setCmiPort(portNumber);
255: setIrmiPort(portNumber);
256: }
257:
258: /**
259: * Set the initial protocols when JOnAS start
260: * @param protocols comma separated list of protocols
261: */
262: public void setProtocols(String protocols) {
263: JReplace propertyReplace = new JReplace();
264: propertyReplace
265: .setConfigurationFile(JOnASBaseTask.CAROL_CONF_FILE);
266: propertyReplace.setToken(PROTOCOLS_PROPERTY + "="
267: + DEFAULT_PROTOCOLS);
268: propertyReplace.setValue(PROTOCOLS_PROPERTY + "=" + protocols);
269: propertyReplace.setLogInfo(INFO + "Setting protocols to : "
270: + protocols);
271: addTask(propertyReplace);
272: }
273:
274: /**
275: * Enable or disable optimization
276: * @param enabled (true or false)
277: */
278: public void setJrmpOptimization(boolean enabled) {
279: // Change only if needed
280: if (!enabled) {
281: return;
282: }
283: JReplace propertyReplace = new JReplace();
284: propertyReplace
285: .setConfigurationFile(JOnASBaseTask.CAROL_CONF_FILE);
286: propertyReplace.setToken(OPTIMIZATION_OFF);
287: propertyReplace.setValue(OPTIMIZATION_ON);
288: propertyReplace.setLogInfo(INFO + "Enable JRMP optimization");
289: addTask(propertyReplace);
290: }
291:
292: }
|