| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| * |
| */ |
| package org.apache.directory.server.core.shared.log; |
| |
| |
| import java.io.File; |
| import java.io.IOException; |
| |
| import org.apache.directory.server.core.api.log.InvalidLogException; |
| import org.apache.directory.server.core.api.log.Log; |
| import org.apache.directory.server.core.api.log.LogAnchor; |
| import org.apache.directory.server.core.api.log.LogScanner; |
| import org.apache.directory.server.core.api.log.UserLogRecord; |
| import org.apache.directory.server.i18n.I18n; |
| |
| |
| /** |
| * Log interface default Implementation. |
| * |
| * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> |
| */ |
| public class DefaultLog implements Log |
| { |
| /** Log manager */ |
| LogManager logManager; |
| |
| /** Log File Manager */ |
| LogFileManager logFileManager; |
| |
| /** LogFlushManager */ |
| LogFlushManager logFlushManager; |
| |
| |
| /** |
| * {@inheritDoc} |
| */ |
| public void init( String logFilepath, String suffix, int logBufferSize, long logFileSize ) throws IOException, |
| InvalidLogException |
| { |
| File logFileDir = new File( logFilepath ); |
| |
| if ( !logFileDir.exists() ) |
| { |
| //LOG.info( "partition directory doesn't exist, creating {}", partitionsDir.getAbsolutePath() ); |
| |
| if ( !logFileDir.mkdirs() ) |
| { |
| throw new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, logFileDir ) ); |
| } |
| } |
| |
| logFileManager = new DefaultLogFileManager( logFilepath, suffix ); |
| |
| logManager = new LogManager( logFileManager ); |
| logManager.initLogManager(); |
| |
| logFlushManager = new LogFlushManager( logManager, logBufferSize, logFileSize ); |
| } |
| |
| |
| /** |
| * {@inheritDoc} |
| */ |
| public void log( UserLogRecord userRecord, boolean sync ) throws IOException, InvalidLogException |
| { |
| logFlushManager.append( userRecord, sync ); |
| } |
| |
| |
| /** |
| * {@inheritDoc} |
| */ |
| public LogScanner beginScan( LogAnchor startPoint ) |
| { |
| LogScanner logScanner = new DefaultLogScanner( startPoint, logFileManager ); |
| |
| return logScanner; |
| } |
| |
| |
| /** |
| * {@inheritDoc} |
| */ |
| public LogScanner beginScan() |
| { |
| LogAnchor startPoint = new LogAnchor(); |
| LogScanner logScanner = new DefaultLogScanner( startPoint, logFileManager ); |
| |
| return logScanner; |
| } |
| |
| |
| /** |
| * {@inheritDoc} |
| */ |
| public void advanceCheckPoint( LogAnchor checkPoint ) |
| { |
| if ( checkPoint == null ) |
| { |
| return; |
| } |
| |
| logManager.advanceCheckPoint( checkPoint ); |
| } |
| |
| |
| /** |
| * {@inheritDoc} |
| */ |
| public LogAnchor getCheckPoint() |
| { |
| return logManager.getCheckPoint(); |
| } |
| |
| |
| /** |
| * {@inheritDoc} |
| */ |
| public void sync( long uptoLSN ) throws IOException, InvalidLogException |
| { |
| logFlushManager.sync( uptoLSN ); |
| } |
| |
| |
| /** |
| * @see Object#toString() |
| */ |
| public String toString() |
| { |
| return "Log{" + logFileManager + "}"; |
| } |
| } |