KickJava   Java API By Example, From Geeks To Geeks.

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


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: DiscoveryCluster.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.Discovery;
34
35 /**
36  * Define DiscoveryCluster task
37  * @author Benoit Pelletier
38  */

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

44     private static final String JavaDoc INFO = "[DiscoveryCluster] ";
45
46     /**
47      * greeting ports range
48      */

49     private String JavaDoc[] greetingPortRange = null;
50
51     /**
52      * source ports range
53      */

54     private String JavaDoc[] sourcePortRange = null;
55
56     /**
57      * multicast port
58      */

59     private String JavaDoc mcastPort = null;
60
61     /**
62      * multicast addr
63      */

64     private String JavaDoc mcastAddr = null;
65
66     /**
67      * ind of master node
68      */

69     private int masterNode = -1;
70
71
72     /**
73      * Default constructor
74      */

75     public DiscoveryCluster() {
76         super();
77     }
78
79     /**
80      * Set master node
81      * @param masterNode inf of the master node
82      */

83     public void setMasterNode(int masterNode) {
84         this.masterNode = masterNode;
85     }
86
87     /**
88      * Set mcastPort
89      * @param mcastPort multicast port to set
90      */

91     public void setMcastPort(String JavaDoc mcastPort) {
92         this.mcastPort = mcastPort;
93     }
94
95     /**
96      * Set mcastAddr
97      * @param mcastAddr multicast address to set
98      */

99     public void setMcastAddr(String JavaDoc mcastAddr) {
100         this.mcastAddr = mcastAddr;
101     }
102
103     /**
104      * Set greeting ports range
105      * @param portRange ports range
106      */

107     public void setGreetingPortRange(String JavaDoc portRange) {
108         this.greetingPortRange = portRange.split(",");
109
110     }
111
112     /**
113      * Set source ports range
114      * @param portRange ports range
115      */

116     public void setSourcePortRange(String JavaDoc portRange) {
117         this.sourcePortRange = portRange.split(",");
118
119     }
120
121     /**
122      * Generates the discovery tasks for each JOnAS's instances
123      */

124     public void generatesTasks() {
125
126         int portInd = 0;
127
128         for (int i = getDestDirSuffixIndFirst(); i <= getDestDirSuffixIndLast(); i++) {
129
130             String JavaDoc destDir = getDestDir(getDestDirPrefix(), i);
131             log(INFO + "tasks generation for " + destDir);
132             // creation of the Discovery tasks
133
Discovery discovery = new Discovery();
134
135             if (i == masterNode) {
136                 discovery.setSourcePort(sourcePortRange[portInd]);
137             }
138             discovery.setGreetingPort(greetingPortRange[portInd]);
139             discovery.setMcastPort(mcastPort);
140             discovery.setMcastAddr(mcastAddr);
141
142             // set destDir for each carol task
143
for (Iterator JavaDoc it = discovery.getTasks().iterator(); it.hasNext();) {
144                 BaseTaskItf task = (BaseTaskItf) it.next();
145                 task.setDestDir(new File JavaDoc(destDir));
146             }
147
148             addTasks(discovery);
149
150             portInd++;
151
152         }
153     }
154 }
Popular Tags