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.policy;
018    
019    import org.apache.activemq.command.ActiveMQDestination;
020    import org.apache.activemq.command.ActiveMQQueue;
021    import org.apache.activemq.command.ActiveMQTopic;
022    
023    /**
024     * A {@link DeadLetterStrategy} where each destination has its own individual
025     * DLQ using the subject naming hierarchy.
026     * 
027     * @org.apache.xbean.XBean
028     * @version $Revision: 564057 $
029     */
030    public class IndividualDeadLetterStrategy extends AbstractDeadLetterStrategy {
031    
032        private String topicPrefix = "ActiveMQ.DLQ.Topic.";
033        private String queuePrefix = "ActiveMQ.DLQ.Queue.";
034        private boolean useQueueForQueueMessages = true;
035        private boolean useQueueForTopicMessages = true;
036    
037        public ActiveMQDestination getDeadLetterQueueFor(ActiveMQDestination originalDestination) {
038            if (originalDestination.isQueue()) {
039                return createDestination(originalDestination, queuePrefix, useQueueForQueueMessages);
040            } else {
041                return createDestination(originalDestination, topicPrefix, useQueueForTopicMessages);
042            }
043        }
044    
045        // Properties
046        // -------------------------------------------------------------------------
047    
048        public String getQueuePrefix() {
049            return queuePrefix;
050        }
051    
052        /**
053         * Sets the prefix to use for all dead letter queues for queue messages
054         */
055        public void setQueuePrefix(String queuePrefix) {
056            this.queuePrefix = queuePrefix;
057        }
058    
059        public String getTopicPrefix() {
060            return topicPrefix;
061        }
062    
063        /**
064         * Sets the prefix to use for all dead letter queues for topic messages
065         */
066        public void setTopicPrefix(String topicPrefix) {
067            this.topicPrefix = topicPrefix;
068        }
069    
070        public boolean isUseQueueForQueueMessages() {
071            return useQueueForQueueMessages;
072        }
073    
074        /**
075         * Sets whether a queue or topic should be used for queue messages sent to a
076         * DLQ. The default is to use a Queue
077         */
078        public void setUseQueueForQueueMessages(boolean useQueueForQueueMessages) {
079            this.useQueueForQueueMessages = useQueueForQueueMessages;
080        }
081    
082        public boolean isUseQueueForTopicMessages() {
083            return useQueueForTopicMessages;
084        }
085    
086        /**
087         * Sets whether a queue or topic should be used for topic messages sent to a
088         * DLQ. The default is to use a Queue
089         */
090        public void setUseQueueForTopicMessages(boolean useQueueForTopicMessages) {
091            this.useQueueForTopicMessages = useQueueForTopicMessages;
092        }
093    
094        // Implementation methods
095        // -------------------------------------------------------------------------
096        protected ActiveMQDestination createDestination(ActiveMQDestination originalDestination, String prefix, boolean useQueue) {
097            String name = prefix + originalDestination.getPhysicalName();
098            if (useQueue) {
099                return new ActiveMQQueue(name);
100            } else {
101                return new ActiveMQTopic(name);
102            }
103        }
104    
105    }