001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.activemq.command;
018    
019    import org.apache.activemq.util.IntrospectionSupport;
020    
021    /**
022     * Used to represent a durable subscription.
023     * 
024     * @openwire:marshaller code="55"
025     * 
026     */
027    public class SubscriptionInfo implements DataStructure {
028    
029        public static final byte DATA_STRUCTURE_TYPE = CommandTypes.DURABLE_SUBSCRIPTION_INFO;
030    
031        protected ActiveMQDestination subscribedDestination;
032        protected ActiveMQDestination destination;
033        protected String clientId;
034        protected String subscriptionName;
035        protected String selector;
036    
037        public byte getDataStructureType() {
038            return DATA_STRUCTURE_TYPE;
039        }
040    
041        /**
042         * @openwire:property version=1
043         */
044        public String getClientId() {
045            return clientId;
046        }
047    
048        public void setClientId(String clientId) {
049            this.clientId = clientId;
050        }
051    
052        /**
053         * This is the a resolved destination that the subscription is receiving
054         * messages from. This will never be a pattern or a composite destination.
055         * 
056         * @openwire:property version=1 cache=true
057         */
058        public ActiveMQDestination getDestination() {
059            return destination;
060        }
061    
062        public void setDestination(ActiveMQDestination destination) {
063            this.destination = destination;
064        }
065    
066        /**
067         * @openwire:property version=1
068         */
069        public String getSelector() {
070            return selector;
071        }
072    
073        public void setSelector(String selector) {
074            this.selector = selector;
075        }
076    
077        /**
078         * @openwire:property version=1
079         */
080        public String getSubcriptionName() {
081            return subscriptionName;
082        }
083    
084        /**
085         * @param subscriptionName *
086         */
087        public void setSubcriptionName(String subscriptionName) {
088            this.subscriptionName = subscriptionName;
089        }
090    
091        public String getSubscriptionName() {
092            return subscriptionName;
093        }
094    
095        public void setSubscriptionName(String subscriptionName) {
096            this.subscriptionName = subscriptionName;
097        }
098    
099        public boolean isMarshallAware() {
100            return false;
101        }
102    
103        @Override
104        public String toString() {
105            return IntrospectionSupport.toString(this);
106        }
107    
108        @Override
109        public int hashCode() {
110            int h1 = clientId != null ? clientId.hashCode() : -1;
111            int h2 = subscriptionName != null ? subscriptionName.hashCode() : -1;
112            return h1 ^ h2;
113        }
114    
115        @Override
116        public boolean equals(Object obj) {
117            boolean result = false;
118            if (obj instanceof SubscriptionInfo) {
119                SubscriptionInfo other = (SubscriptionInfo)obj;
120                result = (clientId == null && other.clientId == null || clientId != null
121                                                                        && other.clientId != null
122                                                                        && clientId.equals(other.clientId))
123                         && (subscriptionName == null && other.subscriptionName == null || subscriptionName != null
124                                                                                           && other.subscriptionName != null
125                                                                                           && subscriptionName
126                                                                                               .equals(other.subscriptionName));
127            }
128            return result;
129        }
130    
131        /**
132         * The destination the client originally subscribed to.. This may not match
133         * the {@see getDestination} method if the subscribed destination uses
134         * patterns or composites.
135         * 
136         * If the subscribed destinationis not set, this just ruturns the
137         * desitination.
138         * 
139         * @openwire:property version=3
140         */
141        public ActiveMQDestination getSubscribedDestination() {
142            if (subscribedDestination == null) {
143                return getDestination();
144            }
145            return subscribedDestination;
146        }
147    
148        public void setSubscribedDestination(ActiveMQDestination subscribedDestination) {
149            this.subscribedDestination = subscribedDestination;
150        }
151    
152    }