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
019
020import org.apache.activemq.broker.Broker;
021import org.apache.activemq.broker.BrokerFilter;
022import org.apache.activemq.broker.ProducerBrokerExchange;
023import org.apache.activemq.command.Message;
024import org.slf4j.Logger;
025import org.slf4j.LoggerFactory;
026
027
028/**
029 * A Plugin which allows to force every incoming message to be PERSISTENT or NON-PERSISTENT. 
030 * 
031 * Useful, if you have set the broker usage policy to process ONLY persistent or ONLY non-persistent
032 * messages. 
033 * @org.apache.xbean.XBean element="forcePersistencyModeBroker"
034 */
035public class ForcePersistencyModeBroker extends BrokerFilter{
036  public static Logger log = LoggerFactory.getLogger(ForcePersistencyModeBroker.class);
037  private boolean persistence = false;
038  
039  /**
040   * @return the persistenceFlag
041   */
042  public boolean isPersistent() {
043    return persistence;
044  }
045
046  /**
047   * @param persistenceFlag the persistenceFlag to set
048   */
049  public void setPersistenceFlag(boolean mode) {
050    this.persistence = mode;
051  }
052
053  /**
054   * Constructor
055   * @param next
056   */
057  public ForcePersistencyModeBroker(Broker next) {
058    super(next);
059    System.out.println(this.getBrokerSequenceId());
060  }
061  
062  /** Sets the persistence mode
063   * @see org.apache.activemq.broker.BrokerFilter#send(org.apache.activemq.broker.ProducerBrokerExchange, org.apache.activemq.command.Message)
064   */
065  public void send(ProducerBrokerExchange producerExchange, Message messageSend) throws Exception {
066    messageSend.getMessage().setPersistent(isPersistent());
067    next.send(producerExchange, messageSend);
068  }
069  
070}
071