KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > jms > admin > PlatformAdmin


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2005 - ScalAgent Distributed Technologies
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * Initial developer(s): Nicolas Tachker (ScalAgent)
21  * Contributor(s):
22  */

23 package org.objectweb.joram.client.jms.admin;
24
25 import java.net.ConnectException JavaDoc;
26 import java.net.UnknownHostException JavaDoc;
27 import java.util.List JavaDoc;
28
29 import fr.dyade.aaa.util.management.MXWrapper;
30 import org.objectweb.joram.shared.JoramTracing;
31 import org.objectweb.util.monolog.api.BasicLevel;
32
33 /**
34  *
35  */

36 public class PlatformAdmin
37   implements PlatformAdminMBean {
38
39   public PlatformAdmin()
40     throws ConnectException JavaDoc, AdminException {
41     connect("root", "root", 60);
42     registerMBean();
43   }
44   
45   public PlatformAdmin(String JavaDoc hostName,
46                        int port,
47                        String JavaDoc name,
48                        String JavaDoc password,
49                        int cnxTimer,
50                        String JavaDoc reliableClass)
51     throws UnknownHostException JavaDoc, ConnectException JavaDoc, AdminException {
52     connect(hostName,port,name,password,cnxTimer,reliableClass);
53     registerMBean();
54   }
55
56   public PlatformAdmin(String JavaDoc hostName,
57                        int port,
58                        String JavaDoc name,
59                        String JavaDoc password,
60                        int cnxTimer)
61     throws UnknownHostException JavaDoc, ConnectException JavaDoc, AdminException {
62     connect(hostName,port,name,password,cnxTimer,
63             "org.objectweb.joram.client.jms.tcp.ReliableTcpClient");
64     registerMBean();
65   }
66
67   public PlatformAdmin(String JavaDoc name,
68                        String JavaDoc password)
69     throws ConnectException JavaDoc, AdminException {
70     collocatedConnect(name,password);
71     registerMBean();
72   }
73
74   public PlatformAdmin(javax.jms.TopicConnectionFactory JavaDoc cnxFact,
75                        String JavaDoc name,
76                        String JavaDoc password)
77     throws ConnectException JavaDoc, AdminException {
78     connect(cnxFact,name,password);
79     registerMBean();
80   }
81
82   private void registerMBean() {
83     try {
84       MXWrapper.registerMBean(this,
85                               "joramClient",
86                               "type=PlatformAdmin");
87     } catch (Exception JavaDoc e) {
88       if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG))
89         JoramTracing.dbgClient.log(BasicLevel.DEBUG,
90                                    "registerMBean",e);
91     }
92   }
93
94   private void unregisterMBean() {
95     try {
96       MXWrapper.unregisterMBean("joramClient",
97                                 "type=PlatformAdmin");
98     } catch (Exception JavaDoc e) {
99       if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG))
100         JoramTracing.dbgClient.log(BasicLevel.DEBUG,
101                                    "unregisterMBean",e);
102     }
103   }
104
105
106   /**
107    * Opens a connection dedicated to administering with the Joram server
108    * which parameters are wrapped by a given
109    * <code>TopicConnectionFactory</code>.
110    *
111    * @param cnxFact The TopicConnectionFactory to use for connecting.
112    * @param name Administrator's name.
113    * @param password Administrator's password.
114    *
115    * @exception ConnectException If connecting fails.
116    * @exception AdminException If the administrator identification is
117    * incorrect.
118    */

119   public void connect(javax.jms.TopicConnectionFactory JavaDoc cnxFact,
120                       String JavaDoc name,
121                       String JavaDoc password)
122     throws ConnectException JavaDoc, AdminException {
123     AdminModule.connect(cnxFact,name,password);
124   }
125
126   /**
127    * Opens a TCP connection with the Joram server running on a given host and
128    * listening to a given port.
129    *
130    * @param host The name or IP address of the host the server is running on.
131    * @param port The number of the port the server is listening to.
132    * @param name Administrator's name.
133    * @param password Administrator's password.
134    * @param cnxTimer Timer in seconds during which connecting to the server
135    * is attempted.
136    * @param reliableClass Reliable class name.
137    *
138    * @exception UnknownHostException If the host is invalid.
139    * @exception ConnectException If connecting fails.
140    * @exception AdminException If the administrator identification is
141    * incorrect.
142    */

