KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > ant > cluster > WebContainerCluster


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2005 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: Benoit Pelletier
22  * --------------------------------------------------------------------------
23  * $Id: WebContainerCluster.java,v 1.1 2005/06/07 08:21:27 pelletib Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.ant.cluster;
28
29 import java.io.File JavaDoc;
30 import java.util.Iterator JavaDoc;
31
32 import org.objectweb.jonas.ant.jonasbase.BaseTaskItf;
33 import org.objectweb.jonas.ant.jonasbase.WebContainer;
34
35 /**
36  * Define WebContainerCluster task
37  * @author Benoit Pelletier
38  */

39 public class WebContainerCluster extends ClusterTasks {
40
41     /**
42      * Info for the logger
43      */

44     private static final String JavaDoc INFO = "[WebContainerCluster] ";
45
46     /**
47      * Name of the container web : tomcat/jetty
48      */

49     private String JavaDoc name = null;
50
51     /**
52      * HTTP ports range
53      */

54     private String JavaDoc[] httpPortRange = null;
55
56     /**
57      * AJP ports range
58      */

59     private String JavaDoc[] ajpPortRange = null;
60
61     /**
62      * Sticky Session : true/false
63      */

64     private boolean stickySession = false;
65
66     /**
67      * mod_jk LB factor ports range
68      */

69     private String JavaDoc[] modJkLbFactorRange = null;
70
71     /**
72      * Director ports range
73      */

74     private String JavaDoc[] directorPortRange = null;
75
76     /**
77      * director LB factor ports range
78      */

79     private String JavaDoc[] directorLbFactorRange = null;
80
81     /**
82      * multicast addr
83      */

84     private String JavaDoc clusterMcastAddr = null;
85
86     /**
87      * multicast port
88      */

89     private String JavaDoc clusterMcastPort = null;
90
91     /**
92      * Cluster Listen Port Range
93      */

94     private String JavaDoc[] clusterListenPortRange = null;
95
96     /**
97      * mod_jk directory
98      */

99     private String JavaDoc modjkDir = null;
100
101     /**
102      * director directory
103      */

104     private String JavaDoc directorDir = null;
105
106     /**
107      * Default constructor
108      */

109     public WebContainerCluster() {
110         super();
111     }
112
113     /**
114      * Set director directory
115      * @param directorDir directory
116      */

117     public void setDirectorDir(String JavaDoc directorDir) {
118         this.directorDir = directorDir;
119     }
120
121     /**
122      * Set mod_jk directory
123      * @param modjkDir directory
124      */

125     public void setModjkDir(String JavaDoc modjkDir) {
126         this.modjkDir = modjkDir;
127     }
128
129     /**
130      * Set clusterMcastAddr
131      * @param clusterMcastAddr multicast address to set
132      */

133     public void setClusterMcastAddr(String JavaDoc clusterMcastAddr) {
134         this.clusterMcastAddr = clusterMcastAddr;
135     }
136
137     /**
138      * Set clusterMcastPort
139      * @param clusterMcastPort multicast port to set
140      */

141     public void setClusterMcastPort(String JavaDoc clusterMcastPort) {
142         this.clusterMcastPort = clusterMcastPort;
143     }
144
145     /**
146      * Set Cluster listen ports range
147      * @param clusterListenPortRange Cluster Listen ports range
148      */

149     public void setClusterListenPortRange(String JavaDoc clusterListenPortRange) {
150         this.clusterListenPortRange = clusterListenPortRange.split(",");
151
152     }
153
154     /**
155      * Set HTTP ports range
156      * @param httpPortRange HTTP ports range
157      */

158     public void setHttpPortRange(String JavaDoc httpPortRange) {
159         this.httpPortRange = httpPortRange.split(",");
160
161     }
162
163     /**
164      * Set AJP ports range
165      * @param ajpPortRange AJP ports range
166      */

167     public void setAjpPortRange(String JavaDoc ajpPortRange) {
168         this.ajpPortRange = ajpPortRange.split(",");
169
170     }
171
172     /**
173      * Set mod_jk lb factor range
174      * @param modJkLbFactorRange load balancing factor range
175      */

176     public void setModJkLbFactorRange(String JavaDoc modJkLbFactorRange) {
177         this.modJkLbFactorRange = modJkLbFactorRange.split(",");
178
179     }
180
181     /**
182      * Set Director ports range
183      * @param directorPortRange Director ports range
184      */

185     public void setDirectorPortRange(String JavaDoc directorPortRange) {
186         this.directorPortRange = directorPortRange.split(",");
187
188     }
189
190     /**
191      * Set director lb factor range
192      * @param directorLbFactorRange load balancing factor range
193      */

194     public void setDirectorLbFactorRange(String JavaDoc directorLbFactorRange) {
195         this.directorLbFactorRange = directorLbFactorRange.split(",");
196
197     }
198
199     /**
200      * Set the name of the web container : jetty or tomcat
201      * @param containerName jetty or tomcat
202      */

203     public void setName(String JavaDoc containerName) {
204
205         this.name = containerName;
206     }
207
208     /**
209      * Set the sticky session
210      * @param stickySession true/false
211      */

212     public void setStickySession(boolean stickySession) {
213
214         this.stickySession = stickySession;
215     }
216
217     /**
218      * Generates the carol tasks for each JOnAS's instances
219      */

220     public void generatesTasks() {
221
222         int portInd = 0;
223
224         ModJk modJk = new ModJk();
225         Director director = new Director();
226
227         // creation of the mod_jk file
228
modJk.createFiles(modjkDir);
229         modJk.setStickySession(stickySession);
230
231         // creation of the Director file
232
director.createFile(directorDir);
233
234         for (int i = getDestDirSuffixIndFirst(); i <= getDestDirSuffixIndLast(); i++) {
235
236             String JavaDoc destDir = getDestDir(getDestDirPrefix(), i);
237
238             log(INFO + "tasks generation for " + destDir);
239
240             // creation of the WebContainer tasks
241
WebContainer webContainer = new WebContainer();
242
243             webContainer.setName(name);
244             webContainer.setPort(httpPortRange[portInd]);
245             webContainer.setAjpPort(ajpPortRange[portInd]);
246             webContainer.setDirectorPort(directorPortRange[portInd]);
247             webContainer.setClusterListenPort(clusterListenPortRange[portInd]);
248             webContainer.setClusterMcastAddr(clusterMcastAddr);
249             webContainer.setClusterMcastPort(clusterMcastPort);
250
251             // mod_jk
252
modJk.addWorker(ajpPortRange[portInd], modJkLbFactorRange[portInd]);
253
254             // director
255
director.addAppServer(directorPortRange[portInd], directorLbFactorRange[portInd]);
256
257             // set destDir for each webContainer task
258
for (Iterator JavaDoc it = webContainer.getTasks().iterator(); it.hasNext();) {
259                 BaseTaskItf task = (BaseTaskItf) it.next();
260                 task.setDestDir(new File JavaDoc(destDir));
261             }
262
263             addTasks(webContainer);
264
265             portInd++;
266
267         }
268
269         modJk.flushFiles();
270         addTasks(modJk);
271
272         director.flushFile();
273         addTasks(director);
274     }
275 }
Popular Tags