com.sun.jini.outrigger.snaplogstore
Class LogOutputFile

java.lang.Object
  extended by com.sun.jini.outrigger.snaplogstore.LogFile
      extended by com.sun.jini.outrigger.snaplogstore.LogOutputFile
All Implemented Interfaces:
LogOps

 class LogOutputFile
extends LogFile
implements LogOps

A class to write a log file, to be read later by LogInputFile. Each operation on the file is forced to disk, so when the operation logging function returns, the data is committed to the log in a recoverable way.

LogOutputFile cannot extend Observable because it must extend LogFile (clearly Observable should have been an interface). It acts as an Observable by having a method that returns its "observable part", which is an object that reports observable events. Right now the only observable event is the switching to a new physical file when the current one becomes full.

Author:
Sun Microsystems, Inc.
See Also:
LogInputFile, Observable

Field Summary
private  long deferedPosition
           
private  long deferedUpdateLength
           
private  byte[] intBuf
           
private static long intBytes
           
private  long logBytes
           
private  FileDescriptor logFD
           
private  RandomAccessFile logFile
           
private static Logger logger
          Logger for logging persistent store related information
private  int maxOps
           
private  Observable observable
           
private  int opCnt
           
private  ObjectOutputStream out
           
private  int suffix
           
private  byte[] zeroBuf
           
 
Fields inherited from class com.sun.jini.outrigger.snaplogstore.LogFile
ABORT_OP, baseDir, baseFile, BATCH_TAKE_OP, BATCH_WRITE_OP, BOOT_OP, CANCEL_OP, COMMIT_OP, JOINSTATE_OP, LOG_TYPE, LOG_VERSION, NOTIFIED_OP, PREPARE_OP, REGISTER_OP, RENEW_OP, TAKE_OP, UUID_OP, WRITE_OP
 
Constructor Summary
LogOutputFile(String basePath, int maxOps)
          Create a LogOutputFile object that will stream output to a series of files described by basePath, as interpreted by the relevant LogFile constructor.
 
Method Summary
 void abortOp(Long txnId)
          Log a transaction abort operation.
 void bootOp(long time, long sessionId)
          Log a server boot.
 void cancelOp(Uuid cookie, boolean expired)
          Log a cancel operation.
(package private)  void close()
          Close the log, but don't remove it.
 void commitOp(Long txnId)
          Log a transaction commit operation.
(package private)  void destroy()
          Override destroy so we can try to close logFile before calling super tries to delete all the files.
private  void failed(Exception e)
           
private  void flush()
          Flush the current output after an operation.
private  void flush(boolean forceToDisk)
          Conditionally flush the current output.
private  void flush(boolean forceToDisk, int effectiveOpCount)
          Conditionally flush the current output.
 void joinStateOp(StorableObject state)
          Log a change in join state
private  void nextPath()
          Switch this over to the next path in the list
(package private)  Observable observable()
          Return an Observable object that represents this object in the Observer/Observable pattern.
 void prepareOp(Long txnId, StorableObject transaction)
          Log a transaction prepare operation.
 void registerOp(StorableResource registration, String type, StorableObject[] templates)
          Log a notify operation.
 void renewOp(Uuid cookie, long expiration)
          Log a renew operation.
 void takeOp(Uuid[] cookies, Long txnId)
          Log a batch take operation.
 void takeOp(Uuid cookie, Long txnId)
          Log a take operation.
 void uuidOp(Uuid uuid)
          Log the Uuid that identifies the space as a whole.
private  void writeInt(int val)
          Write an int value in single write operation.
 void writeOp(StorableResource[] entries, Long txnId)
          Log a batch write operation.
 void writeOp(StorableResource entry, Long txnId)
          Log a write operation.
 
Methods inherited from class com.sun.jini.outrigger.snaplogstore.LogFile
existingLogs
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logFile

private RandomAccessFile logFile

logFD

private FileDescriptor logFD

out

private ObjectOutputStream out

suffix

private int suffix

opCnt

private int opCnt

maxOps

private int maxOps

observable

private Observable observable

logBytes

private long logBytes

intBuf

private final byte[] intBuf

zeroBuf

private final byte[] zeroBuf

deferedUpdateLength

private long deferedUpdateLength

deferedPosition

private long deferedPosition

intBytes

private static final long intBytes
See Also:
Constant Field Values

logger

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

Constructor Detail

LogOutputFile

LogOutputFile(String basePath,
              int maxOps)
        throws IOException
Create a LogOutputFile object that will stream output to a series of files described by basePath, as interpreted by the relevant LogFile constructor. When the file becomes full (the maximum number of operations is reached), the file is closed and a new file with the next highest suffix is created. The Observable notification for this event passes a File argument for the filled file as the argument to Observer.

Throws:
IOException
See Also:
observable()
Method Detail

observable

Observable observable()
Return an Observable object that represents this object in the Observer/Observable pattern.

See Also:
Observer

nextPath

private void nextPath()
               throws IOException
Switch this over to the next path in the list

Throws:
IOException

close

void close()
     throws IOException
Close the log, but don't remove it.

Throws:
IOException

destroy

void destroy()
Override destroy so we can try to close logFile before calling super tries to delete all the files.

