class LogOutputFile extends LogFile implements LogOps
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.
LogInputFile
,
Observable
Modifier and Type | Field and Description |
---|---|
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 |
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 and Description |
---|
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. |
Modifier and Type | Method and Description |
---|---|
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. |
existingLogs
private RandomAccessFile logFile
private FileDescriptor logFD
private ObjectOutputStream out
private int suffix
private int opCnt
private int maxOps
private Observable observable
private long logBytes
private final byte[] intBuf
private final byte[] zeroBuf
private long deferedUpdateLength
private long deferedPosition
private static final long intBytes
private static final Logger logger
LogOutputFile(String basePath, int maxOps) throws IOException
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
.IOException
observable()
Observable observable()
Observable
object that represents this object
in the Observer/Observable pattern.Observer
private void nextPath() throws IOException
IOException
void close() throws IOException
IOException
void destroy()
public void bootOp(long time, long sessionId)
bootOp
in interface LogOps
time
- stamp for this bootsessionId
- of this bootRecover.recoverSessionId(long)
public void joinStateOp(StorableObject state)
joinStateOp
in interface LogOps
state
- to be loggedRecover.recoverJoinState(com.sun.jini.outrigger.StoredObject)
public void writeOp(StorableResource entry, Long txnId)
write
operation.writeOp
in interface LogOps
entry
- to be loggedtxnId
- transaction identifier or null
if
no transaction is active for this writeRecover.recoverWrite(com.sun.jini.outrigger.StoredResource, java.lang.Long)
public void writeOp(StorableResource[] entries, Long txnId)
LogOps
write
operation. If the operation was
performed under a transaction the txnId
is
the identifier for that transaction.writeOp
in interface LogOps
entries
- to be loggedtxnId
- transaction identifier or null
if
no transaction is active for this writeRecover.recoverWrite(com.sun.jini.outrigger.StoredResource, java.lang.Long)
public void takeOp(Uuid cookie, Long txnId)
take
operation.takeOp
in interface LogOps
cookie
- ID identifying the entry target to be takentxnId
- transaction identifier or null
if
no transaction is active for this takeRecover.recoverTake(net.jini.id.Uuid, java.lang.Long)
public void takeOp(Uuid[] cookies, Long txnId)
LogOps
take
operation. If the operation was
performed under a transaction the txnId
is
the identifier for that transaction.takeOp
in interface LogOps
cookies
- IDs identifying the entries to be takentxnId
- transaction identifier or null
if
no transaction is active for this takeRecover.recoverTake(net.jini.id.Uuid, java.lang.Long)
public void registerOp(StorableResource registration, String type, StorableObject[] templates)
notify
operation.registerOp
in interface LogOps
registration
- to be loggedtype
- of registration, passed back via type
parameter of corresponding recoverRegister
calltemplates
- associated with this registrationRecover.recoverRegister(com.sun.jini.outrigger.StoredResource, java.lang.String, com.sun.jini.outrigger.StoredObject[])
public void renewOp(Uuid cookie, long expiration)
renew
operation.renewOp
in interface LogOps
cookie
- ID of the entry or registration associated with this
renewexpiration
- timeStoredResource
public void cancelOp(Uuid cookie, boolean expired)
cancel
operation.public void prepareOp(Long txnId, StorableObject transaction)
prepare
operation.prepareOp
in interface LogOps
txnId
- identifier of the transaction to be preparedtransaction
- object associated with this transactionRecover.recoverTransaction(java.lang.Long, com.sun.jini.outrigger.StoredObject)
public void commitOp(Long txnId)
commit
operation.public void abortOp(Long txnId)
abort
operation.public void uuidOp(Uuid uuid)
LogOps
Uuid
that identifies the space as a whole.uuidOp
in interface LogOps
uuid
- The Uuid
to be stored.Recover.recoverUuid(net.jini.id.Uuid)
private void flush() throws IOException
IOException
private void flush(boolean forceToDisk) throws IOException
forceToDisk
is false
.IOException
private void flush(boolean forceToDisk, int effectiveOpCount) throws IOException
forceToDisk
is false
.IOException
private void writeInt(int val) throws IOException
ObjectIn/OutputStream
and this
method writes directly to the RandomAccessFile
.val
- int valueIOException
- if any other I/O error occursprivate void failed(Exception e) throws InternalSpaceException
InternalSpaceException
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.