com.sun.jini.outrigger.snaplogstore
Class BackEnd

java.lang.Object
  extended by com.sun.jini.outrigger.snaplogstore.BackEnd
All Implemented Interfaces:
Observer

 class BackEnd
extends Object
implements Observer

Back end of snapshot log store. This class consumes logs written by LogOutputFile and stores the state as serilalzied objects. The class processes the logs to optimize what is stored in the snapshot. For example, a take log record will cause the removal of a write log record with the same id (if the transaction is null).

Likewise, cancels will cause the removal of write and register records. Also renew records update the expiration of the entry or registration and are not stored directly in the database.


Nested Class Summary
private  class BackEnd.ConsumerThread
          Thread to consume log files.
private static class BackEnd.LastLog
          This class remembers which log file was the last to be successfully consumed.
 
Field Summary
private  BackEnd.ConsumerThread consumer
          Log file consumer thread.
private  Map entries
           
private  StoredObject joinState
           
private  BackEnd.LastLog lastLog
           
private  String logFileBase
          The base name for the log files.
private static Logger logger
          Logger for logging persistent store related information
private  Map pendingTxns
           
private  Map registrations
           
private  int retry
          Number of times to attempt to restart the consumer thread.
private  Long sessionId
           
private  int SNAPSHOT_VERSION
          Keep logs and snapshot tied, though not necessary
private  SnapshotFile snapshotFile
          Snapshot object
private  String snapshotFileBase
          The base name for the snapshot files
private  byte[] topUuid
           
private static long WAIT_FOR_THREAD
          Max time to wait for the consumer thread to die on destroy
 
Constructor Summary
BackEnd(String path)
          Create a new BackEnd with the given path.
 
Method Summary
(package private)  void abortOp(Long txnId)
          This method aborts a pending transaction.
(package private)  void bootOp(long time, long session)
          This method sets the session id in the database.
(package private)  void cancelOp(byte[] cookie)
          This method processes a logged cancel operation.
(package private)  void close()
          Stop the consumer and close the database.
(package private)  void commitOp(Long txnId)
          This method commits a pending transaction.
private  void consumeLogs(boolean all)
          Consume the log files that exist.
(package private)  void destroy()
          Destroy the consumer thread and database
(package private)  void joinStateOp(StoredObject state)
          Record the join state.
private  InternalSpaceException logAndThrowRecoveryException(String msg, Throwable nested)
          Log and throw an InternalSpaceException to flag a store recovery problem.
private  PendingTxn pendingTxn(Long txnId)
          Return the pending transaction description for the given transaction, creating the object and adding it to the table if necessary.
(package private)  void prepareOp(Long txnId, StoredObject transaction)
          This method prepares a pending transaction.
private  void recoverSnapshot()
           
(package private)  void registerOp(Registration registration)
           
private  void removePendingTxn(Long txnId)
          Remove a pending transaction from the table.
(package private)  void renewOp(byte[] cookie, long expiration)
          This method processes a logged renew operation.
(package private)  void setupStore(Recover space)
          Setup the database store and recover any existing state.
private  void startConsumer()
           
(package private)  void takeOp(byte[] cookie, Long txnId)
          This method records a logged take operation.
 void update(Observable source, Object arg)
           
(package private)  void uuidOp(byte[] uuid)
          This method records the service's top level Uuid
(package private)  void writeOp(Resource entry, Long txnId)
          This method records a logged write operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sessionId

private Long sessionId

joinState

private StoredObject joinState

entries

private Map entries

registrations

private Map registrations

pendingTxns

private Map pendingTxns

topUuid

private byte[] topUuid

lastLog

private BackEnd.LastLog lastLog

retry

private int retry
Number of times to attempt to restart the consumer thread.


snapshotFile

private SnapshotFile snapshotFile
Snapshot object


SNAPSHOT_VERSION

private final int SNAPSHOT_VERSION
Keep logs and snapshot tied, though not necessary

See Also:
Constant Field Values

logFileBase

private String logFileBase
The base name for the log files.


snapshotFileBase

private String snapshotFileBase
The base name for the snapshot files


consumer

private BackEnd.ConsumerThread consumer
Log file consumer thread.


WAIT_FOR_THREAD

private static final long WAIT_FOR_THREAD
Max time to wait for the consumer thread to die on destroy

See Also:
Constant Field Values

logger

private static final Logger logger
Logger for logging persistent store related information

Constructor Detail

BackEnd

BackEnd(String path)
Create a new BackEnd with the given path.

Method Detail

setupStore

void setupStore(Recover space)
Setup the database store and recover any existing state.


recoverSnapshot

private void recoverSnapshot()

startConsumer

private void startConsumer()

update

public void update(Observable source,
                   Object arg)
Specified by:
update in interface Observer

destroy

void destroy()
Destroy the consumer thread and database


close

void close()
Stop the consumer and close the database.


pendingTxn

private PendingTxn pendingTxn(Long txnId)
Return the pending transaction description for the given transaction, creating the object and adding it to the table if necessary.


removePendingTxn

private void removePendingTxn(Long txnId)
Remove a pending transaction from the table. If it isn't there, this call is harmless.


bootOp

void bootOp(long time,
            long session)
This method sets the session id in the database. It's value is only used during recovery after a restart.


joinStateOp

void joinStateOp(StoredObject state)
Record the join state.


writeOp

void writeOp(Resource entry,
             Long txnId)
This method records a logged write operation. If under a transaction the resource is held in a list for the pending transaction. When committed this method will be called again with the resource and a null transaction id.


takeOp

void takeOp(byte[] cookie,
            Long txnId)
This method records a logged take operation. If under a transaction the resource is held in a list for the pending transaction. When committed this method will be called again with the resource and a null transaction id.


registerOp

void registerOp(Registration registration)

renewOp

void renewOp(byte[] cookie,
             long expiration)
This method processes a logged renew operation. Renew operations apply to resources passed into writeOp and registerOp.


cancelOp

void cancelOp(byte[] cookie)
This method processes a logged cancel operation. Cancel operations apply to resources passed into writeOp and registerOp.


prepareOp

void prepareOp(Long txnId,
               StoredObject transaction)
This method prepares a pending transaction.


commitOp

void commitOp(Long txnId)
This method commits a pending transaction.


abortOp

void abortOp(Long txnId)
This method aborts a pending transaction.


uuidOp

void uuidOp(byte[] uuid)
This method records the service's top level Uuid

Parameters:
uuid - The service's Uuid represented as a byte[16].

consumeLogs

private void consumeLogs(boolean all)
Consume the log files that exist. If all is true, all found log files will be processed. If log is false, then all but the most recent will be processed; this will prevent the back end from reading the log file that is currently being produced by the front end.


logAndThrowRecoveryException

private InternalSpaceException logAndThrowRecoveryException(String msg,
                                                            Throwable nested)
Log and throw an InternalSpaceException to flag a store recovery problem.



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