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 */
017package org.apache.activemq.command;
018
019import org.apache.activemq.util.IntrospectionSupport;
020
021/**
022 * Used to represent a durable subscription.
023 *
024 * @openwire:marshaller code="55"
025 *
026 */
027public 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    protected boolean noLocal;
037
038    public SubscriptionInfo() {}
039
040    public SubscriptionInfo(String clientId, String subscriptionName) {
041        this.clientId = clientId;
042        this.subscriptionName = subscriptionName;
043    }
044
045    @Override
046    public byte getDataStructureType() {
047        return DATA_STRUCTURE_TYPE;
048    }
049
050    /**
051     * @openwire:property version=1
052     */
053    public String getClientId() {
054        return clientId;
055    }
056
057    public void setClientId(String clientId) {
058        this.clientId = clientId;
059    }
060
061    /**
062     * This is the a resolved destination that the subscription is receiving
063     * messages from. This will never be a pattern or a composite destination.
064     *
065     * @openwire:property version=1 cache=true
066     */
067    public ActiveMQDestination getDestination() {
068        return destination;
069    }
070
071    public void setDestination(ActiveMQDestination destination) {
072        this.destination = destination;
073    }
074
075    /**
076     * @openwire:property version=1
077     */
078    public String getSelector() {
079        return selector;
080    }
081
082    public void setSelector(String selector) {
083        this.selector = selector;
084    }
085
086    /**
087     * @openwire:property version=1
088     */
089    public String getSubcriptionName() {
090        return subscriptionName;
091    }
092
093    /**
094     * @param subscriptionName *
095     */
096    public void setSubcriptionName(String subscriptionName) {
097        this.subscriptionName = subscriptionName;
098    }
099
100    public String getSubscriptionName() {
101        return subscriptionName;
102    }
103
104    public void setSubscriptionName(String subscriptionName) {
105        this.subscriptionName = subscriptionName;
106    }
107
108    @Override
109    public boolean isMarshallAware() {
110        return false;
111    }
112
113    @Override
114    public String toString() {
115        return IntrospectionSupport.toString(this);
116    }
117
118    @Override
119    public int hashCode() {
120        int h1 = clientId != null ? clientId.hashCode() : -1;
121        int h2 = subscriptionName != null ? subscriptionName.hashCode() : -1;
122        return h1 ^ h2;
123    }
124
125    @Override
126    public boolean equals(Object obj) {
127        boolean result = false;
128        if (obj instanceof SubscriptionInfo) {
129            SubscriptionInfo other = (SubscriptionInfo)obj;
130            result = (clientId == null && other.clientId == null || clientId != null
131                                                                    && other.clientId != null
132                                                                    && clientId.equals(other.clientId))
133                     && (subscriptionName == null && other.subscriptionName == null || subscriptionName != null
134                                                                                       && other.subscriptionName != null
135                                                                                       && subscriptionName
136                                                                                           .equals(other.subscriptionName));
137        }
138        return result;
139    }
140
141    /**
142     * The destination the client originally subscribed to.. This may not match
143     * the {@see getDestination} method if the subscribed destination uses
144     * patterns or composites.
145     *
146     * If the subscribed destinationis not set, this just ruturns the
147     * desitination.
148     *
149     * @openwire:property version=3
150     */
151    public ActiveMQDestination getSubscribedDestination() {
152        if (subscribedDestination == null) {
153            return getDestination();
154        }
155        return subscribedDestination;
156    }
157
158    public void setSubscribedDestination(ActiveMQDestination subscribedDestination) {
159        this.subscribedDestination = subscribedDestination;
160    }
161
162    /**
163     * @openwire:property version=11
164     */
165    public boolean isNoLocal() {
166        return noLocal;
167    }
168
169    public void setNoLocal(boolean noLocal) {
170        this.noLocal = noLocal;
171    }
172}