Overrides:
destroy in class LogFile

bootOp

public void bootOp(long time,
                   long sessionId)
Log a server boot.

Specified by:
bootOp in interface LogOps
Parameters:
time - stamp for this boot
sessionId - of this boot
See Also:
Recover.recoverSessionId(long)

joinStateOp

public void joinStateOp(StorableObject state)
Log a change in join state

Specified by:
joinStateOp in interface LogOps
Parameters:
state - to be logged
See Also:
Recover.recoverJoinState(com.sun.jini.outrigger.StoredObject)

writeOp

public void writeOp(StorableResource entry,
                    Long txnId)
Log a write operation.

Specified by:
writeOp in interface LogOps
Parameters:
entry - to be logged
txnId - transaction identifier or null if no transaction is active for this write
See Also:
Recover.recoverWrite(com.sun.jini.outrigger.StoredResource, java.lang.Long)

writeOp

public void writeOp(StorableResource[] entries,
                    Long txnId)
Description copied from interface: LogOps
Log a batch write operation. If the operation was performed under a transaction the txnId is the identifier for that transaction.

Specified by:
writeOp in interface LogOps
Parameters:
entries - to be logged
txnId - transaction identifier or null if no transaction is active for this write
See Also:
Recover.recoverWrite(com.sun.jini.outrigger.StoredResource, java.lang.Long)

takeOp

public void takeOp(Uuid cookie,
                   Long txnId)
Log a take operation.

Specified by:
takeOp in interface LogOps
Parameters:
cookie - ID identifying the entry target to be taken
txnId - transaction identifier or null if no transaction is active for this take
See Also:
Recover.recoverTake(net.jini.id.Uuid, java.lang.Long)

takeOp

public void takeOp(Uuid[] cookies,
                   Long txnId)
Description copied from interface: LogOps
Log a batch take operation. If the operation was performed under a transaction the txnId is the identifier for that transaction.

Specified by:
takeOp in interface LogOps
Parameters:
cookies - IDs identifying the entries to be taken
txnId - transaction identifier or null if no transaction is active for this take
See Also:
Recover.recoverTake(net.jini.id.Uuid, java.lang.Long)

registerOp

public void registerOp(StorableResource registration,
                       String type,
                       StorableObject[] templates)
Log a notify operation.

Specified by:
registerOp in interface LogOps
Parameters:
registration - to be logged
type - of registration, passed back via type parameter of corresponding recoverRegister call
templates - associated with this registration
See Also:
Recover.recoverRegister(com.sun.jini.outrigger.StoredResource, java.lang.String, com.sun.jini.outrigger.StoredObject[])

renewOp

public void renewOp(Uuid cookie,
                    long expiration)
Log a renew operation.

Specified by:
renewOp in interface LogOps
Parameters:
cookie - ID of the entry or registration associated with this renew
expiration - time
See Also:
StoredResource

cancelOp

public void cancelOp(Uuid cookie,
                     boolean expired)
Log a cancel operation.

Specified by:
cancelOp in interface LogOps
Parameters:
cookie - ID of the entry or registration to cancel
expired - is true if the cancel was due to a lease expiration

prepareOp

public void prepareOp(Long txnId,
                      StorableObject transaction)
Log a transaction prepare operation.

Specified by:
prepareOp in interface LogOps
Parameters:
txnId - identifier of the transaction to be prepared
transaction - object associated with this transaction
See Also:
Recover.recoverTransaction(java.lang.Long, com.sun.jini.outrigger.StoredObject)

commitOp

public void commitOp(Long txnId)
Log a transaction commit operation.

Specified by:
commitOp in interface LogOps
Parameters:
txnId - identifier of the transaction to be committed

abortOp

public void abortOp(Long txnId)
Log a transaction abort operation.

Specified by:
abortOp in interface LogOps
Parameters:
txnId - identifier of the transaction to be aborted

uuidOp

public void uuidOp(Uuid uuid)
Description copied from interface: LogOps
Log the Uuid that identifies the space as a whole.

Specified by:
uuidOp in interface LogOps
Parameters:
uuid - The Uuid to be stored.
See Also:
Recover.recoverUuid(net.jini.id.Uuid)

flush

private void flush()
            throws IOException
Flush the current output after an operation. If the number of operations is exceeded, shift over to the next path.

Throws:
IOException

flush

private void flush(boolean forceToDisk)
            throws IOException
Conditionally flush the current output. If the number of operations is exceeded, shift over to the next path even if forceToDisk is false.

Throws:
IOException

flush

private void flush(boolean forceToDisk,
                   int effectiveOpCount)
            throws IOException
Conditionally flush the current output. If the number of operations is exceeded, shift over to the next path even if forceToDisk is false.

Throws:
IOException

writeInt

private void writeInt(int val)
               throws IOException
Write an int value in single write operation. Note we only use this method when writing log file and recored headers. We can't use it inside records because the data inside records is written/read using ObjectIn/OutputStream and this method writes directly to the RandomAccessFile.

Parameters:
val - int value
Throws:
IOException - if any other I/O error occurs

failed

private void failed(Exception e)
             throws InternalSpaceException
Throws:
InternalSpaceException


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