private class RegistrarImpl.LocalLogHandler extends LogHandler
At any point during processing in a persistent Registrar instance, there will exist both a 'snapshot' of the Registrar'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 Registrar when it is restarted or reactivated (for example, after a crash or network outage).
This class contains the methods that are used to record and recover the snapshot of the Registrar'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 persistent Registrar'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 Registrar. That data represents many changes -- over time -- to the Registrar'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 Registrar's state at a particular point in time.
The data written to the snapshot file is shown below:
NOTE: The following lines must be added to the Registrar'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 and Description |
---|
RegistrarImpl.LocalLogHandler()
Simple constructor
|
Modifier and Type | Method and Description |
---|---|
void |
applyUpdate(Object logRecObj)
Required method implementing 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.
|
readUpdate, writeUpdate
public RegistrarImpl.LocalLogHandler()
public void snapshot(OutputStream out) throws IOException
LogHandler
snapshot
in class LogHandler
out
- the output streamIOException
public void recover(InputStream in) throws IOException, ClassNotFoundException
LogHandler
recover
in class LogHandler
in
- the input streamIOException
ClassNotFoundException
public void applyUpdate(Object logRecObj)
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 Registrar in a way dictated by the type of record that was retrieved.
applyUpdate
in class LogHandler
logRecObj
- the update objectCopyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.