private class MailboxImpl.LocalLogHandler extends LogHandler
At any point during processing in the mailbox, there will exist both a 'snapshot' of the mailbox'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 mailbox after a crash or a network outage (or if the mailbox 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 mailbox'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 mailbox'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 mailbox. That data represents many changes -- over time -- to the mailbox'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 mailbox's state at a particular point in time.
During recovery, the state of the mailbox 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 mailbox'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 |
---|
MailboxImpl.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 MailboxImpl.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 mailbox 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.