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: ClusterTasks.java 6896 2005-06-07 08:21:28Z pelletib $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas.ant.cluster;
026:
027: import java.util.ArrayList;
028: import java.util.List;
029:
030: import org.apache.tools.ant.Task;
031:
032: import org.objectweb.jonas.ant.jonasbase.Tasks;
033:
034: /**
035: * Defines a common cluster task
036: * @author Benoit Pelletier
037: */
038: public abstract class ClusterTasks extends Tasks {
039:
040: /**
041: * Archictecture of the JOnAS's instances : contain both Web level and Ejb level
042: */
043: protected static final String ARCH_BOTH_WEB_EJB = "bothWebEjb";
044:
045: /**
046: * Archictecture of the JOnAS's instances : separate Web level and Ejb level
047: */
048: protected static final String ARCH_SEPARATED_WEB_EJB = "separatedWebEjb";
049:
050: /**
051: * Information for the logger
052: */
053: private String logInfo = null;
054:
055: /**
056: * Prefix to the destination directory (JONAS_BASE)
057: */
058: private String destDirPrefix = null;
059:
060: /**
061: * First index for the destDir suffix
062: */
063: private int destDirSuffixIndFirst = -1;
064:
065: /**
066: * Last index for the destDir suffix
067: */
068: private int destDirSuffixIndLast = -1;
069:
070: /**
071: * Cluster tasks List
072: */
073: private List clusterTasks = null;
074:
075: /**
076: * Cluster architecture : share instance for web/ejb or separate them
077: */
078: private String arch = null;
079:
080: /**
081: * Root task set just for logging purpose
082: */
083: private Task rootTask = null;
084:
085: /**
086: * Constructor
087: */
088: public ClusterTasks() {
089: clusterTasks = new ArrayList();
090: }
091:
092: /**
093: * Set directory prefix
094: * @param destDirPrefix The destDirPrefix to set.
095: */
096: public void setDestDirPrefix(String destDirPrefix) {
097: this .destDirPrefix = destDirPrefix;
098: }
099:
100: /**
101: * Gets the prefix of the destination directory
102: * @return the prefix of the destination directory
103: */
104: public String getDestDirPrefix() {
105: return destDirPrefix;
106: }
107:
108: /**
109: * @param destDirSuffixIndFirst The destDirSuffixIndFirst to set.
110: */
111: public void setDestDirSuffixIndFirst(int destDirSuffixIndFirst) {
112: this .destDirSuffixIndFirst = destDirSuffixIndFirst;
113: }
114:
115: /**
116: * Gets the first index of the destDir suffix
117: * @return the first index of the destDir suffix
118: */
119: public int getDestDirSuffixIndFirst() {
120: return destDirSuffixIndFirst;
121: }
122:
123: /**
124: * @param destDirSuffixIndLast The destDirSuffixIndLast to set.
125: */
126: public void setDestDirSuffixIndLast(int destDirSuffixIndLast) {
127: this .destDirSuffixIndLast = destDirSuffixIndLast;
128: }
129:
130: /**
131: * Gets the last index of the destDir suffix
132: * @return the last index of the destDir suffix
133: */
134: public int getDestDirSuffixIndLast() {
135: return destDirSuffixIndLast;
136: }
137:
138: /**
139: * Gets logger info (to be displayed)
140: * @return logger info
141: * @see org.objectweb.jonas.ant.jonasbase.BaseTaskItf#getLogInfo()
142: */
143: public String getLogInfo() {
144: return logInfo;
145: }
146:
147: /**
148: * Set the info to be displayed by the logger
149: * @param logInfo information to be displayed
150: * @see org.objectweb.jonas.ant.jonasbase.BaseTaskItf#setLogInfo(java.lang.String)
151: */
152: public void setLogInfo(String logInfo) {
153: this .logInfo = logInfo;
154: }
155:
156: /**
157: * Build dest dir with an index
158: * @param destDirPrefix destination directory prefix
159: * @param i index
160: * @return destination directory
161: */
162: public static String getDestDir(String destDirPrefix, int i) {
163: String destDir = destDirPrefix + i;
164: return destDir;
165: }
166:
167: /**
168: * Set architecture
169: * @param arch the architecture
170: */
171: public void setArch(String arch) {
172: this .arch = arch;
173: }
174:
175: /**
176: * Get architecture
177: * @return architecture
178: */
179: public String getArch() {
180: return arch;
181: }
182:
183: /**
184: * Set root task
185: * @param rootTask root task
186: */
187: public void setRootTask(Task rootTask) {
188: this .rootTask = rootTask;
189: }
190:
191: /**
192: * Get root Task
193: * @return rootTask root task
194: */
195: public Task getRootTask() {
196: return rootTask;
197: }
198:
199: /**
200: * Add a task to the list of defined tasks
201: * @param ct task to add
202: */
203: public void addClusterTask(ClusterTasks ct) {
204: clusterTasks.add(ct);
205: }
206:
207: /**
208: * @return a list of all tasks to do
209: */
210: public List getClusterTasks() {
211: return clusterTasks;
212: }
213:
214: /**
215: * Logging
216: * @param msg message to log
217: */
218: public void log(String msg) {
219:
220: if (rootTask != null) {
221: rootTask.log(msg);
222: }
223: }
224:
225: /**
226: * Abstract generatesTasks()
227: */
228: public abstract void generatesTasks();
229: }
|