KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > jms > Topic


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

25 package org.objectweb.joram.client.jms;
26
27 import java.net.ConnectException JavaDoc;
28 import java.util.Vector JavaDoc;
29 import java.util.Hashtable JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Properties JavaDoc;
32  
33 import javax.jms.JMSException JavaDoc;
34 import javax.naming.NamingException JavaDoc;
35
36 import org.objectweb.joram.client.jms.admin.AdminException;
37 import org.objectweb.joram.client.jms.admin.AdminModule;
38
39 import org.objectweb.joram.shared.admin.*;
40
41 import org.objectweb.util.monolog.api.BasicLevel;
42 import org.objectweb.joram.shared.JoramTracing;
43
44 import fr.dyade.aaa.util.management.MXWrapper;
45
46 /**
47  * Implements the <code>javax.jms.Topic</code> interface and provides
48  * Joram specific administration and monitoring methods. This is a proxy
49  * object a client uses to specify the destination of messages it is
50  * sending and the source of messages it receives.
51  */

52 public class Topic extends Destination implements javax.jms.Topic JavaDoc, TopicMBean {
53   private final static String JavaDoc TOPIC_TYPE = "topic";
54
55   public static boolean isTopic(String JavaDoc type) {
56     return Destination.isAssignableTo(type, TOPIC_TYPE);
57   }
58
59   // Used by jndi2 SoapObjectHelper
60
public Topic() {
61     super(TOPIC_TYPE);
62   }
63
64   public Topic(String JavaDoc name) {
65     super(name, TOPIC_TYPE);
66   }
67
68   protected Topic(String JavaDoc name, String JavaDoc type) {
69     super(name, type);
70   }
71
72   /**
73    * Gets the The Joram's internal unique identifier of this topic.
74    * API method.
75    *
76    * @exception JMSException Actually never thrown.
77    */

78   public String JavaDoc getTopicName() throws JMSException JavaDoc {
79     return getName();
80   }
81
82   /**
83    * Admin method creating and deploying (or retrieving) a topic on a
84    * given server. First a destination with the specified name is searched
85    * on the given server, if it does not exist it is created. In any case,
86    * its provider-specific address is returned.
87    * <p>
88    * The request fails if the target server does not belong to the platform,
89    * or if the destination deployement fails server side.
90    *
91    * @param serverId The identifier of the server where deploying the topic.
92    * @param name The name of the topic.
93    * @param className The topic class name.
94    * @param prop The topic properties.
95    *
96    * @exception ConnectException If the admin connection is closed or broken.
97    * @exception AdminException If the request fails.
98    */

99   public static Topic create(int serverId,
100                              String JavaDoc name,
101                              String JavaDoc className,
102                              Properties JavaDoc prop)
103     throws ConnectException JavaDoc, AdminException {
104     Topic topic = new Topic();
105     doCreate(serverId, name, className, prop, topic, TOPIC_TYPE);
106
107     StringBuffer JavaDoc buff = new StringBuffer JavaDoc();
108     buff.append("type=").append(TOPIC_TYPE);
109     buff.append(",name=").append(name);
110     try {
111       MXWrapper.registerMBean(topic, "joramClient", buff.toString());
112     } catch (Exception JavaDoc e) {
113       if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG))
114         JoramTracing.dbgClient.log(BasicLevel.DEBUG, "registerMBean", e);
115     }
116     return topic;
117   }
118
119   /**
120    * Admin method creating and deploying a topic on a given server.
121    * <p>
122    * The request fails if the target server does not belong to the platform,
123    * or if the destination deployement fails server side.
124    *
125    * @param serverId The identifier of the server where deploying the topic.
126    * @param className The topic class name.
127    * @param prop The topic properties.
128    *
129    * @exception ConnectException If the admin connection is closed or broken.
130    * @exception AdminException If the request fails.
131    */

