com.sun.jini.norm
Class PersistentStore

java.lang.Object
  extended by com.sun.jini.norm.PersistentStore

 class PersistentStore
extends Object

Class that actually stores a Norm server's state to disk. Basically a wrapper around ReliableLog with the addition of lock management.

Author:
Sun Microsystems, Inc.

Field Summary
private static ThreadLocal lockState
          Thread local that tracks if (and how many times) the current thread has acquired a non-exclusive mutator lock.
private  ReliableLog log
          Object we use to reliably and persistently log updates to our state, or null if not persistent.
private static Logger logger
          Logger for logging messages for this class
private  LogHandler logHandler
          Object that handles the recovery of logs, or null if not persistent
private  ReadersWriter mutatorLock
          No mutation of persistent state can occur during a snapshot, however, we can have multiple mutators, use ReadersWriter object to manage this invariant.
private  NormServerBaseImpl server
          The NormServer we are part of
private  File storeLocation
          Location of the persistent store, or null if not persistent
private  List subStores
          A list of all of the sub-stores
private  int updateCount
          Number of updates since last snapshot
private static Long zero
          Cache a Long object with a zero value
 
Constructor Summary
PersistentStore(String logDir, LogHandler logHandler, NormServerBaseImpl server)
          Construct a store that will persist its data to the specified directory.
 
Method Summary
(package private)  void acquireMutatorLock()
          Block until we can acquire a non-exclusive mutator lock on the server's persistent state.
(package private)  void addSubStore(SubStore subStore)
          Inform the store of a sub-store
(package private)  void destroy()
          Destroy the store.
(package private)  void releaseMutatorLock()
          Release one level of mutator locks if this thread holds at least one.
(package private)  void snapshot()
          Generate a snapshot, will perform the necessary locking to ensure no threads are mutating the state of the server before creating the snapshot.
(package private)  void update(Object o)
          Log an update.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final Logger logger
Logger for logging messages for this class


log

private ReliableLog log
Object we use to reliably and persistently log updates to our state, or null if not persistent.


mutatorLock

private final ReadersWriter mutatorLock
No mutation of persistent state can occur during a snapshot, however, we can have multiple mutators, use ReadersWriter object to manage this invariant. Note as far as the lock is concerned the mutators are the readers and snapshot thread the writer since for us mutation is the non-exclusive operation.


lockState

private static final ThreadLocal lockState
Thread local that tracks if (and how many times) the current thread has acquired a non-exclusive mutator lock.


zero

private static final Long zero
Cache a Long object with a zero value


storeLocation

private final File storeLocation
Location of the persistent store, or null if not persistent


logHandler

private final LogHandler logHandler
Object that handles the recovery of logs, or null if not persistent


server

private final NormServerBaseImpl server
The NormServer we are part of


updateCount

private int updateCount
Number of updates since last snapshot


subStores

private List subStores
A list of all of the sub-stores

Constructor Detail

PersistentStore

PersistentStore(String logDir,
                LogHandler logHandler,
                NormServerBaseImpl server)
          throws StoreException
Construct a store that will persist its data to the specified directory.

Parameters:
logDir - directory where the store should persist its data, which must exist, unless it is null, in which case there is no persistence
logHandler - object that will process the log and last snapshot to recover the server's state
server - the server is called back after an update so it can decide whether or not to do a snapshot
Throws:
StoreException - if there is a problem setting up the store
Method Detail

destroy

void destroy()
       throws IOException
Destroy the store.

Throws:
IOException - if it has difficulty removing the log files

addSubStore

void addSubStore(SubStore subStore)
           throws StoreException
Inform the store of a sub-store

Throws:
StoreException

acquireMutatorLock

void acquireMutatorLock()
Block until we can acquire a non-exclusive mutator lock on the server's persistent state. This lock should be acquired in a try block and a releaseMutatorLock call should be placed in a finally block.


releaseMutatorLock

void releaseMutatorLock()
Release one level of mutator locks if this thread holds at least one.


update

void update(Object o)
Log an update. Will flush to disk before returning.

Throws:
IllegalStateException - if the current thread does not hold a non-exclusive mutator lock
IOException
See Also:
ReliableLog.update(java.lang.Object)

snapshot

void snapshot()
        throws IOException
Generate a snapshot, will perform the necessary locking to ensure no threads are mutating the state of the server before creating the snapshot.

Throws:
IOException
See Also:
ReliableLog.snapshot()


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