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.broker.region;
018
019 import org.apache.activemq.broker.BrokerService;
020 import org.apache.activemq.broker.ConnectionContext;
021 import org.apache.activemq.command.ActiveMQDestination;
022 import org.apache.activemq.command.ActiveMQTempDestination;
023 import org.apache.activemq.store.TopicMessageStore;
024 import org.apache.activemq.thread.Task;
025 import org.apache.activemq.thread.TaskRunnerFactory;
026
027 /**
028 * The Topic is a destination that sends a copy of a message to every active
029 * Subscription registered.
030 *
031 *
032 */
033 public class TempTopic extends Topic implements Task{
034 private final ActiveMQTempDestination tempDest;
035 /**
036 * @param brokerService
037 * @param destination
038 * @param store
039 * @param parentStats
040 * @param taskFactory
041 * @throws Exception
042 */
043 public TempTopic(BrokerService brokerService,
044 ActiveMQDestination destination, TopicMessageStore store,
045 DestinationStatistics parentStats, TaskRunnerFactory taskFactory)
046 throws Exception {
047 super(brokerService, destination, store, parentStats, taskFactory);
048 this.tempDest = (ActiveMQTempDestination) destination;
049
050 }
051
052 public void addSubscription(ConnectionContext context, Subscription sub) throws Exception {
053 // Only consumers on the same connection can consume from
054 // the temporary destination
055 // However, we could have failed over - and we do this
056 // check client side anyways ....
057 if (!context.isFaultTolerant()
058 && (!context.isNetworkConnection() && !tempDest
059 .getConnectionId().equals(
060 sub.getConsumerInfo().getConsumerId()
061 .getConnectionId()))) {
062
063 tempDest.setConnectionId(sub.getConsumerInfo().getConsumerId().getConnectionId());
064 if (LOG.isDebugEnabled()) {
065 LOG.debug(" changed ownership of " + this + " to "+ tempDest.getConnectionId());
066 }
067 }
068 super.addSubscription(context, sub);
069 }
070
071 public void initialize() {
072 }
073 }