132   public static Topic create(int serverId,
133                              String JavaDoc className,
134                              Properties JavaDoc prop)
135                 throws ConnectException JavaDoc, AdminException {
136     return create(serverId, null, className, prop);
137   }
138
139   /**
140    * Admin method creating and deploying a topic on a given server.
141    * It creates a Jorram's standart topic.
142    * <p>
143    * The request fails if the target server does not belong to the platform,
144    * or if the destination deployement fails server side.
145    *
146    * @param serverId The identifier of the server where deploying the topic.
147    * @param prop The topic properties.
148    *
149    * @exception ConnectException If the admin connection is closed or broken.
150    * @exception AdminException If the request fails.
151    */

152   public static Topic create(int serverId, Properties JavaDoc prop)
153                 throws ConnectException JavaDoc, AdminException {
154     return create(serverId, "org.objectweb.joram.mom.dest.Topic", prop);
155   }
156
157   /**
158    * Admin method creating and deploying (or retrieving) a topic on a given
159    * server with a given name. First a destination with the specified name is
160    * searched on the given server, if it does not exist it is created. In any
161    * case, its provider-specific address is returned.
162    * <p>
163    * The request fails if the target server does not belong to the platform,
164    * or if the destination deployement fails server side.
165    *
166    * @param serverId The identifier of the server where deploying the topic.
167    * @param name The topic name.
168    *
169    * @exception ConnectException If the admin connection is closed or broken.
170    * @exception AdminException If the request fails.
171    */

172   public static Topic create(int serverId, String JavaDoc name)
173                 throws ConnectException JavaDoc, AdminException {
174     return create(serverId, name, "org.objectweb.joram.mom.dest.Topic", null);
175   }
176
177   /**
178    * Admin method creating and deploying (or retrieving) a topic on the
179    * local server. First a destination with the specified name is searched
180    * on the given server, if it does not exist it is created. In any case,
181    * its provider-specific address is returned.
182    * <p>
183    * The request fails if the destination deployement fails server side.
184    *
185    * @param name The topic name.
186    *
187    * @exception ConnectException If the admin connection is closed or broken.
188    * @exception AdminException If the request fails.
189    */

190   public static Topic create(String JavaDoc name)
191                 throws ConnectException JavaDoc, AdminException {
192     return create(AdminModule.getLocalServerId(),
193                   name,
194                   "org.objectweb.joram.mom.dest.Topic",
195                   null);
196   }
197  
198   /**
199    * Admin method creating and deploying a topic on a given server.
200    * <p>
201    * The request fails if the target server does not belong to the platform,
202    * or if the destination deployement fails server side.
203    *
204    * @param serverId The identifier of the server where deploying the topic.
205    *
206    * @exception ConnectException If the admin connection is closed or broken.
207    * @exception AdminException If the request fails.
208    */

209   public static Topic create(int serverId)
210                 throws ConnectException JavaDoc, AdminException {
211     return create(serverId, null, "org.objectweb.joram.mom.dest.Topic", null);
212   }
213
214   /**
215    * Admin method creating and deploying a topic on the local server.
216    * <p>
217    * The request fails if the destination deployement fails server side.
218    *
219    * @exception ConnectException If the admin connection is closed or broken.
220    * @exception AdminException If the request fails.
221    */

222   public static Topic create() throws ConnectException JavaDoc, AdminException {
223     return create(AdminModule.getLocalServerId());
224   }
225
226   /**
227    * Monitoring method returning the hierarchical father of this topic,
228    * null if none.
229    * <p>
230    * The request fails if the topic is deleted server side.
231    *
232    * @exception ConnectException If the admin connection is closed or broken.
233    * @exception AdminException If the request fails.
234    */

235   public Topic getHierarchicalFather() throws ConnectException JavaDoc, AdminException
236   {
237     Monitor_GetFather request = new Monitor_GetFather(agentId);
238     Monitor_GetFatherRep reply =
239       (Monitor_GetFatherRep) AdminModule.doRequest(request);
240
241     if (reply.getFatherId() == null)
242       return null;
243     else
244       return new Topic(reply.getFatherId());
245   }
246
247   /**
248    * Monitoring method returning the list describing the cluster this topic
249    * is part of.
250    * <p>
251    * The request fails if the topic is deleted server side.
252    *
253    * @exception ConnectException If the admin connection is closed or broken.
254    * @exception AdminException If the request fails.
255    */

