KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Enumeration JavaDoc;
49 import java.util.Vector JavaDoc;
50 import java.io.Serializable JavaDoc;
51 import javax.jms.JMSException JavaDoc;
52 import javax.jms.Message JavaDoc;
53 import javax.jms.Queue JavaDoc;
54 import javax.jms.QueueBrowser JavaDoc;
55
56 import org.mr.api.jms.selector.syntax.Selector;
57 import org.mr.kernel.services.ServiceConsumer;
58 import org.mr.core.protocol.MantaBusMessage;
59 /**
60  * This class represents a
61  *
62  * @version 1.0
63  * @since Jan 19, 2004
64  * @author Nimo
65  *
66  */

67 public class MantaQueueBrowser implements Serializable JavaDoc, QueueBrowser JavaDoc{
68
69     /**
70      * Creates a new QueueBrowser.
71      *
72      * @param clientId - the client id for this browser.
73      * @param sess - the creating session
74      * @param queue - the queue to browse.
75      * @param messageSelector - a message selector
76      * @param service - the MantaService for this browser.
77      * @throws JMSException
78      */

79     public MantaQueueBrowser(String JavaDoc clientId, MantaSession sess, Queue JavaDoc queue,String JavaDoc messageSelector, ServiceConsumer service) throws JMSException JavaDoc{
80         theQueue = queue;
81         creatingSession = sess;
82         this.clientId = clientId;
83         this.service = service;
84         
85         if (messageSelector!=null && messageSelector.length()==0)
86             messageSelector = null;
87         
88         new Selector(messageSelector);
89         theMessageSelector = messageSelector;
90                 
91     }//MantaQueueBrowser
92

93     /**
94      * Closes the <CODE>QueueBrowser</CODE>.
95      *
96      * <P>Since a provider may allocate some resources on behalf of a
97      * QueueBrowser outside the Java virtual machine, clients should close them
98      * when they
99      * are not needed. Relying on garbage collection to eventually reclaim
100      * these resources may not be timely enough.
101      *
102      * @exception JMSException if the JMS provider fails to close this
103      * browser due to some internal error.
104      */

105     public void close() throws JMSException JavaDoc {
106         creatingSession.removeBrowser(this);
107         creatingSession = null;
108         theMessageSelector=null;
109         theQueue=null;
110         service=null;
111         clientId=null;
112     }
113
114     /**
115      * Gets an enumeration for browsing the current queue messages in the
116      * order they would be received.
117      *
118      * @return an enumeration for browsing the messages
119      *
120      * @exception JMSException if the JMS provider fails to get the
121      * enumeration for this browser
122      * due to some internal error.
123      */

124     public Enumeration JavaDoc getEnumeration() throws JMSException JavaDoc {
125         //this is the MantaBusMessages Enumeration.
126
Enumeration JavaDoc busMessages = creatingSession.getMessagesFor(this);
127         
128         Vector JavaDoc messages = new Vector JavaDoc();
129         while (busMessages.hasMoreElements()) {
130             Message JavaDoc orig =MantaMessageConsumer.convertToJMSMessage((MantaBusMessage)busMessages.nextElement(),creatingSession);
131             messages.add(orig);
132         }
133         busMessages = null;
134         
135         return messages.elements();
136     }
137
138     /**
139      * Gets this queue browser's message selector expression.
140      *
141      * @return this queue browser's message selector, or null if no
142      * message selector exists for the message consumer (that is, if
143      * the message selector was not set or was set to null or the
144      * empty string)
145      *
146      * @exception JMSException if the JMS provider fails to get the
147      * message selector for this browser
148      * due to some internal error.
149      */

150     public String JavaDoc getMessageSelector() throws JMSException JavaDoc {
151         return theMessageSelector;
152     }//getMessageSelector
153

154
155     /**
156      * Gets the queue associated with this queue browser.
157      *
158      * @return the queue
159      *
160      * @exception JMSException if the JMS provider fails to get the
161      * queue associated with this browser
162      * due to some internal error.
163      */

164     public Queue JavaDoc getQueue() throws JMSException JavaDoc {
165         return theQueue;
166     }//getQueue
167

168     /**
169      * Gets the service associated with this browser.
170      *
171      * @return - the service object.
172      */

173     public ServiceConsumer getService() {
174         return service;
175     }
176     private Queue JavaDoc theQueue = null;
177     
178     /**
179      * Gets the client id for this browser.
180      *
181      * @return the client id
182      *
183      */

184     String JavaDoc getClientId() {
185         return this.clientId;
186     }
187     
188     //The message selector object associated with the queue browser
189
protected String JavaDoc theMessageSelector = null;
190     
191     private MantaSession creatingSession;
192     
193     String JavaDoc clientId;
194     ServiceConsumer service;
195 }
196
Popular Tags