01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * 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;
25:
26: import org.jboss.mq.SpyTopic;
27: import org.jboss.mq.pm.Tx;
28: import org.jboss.mq.selectors.Selector;
29:
30: /**
31: * This class adds a selector to a persistent queue.
32: *
33: * Factored out of JMSTopic.
34: *
35: * @author Adrian Brock (Adrian.Brock@HappeningTimes.com)
36: * @created 24th October 2002
37: */
38: public class SelectorPersistentQueue extends PersistentQueue {
39: // Attributes ----------------------------------------------------
40:
41: /**
42: * The string representation of the selector
43: */
44: String selectorString;
45:
46: /**
47: * The implementation of the selector
48: */
49: Selector selector;
50:
51: // Constructor ---------------------------------------------------
52:
53: /**
54: * Create a new persistent queue with a selector
55: *
56: * @param server the destination manager
57: * @param dstopic the topic with a durable subscription
58: * @param selector the selector string
59: * @exception JMSException for an error
60: */
61: public SelectorPersistentQueue(JMSDestinationManager server,
62: SpyTopic dstopic, String selector,
63: BasicQueueParameters parameters) throws JMSException {
64: super (server, dstopic, parameters);
65: this .selectorString = selector;
66: this .selector = new Selector(selector);
67: }
68:
69: // Public --------------------------------------------------------
70:
71: /**
72: * Filters the message with the selector before adding to the queue
73:
74: * @param mesRef the message
75: * @param txId the transaction
76: * @exception JMSException for an error
77: */
78: public void addMessage(MessageReference mesRef, Tx txId)
79: throws JMSException {
80: if (selector.test(mesRef.getHeaders()))
81: super.addMessage(mesRef, txId);
82: else
83: server.getMessageCache().remove(mesRef);
84: }
85: }
|