KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > broker > region > policy > IndividualDeadLetterStrategy


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.broker.region.policy;
19
20 import org.apache.activemq.command.ActiveMQDestination;
21 import org.apache.activemq.command.ActiveMQQueue;
22 import org.apache.activemq.command.ActiveMQTopic;
23
24 /**
25  * A {@link DeadLetterStrategy} where each destination has its own individual
26  * DLQ using the subject naming hierarchy.
27  *
28  * @org.apache.xbean.XBean
29  *
30  * @version $Revision: 426366 $
31  */

32 public class IndividualDeadLetterStrategy implements DeadLetterStrategy {
33
34     private String JavaDoc topicPrefix = "ActiveMQ.DLQ.Topic.";
35     private String JavaDoc queuePrefix = "ActiveMQ.DLQ.Queue.";
36     private boolean useQueueForQueueMessages = true;
37     private boolean useQueueForTopicMessages = true;
38
39     public ActiveMQDestination getDeadLetterQueueFor(ActiveMQDestination originalDestination) {
40         if (originalDestination.isQueue()) {
41             return createDestination(originalDestination, queuePrefix, useQueueForQueueMessages);
42         }
43         else {
44             return createDestination(originalDestination, topicPrefix, useQueueForTopicMessages);
45         }
46     }
47
48     // Properties
49
// -------------------------------------------------------------------------
50

51     public String JavaDoc getQueuePrefix() {
52         return queuePrefix;
53     }
54
55     /**
56      * Sets the prefix to use for all dead letter queues for queue messages
57      */

58     public void setQueuePrefix(String JavaDoc queuePrefix) {
59         this.queuePrefix = queuePrefix;
60     }
61
62     public String JavaDoc getTopicPrefix() {
63         return topicPrefix;
64     }
65
66     /**
67      * Sets the prefix to use for all dead letter queues for topic messages
68      */

69     public void setTopicPrefix(String JavaDoc topicPrefix) {
70         this.topicPrefix = topicPrefix;
71     }
72
73     public boolean isUseQueueForQueueMessages() {
74         return useQueueForQueueMessages;
75     }
76
77     /**
78      * Sets whether a queue or topic should be used for queue messages sent to a
79      * DLQ. The default is to use a Queue
80      */

81     public void setUseQueueForQueueMessages(boolean useQueueForQueueMessages) {
82         this.useQueueForQueueMessages = useQueueForQueueMessages;
83     }
84
85     public boolean isUseQueueForTopicMessages() {
86         return useQueueForTopicMessages;
87     }
88
89     /**
90      * Sets whether a queue or topic should be used for topic messages sent to a
91      * DLQ. The default is to use a Queue
92      */

93     public void setUseQueueForTopicMessages(boolean useQueueForTopicMessages) {
94         this.useQueueForTopicMessages = useQueueForTopicMessages;
95     }
96
97     // Implementation methods
98
// -------------------------------------------------------------------------
99
protected ActiveMQDestination createDestination(ActiveMQDestination originalDestination, String JavaDoc prefix, boolean useQueue) {
100         String JavaDoc name = prefix + originalDestination.getPhysicalName();
101         if (useQueue) {
102             return new ActiveMQQueue(name);
103         }
104         else {
105             return new ActiveMQTopic(name);
106         }
107     }
108
109 }
110
Popular Tags