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