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 */
018 package org.apache.hadoop.hdfs.server.datanode.fsdataset;
019
020 import java.io.Closeable;
021 import java.io.IOException;
022 import 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 */
029 public 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 /**
039 * To append text to the logs.
040 */
041 public interface Appender extends Appendable, Closeable {
042 }
043
044 /**
045 * Create an iterator to iterate the lines in the logs.
046 *
047 * @param skipPrevious Should it skip reading the previous log?
048 * @return a new iterator.
049 */
050 public LineIterator iterator(boolean skipPrevious) throws IOException;
051
052 /**
053 * @return the only appender to append text to the logs.
054 * The same object is returned if it is invoked multiple times.
055 */
056 public Appender appender();
057
058 /**
059 * Roll current to previous.
060 *
061 * @return true if the rolling succeeded.
062 * When it returns false, it is not equivalent to an error.
063 * It means that the rolling cannot be performed at the moment,
064 * e.g. the logs are being read.
065 */
066 public boolean roll() throws IOException;
067 }