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.ActiveMQMessageAudit;
020 import org.apache.activemq.command.Message;
021 import org.slf4j.Logger;
022 import org.slf4j.LoggerFactory;
023
024 /**
025 * A strategy for choosing which destination is used for dead letter queue
026 * messages.
027 *
028 *
029 */
030 public abstract class AbstractDeadLetterStrategy implements DeadLetterStrategy {
031 private static final Logger LOG = LoggerFactory.getLogger(AbstractDeadLetterStrategy.class);
032 private boolean processNonPersistent = false;
033 private boolean processExpired = true;
034 private boolean enableAudit = true;
035 private ActiveMQMessageAudit messageAudit = new ActiveMQMessageAudit();
036
037 public boolean isSendToDeadLetterQueue(Message message) {
038 boolean result = false;
039 if (message != null) {
040 result = true;
041 if (enableAudit && messageAudit.isDuplicate(message)) {
042 result = false;
043 if (LOG.isDebugEnabled()) {
044 LOG.debug("Not adding duplicate to DLQ: " + message.getMessageId() + ", dest: " + message.getDestination());
045 }
046 }
047 if (!message.isPersistent() && !processNonPersistent) {
048 result = false;
049 }
050 if (message.isExpired() && !processExpired) {
051 result = false;
052 }
053 }
054 return result;
055 }
056
057 /**
058 * @return the processExpired
059 */
060 public boolean isProcessExpired() {
061 return this.processExpired;
062 }
063
064 /**
065 * @param processExpired the processExpired to set
066 */
067 public void setProcessExpired(boolean processExpired) {
068 this.processExpired = processExpired;
069 }
070
071 /**
072 * @return the processNonPersistent
073 */
074 public boolean isProcessNonPersistent() {
075 return this.processNonPersistent;
076 }
077
078 /**
079 * @param processNonPersistent the processNonPersistent to set
080 */
081 public void setProcessNonPersistent(boolean processNonPersistent) {
082 this.processNonPersistent = processNonPersistent;
083 }
084
085 public boolean isEnableAudit() {
086 return enableAudit;
087 }
088
089 public void setEnableAudit(boolean enableAudit) {
090 this.enableAudit = enableAudit;
091 }
092 }