KickJava   Java API By Example, From Geeks To Geeks.

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


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.TopicSubscriber JavaDoc;
27 import javax.jms.JMSException JavaDoc;
28 import javax.jms.Topic JavaDoc;
29
30
31 /**
32  * Implementation of <code>javax.jms.TopicSubscriber</code>.
33  *
34  * @see javax.jms.TopicSubscriber
35  *
36  * @author Dan Greff
37  */

38 public final class JmsTopicSubscriber extends JmsMessageConsumer
39   implements TopicSubscriber JavaDoc
40 {
41
42
43     /////////////////////////////////////////////////////////////////////////
44
// Private Instance Variables //
45
/////////////////////////////////////////////////////////////////////////
46
private final JmsTopic topic;
47   private final boolean noLocal;
48   private final JmsOperand filter;
49   
50
51     /////////////////////////////////////////////////////////////////////////
52
// Constructors //
53
/////////////////////////////////////////////////////////////////////////
54
JmsTopicSubscriber(JmsTopicSession session,
55                      String JavaDoc selector,
56                      JmsTopic topic,
57                      boolean nolocal,
58                      String JavaDoc durableID)
59     throws JMSException JavaDoc
60   {
61     super(session, selector);
62     this.topic = topic;
63     this.noLocal = nolocal;
64   
65     //
66
// Allow the topic to append or modify the selector as
67
// needed.
68
//
69
this.selector = topic.prepareContentFilter(selector);
70     
71     if (durableID == null || durableID.length() == 0) {
72       // NonDurable Subscriber initialization
73

74       // create the real filter
75
filter = Parser.getInstance().parseFilter(this.selector);
76
77       mySession.addConsumer(this);
78     }
79     else {
80       // DTG: have not finished work on Durable Subscriptions yet, so
81
// as convincing as this may be, it doesn't work.
82

83       // Durable Subscriber initialization
84
String JavaDoc uniqueID = createUniqueID();
85       
86       // Swap the selectors
87
String JavaDoc userSelector = this.selector;
88       this.selector = generateSystemFilter(durableID, uniqueID);
89       
90       this.filter = Parser.getInstance().parseFilter(this.selector);
91       mySession.addConsumer(this);
92       
93       session.sendQueueRequest(durableID, // queue name
94
uniqueID, // receiverID
95
userSelector, // user filter
96
JmsSession.DURABLE_SUBSCRIBER_CRT); // type
97
}
98   }
99
100     //////////////////////////////////////////////////////////////////////////
101
// Public Methods //
102
//////////////////////////////////////////////////////////////////////////
103

104   public Topic JavaDoc getTopic() throws JMSException JavaDoc
105   {
106     return topic;
107   }
108
109   public boolean getNoLocal() throws JMSException JavaDoc
110   {
111     return noLocal;
112   }
113
114
115     //////////////////////////////////////////////////////////////////////////
116
// Package Methods //
117
//////////////////////////////////////////////////////////////////////////
118

119   /*
120    * Call by JmsSession when routing a message to subscribers on the Session.
121    * Once the Session has the subscriber filter, it evaluates the current
122    * message to be routed against the filter in order to determine if this
123    * subscriber needs the given message.
124    */

125   final JmsOperand getFilter()
126   {
127     return this.filter;
128   }
129   
130 }
131
Popular Tags