001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.jms.client;
023:
024: import javax.jms.Destination;
025: import javax.jms.JMSException;
026: import javax.jms.Message;
027: import javax.jms.MessageConsumer;
028: import javax.jms.MessageListener;
029: import javax.jms.Queue;
030: import javax.jms.QueueReceiver;
031: import javax.jms.Topic;
032: import javax.jms.TopicSubscriber;
033:
034: /**
035: * A consumer
036: *
037: * @author <a href="mailto:adrian@jboss.org>Adrian Brock</a>
038: * @version $Revision: 57195 $
039: */
040: public class JBossConsumer implements MessageConsumer, QueueReceiver,
041: TopicSubscriber {
042: // Constants -----------------------------------------------------
043:
044: // Attributes ----------------------------------------------------
045:
046: /** The delegate */
047: private ConsumerDelegate delegate;
048:
049: /** The default destination */
050: private Destination defaultDestination;
051:
052: /** The message listener */
053: private MessageListener listener;
054:
055: /** The message selector */
056: private String selector;
057:
058: /** The no local flag */
059: private boolean noLocal;
060:
061: // Static --------------------------------------------------------
062:
063: // Constructors --------------------------------------------------
064:
065: /**
066: * Create a new JBossBrowser
067: *
068: * @param delegate the delegate
069: * @param destination the destination
070: * @param selector the selector
071: * @param noLocal the no local flag
072: * @throws JMSException for any error
073: */
074: public JBossConsumer(ConsumerDelegate delegate,
075: Destination destination, String selector, boolean noLocal)
076: throws JMSException {
077: this .delegate = delegate;
078: this .defaultDestination = destination;
079: this .selector = selector;
080: this .noLocal = noLocal;
081: }
082:
083: // Public --------------------------------------------------------
084:
085: public Destination getDestination() throws JMSException {
086: return defaultDestination;
087: }
088:
089: // MessageConsumer implementation --------------------------------
090:
091: public void close() throws JMSException {
092: delegate.closing();
093: delegate.close();
094: }
095:
096: public MessageListener getMessageListener() throws JMSException {
097: return listener;
098: }
099:
100: public String getMessageSelector() throws JMSException {
101: return selector;
102: }
103:
104: public Message receive() throws JMSException {
105: return receive(0);
106: }
107:
108: public Message receive(long timeout) throws JMSException {
109: return delegate.receive(timeout);
110: }
111:
112: public Message receiveNoWait() throws JMSException {
113: return receive(-1);
114: }
115:
116: public void setMessageListener(MessageListener listener)
117: throws JMSException {
118: delegate.setMessageListener(listener);
119: this .listener = listener;
120: }
121:
122: // QueueReceiver implementation ----------------------------------
123:
124: public Queue getQueue() throws JMSException {
125: return (Queue) getDestination();
126: }
127:
128: // TopicSubscriber implementation --------------------------------
129:
130: public boolean getNoLocal() throws JMSException {
131: return noLocal;
132: }
133:
134: public Topic getTopic() throws JMSException {
135: return (Topic) getDestination();
136: }
137:
138: // Protected -----------------------------------------------------
139:
140: // Package Private -----------------------------------------------
141:
142: // Private -------------------------------------------------------
143:
144: // Inner Classes -------------------------------------------------
145: }
|