KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > presumo > jms > client > JmsQueueReceiver


1 /**
2  * This file is part of Presumo.
3  *
4  * Presumo is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * Presumo is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Presumo; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  *
19  * Copyright 2001 Dan Greff
20  */

21 package com.presumo.jms.client;
22
23 import com.presumo.jms.selector.JmsOperand;
24 import com.presumo.jms.selector.Parser;
25
26 import javax.jms.QueueReceiver JavaDoc;
27 import javax.jms.JMSException JavaDoc;
28 import javax.jms.Queue JavaDoc;
29
30 public final class JmsQueueReceiver extends JmsMessageConsumer
31   implements QueueReceiver JavaDoc
32 {
33     /////////////////////////////////////////////////////////////////////////
34
// Private Instance Variables //
35
/////////////////////////////////////////////////////////////////////////
36
private final JmsQueue queue;
37   private final JmsOperand filter;
38   
39
40     /////////////////////////////////////////////////////////////////////////
41
// Constructors //
42
/////////////////////////////////////////////////////////////////////////
43
JmsQueueReceiver(JmsQueueSession session,
44                    String JavaDoc selector,
45                    JmsQueue queue,
46                    boolean forBrowser)
47     throws JMSException JavaDoc
48   {
49     super(session, selector);
50     this.queue = queue;
51
52     String JavaDoc uniqueID = createUniqueID();
53       
54     // Swap the selectors
55
String JavaDoc userSelector = this.selector;
56     this.selector = generateSystemFilter(queue.getQueueName(), uniqueID);
57       
58     this.filter = Parser.getInstance().parseFilter(this.selector);
59     mySession.addConsumer(this);
60       
61     int type = (forBrowser) ? JmsSession.QUEUE_BROWSER_CRT :
62                               JmsSession.QUEUE_RECEIVER_CRT;
63     session.sendQueueRequest(queue.getQueueName(), // queue name
64
uniqueID, // receiverID
65
userSelector, // user filter
66
type); // type
67

68   }
69
70     //////////////////////////////////////////////////////////////////////////
71
// Public Methods //
72
//////////////////////////////////////////////////////////////////////////
73

74   public Queue JavaDoc getQueue() throws JMSException JavaDoc
75   {
76     return queue;
77   }
78
79     //////////////////////////////////////////////////////////////////////////
80
// Package Methods //
81
//////////////////////////////////////////////////////////////////////////
82

83   final JmsOperand getFilter()
84   {
85     return this.filter;
86   }
87   
88 }
89
Popular Tags