Source Code Cross Referenced for JOnASClusterConfigTask.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » ant » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.ant 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 2005 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: Benoit Pelletier
022:         * --------------------------------------------------------------------------
023:         * $Id: JOnASClusterConfigTask.java 9228 2006-07-24 07:02:58Z pelletib $
024:         * --------------------------------------------------------------------------
025:         */package org.objectweb.jonas.ant;
026:
027:        import java.io.File;
028:        import java.util.ArrayList;
029:        import java.util.Iterator;
030:        import java.util.List;
031:
032:        import org.apache.tools.ant.BuildException;
033:        import org.apache.tools.ant.Project;
034:        import org.apache.tools.ant.Task;
035:        import org.apache.tools.ant.taskdefs.Copy;
036:        import org.apache.tools.ant.types.FileSet;
037:
038:        import org.objectweb.jonas.ant.cluster.Common;
039:        import org.objectweb.jonas.ant.cluster.ClusterDaemon;
040:        import org.objectweb.jonas.ant.cluster.ClusterTasks;
041:        import org.objectweb.jonas.ant.cluster.EjbLevel;
042:        import org.objectweb.jonas.ant.cluster.Script;
043:
044:        import org.objectweb.jonas.ant.cluster.WebLevel;
045:
046:        import org.objectweb.jonas.ant.jonasbase.BaseTaskItf;
047:        import org.objectweb.jonas.ant.jonasbase.Tasks;
048:
049:        /**
050:         * Class used to create a JOnAS Cluster Configuration
051:         * @author Benoit Pelletier
052:         */
053:        public class JOnASClusterConfigTask extends Task {
054:
055:            /**
056:             * Archictecture of the JOnAS's instances : contain both Web level and Ejb level
057:             */
058:            private static final String ARCH_BOTH_WEB_EJB = "bothWebEjb";
059:
060:            /**
061:             * Archictecture of the JOnAS's instances : separate Web level and Ejb level
062:             */
063:            private static final String ARCH_DIFF_WEB_EJB = "diffWebEjb";
064:
065:            /**
066:             * Source directory (JOnAS root)
067:             */
068:            private File jonasRoot = null;
069:
070:            /**
071:             * Destination directory prefix (used to create the jonasBase(s))
072:             */
073:            private String destDirPrefix = null;
074:
075:            /**
076:             * cluster daemon destination directory
077:             */
078:            private String cdDir = null;
079:
080:            /**
081:             * Cluster architecture : share instance for web/ejb or separate them
082:             */
083:            private String arch = null;
084:
085:            /**
086:             * number of JOnAS's instance for web level
087:             */
088:            private int webInstNb = -1;
089:
090:            /**
091:             * number of JOnAS's instance for ejb level
092:             */
093:            private int ejbInstNb = -1;
094:
095:            /**
096:             * Update only JONAS_BASE without erasing it
097:             */
098:            private boolean onlyUpdate = false;
099:
100:            /**
101:             * List of tasks to do
102:             */
103:            private List tasks = null;
104:
105:            /**
106:             * Constructor
107:             */
108:            public JOnASClusterConfigTask() {
109:                tasks = new ArrayList();
110:            }
111:
112:            /**
113:             * Creates a new JONAS_BASE or update it
114:             * @param destDir destination directory
115:             */
116:            private void createJonasBase(String destDir) {
117:                File destDirFile = new File(destDir);
118:                File jprops = new File(destDir + File.separator + "conf"
119:                        + File.separator + "jonas.properties");
120:
121:                if (onlyUpdate) {
122:                    if (jprops.exists()) {
123:                        log("Only updating JONAS_BASE in the directory '"
124:                                + destDir + "' from source directory '"
125:                                + jonasRoot + "'", Project.MSG_INFO);
126:                        JOnASAntTool.updateJonasBase(this , jonasRoot,
127:                                destDirFile);
128:
129:                        return;
130:                    } else {
131:                        throw new BuildException("JOnAS base directory '"
132:                                + destDir + "' doesn't exists. Cannot update.");
133:                    }
134:                }
135:
136:                log("Creating JONAS_BASE in the directory '" + destDir
137:                        + "' from source directory '" + jonasRoot + "'",
138:                        Project.MSG_INFO);
139:                Copy copy = new Copy();
140:                JOnASAntTool.configure(this , copy);
141:                copy.setTodir(destDirFile);
142:                FileSet fileSet = new FileSet();
143:                fileSet.setDir(new File(new File(jonasRoot, "templates"),
144:                        "conf"));
145:                copy.addFileset(fileSet);
146:                copy.setOverwrite(true);
147:                copy.execute();
148:            }
149:
150:            /**
151:             * Updates a JONAS_BASE
152:             * @param destDir destination directory
153:             */
154:            private void updateJonasBase(String destDir) {
155:                File destDirFile = new File(destDir);
156:                JOnASAntTool.updateJonasBase(this , jonasRoot, destDirFile);
157:            }
158:
159:            /**
160:             * Run this task
161:             * @see org.apache.tools.ant.Task#execute()
162:             */
163:            public void execute() {
164:                if (jonasRoot == null) {
165:                    throw new BuildException("jonasRoot element is not set");
166:                }
167:
168:                if (destDirPrefix == null) {
169:                    throw new BuildException("destDirPrefix element is not set");
170:                }
171:
172:                if (cdDir == null) {
173:                    throw new BuildException("cdDir element is not set");
174:                }
175:
176:                if (jonasRoot.getPath().equals(destDirPrefix)) {
177:                    throw new BuildException(
178:                            "jonasRoot and destDirPrefix is the same path !");
179:                }
180:
181:                // First, JONAS_BASE creation
182:                for (int i = 1; i <= webInstNb + ejbInstNb; i++) {
183:
184:                    String destDir = ClusterTasks.getDestDir(destDirPrefix, i);
185:                    createJonasBase(destDir);
186:                }
187:
188:                // Creates JONAS_BASE for the cluster daemon
189:                createJonasBase(cdDir);
190:
191:                // 2nd, executes the tasks
192:                for (Iterator it = tasks.iterator(); it.hasNext();) {
193:                    BaseTaskItf task = (BaseTaskItf) it.next();
194:                    task.setJonasRoot(jonasRoot);
195:                    JOnASAntTool.configure(this , (Task) task);
196:                    String info = task.getLogInfo();
197:                    if (info != null) {
198:                        log(info, Project.MSG_INFO);
199:                    }
200:
201:                    task.execute();
202:                }
203:
204:                // Then update JonasBase
205:                for (int i = 1; i <= webInstNb + ejbInstNb; i++) {
206:                    String destDir = ClusterTasks.getDestDir(destDirPrefix, i);
207:                    updateJonasBase(destDir);
208:                }
209:
210:                // Update JONAS_BASE for the cluster daemon
211:                updateJonasBase(cdDir);
212:            }
213:
214:            /**
215:             * Add tasks for configured object
216:             * @param subTasks some tasks to do on files
217:             */
218:            public void addTasks(Tasks subTasks) {
219:                if (subTasks != null) {
220:                    for (Iterator it = subTasks.getTasks().iterator(); it
221:                            .hasNext();) {
222:                        tasks.add(it.next());
223:                    }
224:                }
225:            }
226:
227:            /**
228:             * Set the destination directory prefix
229:             * @param destDirPrefix the destination directory prefix
230:             */
231:            public void setDestDirPrefix(String destDirPrefix) {
232:                this .destDirPrefix = destDirPrefix;
233:            }
234:
235:            /**
236:             * Set the cluster daemon directory
237:             * @param cdDir the destination directory for the cluster daemon configuration
238:             */
239:            public void setCdDir(String cdDir) {
240:                this .cdDir = cdDir;
241:            }
242:
243:            /**
244:             * Set the source directory for the replacement
245:             * @param jonasRoot the source directory
246:             */
247:            public void setJonasRoot(File jonasRoot) {
248:                this .jonasRoot = jonasRoot;
249:            }
250:
251:            /**
252:             * Set architecture
253:             * @param arch the architecture
254:             */
255:            public void setArch(String arch) {
256:                this .arch = arch;
257:            }
258:
259:            /**
260:             * Set the web instances number
261:             * @param webInstNb number of web instances
262:             */
263:            public void setWebInstNb(int webInstNb) {
264:                this .webInstNb = webInstNb;
265:            }
266:
267:            /**
268:             * Set the ejb instances number
269:             * @param ejbInstNb number of ejb instances
270:             */
271:            public void setEjbInstNb(int ejbInstNb) {
272:                this .ejbInstNb = ejbInstNb;
273:            }
274:
275:            /**
276:             * Add tasks for the common instances (both web & ejb )
277:             * @param common common tasks to do
278:             */
279:            public void addConfiguredCommon(Common common) {
280:                common.setRootTask(this );
281:                common.setDestDirPrefix(destDirPrefix);
282:                common.setDestDirSuffixIndFirst(1);
283:                common.setDestDirSuffixIndLast(webInstNb + ejbInstNb);
284:                common.setArch(arch);
285:                common.generatesTasks();
286:                addTasks(common);
287:            }
288:
289:            /**
290:             * Add tasks for the web level instances
291:             * If choosen architecture is both web and ejb within the same JOnAS,
292:             * the tasks are added to all instances
293:             * @param webLevel tasks to do on files
294:             */
295:            public void addConfiguredWebLevel(WebLevel webLevel) {
296:                webLevel.setRootTask(this );
297:                webLevel.setDestDirPrefix(destDirPrefix);
298:                webLevel.setArch(arch);
299:
300:                if (arch.compareTo(ARCH_BOTH_WEB_EJB) == 0) {
301:                    webLevel.setDestDirSuffixIndFirst(1);
302:                    webLevel.setDestDirSuffixIndLast(webInstNb + ejbInstNb);
303:                } else if (arch.compareTo(ARCH_DIFF_WEB_EJB) == 0) {
304:                    webLevel.setDestDirSuffixIndFirst(1);
305:                    webLevel.setDestDirSuffixIndLast(webInstNb);
306:                } else {
307:                    handleErrorOutput("Invalide architecture choice : " + arch);
308:                }
309:                webLevel.generatesTasks();
310:                addTasks(webLevel);
311:            }
312:
313:            /**
314:             * Add tasks for the ejb level instances
315:             * If choosen architecture is both web and ejb within the same JOnAS,
316:             * the tasks are added to all instances
317:             * @param ejbLevel tasks to do on files
318:             */
319:            public void addConfiguredEjbLevel(EjbLevel ejbLevel) {
320:                ejbLevel.setRootTask(this );
321:                ejbLevel.setDestDirPrefix(destDirPrefix);
322:                ejbLevel.setArch(arch);
323:
324:                if (arch.compareTo(ARCH_BOTH_WEB_EJB) == 0) {
325:                    ejbLevel.setDestDirSuffixIndFirst(1);
326:                    ejbLevel.setDestDirSuffixIndLast(webInstNb + ejbInstNb);
327:                } else if (arch.compareTo(ARCH_DIFF_WEB_EJB) == 0) {
328:                    ejbLevel.setDestDirSuffixIndFirst(webInstNb + 1);
329:                    ejbLevel.setDestDirSuffixIndLast(webInstNb + ejbInstNb);
330:                } else {
331:                    handleErrorOutput("Invalide architecture choice : " + arch);
332:                }
333:                ejbLevel.generatesTasks();
334:                addTasks(ejbLevel);
335:            }
336:
337:            /**
338:             * Add tasks for the is
339:             * @param script Tasks to do on files
340:             */
341:            public void addConfiguredScript(Script script) {
342:                script.setRootTask(this );
343:                script.setLogInfo("Script");
344:                script.setInstNb(webInstNb + ejbInstNb);
345:                script.setDestDirPrefix(destDirPrefix);
346:                script.generatesTasks();
347:                addTasks(script);
348:            }
349:
350:            /**
351:             * Add tasks for the is
352:             * @param script Tasks to do on files
353:             */
354:            public void addConfiguredClusterDaemon(ClusterDaemon clusterDaemon) {
355:                clusterDaemon.setRootTask(this );
356:                clusterDaemon.setLogInfo("ClusterDaemon");
357:                clusterDaemon.setInstNb(webInstNb + ejbInstNb);
358:                clusterDaemon.setDestDirPrefix(destDirPrefix);
359:                clusterDaemon.setJonasRoot(jonasRoot.getAbsolutePath());
360:                clusterDaemon.generatesTasks();
361:                addTasks(clusterDaemon);
362:            }
363:
364:            /**
365:             * Set if this is only an update or a new JONAS_BASE
366:             * @param onlyUpdate If true update, else create and then update
367:             */
368:            public void setUpdate(boolean onlyUpdate) {
369:                this.onlyUpdate = onlyUpdate;
370:            }
371:
372:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.