Path: blob/master/src/java.rmi/share/classes/sun/rmi/log/LogHandler.java
41155 views
/*1* Copyright (c) 1997, 2001, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.rmi.log;2627import java.io.*;28import sun.rmi.server.MarshalOutputStream;29import sun.rmi.server.MarshalInputStream;3031/**32* A LogHandler represents snapshots and update records as serializable33* objects.34*35* This implementation does not know how to create an initial snaphot or36* apply an update to a snapshot. The client must specifiy these methods37* via a subclass.38*39* @see ReliableLog40*41* @author Ann Wollrath42*/43public abstract44class LogHandler {4546/**47* Creates a LogHandler for a ReliableLog.48*/49public LogHandler() {}5051/**52* Creates and returns the initial state of data structure that needs53* to be stably stored. This method is called when a ReliableLog is54* created.55* @return the initial state56* @exception Exception can raise any exception57*/58public abstract59Object initialSnapshot() throws Exception;6061/**62* Writes the snapshot object to a stream. This callback is63* invoked when the client calls the snaphot method of ReliableLog.64* @param out the output stream65* @param value the snapshot66* @exception Exception can raise any exception67*/68public69void snapshot(OutputStream out, Object value) throws Exception {70MarshalOutputStream s = new MarshalOutputStream(out);71s.writeObject(value);72s.flush();73}7475/**76* Read the snapshot object from a stream and returns the snapshot.77* This callback is invoked when the client calls the recover method78* of ReliableLog.79* @param in the input stream80* @return the state (snapshot)81* @exception Exception can raise any exception82*/8384public85Object recover(InputStream in) throws Exception {86MarshalInputStream s = new MarshalInputStream(in);87return s.readObject();88}8990/**91* Writes the representation (a serializable object) of an update92* to a stream. This callback is invoked when the client calls the93* update method of ReliableLog.94* @param out the output stream95* @param value the snapshot96* @exception Exception can raise any exception97*/98public99void writeUpdate(LogOutputStream out, Object value) throws Exception {100101MarshalOutputStream s = new MarshalOutputStream(out);102s.writeObject(value);103s.flush();104}105106/**107* Reads a stably logged update (a serializable object) from a108* stream. This callback is invoked during recovery, once for109* every record in the log. After reading the update, this method110* invokes the applyUpdate (abstract) method in order to obtain111* the new snapshot value. It then returns the new snapshot.112*113* @param in the input stream114* @param state the current state115* @return the new state116* @exception Exception can raise any exception117*/118public119Object readUpdate(LogInputStream in, Object state) throws Exception {120MarshalInputStream s = new MarshalInputStream(in);121return applyUpdate(s.readObject(), state);122}123124/**125* Reads a stably logged update (a serializable object) from a stream.126* This callback is invoked during recovery, once for every record in the127* log. After reading the update, this method is invoked in order to128* obtain the new snapshot value. The method should apply the update129* object to the current state <code>state</code> and return the new130* state (the new snapshot value).131* @param update the update object132* @param state the current state133* @return the new state134* @exception Exception can raise any exception135*/136public abstract137Object applyUpdate(Object update, Object state) throws Exception;138139}140141142