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