143   public void connect(String JavaDoc hostName,
144                       int port,
145                       String JavaDoc name,
146                       String JavaDoc password,
147                       int cnxTimer,
148                       String JavaDoc reliableClass)
149     throws UnknownHostException JavaDoc, ConnectException JavaDoc, AdminException {
150     AdminModule.connect(hostName,port,name,password,cnxTimer,reliableClass);
151   }
152   
153   /**
154    * Opens a TCP connection with the Joram server running on the default
155    * "locahost" host and listening to the default 16010 port.
156    *
157    * @param name Administrator's name.
158    * @param password Administrator's password.
159    * @param cnxTimer Timer in seconds during which connecting to the server
160    * is attempted.
161    *
162    * @exception UnknownHostException Never thrown.
163    * @exception ConnectException If connecting fails.
164    * @exception AdminException If the administrator identification is
165    * incorrect.
166    */

167   public void connect(String JavaDoc name, String JavaDoc password, int cnxTimer)
168     throws ConnectException JavaDoc, AdminException {
169     try {
170       connect("localhost",
171               16010,
172               name,
173               password,
174               cnxTimer,
175               "org.objectweb.joram.client.jms.tcp.ReliableTcpClient");
176     } catch (UnknownHostException JavaDoc exc) {
177       throw new AdminException(exc.getMessage());
178     }
179   }
180
181   /**
182    * Opens a connection with the collocated JORAM server.
183    *
184    * @param name Administrator's name.
185    * @param password Administrator's password.
186    *
187    * @exception ConnectException If connecting fails.
188    * @exception AdminException If the administrator identification is
189    * incorrect.
190    */

191   public void collocatedConnect(String JavaDoc name, String JavaDoc password)
192     throws ConnectException JavaDoc, AdminException {
193     AdminModule.collocatedConnect(name,password);
194   }
195
196   /** Closes the administration connection. */
197   public void disconnect() {
198     AdminModule.disconnect();
199   }
200   
201   /** Closes the administration connection
202    * and unregister the MBean.
203    */

204   public void exit() {
205     disconnect();
206     unregisterMBean();
207   }
208
209   /**
210    * Stops a given server of the platform.
211    * <p>
212    * The request fails if the target server does not belong to the platform.
213    *
214    * @param serverId Identifier of the server to stop.
215    *
216    * @exception ConnectException If the connection fails.
217    * @exception AdminException If the request fails.
218    */

219   public void stopServer(int serverId)
220     throws ConnectException JavaDoc, AdminException {
221     AdminModule.stopServer(serverId);
222   }
223
224   /**
225    * Stops the platform local server.
226    *
227    * @exception ConnectException If the connection fails.
228    * @exception AdminException Never thrown.
229    */

230   public void stopServer()
231     throws ConnectException JavaDoc, AdminException {
232     AdminModule.stopServer();
233   }
234
235   /**
236    * Adds a server to the platform.
237    *
238    * @param serverId Id of the added server
239    * @param hostName Address of the host where the added server is started
240    * @param domainName Name of the domain where the server is added
241    * @param port Listening port of the server in the specified domain
242    * @param serverName Name of the added server
243    *
244    * @exception ConnectException If the connection fails.
245    * @exception AdminException If the request fails.
246    */

247   public void addServer(int sid,
248                         String JavaDoc hostName,
249                         String JavaDoc domainName,
250                         int port,
251                         String JavaDoc serverName)
252     throws ConnectException JavaDoc, AdminException {
253     AdminModule.addServer(sid,hostName,domainName,port,serverName);
254   }
255
256   /**
257    * Removes a server from the platform.
258    *
259    * @param sid Id of the removed server
260    *
261    * @exception ConnectException If the connection fails.
262    * @exception AdminException If the request fails.
263    */

264   public void removeServer(int sid)
265     throws ConnectException JavaDoc, AdminException {
266     AdminModule.removeServer(sid);
267   }
268
269   /**
270    * Adds a domain to the platform.
271    *
272    * @param domainName Name of the added domain
273    * @param sid Id of the router server that
274    * gives access to the added domain
275    * @param port Listening port in the added domain of the
276    * router server
277    *
278    * @exception ConnectException If the connection fails.
279    * @exception AdminException If the request fails.
280    */

281   public void addDomain(String JavaDoc domainName,
282                         int sid,
283                         int port)
284     throws ConnectException JavaDoc, AdminException {
285     AdminModule.addDomain(domainName,sid,port);
286   }
287
288   /**
289    * Removes a domain from the platform.
290    *
291    * @param domainName Name of the added domain
292    *
293    * @exception ConnectException If the connection fails.
294    * @exception AdminException If the request fails.
295    */

