|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.continuent.tungsten.replicator.thl.log.LogFile
public class LogFile
This class manages I/O on a physical log file. It handles streams to read or write from the underlying file.
| Field Summary | |
|---|---|
static int |
HEADER_LENGTH
|
static int |
NO_WAIT
Return immediately from write when there are no data. |
| Constructor Summary | |
|---|---|
LogFile(java.io.File file)
Creates a log file from a simple file. |
|
LogFile(java.io.File parentDirectory,
java.lang.String fileName)
Creates a file from a parent directory and child filename. |
|
| Method Summary | |
|---|---|
protected void |
assertAnyMode()
Returns only if log file is in read or write mode. |
protected void |
assertReadMode()
Returns only if log file is in read mode. |
protected void |
assertWriteMode()
Returns only if log file is in write mode. |
void |
close()
Flush and close file. |
void |
create(long seqno)
Create a new log file. |
void |
flush()
Synchronizes file writes using flush with optional fsync. |
long |
getBaseSeqno()
Returns the base sequence number from the file header. |
int |
getBufferSize()
|
java.io.File |
getFile()
Returns the log file. |
long |
getFlushIntervalMillis()
|
long |
getLength()
Returns the length of the file, including any unbuffered writes. |
LogFlushTask |
getLogFlushTask()
Returns the current log flush task, if any. |
long |
getOffset()
Returns the current position in the log file. |
boolean |
isFsyncOnFlush()
|
void |
openRead()
Open the log file for reading. |
void |
openWrite()
Prepare the log file for writing. |
protected int |
readInt()
Read a single integer. |
protected long |
readLong()
Reads a single long. |
LogRecord |
readRecord(int waitMillis)
Reads a record from the file into a byte array. |
protected short |
readShort()
Reads a single short. |
void |
seekOffset(long offset)
Seeks to a particular offset in the file. |
void |
setBufferSize(int bufferSize)
|
void |
setFlushIntervalMillis(long flushIntervalMillis)
|
void |
setFsyncOnFlush(boolean fsyncOnFlush)
|
void |
setLength(long length)
Truncate the file to the provided length. |
void |
setLogSyncTask(LogFlushTask logFlushTask)
Sets the log flush task. |
java.lang.String |
toString()
Returns a nicely formatting description of the file. |
protected void |
write(int myInt)
|
protected void |
write(long seqno)
|
protected void |
write(short myShort)
|
boolean |
writeRecord(LogRecord record,
int logFileSize)
Writes a buffer to the log file and returns true if we have exceeded the log file size. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int HEADER_LENGTH
public static final int NO_WAIT
| Constructor Detail |
|---|
public LogFile(java.io.File parentDirectory,
java.lang.String fileName)
parentDirectory - Log file directoryfileName - Log file namepublic LogFile(java.io.File file)
file - Log file specification| Method Detail |
|---|
public java.io.File getFile()
public LogFlushTask getLogFlushTask()
public void setLogSyncTask(LogFlushTask logFlushTask)
public long getFlushIntervalMillis()
public void setFlushIntervalMillis(long flushIntervalMillis)
public boolean isFsyncOnFlush()
public void setFsyncOnFlush(boolean fsyncOnFlush)
public int getBufferSize()
public void setBufferSize(int bufferSize)
public void openRead()
throws ReplicatorException,
java.lang.InterruptedException
ReplicatorException - Thrown if file cannot be opened
java.lang.InterruptedException - Thrown if thread is interrupted
public void openWrite()
throws ReplicatorException,
java.lang.InterruptedException
ReplicatorException - Thrown if file cannot be opened
java.lang.InterruptedException - Thrown if we are interrupted
public void create(long seqno)
throws ReplicatorException,
java.lang.InterruptedException
seqno - Base sequence number of this file (written to header)
ReplicatorException
java.lang.InterruptedExceptionpublic void close()
protected void assertAnyMode()
throws ReplicatorException
ReplicatorException
protected void assertWriteMode()
throws ReplicatorException,
java.lang.InterruptedException
ReplicatorException
java.lang.InterruptedException
protected void assertReadMode()
throws ReplicatorException,
java.lang.InterruptedException
ReplicatorException
java.lang.InterruptedExceptionpublic long getBaseSeqno()
public long getLength()
throws ReplicatorException
ReplicatorException
public long getOffset()
throws ReplicatorException
ReplicatorException
public void seekOffset(long offset)
throws java.io.IOException,
ReplicatorException,
java.lang.InterruptedException
java.io.IOException - If positioning results in an error.
ReplicatorException
java.lang.InterruptedException
public LogRecord readRecord(int waitMillis)
throws java.io.IOException,
java.lang.InterruptedException,
LogTimeoutException,
ReplicatorException
waitMillis - Number of milliseconds to wait for data to be
available. 0 means do not wait.
java.io.IOException - Thrown if there is an I/O error
java.lang.InterruptedException - Thrown if we are interrupted
LogTimeoutException - Thrown if we timeout while waiting for data
to appear
ReplicatorException
protected short readShort()
throws java.io.IOException,
ReplicatorException,
java.lang.InterruptedException
java.io.IOException
ReplicatorException
java.lang.InterruptedException
protected int readInt()
throws java.io.IOException,
ReplicatorException,
java.lang.InterruptedException
java.io.IOException
ReplicatorException
java.lang.InterruptedException
protected long readLong()
throws java.io.IOException,
ReplicatorException,
java.lang.InterruptedException
java.io.IOException
ReplicatorException
java.lang.InterruptedException
public void setLength(long length)
throws ReplicatorException,
java.lang.InterruptedException
length - New file length
ReplicatorException
java.lang.InterruptedException
protected void write(int myInt)
throws java.io.IOException,
ReplicatorException,
java.lang.InterruptedException
java.io.IOException
ReplicatorException
java.lang.InterruptedException
protected void write(long seqno)
throws java.io.IOException,
ReplicatorException,
java.lang.InterruptedException
java.io.IOException
ReplicatorException
java.lang.InterruptedException
protected void write(short myShort)
throws java.io.IOException,
ReplicatorException,
java.lang.InterruptedException
java.io.IOException
ReplicatorException
java.lang.InterruptedException
public boolean writeRecord(LogRecord record,
int logFileSize)
throws java.io.IOException,
java.lang.InterruptedException,
ReplicatorException
record - Log record to writelogFileSize - Maximum log file size
java.io.IOException
java.lang.InterruptedException
ReplicatorException
public void flush()
throws java.io.IOException,
ReplicatorException,
java.lang.InterruptedException
java.io.IOException
ReplicatorException
java.lang.InterruptedExceptionpublic java.lang.String toString()
toString in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||