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.io.File;
020
021import org.apache.activemq.broker.Broker;
022import org.apache.activemq.broker.BrokerPlugin;
023
024import static org.apache.activemq.plugin.SubQueueSelectorCacheBroker.MAX_PERSIST_INTERVAL;
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 * @author Roelof Naude roelof(dot)naude(at)gmail.com
035 *@org.apache.xbean.XBean element="virtualSelectorCacheBrokerPlugin"
036 */
037public class SubQueueSelectorCacheBrokerPlugin implements BrokerPlugin {
038
039
040    private File persistFile;
041    private boolean singleSelectorPerDestination = false;
042    private boolean ignoreWildcardSelectors = false;
043    private long persistInterval = MAX_PERSIST_INTERVAL;
044
045    @Override
046    public Broker installPlugin(Broker broker) throws Exception {
047        SubQueueSelectorCacheBroker rc = new SubQueueSelectorCacheBroker(broker, persistFile);
048        rc.setSingleSelectorPerDestination(singleSelectorPerDestination);
049        rc.setPersistInterval(persistInterval);
050        rc.setIgnoreWildcardSelectors(ignoreWildcardSelectors);
051        return rc;
052    }
053
054    /**
055     * Sets the location of the persistent cache
056     */
057    public void setPersistFile(File persistFile) {
058        this.persistFile = persistFile;
059    }
060
061    public File getPersistFile() {
062        return persistFile;
063    }
064
065    public boolean isSingleSelectorPerDestination() {
066        return singleSelectorPerDestination;
067    }
068
069    public void setSingleSelectorPerDestination(boolean singleSelectorPerDestination) {
070        this.singleSelectorPerDestination = singleSelectorPerDestination;
071    }
072
073    public long getPersistInterval() {
074        return persistInterval;
075    }
076
077    public void setPersistInterval(long persistInterval) {
078        this.persistInterval = persistInterval;
079    }
080
081    public boolean isIgnoreWildcardSelectors() {
082        return ignoreWildcardSelectors;
083    }
084
085    public void setIgnoreWildcardSelectors(boolean ignoreWildcardSelectors) {
086        this.ignoreWildcardSelectors = ignoreWildcardSelectors;
087    }
088}