001/*
002 *   Licensed to the Apache Software Foundation (ASF) under one
003 *   or more contributor license agreements.  See the NOTICE file
004 *   distributed with this work for additional information
005 *   regarding copyright ownership.  The ASF licenses this file
006 *   to you under the Apache License, Version 2.0 (the
007 *   "License"); you may not use this file except in compliance
008 *   with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *   Unless required by applicable law or agreed to in writing,
013 *   software distributed under the License is distributed on an
014 *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *   KIND, either express or implied.  See the License for the
016 *   specific language governing permissions and limitations
017 *   under the License.
018 *
019 */
020package org.apache.directory.server.core.api.journal;
021
022
023import java.io.IOException;
024
025import org.apache.directory.api.ldap.model.ldif.LdifEntry;
026import org.apache.directory.server.core.api.DirectoryService;
027import org.apache.directory.server.core.api.LdapPrincipal;
028
029
030/**
031 * A store for change events on the directory which exposes methods for 
032 * managing, querying and in general performing legal operations on the log.
033 *
034 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
035 */
036public interface JournalStore
037{
038    /**
039     * Initialize the store.
040     * 
041     * @param service The associated DirectoryService
042     * @throws IOException If the initialization failed
043     */
044    void init( DirectoryService service ) throws IOException;
045
046
047    /**
048     * Write the changes on disk
049     * 
050     * @throws IOException If the write failed
051     */
052    void sync() throws IOException;
053
054
055    /**
056     * Destroy the logs. 
057     * 
058     * @throws IOException If we can't destroy the logs
059     */
060    void destroy() throws IOException;
061
062
063    /**
064     * Gets the current revision of the server (a.k.a. the HEAD revision).
065     *
066     * @return the current revision of the server
067     */
068    long getCurrentRevision();
069
070
071    /**
072     * Records a change as a forward LDIF and the authorized principal
073     *
074     * @param principal The principal who is logging the change
075     * @param revision The operation revision
076     * @param forward The change to log
077     * @return <code>true</code> if the entry has been written
078     */
079    boolean log( LdapPrincipal principal, long revision, LdifEntry forward );
080
081
082    /**
083     * Records a ack for a change
084     *
085     * @param revision The change revision which is acked
086     * @return <code>true</code> if the ack has been written
087     */
088    boolean ack( long revision );
089
090
091    /**
092     * Records a nack for a change
093     *
094     * @param revision The change revision which is nacked
095     * @return <code>true</code> if the nack has been written
096     */
097    boolean nack( long revision );
098
099
100    /**
101     * The file name to use as the journal file. Default to 
102     * 'journal.ldif'
103     * @param fileName the fileName to set
104     */
105    void setFileName( String fileName );
106
107
108    /**
109     * The working directory on which the journal file will be stored. Default
110     * to 'server-work'
111     * @param workingDirectory The working directory in which the journal file
112     * will be stored
113     */
114    void setWorkingDirectory( String workingDirectory );
115}