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 */ 017package org.apache.activemq.plugin; 018 019import java.util.ArrayList; 020import java.util.StringTokenizer; 021import java.util.regex.Pattern; 022 023import org.apache.activemq.broker.Broker; 024import org.apache.activemq.broker.BrokerPlugin; 025import org.slf4j.Logger; 026import org.slf4j.LoggerFactory; 027 028/** 029 * @org.apache.xbean.XBean element="discardingDLQBrokerPlugin" 030 * @version 1.0 031 */ 032public class DiscardingDLQBrokerPlugin implements BrokerPlugin { 033 034 public DiscardingDLQBrokerPlugin() { 035 } 036 037 public static Logger log = LoggerFactory.getLogger(DiscardingDLQBrokerPlugin.class); 038 private boolean dropTemporaryTopics = true; 039 private boolean dropTemporaryQueues = true; 040 private boolean dropAll = true; 041 private String dropOnly; 042 private int reportInterval = 1000; 043 044 /** 045 * Installs the plugin into the intercepter chain of the broker, returning the new 046 * intercepted broker to use. 047 * 048 * @param broker Broker 049 * 050 * @return Broker 051 * 052 * @throws Exception 053 */ 054 @Override 055 public Broker installPlugin(Broker broker) throws Exception { 056 log.info("Installing Discarding Dead Letter Queue broker plugin[dropAll={}; dropTemporaryTopics={}; dropTemporaryQueues={}; dropOnly={}; reportInterval={}]", new Object[]{ 057 isDropAll(), isDropTemporaryTopics(), isDropTemporaryQueues(), getDropOnly(), reportInterval 058 }); 059 DiscardingDLQBroker cb = new DiscardingDLQBroker(broker); 060 cb.setDropAll(isDropAll()); 061 cb.setDropTemporaryQueues(isDropTemporaryQueues()); 062 cb.setDropTemporaryTopics(isDropTemporaryTopics()); 063 cb.setDestFilter(getDestFilter()); 064 cb.setReportInterval(getReportInterval()); 065 return cb; 066 } 067 068 public boolean isDropAll() { 069 return dropAll; 070 } 071 072 public boolean isDropTemporaryQueues() { 073 return dropTemporaryQueues; 074 } 075 076 public boolean isDropTemporaryTopics() { 077 return dropTemporaryTopics; 078 } 079 080 public String getDropOnly() { 081 return dropOnly; 082 } 083 084 public int getReportInterval() { 085 return reportInterval; 086 } 087 088 public void setDropTemporaryTopics(boolean dropTemporaryTopics) { 089 this.dropTemporaryTopics = dropTemporaryTopics; 090 } 091 092 public void setDropTemporaryQueues(boolean dropTemporaryQueues) { 093 this.dropTemporaryQueues = dropTemporaryQueues; 094 } 095 096 public void setDropAll(boolean dropAll) { 097 this.dropAll = dropAll; 098 } 099 100 public void setDropOnly(String dropOnly) { 101 this.dropOnly = dropOnly; 102 } 103 104 public void setReportInterval(int reportInterval) { 105 this.reportInterval = reportInterval; 106 } 107 108 public Pattern[] getDestFilter() { 109 if (getDropOnly()==null) return null; 110 ArrayList<Pattern> list = new ArrayList<Pattern>(); 111 StringTokenizer t = new StringTokenizer(getDropOnly()," "); 112 while (t.hasMoreTokens()) { 113 String s = t.nextToken(); 114 if (s!=null && s.trim().length()>0) list.add(Pattern.compile(s)); 115 } 116 if (list.size()==0) return null; 117 return list.toArray(new Pattern[0]); 118 } 119}