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 static org.apache.activemq.plugin.SubQueueSelectorCacheBroker.MAX_PERSIST_INTERVAL; 020 021import java.io.File; 022 023import org.apache.activemq.broker.Broker; 024import org.apache.activemq.broker.BrokerPlugin; 025 026/** 027 * A plugin which allows the caching of the selector from a subscription queue. 028 * <p/> 029 * This stops the build-up of unwanted messages, especially when consumers may 030 * disconnect from time to time when using virtual destinations. 031 * <p/> 032 * This is influenced by code snippets developed by Maciej Rakowicz 033 * 034 * @org.apache.xbean.XBean element="virtualSelectorCacheBrokerPlugin" 035 */ 036public class SubQueueSelectorCacheBrokerPlugin implements BrokerPlugin { 037 038 039 private File persistFile; 040 private boolean singleSelectorPerDestination = false; 041 private boolean ignoreWildcardSelectors = false; 042 private long persistInterval = MAX_PERSIST_INTERVAL; 043 044 @Override 045 public Broker installPlugin(Broker broker) throws Exception { 046 SubQueueSelectorCacheBroker rc = new SubQueueSelectorCacheBroker(broker, persistFile); 047 rc.setSingleSelectorPerDestination(singleSelectorPerDestination); 048 rc.setPersistInterval(persistInterval); 049 rc.setIgnoreWildcardSelectors(ignoreWildcardSelectors); 050 return rc; 051 } 052 053 /** 054 * Sets the location of the persistent cache 055 */ 056 public void setPersistFile(File persistFile) { 057 this.persistFile = persistFile; 058 } 059 060 public File getPersistFile() { 061 return persistFile; 062 } 063 064 public boolean isSingleSelectorPerDestination() { 065 return singleSelectorPerDestination; 066 } 067 068 public void setSingleSelectorPerDestination(boolean singleSelectorPerDestination) { 069 this.singleSelectorPerDestination = singleSelectorPerDestination; 070 } 071 072 public long getPersistInterval() { 073 return persistInterval; 074 } 075 076 public void setPersistInterval(long persistInterval) { 077 this.persistInterval = persistInterval; 078 } 079 080 public boolean isIgnoreWildcardSelectors() { 081 return ignoreWildcardSelectors; 082 } 083 084 public void setIgnoreWildcardSelectors(boolean ignoreWildcardSelectors) { 085 this.ignoreWildcardSelectors = ignoreWildcardSelectors; 086 } 087}