KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > api > jms > MantaTopic


1 /*
2  * Copyright 2002 by
3  * <a HREF="http://www.coridan.com">Coridan</a>
4  * <a HREF="mailto: support@coridan.com ">support@coridan.com</a>
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is "MantaRay" (TM).
17  *
18  * The Initial Developer of the Original Code is Nimo.
19  * Portions created by the Initial Developer are Copyright (C) 2006
20  * Coridan Inc. All Rights Reserved.
21  *
22  * Contributor(s): all the names of the contributors are added in the source
23  * code where applicable.
24  *
25  * Alternatively, the contents of this file may be used under the terms of the
26  * LGPL license (the "GNU LESSER GENERAL PUBLIC LICENSE"), in which case the
27  * provisions of LGPL are applicable instead of those above. If you wish to
28  * allow use of your version of this file only under the terms of the LGPL
29  * License and not to allow others to use your version of this file under
30  * the MPL, indicate your decision by deleting the provisions above and
31  * replace them with the notice and other provisions required by the LGPL.
32  * If you do not delete the provisions above, a recipient may use your version
33  * of this file under either the MPL or the GNU LESSER GENERAL PUBLIC LICENSE.
34  
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Lesser General Public License as published by the Free Software Foundation;
39  * either version 2.1 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
44  * License for more details.
45  */

46 package org.mr.api.jms;
47
48 import javax.jms.Destination JavaDoc;
49 import javax.jms.JMSException JavaDoc;
50 import javax.jms.Topic JavaDoc;
51
52 import org.mr.MantaAgent;
53 import org.mr.MantaAgentConstants;
54 import org.mr.core.configuration.ConfigManager;
55 import org.mr.core.util.byteable.Byteable;
56 import org.mr.core.util.byteable.ByteableInputStream;
57 import org.mr.core.util.byteable.ByteableOutputStream;
58 import org.mr.core.util.byteable.ByteableRegistry;
59 import org.mr.kernel.services.topics.VirtualTopicManager;
60
61 import java.io.IOException JavaDoc;
62 import java.io.Serializable JavaDoc;
63
64 /** A <CODE>Topic</CODE> object encapsulates a provider-specific topic name.
65   * It is the way a client specifies the identity of a topic to JMS API methods.
66  * For those methods that use a <CODE>Destination</CODE> as a parameter, a
67   * <CODE>Topic</CODE> object may used as an argument . For
68   * example, a Topic can be used to create a <CODE>MessageConsumer</CODE>
69   * and a <CODE>MessageProducer</CODE>
70   * by calling:
71   *<UL>
72   *<LI> <CODE>Session.CreateConsumer(Destination destination)</CODE>
73   *<LI> <CODE>Session.CreateProducer(Destination destination)</CODE>
74   *
75   *</UL>
76   *
77   * <P>Many publish/subscribe (pub/sub) providers group topics into hierarchies
78   * and provide various options for subscribing to parts of the hierarchy. The
79   * JMS API places no restriction on what a <CODE>Topic</CODE> object
80   * represents. It may be a leaf in a topic hierarchy, or it may be a larger
81   * part of the hierarchy.
82   *
83   * <P>The organization of topics and the granularity of subscriptions to
84   * them is an important part of a pub/sub application's architecture. The JMS
85   * API
86   * does not specify a policy for how this should be done. If an application
87   * takes advantage of a provider-specific topic-grouping mechanism, it
88   * should document this. If the application is installed using a different
89   * provider, it is the job of the administrator to construct an equivalent
90   * topic architecture and create equivalent <CODE>Topic</CODE> objects.
91   *
92   * @author Nimo
93   */

94 public class MantaTopic extends MantaDestination implements Serializable JavaDoc, Topic JavaDoc, Destination JavaDoc {
95     
96
97     /**
98      * Construct a Topic in the system.
99      *
100      * @param name - the name of the topic to create.
101      */

102     public MantaTopic(String JavaDoc name) throws JMSException JavaDoc {
103         setName(name);
104     } //MantaTopic
105

106     /**
107      * Consturcts a nameless topic. this shouldn't be used.
108      *
109      */

110     public MantaTopic() {
111         this.destinationName = " ";
112     }
113     
114     public void setName(String JavaDoc name) throws JMSException JavaDoc {
115         if(MantaAgent.isStarted()){
116             MantaAgent.getInstance().getSingletonRepository()
117             .getVirtualTopicManager().validateTopicName(name);
118         }
119         
120         this.destinationName = name;
121     }
122     
123     
124     /**
125      * Returns a string representation of this object.
126      *
127      */

128     public String JavaDoc toString() {
129         return this.destinationName;
130     } //toString
131

132     /**
133      * Returns the name of the topic.
134      */

135     public String JavaDoc getTopicName() {
136         return this.destinationName;
137     }
138     
139     
140     public static final String JavaDoc BYTEABLENAME = "MantaTopic";
141     public String JavaDoc getByteableName() {
142
143         return BYTEABLENAME;
144     }
145
146     
147     public void toBytes(ByteableOutputStream out) throws IOException JavaDoc {
148
149         out.writeUTF(this.destinationName);
150
151     }
152
153     public Byteable createInstance(ByteableInputStream in) throws IOException JavaDoc {
154
155         MantaTopic mt;
156         try {
157             mt = new MantaTopic(in.readUTF());
158         } catch (JMSException JavaDoc e) {
159             throw new IOException JavaDoc("Can't create topic: "+e.getMessage());
160         }
161         return mt;
162     }
163
164     public void registerToByteableRegistry() {
165         ByteableRegistry.registerByteableFactory(getByteableName() , this);
166         
167     }
168     
169     public static void register() throws JMSException JavaDoc{
170         MantaTopic instance = new MantaTopic();
171         instance.registerToByteableRegistry();
172     }
173    
174
175     
176 }//MantaTopic
177
Popular Tags