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.plugin; 018 019 020 import org.apache.activemq.broker.Broker; 021 import org.apache.activemq.broker.BrokerPlugin; 022 import org.slf4j.Logger; 023 import org.slf4j.LoggerFactory; 024 025 026 /** 027 * A Plugin which allows to force every incoming message to be PERSISTENT or NON-PERSISTENT. 028 * 029 * Useful, if you have set the broker usage policy to process ONLY persistent or ONLY non-persistent 030 * messages. 031 * @org.apache.xbean.XBean element="forcePersistencyModeBrokerPlugin" 032 */ 033 public class ForcePersistencyModeBrokerPlugin implements BrokerPlugin { 034 private static Logger LOG = LoggerFactory.getLogger(ForcePersistencyModeBrokerPlugin.class); 035 private boolean persistenceFlag = false; 036 037 /** 038 * Constructor 039 */ 040 public ForcePersistencyModeBrokerPlugin() { 041 } 042 043 /** 044 * @param broker 045 * @return the Broker 046 * @throws Exception 047 * @see org.apache.activemq.broker.BrokerPlugin#installPlugin(org.apache.activemq.broker.Broker) 048 */ 049 050 public Broker installPlugin(Broker broker) throws Exception{ 051 ForcePersistencyModeBroker pB = new ForcePersistencyModeBroker(broker); 052 pB.setPersistenceFlag(isPersistenceForced()); 053 LOG.info("Installing ForcePersistencyModeBroker plugin: persistency enforced=" + pB.isPersistent()); 054 return pB; 055 } 056 057 /** Sets the persistency mode. 058 * 059 * @param persistenceFlag 060 */ 061 public void setPersistenceFlag(final boolean persistenceFlag) { 062 this.persistenceFlag = persistenceFlag; 063 } 064 065 /** 066 * @return the mode the (activated) plugin will set the message delivery mode 067 */ 068 public final boolean isPersistenceForced() { 069 return persistenceFlag; 070 } 071 072 } 073