KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mq > server > ExclusiveQueue


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.mq.server;
23
24 import javax.jms.JMSException JavaDoc;
25
26 import org.jboss.mq.SpyDestination;
27 import org.jboss.mq.Subscription;
28
29 /**
30  * This class implements a basic queue with an exclusive subscription.
31  *
32  * @author Adrian Brock (Adrian.Brock@HappeningTimes.com)
33  * @created 28th October 2002
34  */

35 public class ExclusiveQueue
36    extends BasicQueue
37 {
38    Subscription exclusive;
39    boolean removed = false;
40
41    public ExclusiveQueue
42    (
43       JMSDestinationManager server,
44       SpyDestination destination,
45       Subscription exclusive,
46       BasicQueueParameters parameters
47    )
48       throws JMSException JavaDoc
49    {
50       super
51       (
52          server,
53          destination.toString() + "." + exclusive.connectionToken.getClientID() + '.' + exclusive.subscriptionId,
54          parameters
55       );
56       this.exclusive = exclusive;
57    }
58
59    public Subscription getExclusiveSubscription()
60    {
61       return exclusive;
62    }
63
64    public void addMessage(MessageReference mesRef, org.jboss.mq.pm.Tx txId)
65       throws JMSException JavaDoc
66    {
67       // Ignore the message if we are not interested
68
if (removed || exclusive.accepts(mesRef.getHeaders()) == false)
69          dropMessage(mesRef);
70       else
71          super.addMessage( mesRef, txId );
72    }
73
74    public void restoreMessage(MessageReference mesRef)
75    {
76       if (removed)
77          dropMessage(mesRef);
78       else
79          super.restoreMessage(mesRef);
80    }
81
82    protected void nackMessage(MessageReference mesRef)
83    {
84       if (removed)
85          dropMessage(mesRef);
86       else
87          super.nackMessage(mesRef);
88    }
89
90    public void removeSubscriber(Subscription sub)
91    {
92       removed = true;
93       super.removeSubscriber(sub);
94    }
95 }
96
Popular Tags