public static class Log.Writer
extends java.lang.Object
Log
. This class is not safe
for use from multiple threads and instances should be thrown out
after any Log.WriterFailedException
is thrown.Constructor and Description |
---|
Writer(Log log,
long timeout,
java.util.concurrent.TimeUnit unit,
int retries)
Constructs a writer linked the given
Log . |
Modifier and Type | Method and Description |
---|---|
Log.Position |
append(byte[] data,
long timeout,
java.util.concurrent.TimeUnit unit)
Attempts to append to the log with the specified data returning
the new end position of the log if successful.
|
protected void |
finalize() |
protected void |
initialize(Log log,
long timeout,
java.util.concurrent.TimeUnit unit,
int retries) |
Log.Position |
truncate(Log.Position to,
long timeout,
java.util.concurrent.TimeUnit unit)
Attempts to truncate the log (from the beginning to the
specified position exclusive) If the position is invalid, an
Log.WriterFailedException will get thrown. |
public Writer(Log log, long timeout, java.util.concurrent.TimeUnit unit, int retries)
Log
.log
- The log that this writer will access.timeout
- Max number of time units to wait before a
TimeoutException
.unit
- Type of time units used for the timeout, e.g. seconds,
minutes, etc.retries
- Number of retriesTimeUnit
public Log.Position append(byte[] data, long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.TimeoutException, Log.WriterFailedException
data
- Data to append to the log.timeout
- Max number of time units to wait before a
TimeoutException
.unit
- Type of time units used for the timeout, e.g. seconds,
minutes, etc.java.util.concurrent.TimeoutException
- If the append doesn't happen before the
timeout.Log.WriterFailedException
- If the append fails due that the writer
no longer has the ability to perform its
operations (e.g., because it was
superseded by another writer).TimeUnit
,
Log.WriterFailedException
public Log.Position truncate(Log.Position to, long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.TimeoutException, Log.WriterFailedException
Log.WriterFailedException
will get thrown. Unfortunately, this will
also get thrown in other circumstances (e.g., disk failure) and
therefore it is currently impossible to tell these two cases
apart.to
- The log will be truncated up to this point.timeout
- Max number of time units to wait before a
TimeoutException
.unit
- Type of time units used for the timeout, e.g. seconds,
minutes, etc.java.util.concurrent.TimeoutException
- If the truncation doesn't happen before
the timeout.Log.WriterFailedException
- If the truncation fails due an invalid
position or if the writer no longer has
the ability to perform its operations
(e.g., because it was superseded by
another writer).protected void initialize(Log log, long timeout, java.util.concurrent.TimeUnit unit, int retries)
protected void finalize()
finalize
in class java.lang.Object