/*
 * 
 * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * The contents of this file are subject to the Sun Community Source
 * License v3.0/Jini Technology Specific Attachment v 1.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://wwws.sun.com/software/jini/licensing/SCSL3_JiniTSA1.html.
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and limitations
 * under the License.
 * 
 * The Reference Code is Jini Technology Core Platform code, v2.0. The
 * Developer of the Reference Code is Sun Microsystems, Inc.
 * 
 * Contributor(s): Sun Microsystems, Inc.
 * 
 * The contents of this file comply with the Jini Technology Core
 * Platform Compatibility Kit, v2.0A.
 * 
 * Tester(s): Sun Microsystems, Inc.
 * 
 * Test Platform(s):
 * Java 2 SDK, Standard Edition, Version 1.4.2_03 for Solaris(TM)SPARC/x86
 * Java 2 SDK, Standard Edition, Version 1.4.2_03 for Linux (Intel x86)
 * Java 2 SDK, Standard Edition, Version 1.4.2_03 for Windows (Intel Platform)
 * 
 */
package com.sun.jini.mahalo.log;

import com.sun.jini.logging.Levels;
import com.sun.jini.mahalo.log.MultiLogManager.LogRemovalManager;
import com.sun.jini.mahalo.TxnManager;

import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import java.io.*;

/**
 * An implementation of a non-persistent <code>Log</code>.
 *
 * @author Sun Microsystems, Inc.
 *
 * @see com.sun.jini.mahalo.log.Log
 */
public class TransientLogFile implements Log {
    /** Unique ID associated with this log */
    private /*final*/ long cookie;

    /** Logger for persistence related messages */
    private static final Logger persistenceLogger = 
        Logger.getLogger(TxnManager.MAHALO + ".persistence");

    /** Logger for operations related messages */
    private static final Logger operationsLogger = 
        Logger.getLogger(TxnManager.MAHALO + ".operations");

    /**
     * Simple constructor that simply assigns the given parameter to 
     * an internal field.
     * @param id   the unique identifier for this log
     *
     * @see com.sun.jini.mahalo.log.Log
     * @see com.sun.jini.mahalo.log.LogManager
     * @see com.sun.jini.mahalo.log.MultiLogManager
     * @see com.sun.jini.mahalo.log.MultiLogManager.LogRemovalManager
     */
    public TransientLogFile(long id) {
        if (operationsLogger.isLoggable(Level.FINER)) {
            operationsLogger.entering(TransientLogFile.class.getName(), 
	        "TransientLogFile", new Long(cookie));
	}
        this.cookie = id;
        if (operationsLogger.isLoggable(Level.FINER)) {
            operationsLogger.exiting(TransientLogFile.class.getName(), 
	        "TransientLogFile");
	}
    }

    /**
     * Returns the identifier associated with information in
     * this <code>Log</code>.
     *
     * @see com.sun.jini.mahalo.log.Log
     */
    public long cookie() {
	return cookie;
    }

    /**
     * Add a <code>LogRecord</code> to the <code>Log</code>.
     * This method does nothing with the provided argument.
     *
     * @param rec the record to be ignored.
     *
     * @see com.sun.jini.mahalo.log.LogRecord
     */
    public void write(LogRecord rec) throws LogException {
        if (operationsLogger.isLoggable(Level.FINER)) {
            operationsLogger.entering(TransientLogFile.class.getName(), 
	        "write", rec);
	}
	if (persistenceLogger.isLoggable(Level.FINEST)) {
            persistenceLogger.log(Level.FINEST,
                "(ignored) write called for cookie: {0}", new Long(cookie));
	}
        if (operationsLogger.isLoggable(Level.FINER)) {
            operationsLogger.exiting(TransientLogFile.class.getName(), 
	        "write");
	}
    }

    /**
     * Invalidate the log. This method does nothing.
     */
    public void invalidate() throws LogException {
        if (operationsLogger.isLoggable(Level.FINER)) {
            operationsLogger.entering(TransientLogFile.class.getName(), 
	        "invalidate");
	}
	if (persistenceLogger.isLoggable(Level.FINEST)) {
            persistenceLogger.log(Level.FINEST,
                "(ignored) Invalidating log for cookie: {0}", new Long(cookie));
	}
        if (operationsLogger.isLoggable(Level.FINER)) {
            operationsLogger.exiting(TransientLogFile.class.getName(), 
	        "invalidate");
	}
    }

    /**
     * Recover information from the log. Does nothing.
     *
     * @param client who to inform with information from the log.
     *
     * @see com.sun.jini.mahalo.log.LogRecovery
     */
    public void recover(LogRecovery client) throws LogException {
        if (operationsLogger.isLoggable(Level.FINER)) {
            operationsLogger.entering(MultiLogManager.class.getName(), 
	        "recover", client);
	}
	if (persistenceLogger.isLoggable(Level.FINEST)) {
            persistenceLogger.log(Level.FINEST,
                "(ignored) Recovering for: {0}", new Long(cookie));
	}
        if (operationsLogger.isLoggable(Level.FINER)) {
            operationsLogger.exiting(MultiLogManager.class.getName(), 
	        "recover");
	}
    }
}
