KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.walend.somnifugi;
2
3 import java.util.Enumeration JavaDoc;
4
5 import javax.naming.Referenceable JavaDoc;
6 import javax.naming.Reference JavaDoc;
7 import javax.naming.NamingException JavaDoc;
8 import javax.naming.Context JavaDoc;
9
10 import javax.jms.Queue JavaDoc;
11 import javax.jms.Message JavaDoc;
12 import javax.jms.JMSException JavaDoc;
13
14 import net.walend.somnifugi.channel.Channel;
15 import net.walend.somnifugi.channel.Puttable;
16 import net.walend.somnifugi.channel.Takable;
17 import net.walend.somnifugi.channel.ChannelFactory;
18
19 /**
20 A Queue. Note that, because Somnifugi JMS does not support persistent messages, any messages still in the queue are lost when the VM stops.
21
22 @author <a HREF="http://walend.net">David Walend</a> <a HREF="mailto:david@walend.net">david@walend.net</a>
23  */

24
25 public class SomniQueue
26     extends SomniDestination
27     implements Queue JavaDoc, Referenceable JavaDoc
28 {
29     private static final long serialVersionUID = 0L;
30
31     private final Channel<Message JavaDoc> channel;
32
33     protected SomniQueue(String JavaDoc name,ChannelFactory<Message JavaDoc> factory,Context JavaDoc context)
34         throws SomniNamingException
35     {
36         super(name,factory,context);
37         
38         channel = factory.createChannel(name,context);
39     }
40
41     //Queue methods
42
/** Gets the name of this queue.
43  
44 <P>Clients that depend upon the name are not portable.
45  
46 @return the queue name
47  
48 @exception JMSException if the JMS provider implementation of
49                         <CODE>Queue</CODE> fails to return the queue
50                         name due to some internal
51                         error.
52       */

53     public String JavaDoc getQueueName()
54         throws JMSException JavaDoc
55     {
56         return getName();
57     }
58
59     /** Returns a string representation of this object.
60       *
61 @return the provider-specific identity values for this queue
62       */

63     public String JavaDoc toString()
64     {
65         return getName();
66     }
67
68     protected Puttable<Message JavaDoc> getPuttable()
69     {
70         return channel.getPuttable();
71     }
72
73     protected Takable<Message JavaDoc> getTakable()
74     {
75         return channel.getTakable();
76     }
77
78     Takable<Message JavaDoc> getTakable(SomniMessageSelector messageSelector)
79         throws SomniMessageSelectorException
80     {
81         if(!channel.supportsMessageSelectors())
82         {
83             throw new SomniMessageSelectorException(channel.getClass().getName()+" used by "+getName()+"does not support message selectors");
84         }
85         
86         return channel.getTakable(messageSelector);
87     }
88
89     Enumeration JavaDoc snapShot()
90     {
91         return getTakable().snapShot();
92     }
93     
94     Enumeration JavaDoc snapShot(SomniMessageSelector messageSelector)
95         throws SomniMessageSelectorException
96     {
97         return getTakable().snapShot(messageSelector);
98     }
99     
100     //Referenceable
101
public Reference JavaDoc getReference()
102         throws NamingException JavaDoc
103     {
104         return new Reference JavaDoc(this.getClass().getName(),SomniQueueFactory.class.getName(),null);
105     }
106 }
107
108 /* Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 David Walend
109 All rights reserved.
110
111 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
112
113 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
114
115 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.
116
117 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.
118
119 Credits in redistributions in source or binary forms must include a link to http://somnifugi.sourceforge.net .
120
121 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.
122 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.
123
124 =================================================================================
125
126 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>.
127  */

128
Popular Tags