0N/A/*
2362N/A * Copyright (c) 1997, 2001, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.rmi.log;
0N/A
0N/Aimport java.io.*;
0N/Aimport sun.rmi.server.MarshalOutputStream;
0N/Aimport sun.rmi.server.MarshalInputStream;
0N/A
0N/A/**
0N/A * A LogHandler represents snapshots and update records as serializable
0N/A * objects.
0N/A *
0N/A * This implementation does not know how to create an initial snaphot or
0N/A * apply an update to a snapshot. The client must specifiy these methods
0N/A * via a subclass.
0N/A *
0N/A * @see ReliableLog
0N/A *
0N/A * @author Ann Wollrath
0N/A */
0N/Apublic abstract
0N/Aclass LogHandler {
0N/A
0N/A /**
0N/A * Creates a LogHandler for a ReliableLog.
0N/A */
0N/A public LogHandler() {}
0N/A
0N/A /**
0N/A * Creates and returns the initial state of data structure that needs
0N/A * to be stably stored. This method is called when a ReliableLog is
0N/A * created.
0N/A * @return the initial state
0N/A * @exception Exception can raise any exception
0N/A */
0N/A public abstract
0N/A Object initialSnapshot() throws Exception;
0N/A
0N/A /**
0N/A * Writes the snapshot object to a stream. This callback is
0N/A * invoked when the client calls the snaphot method of ReliableLog.
0N/A * @param out the output stream
0N/A * @param value the snapshot
0N/A * @exception Exception can raise any exception
0N/A */
0N/A public
0N/A void snapshot(OutputStream out, Object value) throws Exception {
0N/A MarshalOutputStream s = new MarshalOutputStream(out);
0N/A s.writeObject(value);
0N/A s.flush();
0N/A }
0N/A
0N/A /**
0N/A * Read the snapshot object from a stream and returns the snapshot.
0N/A * This callback is invoked when the client calls the recover method
0N/A * of ReliableLog.
0N/A * @param in the input stream
0N/A * @return the state (snapshot)
0N/A * @exception Exception can raise any exception
0N/A */
0N/A
0N/A public
0N/A Object recover(InputStream in) throws Exception {
0N/A MarshalInputStream s = new MarshalInputStream(in);
0N/A return s.readObject();
0N/A }
0N/A
0N/A /**
0N/A * Writes the representation (a serializable object) of an update
0N/A * to a stream. This callback is invoked when the client calls the
0N/A * update method of ReliableLog.
0N/A * @param out the output stream
0N/A * @param value the snapshot
0N/A * @exception Exception can raise any exception
0N/A */
0N/A public
0N/A void writeUpdate(LogOutputStream out, Object value) throws Exception {
0N/A
0N/A MarshalOutputStream s = new MarshalOutputStream(out);
0N/A s.writeObject(value);
0N/A s.flush();
0N/A }
0N/A
0N/A /**
0N/A * Reads a stably logged update (a serializable object) from a
0N/A * stream. This callback is invoked during recovery, once for
0N/A * every record in the log. After reading the update, this method
0N/A * invokes the applyUpdate (abstract) method in order to obtain
0N/A * the new snapshot value. It then returns the new snapshot.
0N/A *
0N/A * @param in the input stream
0N/A * @param state the current state
0N/A * @return the new state
0N/A * @exception Exception can raise any exception
0N/A */
0N/A public
0N/A Object readUpdate(LogInputStream in, Object state) throws Exception {
0N/A MarshalInputStream s = new MarshalInputStream(in);
0N/A return applyUpdate(s.readObject(), state);
0N/A }
0N/A
0N/A /**
0N/A * Reads a stably logged update (a serializable object) from a stream.
0N/A * This callback is invoked during recovery, once for every record in the
0N/A * log. After reading the update, this method is invoked in order to
0N/A * obtain the new snapshot value. The method should apply the update
0N/A * object to the current state <code>state</code> and return the new
0N/A * state (the new snapshot value).
0N/A * @param update the update object
0N/A * @param state the current state
0N/A * @return the new state
0N/A * @exception Exception can raise any exception
0N/A */
0N/A public abstract
0N/A Object applyUpdate(Object update, Object state) throws Exception;
0N/A
0N/A}