001 /** 002 * 003 * Copyright 2004 Protique Ltd 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * 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 **/ 018 019 package org.activemq.service.boundedvm; 020 021 022 import javax.jms.JMSException; 023 024 import org.activemq.broker.BrokerClient; 025 import org.activemq.broker.BrokerConnector; 026 import org.activemq.filter.Filter; 027 import org.activemq.message.ActiveMQDestination; 028 import org.activemq.message.ActiveMQMessage; 029 import org.activemq.message.BrokerInfo; 030 import org.activemq.message.ConsumerInfo; 031 032 /** 033 * A holder for Transient consumer info and message routing 034 * 035 * @version $Revision: 1.1.1.1 $ 036 */ 037 public abstract class TransientSubscription { 038 protected Filter filter; 039 protected ConsumerInfo consumerInfo; 040 protected BrokerClient client; 041 protected String brokerName; 042 protected String clusterName; 043 044 /** 045 * Construct the TransientSubscription 046 * @param filter 047 * @param info 048 */ 049 public TransientSubscription(Filter filter, ConsumerInfo info, BrokerClient client) { 050 this.filter = filter; 051 this.consumerInfo = info; 052 this.client = client; 053 if (client != null) { 054 BrokerConnector connector = client.getBrokerConnector(); 055 if (connector != null) { 056 BrokerInfo bi = connector.getBrokerInfo(); 057 if (bi != null) { 058 this.brokerName = bi.getBrokerName(); 059 this.clusterName = bi.getClusterName(); 060 } 061 } 062 } 063 } 064 065 066 /** 067 * determines if the Subscription is interested in the message 068 * 069 * @param message 070 * @return true if this Subscription will accept the message 071 * @throws JMSException 072 */ 073 public abstract boolean isTarget(ActiveMQMessage message) throws JMSException; 074 075 /** 076 * @return Returns the consumerInfo. 077 */ 078 public ConsumerInfo getConsumerInfo() { 079 return consumerInfo; 080 } 081 /** 082 * @param consumerInfo The consumerInfo to set. 083 */ 084 public void setConsumerInfo(ConsumerInfo consumerInfo) { 085 this.consumerInfo = consumerInfo; 086 } 087 /** 088 * @return Returns the filter. 089 */ 090 public Filter getFilter() { 091 return filter; 092 } 093 /** 094 * @param filter The filter to set. 095 */ 096 public void setFilter(Filter filter) { 097 this.filter = filter; 098 } 099 100 /** 101 * close the subscription 102 */ 103 public void close(){ 104 } 105 106 /** 107 * @return Returns the destination. 108 */ 109 public ActiveMQDestination getDestination() { 110 return consumerInfo.getDestination(); 111 } 112 113 /** 114 * @return true if this subscription is for a non-broker consumer 115 */ 116 public boolean isLocalSubscription() { 117 boolean localSubscription = true; 118 if (client != null) { 119 localSubscription = !(client.isClusteredConnection() ); 120 } 121 return localSubscription; 122 } 123 }