KickJava   Java API By Example, From Geeks To Geeks.

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


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: Discovery.java,v 1.1 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  * Defines properties for carol.properties
33  * @author Florent Benoit
34  */

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

40     private static final String JavaDoc INFO = "[Discovery] ";
41
42     /**
43      * Default mcast addr
44      */

45     private static final String JavaDoc DEFAULT_DISCOVERY_MCASTADDR = "224.224.224.224";
46
47     /**
48      * Default mcast port
49      */

50     private static final String JavaDoc DEFAULT_DISCOVERY_MCASTPORT = "9080";
51
52     /**
53      * Default greeting port
54      */

55     private static final String JavaDoc DEFAULT_DISCOVERY_GREETING_PORT = "9899";
56
57     /**
58      * Default source port
59      */

60     private static final String JavaDoc DEFAULT_DISCOVERY_SOURCE_PORT = "9888";
61
62     /**
63      * Discovery mcast addr property
64      */

65     private static final String JavaDoc DISCOVERY_MCASTADDR_PROPERTY = "jonas.service.discovery.multicast.address";
66
67     /**
68      * Discovery mcast port property
69      */

70     private static final String JavaDoc DISCOVERY_MCASTPORT_PROPERTY = "jonas.service.discovery.multicast.port";
71
72     /**
73      * Discovery master property
74      */

75     private static final String JavaDoc DISCOVERY_MASTER_PROPERTY = "jonas.service.discovery.master";
76
77     /**
78      * Discovery greeting port property
79      */

80     private static final String JavaDoc DISCOVERY_GREETING_PORT_PROPERTY = "jonas.service.discovery.greeting.port";
81
82     /**
83      * Discovery greeting timeout property
84      */

85     private static final String JavaDoc DISCOVERY_GREETING_TIMEOUT_PROPERTY = "jonas.service.discovery.greeting.timeout";
86
87     /**
88      * Discovery source port property
89      */

90     private static final String JavaDoc DISCOVERY_SOURCE_PORT_PROPERTY = "jonas.service.discovery.source.port";
91
92     /**
93      * Default constructor
94      */

95     public Discovery() {
96         super();
97     }
98
99     /**
100      * Set the source port for the discovery service
101      * @param portNumber port number
102      */

103     public void setSourcePort(String JavaDoc portNumber) {
104         enableMaster();
105
106         // Token to replace
107
String JavaDoc token = DISCOVERY_SOURCE_PORT_PROPERTY + "=" + DEFAULT_DISCOVERY_SOURCE_PORT;
108         String JavaDoc value = DISCOVERY_SOURCE_PORT_PROPERTY + "=" + portNumber;
109         JReplace propertyReplace = new JReplace();
110         propertyReplace.setLogInfo(INFO + "Setting source port for discovery");
111         propertyReplace.setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE);
112         propertyReplace.setToken(token);
113         propertyReplace.setValue(value);
114         addTask(propertyReplace);
115     }
116
117     /**
118      * Enable greeting part of discovery service
119      */

120     private void enableMaster() {
121         // 1st Token to replace
122
String JavaDoc token1 = "#" + DISCOVERY_MASTER_PROPERTY;
123         String JavaDoc value1 = DISCOVERY_MASTER_PROPERTY;
124         JReplace propertyReplace1 = new JReplace();
125         propertyReplace1.setLogInfo(INFO + "Enable master node for discovery");
126         propertyReplace1.setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE);
127         propertyReplace1.setToken(token1);
128         propertyReplace1.setValue(value1);
129         addTask(propertyReplace1);
130
131         //2nd Token to replace
132
String JavaDoc token2 = "#" + DISCOVERY_SOURCE_PORT_PROPERTY;
133         String JavaDoc value2 = DISCOVERY_SOURCE_PORT_PROPERTY;
134         JReplace propertyReplace2 = new JReplace();
135         propertyReplace2.setLogInfo(INFO + "Enable greeting timeout for discovery");
136         propertyReplace2.setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE);
137         propertyReplace2.setToken(token2);
138         propertyReplace2.setValue(value2);
139         addTask(propertyReplace2);
140     }
141
142     /**
143      * Enable greeting part of discovery service
144      */

145     private void enableGreeting() {
146         // 1st Token to replace
147
String JavaDoc token1 = "#" + DISCOVERY_GREETING_PORT_PROPERTY;
148         String JavaDoc value1 = DISCOVERY_GREETING_PORT_PROPERTY;
149         JReplace propertyReplace1 = new JReplace();
150         propertyReplace1.setLogInfo(INFO + "Enable greeting port for discovery");
151         propertyReplace1.setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE);
152         propertyReplace1.setToken(token1);
153         propertyReplace1.setValue(value1);
154         addTask(propertyReplace1);
155
156         //2nd Token to replace
157
String JavaDoc token2 = "#" + DISCOVERY_GREETING_TIMEOUT_PROPERTY;
158         String JavaDoc value2 = DISCOVERY_GREETING_TIMEOUT_PROPERTY;
159         JReplace propertyReplace2 = new JReplace();
160         propertyReplace2.setLogInfo(INFO + "Enable greeting timeout for discovery");
161         propertyReplace2.setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE);
162         propertyReplace2.setToken(token2);
163         propertyReplace2.setValue(value2);
164         addTask(propertyReplace2);
165    }
166
167     /**
168      * Set the port for the discovery service
169      * @param portNumber port number
170      */

171     public void setGreetingPort(String JavaDoc portNumber) {
172         enableGreeting();
173         // Token to replace
174
String JavaDoc token = DISCOVERY_GREETING_PORT_PROPERTY + "=" + DEFAULT_DISCOVERY_GREETING_PORT;
175         String JavaDoc value = DISCOVERY_GREETING_PORT_PROPERTY + "=" + portNumber;
176         JReplace propertyReplace = new JReplace();
177         propertyReplace.setLogInfo(INFO + "Setting greeting port for discovery");
178         propertyReplace.setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE);
179         propertyReplace.setToken(token);
180         propertyReplace.setValue(value);
181         addTask(propertyReplace);
182     }
183
184     /**
185      * Set mcastAddr
186      * @param mcastAddr multicast address
187      */

188     public void setMcastAddr(String JavaDoc mcastAddr) {
189
190         // Token to replace
191
String JavaDoc token = DISCOVERY_MCASTADDR_PROPERTY + "=" + DEFAULT_DISCOVERY_MCASTADDR;
192         String JavaDoc value = DISCOVERY_MCASTADDR_PROPERTY + "=" + mcastAddr;
193         JReplace propertyReplace = new JReplace();
194         propertyReplace.setLogInfo(INFO + "Setting mcastaddr for discovery");
195         propertyReplace.setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE);
196         propertyReplace.setToken(token);
197         propertyReplace.setValue(value);
198         addTask(propertyReplace);
199
200     }
201
202     /**
203      * Set mcastPort
204      * @param mcastPort multicast port
205      */

206     public void setMcastPort(String JavaDoc mcastPort) {
207
208         // Token to replace
209
String JavaDoc token = DISCOVERY_MCASTPORT_PROPERTY + "=" + DEFAULT_DISCOVERY_MCASTPORT;
210         String JavaDoc value = DISCOVERY_MCASTPORT_PROPERTY + "=" + mcastPort;
211         JReplace propertyReplace = new JReplace();
212         propertyReplace.setLogInfo(INFO + "Setting mcastport for discovery");
213         propertyReplace.setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE);
214         propertyReplace.setToken(token);
215         propertyReplace.setValue(value);
216         addTask(propertyReplace);
217
218     }
219 }
Popular Tags