/** 
 * 
 * Copyright 2004 Protique Ltd
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 * 
 **/
package org.codehaus.activemq.store;

import org.codehaus.activemq.message.ActiveMQMessage;
import org.codehaus.activemq.message.MessageAck;
import org.codehaus.activemq.service.MessageIdentity;
import org.codehaus.activemq.service.QueueMessageContainer;
import org.codehaus.activemq.service.Service;

import javax.jms.JMSException;

/**
 * Represents a message store which is used by the persistent {@link org.codehaus.activemq.service.MessageContainer}
 * implementations
 *
 * @version $Revision: 1.2 $
 */
public interface MessageStore extends Service {

    /**
     * Adds a message to the message store
     */
    public MessageIdentity addMessage(ActiveMQMessage message) throws JMSException;

    /**
     * Looks up a message using either the String messageID or
     * the messageNumber. Implementations are encouraged to fill in the missing
     * key if its easy to do so.
     *
     * @param identity which contains either the messageID or the messageNumber
     * @return the message or null if it does not exist
     */
    public ActiveMQMessage getMessage(MessageIdentity identity) throws JMSException;

    /**
     * Removes a message from the message store.
     *
     * @param identity which contains either the messageID or the messageNumber
     * @param ack the ack request that cause the message to be removed.
     */
    public void removeMessage(MessageIdentity identity, MessageAck ack) throws JMSException;

    /**
     * Removes all the messages from the message store.
     */
    public void removeAllMessages() throws JMSException;
    
    /**
     * Recover any messages to be delivered onto the dispatch queue.
     * <p/>
     * Only called when this store is used for durable queues.
     *
     * @param container
     */
    public void recover(QueueMessageContainer container) throws JMSException;
        
}
