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, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hdfs.server.datanode.fsdataset;
019
020import java.io.Closeable;
021import java.io.IOException;
022import java.util.Iterator;
023
024/**
025 * Rolling logs consist of a current log and a set of previous logs.
026 *
027 * The implementation should support a single appender and multiple readers.
028 */
029public interface RollingLogs {
030  /**
031   * To iterate the lines of the logs.
032   */
033  public interface LineIterator extends Iterator<String>, Closeable {
034    /** Is the iterator iterating the previous? */
035    public boolean isPrevious();
036
037    /**
038     * Is the last read entry from previous? This should be called after
039     * reading.
040     */
041    public boolean isLastReadFromPrevious();
042  }
043
044  /**
045   * To append text to the logs.
046   */
047  public interface Appender extends Appendable, Closeable {
048  }
049
050  /**
051   * Create an iterator to iterate the lines in the logs.
052   * 
053   * @param skipPrevious Should it skip reading the previous log? 
054   * @return a new iterator.
055   */
056  public LineIterator iterator(boolean skipPrevious) throws IOException;
057
058  /**
059   * @return the only appender to append text to the logs.
060   *   The same object is returned if it is invoked multiple times.
061   */
062  public Appender appender();
063
064  /**
065   * Roll current to previous.
066   *
067   * @return true if the rolling succeeded.
068   *   When it returns false, it is not equivalent to an error. 
069   *   It means that the rolling cannot be performed at the moment,
070   *   e.g. the logs are being read.
071   */
072  public boolean roll() throws IOException;
073}