KickJava   Java API By Example, From Geeks To Geeks.

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


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: WebContainer.java,v 1.3 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  * Allow to configure the WebContainer service
33  * @author Florent Benoit
34  */

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

40     private static final String JavaDoc INFO = "[WebContainer] ";
41
42     /**
43      * Name of the implementation class for Jetty
44      */

45     private static final String JavaDoc JETTY_SERVICE = "org.objectweb.jonas.web.jetty50.JettyJWebContainerServiceImpl";
46
47     /**
48      * Name of the implementation class for Tomcat
49      */

50     private static final String JavaDoc TOMCAT_SERVICE = "org.objectweb.jonas.web.wrapper.catalina55.CatalinaJWebContainerServiceWrapper";
51
52     /**
53      * Name of the implementation class for the default service (tomcat)
54      */

55     private static final String JavaDoc DEFAULT_SERVICE = TOMCAT_SERVICE;
56
57     /**
58      * Default port number
59      */

60     private static final String JavaDoc DEFAULT_PORT = "9000";
61
62     /**
63      * Name of the service Tomcat
64      */

65     private static final String JavaDoc TOMCAT_SERVICE_NAME = "<Service name=\"Tomcat-JOnAS\">";
66
67     /**
68      * Flag allowing to know whether cluster service has been enabled
69      */

70     private boolean clusterIsEnabled = false;
71
72     /**
73      * Default listen cluster port number
74      */

75     private static final String JavaDoc DEFAULT_CLUSTER_LISTEN_PORT = "4001";
76
77     /**
78      * Default cluster multicast addr
79      */

80     private static final String JavaDoc DEFAULT_CLUSTER_MULTICAST_ADDR = "228.0.0.4";
81
82     /**
83      * Default cluster multicast port
84      */

85     private static final String JavaDoc DEFAULT_CLUSTER_MULTICAST_PORT = "45564";
86
87     /**
88      * Default constructor
89      */

90     public WebContainer() {
91         super();
92     }
93
94     /**
95      * Set the port number for the WebContainer
96      * @param portNumber the port for the web Container
97      */

98     public void setPort(String JavaDoc portNumber) {
99         // For tomcat
100
JReplace propertyReplace = new JReplace();
101         propertyReplace.setConfigurationFile(JOnASBaseTask.TOMCAT_CONF_FILE);
102         propertyReplace.setToken(DEFAULT_PORT);
103         propertyReplace.setValue(portNumber);
104         propertyReplace.setLogInfo(INFO + "Setting Tomcat port number to : " + portNumber);
105         addTask(propertyReplace);
106
107         // For Jetty
108
propertyReplace = new JReplace();
109         propertyReplace.setConfigurationFile(JOnASBaseTask.JETTY_CONF_FILE);
110         propertyReplace.setToken(DEFAULT_PORT);
111         propertyReplace.setValue(portNumber);
112         propertyReplace.setLogInfo(INFO + "Setting Jetty port number to : " + portNumber);
113         addTask(propertyReplace);
114     }
115
116
117     /**
118      * Set the name of the web container : jetty or tomcat
119      * @param containerName jetty or tomcat
120      */

121     public void setName(String JavaDoc containerName) {
122
123         String JavaDoc service = null;
124
125         if (containerName.equalsIgnoreCase("jetty")) {
126             service = JETTY_SERVICE;
127         } else {
128             service = TOMCAT_SERVICE;
129         }
130
131         // Replace the service in jonas.properties file
132
JReplace propertyReplace = new JReplace();
133         propertyReplace.setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE);
134         propertyReplace.setToken(DEFAULT_SERVICE);
135         propertyReplace.setValue(service);
136         propertyReplace.setLogInfo(INFO + "Setting service to : " + service);
137         addTask(propertyReplace);
138     }
139
140     /**
141      * Set the AJP port number for the WebContainer
142      * @param portNumber the AJP port
143      */

