com.sun.jini.fiddler
Class FiddlerImpl.LocalLogHandler

java.lang.Object
  extended by com.sun.jini.reliableLog.LogHandler
      extended by com.sun.jini.fiddler.FiddlerImpl.LocalLogHandler
Enclosing class:
FiddlerImpl

private class FiddlerImpl.LocalLogHandler
extends LogHandler

Handler class for the persistent storage facility.

At any point during processing in this service, there will exist both a 'snapshot' of the service's state and a set of records detailing each significant change that has occurred to the state since the snapshot was taken. The snapshot information and the incremental change information will be stored in separate files called, respectively, the snapshot file and the log file. Together, these files are used to recover the state of the service after a crash or a network outage (or if the service or its ActivationGroup is un-registered and then re-registered through the Activation Daemon).

This class contains the methods that are used to record and recover the snapshot of the service's state; as well as the method used to apply the state changes that were recorded in the log file.

When the ReliableLog class is instantiated, a new instance of this class is passed to its constructor so that the methods of this class may be invoked by the methods defined in the ReliableLog. Because this class extends the LogHandler class associated with the ReliableLog class, this class must provide implementations of the abstract methods declared in the LogHandler. Also, some of the methods defined in this class override the methods of the LogHandler in order to customize the handling of snapshot creation and retrieval.

Each significant change to the service's state is written to the log file as an individual record (when addLogRecord() is invoked). After the number of records logged exceeds a pre-defined threshold, a snapshot of the state is recorded by invoking -- through the ReliableLog and its LogHandler -- the snapshot() method defined in this class. After the snapshot is taken, the log file is cleared and the incremental log process starts over.

The contents of the snapshot file reflect the DATA contained in the fields making up the current state of the service. That data represents many changes -- over time -- to the service's state. On the other hand, each record written to the log file is an object that reflects both the data used and the ACTIONS taken to make one change to the service's state at a particular point in time.

During recovery, the state of the service at the time of a crash or outage is re-constructed by first retrieving the 'base' state from the snapshot file; and then modifying that base state according to the records retrieved from the log file. The reconstruction of the base state is achieved by invoking the recover() method defined in this class. The modifications recorded in the log file are then applied to the base state by invoking the applyUpdate() method defined in this class. Both recover() and applyUpdate() are invoked through the ReliableLog and its associated LogHandler.

NOTE: The following lines must be added to the service's policy file

     permission java.io.FilePermission "dirname",   "read,write,delete";
     permission java.io.FilePermission "dirname/-", "read,write,delete";
 
where 'dirname' is the name of the directory path (relative or absolute) where the snapshot and log file will be maintained.


Constructor Summary
FiddlerImpl.LocalLogHandler()
          No-arg public constructor
 
Method Summary
 void applyUpdate(Object logRecObj)
          Required method that implements the abstract applyUpdate() defined in ReliableLog's associated LogHandler class.
 void recover(InputStream in)
          Read the snapshot from a stream.
 void snapshot(OutputStream out)
          Writes the snapshot to a stream.
 
Methods inherited from class com.sun.jini.reliableLog.LogHandler
readUpdate, writeUpdate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FiddlerImpl.LocalLogHandler

public FiddlerImpl.LocalLogHandler()
No-arg public constructor

Method Detail

snapshot

public void snapshot(OutputStream out)
              throws IOException
Description copied from class: LogHandler
Writes the snapshot to a stream. This callback is invoked when the client calls the snaphot method of ReliableLog.

Specified by:
snapshot in class LogHandler
Parameters:
out - the output stream
Throws:
IOException

recover

public void recover(InputStream in)
             throws IOException,
                    ClassNotFoundException
Description copied from class: LogHandler
Read the snapshot from a stream. This callback is invoked when the client calls the recover method of ReliableLog.

Specified by:
recover in class LogHandler
Parameters:
in - the input stream
Throws:
IOException
ClassNotFoundException

applyUpdate

public void applyUpdate(Object logRecObj)
Required method that implements the abstract applyUpdate() defined in ReliableLog's associated LogHandler class.

During state recovery, the recover() method defined in the ReliableLog class is invoked. That method invokes the method recoverUpdates() which invokes the method readUpdates(). Both of those methods are defined in ReliableLog. The method readUpdates() retrieves a record from the log file and then invokes this method.

This method invokes the version of the method apply() that corresponds to the particular type of 'log record' object that is input as the first argument. The log record object and its corresponding apply() method are defined in one of the so-called LogObj classes. Any instance of one the LogObj classes is an implementation of the LogRecord interface. The particular implementation that is input to this method is dependent on the type of record that was originally logged. The apply() method will then modify the state of the service in a way dictated by the type of record that was retrieved.

Specified by:
applyUpdate in class LogHandler
Parameters:
logRecObj - the update object


Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.