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
018package org.apache.activemq.store;
019
020import java.io.IOException;
021import java.util.concurrent.locks.Lock;
022
023import org.apache.activemq.broker.ConnectionContext;
024import org.apache.activemq.command.MessageId;
025
026/**
027 * Represents a message store which is used by the persistent implementations
028 * 
029 * 
030 */
031public interface ReferenceStore extends MessageStore {
032
033    public class ReferenceData {
034        long expiration;
035        int fileId;
036        int offset;
037
038        public long getExpiration() {
039            return expiration;
040        }
041
042        public void setExpiration(long expiration) {
043            this.expiration = expiration;
044        }
045
046        public int getFileId() {
047            return fileId;
048        }
049
050        public void setFileId(int file) {
051            this.fileId = file;
052        }
053
054        public int getOffset() {
055            return offset;
056        }
057
058        public void setOffset(int offset) {
059            this.offset = offset;
060        }
061
062        @Override
063        public String toString() {
064            return "ReferenceData fileId=" + fileId + ", offset=" + offset + ", expiration=" + expiration;
065        }
066    }
067
068    /**
069     * Adds a message reference to the message store
070     * @return true if reference was added, false if it is a duplicate and not added
071     */
072    boolean addMessageReference(ConnectionContext context, MessageId messageId, ReferenceData data) throws IOException;
073
074    /**
075     * Looks up a message using either the String messageID or the
076     * messageNumber. Implementations are encouraged to fill in the missing key
077     * if its easy to do so.
078     */
079    ReferenceData getMessageReference(MessageId identity) throws IOException;
080
081    /**
082     * @return true if it supports external batch control
083     */
084    boolean supportsExternalBatchControl();
085
086    void setBatch(MessageId startAfter);
087    
088    Lock getStoreLock();
089    
090}