144     public void setAjpPort(String JavaDoc portNumber) {
145         // For tomcat
146
JReplace propertyReplace = new JReplace();
147         propertyReplace.setConfigurationFile(JOnASBaseTask.TOMCAT_CONF_FILE);
148         propertyReplace.setToken(TOMCAT_SERVICE_NAME);
149         String JavaDoc value = TOMCAT_SERVICE_NAME + "\n"
150         +
151         " <!-- Define an AJP 1.3 Connector on port " + portNumber + " -->" + "\n"
152         +
153         " <Connector port=\"" + portNumber + "\" enableLookups=\"false\" redirectPort=\"8443\" protocol=\"AJP/1.3\" />" + "\n";
154         propertyReplace.setValue(value);
155         propertyReplace.setLogInfo(INFO + "Setting Tomcat AJP Connector to : " + portNumber);
156         addTask(propertyReplace);
157     }
158
159     /**
160      * Set the Director port number for the WebContainer
161      * @param portNumber the Director port
162      */

163     public void setDirectorPort(String JavaDoc portNumber) {
164         // For tomcat
165
JReplace propertyReplace = new JReplace();
166         propertyReplace.setConfigurationFile(JOnASBaseTask.TOMCAT_CONF_FILE);
167         propertyReplace.setToken(TOMCAT_SERVICE_NAME);
168         String JavaDoc value = TOMCAT_SERVICE_NAME + "\n"
169         +
170         " <!-- Define a Director Connector on port " + portNumber + " -->" + "\n"
171         +
172         " <Connector protocol=\"org.enhydra.servlet.connectionMethods.EnhydraDirector.DirectorProtocol\"" + "\n"
173         +
174         " port=\"" + portNumber + "\"\n"
175         +
176         " threadTimeout = \"300\"" + "\n"
177         +
178         " clientTimeout = \"30\"" + "\n"
179         +
180         " sessionAffinity = \"false\"" + "\n"
181         +
182         " queueSize = \"400\"" + "\n"
183         +
184         " numThreads = \"200\"" + "\n"
185         +
186         " bindAddress = \"(All Interfaces)\"" + "\n"
187         +
188         " authKey = \"(Unauthenticated)\"" + "\n"
189         +
190         " />" + "\n";
191         propertyReplace.setValue(value);
192         propertyReplace.setLogInfo(INFO + "Setting Tomcat AJP Connector to : " + portNumber);
193         addTask(propertyReplace);
194     }
195
196     /**
197      * Enable the cluster feature (if not already made)
198      */

