@@ -0,0 +1,3460 @@
+/*%0A * Licensed to the University of California, Berkeley under one or more contributor license%0A * agreements. See the NOTICE file distributed with this work for additional information regarding%0A * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the%0A * %22License%22); you may not use this file except in compliance with the License. You may obtain a%0A * copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software distributed under the License%0A * is distributed on an %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express%0A * or implied. See the License for the specific language governing permissions and limitations under%0A * the License.%0A */%0A%0Apackage tachyon.master.journal;%0A%0Aimport java.io.IOException;%0A%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport tachyon.Constants;%0Aimport tachyon.master.Master;%0A%0Apublic final class JournalTailer %7B%0A  private static final Logger LOG = LoggerFactory.getLogger(Constants.LOGGER_TYPE);%0A%0A  private final Master mMaster;%0A  private final Journal mJournal;%0A  private final JournalReader mReader;%0A%0A  public JournalTailer(Master master, Journal journal) %7B%0A    mMaster = master;%0A    mJournal = journal;%0A    mReader = mJournal.getNewReader();%0A  %7D%0A%0A  /**%0A   * Returns whether or not the tailer is currently valid.%0A   *%0A   * @return true if this tailer is valid.%0A   */%0A  public boolean isValid() %7B%0A    return mReader.isValid();%0A  %7D%0A%0A  /**%0A   * Returns the last modified time for the checkpoint file.%0A   *%0A   * @return the last modified time of the checkpoint file in ms.%0A   * @throws IOException%0A   */%0A  public long getCheckpointLastModifiedTime() throws IOException %7B%0A    return mReader.getCheckpointLastModifiedTime();%0A  %7D%0A%0A  /**%0A   * Load and (optionally) process the journal checkpoint file.%0A   *%0A   * @param applyToMaster if true, apply all the checkpoint events to the master. Otherwise, simply%0A   *        open the checkpoint file.%0A   * @throws IOException%0A   */%0A  public void processJournalCheckpoint(boolean applyToMaster) throws IOException %7B%0A    // Load the checkpoint file.%0A    LOG.info(%22Loading checkpoint file: %22 + mJournal.getCheckpointFilePath());%0A    JournalInputStream is = mReader.getCheckpointInputStream();%0A    if (applyToMaster) %7B%0A      mMaster.processJournalCheckpoint(is);%0A    %7D%0A  %7D%0A%0A  /**%0A   * Process all the next journal log files. %7B@link #processJournalCheckpoint(boolean)%7D must have%0A   * been called previously.%0A   *%0A   * @return the number of log files processed.%0A   * @throws IOException%0A   */%0A  public int processNextJournalLogFiles() throws IOException %7B%0A    int numProcessed = 0;%0A    while (true) %7B%0A      if (!mReader.isValid()) %7B%0A        LOG.info(%22The checkpoint is out of date. Must reload checkpoint file. %22%0A            + mJournal.getCheckpointFilePath());%0A        return numProcessed;%0A      %7D%0A%0A      // Process the new completed log file, if it exists.%0A      JournalInputStream inputStream = mReader.getNextInputStream();%0A      if (inputStream != null) %7B%0A        LOG.info(%22Processing a completed log file.%22);%0A        JournalEntry entry;%0A        while ((entry = inputStream.getNextEntry()) != null) %7B%0A          mMaster.processJournalEntry(entry);%0A        %7D%0A        inputStream.close();%0A        numProcessed ++;%0A        LOG.info(%22Finished processing the log file.%22);%0A      %7D else %7B%0A        return numProcessed;%0A      %7D%0A    %7D%0A  %7D%0A%7D%0A

Create journal tailer