296   public void removeDomain(String JavaDoc domainName)
297     throws ConnectException JavaDoc, AdminException {
298     AdminModule.removeDomain(domainName);
299   }
300
301   /**
302    * Returns the current servers configuration (a3servers.xml).
303    *
304    * @exception ConnectException If the connection fails.
305    * @exception AdminException If the request fails.
306    */

307   public String JavaDoc getConfiguration()
308     throws ConnectException JavaDoc, AdminException {
309     return AdminModule.getConfiguration();
310   }
311
312   /**
313    * Returns the list of the platform's servers' identifiers.
314    */

315   public List JavaDoc getServersIds() {
316     try {
317       return AdminModule.getServersIds();
318     } catch (Exception JavaDoc exc) {
319     return null;
320     }
321   }
322
323   /**
324    * Returns the list of the servers' identifiers that belong
325    * to the specified domain
326    *
327    * @exception ConnectException If the connection fails.
328    * @exception AdminException Never thrown.
329    */

330   public List JavaDoc getServersIds(String JavaDoc domainName)
331     throws ConnectException JavaDoc, AdminException {
332     return AdminModule.getServersIds(domainName);
333   }
334
335   /**
336    * Returns the list of the domain names that
337    * contains the specified server.
338    *
339    * @exception ConnectException If the connection fails.
340    * @exception AdminException Never thrown.
341    */

342   public String JavaDoc[] getDomainNames(int serverId)
343     throws ConnectException JavaDoc, AdminException {
344     return AdminModule.getDomainNames(serverId);
345   }
346
347   /**
348    * Sets a given value as the default threshold for a given server (-1 for
349    * unsetting previous value).
350    * <p>
351    * The request fails if the target server does not belong to the platform.
352    *
353    * @param serverId The identifier of the server.
354    * @param threshold The threshold value to be set.
355    *
356    * @exception ConnectException If the connection fails.
357    * @exception AdminException If the request fails.
358    */

359   public void setDefaultThreshold(int serverId, int threshold)
360     throws ConnectException JavaDoc, AdminException {
361     AdminModule.setDefaultThreshold(serverId,threshold);
362   }
363
364   /**
365    * Sets a given value as the default threshold for the local server (-1 for
366    * unsetting previous value).
367    *
368    * @param threshold The threshold value to be set.
369    *
370    * @exception ConnectException If the connection fails.
371    * @exception AdminException Never thrown.
372    */

373   public void setDefaultThreshold(int threshold)
374     throws ConnectException JavaDoc, AdminException {
375     AdminModule.setDefaultThreshold(threshold);
376   }
377
378   /**
379    * Returns the default threshold value for a given server, -1 if not set.
380    * <p>
381    * The request fails if the target server does not belong to the platform.
382    *
383    * @exception ConnectException If the connection fails.
384    * @exception AdminException If the request fails.
385    */

386   public int getDefaultThreshold(int serverId)
387     throws ConnectException JavaDoc, AdminException {
388     return AdminModule.getDefaultThreshold(serverId);
389   }
390
391   /**
392    * Returns the default threshold value for the local server, -1 if not set.
393    *
394    * @exception ConnectException If the connection fails.
395    * @exception AdminException Never thrown.
396    */

397   public int getDefaultThreshold()
398     throws ConnectException JavaDoc, AdminException {
399     return AdminModule.getDefaultThreshold();
400   }
401
402   /**
403    * Returns the identifier of the server the module is connected to.
404    *
405    * @exception ConnectException If the admin connection is not established.
406    */

407   public int getLocalServerId()
408     throws ConnectException JavaDoc {
409     return AdminModule.getLocalServerId();
410   }
411
412   /**
413    * Returns the host name of the server the module is connected to.
414    *
415    * @exception ConnectException If the admin connection is not established.
416    */

417   public String JavaDoc getLocalHost()
418     throws ConnectException JavaDoc {
419     return AdminModule.getLocalHost();
420   }
421
422   /**
423    * Returns the port number of the server the module is connected to.
424    *
425    * @exception ConnectException If the admin connection is not established.
426    */

427   public int getLocalPort()
428     throws ConnectException JavaDoc {
429     return AdminModule.getLocalPort();
430   }
431 }
432
Popular Tags