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.broker.region.policy;
018
019
020import org.apache.activemq.Service;
021import org.apache.activemq.broker.Broker;
022import org.apache.activemq.broker.ConnectionContext;
023import org.apache.activemq.broker.region.MessageReference;
024import org.apache.activemq.broker.region.SubscriptionRecovery;
025import org.apache.activemq.broker.region.Topic;
026import org.apache.activemq.command.ActiveMQDestination;
027import org.apache.activemq.command.Message;
028
029/**
030 * Abstraction to allow different recovery policies to be plugged
031 * into the region implementations.  This is used by a topic to retroactively recover
032 * messages that the subscription missed.
033 * 
034 * 
035 */
036public interface SubscriptionRecoveryPolicy extends Service {
037    
038    /**
039     * A message was sent to the destination.
040     * 
041     * @param context
042     * @param message
043     * @return true if successful
044     * @throws Exception
045     */
046    boolean add(ConnectionContext context, MessageReference message) throws Exception;
047    
048    /**
049     * Let a subscription recover message held by the policy.
050     * 
051     * @param context
052     * @param topic
053     * @param sub
054     * @throws Exception
055     */
056    void recover(ConnectionContext context, Topic topic, SubscriptionRecovery sub) throws Exception;
057    
058    
059    /**
060     * @param dest 
061     * @return messages
062     * @throws Exception 
063     */
064    Message[] browse(ActiveMQDestination dest) throws Exception;
065
066    /**
067     * Used to copy the policy object.
068     * @return the copy
069     */
070    SubscriptionRecoveryPolicy copy();
071    
072    void setBroker(Broker broker);
073}