199     private void setCluster() {
200         if (!clusterIsEnabled) {
201             JReplace propertyReplace = new JReplace();
202             propertyReplace.setConfigurationFile(JOnASBaseTask.TOMCAT_CONF_FILE);
203             propertyReplace.setToken("</Host>");
204             String JavaDoc value = "\n"
205                 +
206                 " <Cluster className=\"org.apache.catalina.cluster.tcp.SimpleTcpCluster\"" + "\n"
207                 +
208                 " managerClassName=\"org.apache.catalina.cluster.session.DeltaManager\"" + "\n"
209                 +
210                 " expireSessionsOnShutdown=\"false\"" + "\n"
211                 +
212                 " useDirtyFlag=\"true\"" + "\n"
213                 +
214                 " notifyListenersOnReplication=\"true\">" + "\n"
215                 +
216                 " <Membership" + "\n"
217                 +
218                 " className=\"org.apache.catalina.cluster.mcast.McastService\"" + "\n"
219                 +
220                 " mcastAddr=\"228.0.0.4\"" + "\n"
221                 +
222                 " mcastPort=\"45564\"" + "\n"
223                 +
224                 " mcastFrequency=\"500\"" + "\n"
225                 +
226                 " mcastDropTime=\"3000\"/>" + "\n"
227                 +
228
229                 " <Receiver" + "\n"
230                 +
231                 " className=\"org.apache.catalina.cluster.tcp.ReplicationListener\"" + "\n"
232                 +
233                 " tcpListenAddress=\"auto\"" + "\n"
234                 +
235                 " tcpListenPort=\"4001\"" + "\n"
236                 +
237                 " tcpSelectorTimeout=\"100\"" + "\n"
238                 +
239                 " tcpThreadCount=\"6\"/>" + "\n"
240                 +
241
242                 " <Sender" + "\n"
243                 +
244                 " className=\"org.apache.catalina.cluster.tcp.ReplicationTransmitter\"" + "\n"
245                 +
246                 " replicationMode=\"pooled\"" + "\n"
247                 +
248                 " ackTimeout=\"15000\"/>" + "\n"
249                 +
250
251                 " <Valve className=\"org.apache.catalina.cluster.tcp.ReplicationValve\"" + "\n"
252                 +
253                 " filter=\".*\\.gif;.*\\.js;.*\\.jpg;.*\\.png;.*\\.htm;.*\\.html;.*\\.css;.*\\.txt;\"/>" + "\n"
254                 +
255
256 // " <Deployer className=\"org.apache.catalina.cluster.deploy.FarmWarDeployer\"" + "\n" +
257
// " tempDir=\"/tmp/war-temp/\"" + "\n" +
258
// " deployDir=\"/tmp/war-deploy/\"" + "\n" +
259
// " watchDir=\"/tmp/war-listen/\"" + "\n" +
260
// " watchEnabled=\"false\"/>" +"\n" +
261
" </Cluster>" + "\n"
262                 +
263                 " </Host>";
264             propertyReplace.setValue(value);
265             propertyReplace.setLogInfo(INFO + "Setting Cluster");
266             addTask(propertyReplace);
267             clusterIsEnabled = true;
268
269         }
270     }
271
272     /**
273      * Set the listen cluster port number for the WebContainer
274      * @param portNumber the Director port
275      */

276     public void setClusterListenPort(String JavaDoc portNumber) {
277         // For tomcat
278
setCluster();
279         JReplace propertyReplace = new JReplace();
280         propertyReplace.setConfigurationFile(JOnASBaseTask.TOMCAT_CONF_FILE);
281         propertyReplace.setToken(DEFAULT_CLUSTER_LISTEN_PORT);
282         propertyReplace.setValue(portNumber);
283         propertyReplace.setLogInfo(INFO + "Setting Cluster listen port : " + portNumber);
284         addTask(propertyReplace);
285     }
286     /**
287      * Set the multicast addr for the cluster
288      * @param address the multicast address
289      */

290     public void setClusterMcastAddr(String JavaDoc address) {
291         // For tomcat
292
setCluster();
293         JReplace propertyReplace = new JReplace();
294         propertyReplace.setConfigurationFile(JOnASBaseTask.TOMCAT_CONF_FILE);
295         propertyReplace.setToken(DEFAULT_CLUSTER_MULTICAST_ADDR);
296         propertyReplace.setValue(address);
297         propertyReplace.setLogInfo(INFO + "Setting Cluster multicast addr : " + address);
298         addTask(propertyReplace);
299     }
300     /**
301      * Set the multicast port for the cluster
302      * @param portNumber the multicast port
303      */

304     public void setClusterMcastPort(String JavaDoc portNumber) {
305         // For tomcat
306
setCluster();
307         JReplace propertyReplace = new JReplace();
308         propertyReplace.setConfigurationFile(JOnASBaseTask.TOMCAT_CONF_FILE);
309         propertyReplace.setToken(DEFAULT_CLUSTER_MULTICAST_PORT);
310         propertyReplace.setValue(portNumber);
311         propertyReplace.setLogInfo(INFO + "Setting Cluster multicast port : " + portNumber);
312         addTask(propertyReplace);
313     }
314 }
Popular Tags