KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > walend > somnifugi > SomniQueueBrowser


1 package net.walend.somnifugi;
2
3 import java.util.Enumeration JavaDoc;
4
5 import javax.jms.Queue JavaDoc;
6 import javax.jms.QueueBrowser JavaDoc;
7 import javax.jms.JMSException JavaDoc;
8
9 /**
10 A snapshot of the messages in a Queue.
11
12 @author <a HREF="http://walend.net">David Walend</a> <a HREF="mailto:david@walend.net">david@walend.net</a>
13  */

14
15 public class SomniQueueBrowser
16     implements QueueBrowser JavaDoc
17 {
18
19     private SomniQueue queue;
20     private SomniMessageSelector messageSelector = null;
21     
22     SomniQueueBrowser(SomniQueue queue)
23     {
24         this.queue = queue;
25         SomniLogger.IT.fine("Created SomniQueueBrowser for "+queue.getName()+".");
26     }
27     
28     SomniQueueBrowser(SomniQueue queue,String JavaDoc messageSelectorString)
29         throws SomniMessageSelectorException
30     {
31         this.queue = queue;
32         this.messageSelector = new SQL92MessageSelector(messageSelectorString);
33         SomniLogger.IT.fine("Created SomniQueueBrowser for "+queue.getName()+" with messageSelector '"+messageSelectorString+"'.");
34     }
35     
36     /** Gets the queue associated with this queue browser.
37       *
38       * @return the queue
39       *
40       * @exception JMSException if the JMS provider fails to get the
41       * queue associated with this browser
42       * due to some internal error.
43       */

44       public Queue JavaDoc getQueue() throws JMSException JavaDoc
45       {
46           return queue;
47       }
48
49
50     /** Gets this queue browser's message selector expression.
51       *
52       * @return this queue browser's message selector, or null if no
53       * message selector exists for the message consumer (that is, if
54       * the message selector was not set or was set to null or the
55       * empty string)
56       *
57       * @exception JMSException if the JMS provider fails to get the
58       * message selector for this browser
59       * due to some internal error.
60       */

61       public String JavaDoc getMessageSelector() throws JMSException JavaDoc
62       {
63           return messageSelector.toString();
64       }
65
66
67     /** Gets an enumeration for browsing the current queue messages in the
68       * order they would be received.
69       *
70       * @return an enumeration for browsing the messages
71       *
72       * @exception JMSException if the JMS provider fails to get the
73       * enumeration for this browser
74       * due to some internal error.
75       */

76       public Enumeration JavaDoc getEnumeration() throws JMSException JavaDoc
77       {
78           if(messageSelector == null)
79           {
80               return queue.snapShot();
81           }
82           else
83           {
84               return queue.snapShot(messageSelector);
85           }
86       }
87
88
89     /** Closes the <CODE>QueueBrowser</CODE>.
90       *
91       * <P>Since a provider may allocate some resources on behalf of a
92       * QueueBrowser outside the Java virtual machine, clients should close them
93       * when they
94       * are not needed. Relying on garbage collection to eventually reclaim
95       * these resources may not be timely enough.
96       *
97       * @exception JMSException if the JMS provider fails to close this
98       * browser due to some internal error.
99       */

100       public void close() throws JMSException JavaDoc
101       {
102         SomniLogger.IT.fine("Closed SomniQueueBrowser for "+queue.getName()+" with messageSelector '"+messageSelector+"'.");
103       }
104
105 }
106
107 /* Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 David Walend
108 All rights reserved.
109
110 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
111
112 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
113
114 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
115
116 Neither the name of the SomnifugiJMS Project, walend.net, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission from David Walend.
117
118 Credits in redistributions in source or binary forms must include a link to http://somnifugi.sourceforge.net .
119
120 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
121 The net.walend.somnifugi.sql92 package is modified code from the openmq project, https://mq.dev.java.net/ , Copyright (c) of Sun, and carries the CDDL license, repeated here: You can obtain a copy of the license at https://glassfish.dev.java.net/public/CDDLv1.0.html. See the License for the specific language governing permissions and limitations under the License.
122
123 =================================================================================
124
125 For more information and the latest version of this software, please see http://somnifugi.sourceforge.net and http://walend.net or email <a HREF="mailto:david@walend.net">david@walend.net</a>.
126  */

127
Popular Tags