256   public List JavaDoc getClusterFellows() throws ConnectException JavaDoc, AdminException
257   {
258     Monitor_GetCluster request = new Monitor_GetCluster(agentId);
259     Monitor_GetClusterRep reply =
260       (Monitor_GetClusterRep) AdminModule.doRequest(request);
261
262     Vector JavaDoc topics = reply.getTopics();
263     Vector JavaDoc list = new Vector JavaDoc();
264     for (int i = 0; i < topics.size(); i++)
265       list.add(new Topic((String JavaDoc) topics.get(i)));
266     return list;
267   }
268
269   /**
270    * Monitoring method returning the number of users that subscribes on
271    * this topic.
272    * If a client has many subscriptions it is only counted once.
273    * <p>
274    * The request fails if the topic is deleted server side.
275    *
276    * @exception ConnectException If the admin connection is closed or broken.
277    * @exception AdminException If the request fails.
278    */

279   public int getSubscriptions() throws ConnectException JavaDoc, AdminException
280   {
281     Monitor_GetSubscriptions request = new Monitor_GetSubscriptions(agentId);
282     Monitor_GetNumberRep reply =
283       (Monitor_GetNumberRep) AdminModule.doRequest(request);
284     return reply.getNumber();
285   }
286
287   public String JavaDoc[] getSubscriberIds()
288     throws AdminException, ConnectException JavaDoc {
289       GetSubscriberIdsRep reply =
290         (GetSubscriberIdsRep)AdminModule.doRequest(
291           new GetSubscriberIds(agentId));
292       return reply.getSubscriberIds();
293     }
294
295   /**
296    * Adds a topic into the cluster this topic belongs to.
297    * If this topic doesn't belong to a cluster then a cluster is
298    * created by clustering this topic with the added topic.
299    * <p>
300    * The request fails if one or both of the topics are deleted, or
301    * can't belong to a cluster.
302    *
303    * @param addedTopic topic added to the cluster
304    *
305    * @exception ConnectException If the admin connection is closed or broken.
306    * @exception AdminException If the request fails.
307    */

308   public void addClusteredTopic(Topic addedTopic)
309     throws ConnectException JavaDoc, AdminException
310   {
311     AdminModule.doRequest(
312       new SetCluster(agentId,
313                      addedTopic.getName()));
314   }
315
316   /**
317    * Removes this topic from the cluster it belongs to.
318    * <p>
319    * The request fails if the topic does not exist or is not part of any
320    * cluster.
321    *
322    * @exception ConnectException If the admin connection is closed or broken.
323    * @exception AdminException If the request fails.
324    */

325   public void removeFromCluster()
326     throws ConnectException JavaDoc, AdminException
327   {
328     AdminModule.doRequest(new UnsetCluster(agentId));
329   }
330
331   /**
332    * Creates a hierarchical relationship between this topic
333    * and its father topic.
334    * <p>
335    * The request fails if one of the topics does not exist or can't be part
336    * of a hierarchy.
337    *
338    * @param parent
339    *
340    * @exception ConnectException If the admin connection is closed or broken.
341    * @exception AdminException If the request fails.
342    */

343   public void setParent(Topic parent)
344     throws ConnectException JavaDoc, AdminException {
345     if (parent == null)
346       unsetParent();
347     AdminModule.doRequest(
348       new SetFather(parent.getName(), agentId));
349   }
350
351   /**
352    * Unsets the father of this topic.
353    * <p>
354    * The request fails if the topic does not exist or is not part of any
355    * hierarchy.
356    *
357    * @exception ConnectException If the admin connection is closed or broken.
358    * @exception AdminException If the request fails.
359    */

360   public void unsetParent()
361          throws ConnectException JavaDoc, AdminException {
362     AdminModule.doRequest(new UnsetFather(agentId));
363   }
364 }
365
Popular Tags