KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > ant > jonasbase > Carol


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer: Florent BENOIT
22  * --------------------------------------------------------------------------
23  * $Id: Carol.java,v 1.2 2005/06/07 08:21:27 pelletib Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.ant.jonasbase;
28
29 import org.objectweb.jonas.ant.JOnASBaseTask;
30
31 /**
32  * Defines properties for carol.properties
33  * @author Florent Benoit
34  */

35 public class Carol extends Tasks {
36
37     /**
38      * Info for the logger
39      */

40     private static final String JavaDoc INFO = "[Carol] ";
41
42     /**
43      * Protocols property
44      */

45     private static final String JavaDoc PROTOCOLS_PROPERTY = "carol.protocols";
46
47     /**
48      * Default protocols
49      */

50     private static final String JavaDoc DEFAULT_PROTOCOLS = "jrmp";
51
52     /**
53      * Default Host
54      */

55     private static final String JavaDoc DEFAULT_HOST = "localhost";
56
57     /**
58      * Default protocol header
59      */

60     private static final String JavaDoc PROTOCOL_HEADER = "://";
61
62     /**
63      * Default jrmp port number
64      */

65     private static final String JavaDoc DEFAULT_JRMP_PORT = "1099";
66
67     /**
68      * Default jeremie port number
69      */

70     private static final String JavaDoc DEFAULT_JEREMIE_PORT = "2000";
71
72     /**
73      * Default iiop port number
74      */

75     private static final String JavaDoc DEFAULT_IIOP_PORT = "2001";
76
77     /**
78      * Default cmi port number
79      */

80     private static final String JavaDoc DEFAULT_CMI_PORT = "2002";
81
82     /**
83      * Default irmi port number
84      */

85     private static final String JavaDoc DEFAULT_IRMI_PORT = "1098";
86
87     /**
88      * Default cmi mcast addr
89      */

90     private static final String JavaDoc DEFAULT_CMI_MCASTADDR = "224.0.0.35:35467";
91
92     /**
93      * Optimization
94      */

95     private static final String JavaDoc OPTIMIZATION_PROPERTY = "carol.jvm.rmi.local.call=";
96
97     /**
98      * Optimization (off)
99      */

100     private static final String JavaDoc OPTIMIZATION_OFF = OPTIMIZATION_PROPERTY + "false";
101
102     /**
103      * Optimization (on)
104      */

105     private static final String JavaDoc OPTIMIZATION_ON = OPTIMIZATION_PROPERTY + "true";
106
107     /**
108      * CMI mcast addr property
109      */

110     private static final String JavaDoc CMI_MCASTADDR_PROPERTY = "carol.cmi.multicast.address";
111
112     /**
113      * Default constructor
114      */

115     public Carol() {
116         super();
117     }
118
119     /**
120      * Set the port for a protocol
121      * @param protocolName name of the protocol
122      * @param hostName for the protocol
123      * @param portNumber port for a given protocol
124      * @param protocolUrl URL for the protocol (if any)
125      * @param token of the protocol to replace
126      */

127     private void setURL(String JavaDoc protocolName, String JavaDoc hostName, String JavaDoc portNumber, String JavaDoc protocolUrl, String JavaDoc token) {
128         String JavaDoc url = null;
129
130         // Token to replace
131
token = protocolName + PROTOCOL_HEADER + DEFAULT_HOST + ":" + token;
132
133         if (protocolUrl != null) {
134             url = protocolUrl;
135         } else {
136             url = protocolName + PROTOCOL_HEADER + hostName + ":" + portNumber;
137         }
138         JReplace propertyReplace = new JReplace();
139         propertyReplace.setLogInfo(INFO + "Setting URL for protocol '" + protocolName + "' to : " + url);
140         propertyReplace.setConfigurationFile(JOnASBaseTask.CAROL_CONF_FILE);
141         propertyReplace.setToken(token);
142         propertyReplace.setValue(url);
143         addTask(propertyReplace);
144     }
145
146     /**
147      * Set the port for JRMP
148      * @param portNumber port for JRMP
149      */

150     public void setJrmpPort(String JavaDoc portNumber) {
151         setURL("rmi", DEFAULT_HOST, portNumber, null, DEFAULT_JRMP_PORT);
152     }
153
154     /**
155      * Set the port for JEREMIE
156      * @param portNumber port for JEREMIE
157      */

158     public void setJeremiePort(String JavaDoc portNumber) {
159         setURL("jrmi", DEFAULT_HOST, portNumber, null, DEFAULT_JEREMIE_PORT);
160     }
161
162     /**
163      * Set the port for IIOP
164      * @param portNumber port for IIOP
165      */

166     public void setIiopPort(String JavaDoc portNumber) {
167         setURL("iiop", DEFAULT_HOST, portNumber, null, DEFAULT_IIOP_PORT);
168     }
169
170     /**
171      * Set the port for CMI
172      * @param portNumber port for CMI
173      */

174     public void setCmiPort(String JavaDoc portNumber) {
175         setURL("cmi", DEFAULT_HOST, portNumber, null, DEFAULT_CMI_PORT);
176     }
177
178     /**
179      * Set the port for IRMI
180      * @param portNumber port for IRMI
181      */

182     public void setIrmiPort(String JavaDoc portNumber) {
183         setURL("rmi", DEFAULT_HOST, portNumber, null, DEFAULT_IRMI_PORT);
184     }
185
186     /**
187      * Set mcastAddr for CMI
188      * @param mcastAddr multicast address
189      */

190     public void setCmiMcastAddr(String JavaDoc mcastAddr) {
191
192         // Token to replace
193
String JavaDoc token = CMI_MCASTADDR_PROPERTY + "=" + DEFAULT_CMI_MCASTADDR;
194         String JavaDoc value = CMI_MCASTADDR_PROPERTY + "=" + mcastAddr;
195         JReplace propertyReplace = new JReplace();
196         propertyReplace.setLogInfo(INFO + "Setting mcastaddr for protocol cmi");
197         propertyReplace.setConfigurationFile(JOnASBaseTask.CAROL_CONF_FILE);
198         propertyReplace.setToken(token);
199         propertyReplace.setValue(value);
200         addTask(propertyReplace);
201
202     }
203
204     /**
205      * Set the port for all protocols
206      * @param portNumber port for all protocols
207      */

208     public void setDefaultPort(String JavaDoc portNumber) {
209         setJrmpPort(portNumber);
210         setJeremiePort(portNumber);
211         setIiopPort(portNumber);
212         setCmiPort(portNumber);
213         setIrmiPort(portNumber);
214     }
215
216     /**
217      * Set the initial protocols when JOnAS start
218      * @param protocols comma separated list of protocols
219      */

220     public void setProtocols(String JavaDoc protocols) {
221         JReplace propertyReplace = new JReplace();
222         propertyReplace.setConfigurationFile(JOnASBaseTask.CAROL_CONF_FILE);
223         propertyReplace.setToken(PROTOCOLS_PROPERTY + "=" + DEFAULT_PROTOCOLS);
224         propertyReplace.setValue(PROTOCOLS_PROPERTY + "=" + protocols);
225         propertyReplace.setLogInfo(INFO + "Setting protocols to : " + protocols);
226         addTask(propertyReplace);
227     }
228
229     /**
230      * Enable or disable optimization
231      * @param enabled (true or false)
232      */

233     public void setJrmpOptimization(boolean enabled) {
234         // Change only if needed
235
if (!enabled) {
236             return;
237         }
238         JReplace propertyReplace = new JReplace();
239         propertyReplace.setConfigurationFile(JOnASBaseTask.CAROL_CONF_FILE);
240         propertyReplace.setToken(OPTIMIZATION_OFF);
241         propertyReplace.setValue(OPTIMIZATION_ON);
242         propertyReplace.setLogInfo(INFO + "Enable JRMP optimization");
243         addTask(propertyReplace);
244     }
245
246
247 }
Popular Tags