001    /** 
002     * 
003     * Copyright 2004 Protique Ltd
004     * Copyright 2005 Hiram Chirino
005     * 
006     * Licensed under the Apache License, Version 2.0 (the "License"); 
007     * you may not use this file except in compliance with the License. 
008     * You may obtain a copy of the License at 
009     * 
010     * http://www.apache.org/licenses/LICENSE-2.0
011     * 
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS, 
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
015     * See the License for the specific language governing permissions and 
016     * limitations under the License. 
017     * 
018     **/
019    
020    package org.activemq.service.boundedvm;
021    
022    
023    import javax.jms.JMSException;
024    
025    import org.activemq.broker.BrokerClient;
026    import org.activemq.broker.BrokerConnector;
027    import org.activemq.filter.Filter;
028    import org.activemq.message.ActiveMQDestination;
029    import org.activemq.message.ActiveMQMessage;
030    import org.activemq.message.BrokerInfo;
031    import org.activemq.message.ConsumerInfo;
032    
033    /**
034     * A holder for Durable  consumer info and message routing
035     * 
036     * @version $Revision: 1.1.1.1 $
037     */
038    public abstract class DurableSubscription  {
039        protected Filter filter;
040        protected ConsumerInfo consumerInfo;
041        protected BrokerClient client;
042        protected String brokerName;
043        protected String clusterName;
044    
045        /**
046         * Construct the DurableSubscription
047         * @param filter
048         * @param info
049         */
050        public DurableSubscription(Filter filter, ConsumerInfo info, BrokerClient client) {
051            this.filter = filter;
052            this.consumerInfo = info;
053            this.client = client;
054            if (client != null) {
055                BrokerConnector connector = client.getBrokerConnector();
056                if (connector != null) {
057                    BrokerInfo bi = connector.getBrokerInfo();
058                    if (bi != null) {
059                        this.brokerName = bi.getBrokerName();
060                        this.clusterName = bi.getClusterName();
061                    }
062                }
063            }
064        }
065    
066        
067        /**
068         * determines if the Subscription is interested in the message
069         *
070         * @param message
071         * @return true if this Subscription will accept the message
072         * @throws JMSException
073         */
074        public abstract boolean isTarget(ActiveMQMessage message) throws JMSException;
075       
076        /**
077         * @return Returns the consumerInfo.
078         */
079        public ConsumerInfo getConsumerInfo() {
080            return consumerInfo;
081        }
082        /**
083         * @param consumerInfo The consumerInfo to set.
084         */
085        public void setConsumerInfo(ConsumerInfo consumerInfo) {
086            this.consumerInfo = consumerInfo;
087        }
088        /**
089         * @return Returns the filter.
090         */
091        public Filter getFilter() {
092            return filter;
093        }
094        /**
095         * @param filter The filter to set.
096         */
097        public void setFilter(Filter filter) {
098            this.filter = filter;
099        }
100        
101        /**
102         * close the subscription
103         */
104        public void close(){
105        }
106    
107        /**
108         * @return Returns the destination.
109         */
110        public ActiveMQDestination getDestination() {
111            return consumerInfo.getDestination();
112        }
113    
114        /**
115         * @return true if this subscription is for a non-broker consumer
116         */
117        public boolean isLocalSubscription() {
118            boolean localSubscription = true;
119            if (client != null) {
120                localSubscription = !(client.isClusteredConnection() || client.isBrokerConnection());
121            }
122            return localSubscription;
123        }
124    }