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