public class MarkFile extends Object implements AutoCloseable
MarkFile
is used to mark the presence of a running component and to track liveness.
The assumptions are: (1) the version field is an int in size, (2) the timestamp field is a long in size,
and (3) the version field comes before the timestamp field.Constructor and Description |
---|
MarkFile(File markFile,
boolean shouldPreExist,
int versionFieldOffset,
int timestampFieldOffset,
int totalFileLength,
long timeoutMs,
EpochClock epochClock,
IntConsumer versionCheck,
Consumer<String> logger)
Create a
MarkFile if none present. |
MarkFile(File directory,
String filename,
boolean warnIfDirectoryExists,
boolean dirDeleteOnStart,
int versionFieldOffset,
int timestampFieldOffset,
int totalFileLength,
long timeoutMs,
EpochClock epochClock,
IntConsumer versionCheck,
Consumer<String> logger)
Create a directory and mark file if none present.
|
MarkFile(File directory,
String filename,
int versionFieldOffset,
int timestampFieldOffset,
long timeoutMs,
EpochClock epochClock,
IntConsumer versionCheck,
Consumer<String> logger)
Map a pre-existing
MarkFile if one present and is active. |
MarkFile(MappedByteBuffer mappedBuffer,
int versionFieldOffset,
int timestampFieldOffset)
Manage a
MarkFile given a mapped file and offsets of version and timestamp. |
MarkFile(UnsafeBuffer buffer,
int versionFieldOffset,
int timestampFieldOffset)
Manage a
MarkFile given a buffer and offsets of version and timestamp. |
Modifier and Type | Method and Description |
---|---|
UnsafeBuffer |
buffer() |
void |
close() |
void |
deleteDirectory(boolean ignoreFailures) |
static void |
ensureDirectoryExists(File directory,
String filename,
boolean warnIfDirectoryExists,
boolean dirDeleteOnStart,
int versionFieldOffset,
int timestampFieldOffset,
long timeoutMs,
EpochClock epochClock,
IntConsumer versionCheck,
Consumer<String> logger) |
static boolean |
isActive(MappedByteBuffer byteBuffer,
EpochClock epochClock,
long timeoutMs,
int versionFieldOffset,
int timestampFieldOffset,
IntConsumer versionCheck,
Consumer<String> logger) |
boolean |
isClosed() |
static MappedByteBuffer |
mapExistingFile(File markFile,
Consumer<String> logger,
long offset,
long length) |
static MappedByteBuffer |
mapExistingMarkFile(File markFile,
int versionFieldOffset,
int timestampFieldOffset,
long timeoutMs,
EpochClock epochClock,
IntConsumer versionCheck,
Consumer<String> logger) |
static MappedByteBuffer |
mapNewOrExistingMarkFile(File markFile,
boolean shouldPreExist,
int versionFieldOffset,
int timestampFieldOffset,
long totalFileLength,
long timeoutMs,
EpochClock epochClock,
IntConsumer versionCheck,
Consumer<String> logger) |
MappedByteBuffer |
mappedByteBuffer() |
File |
markFile() |
File |
parentDirectory() |
void |
signalReady(int version) |
protected static void |
sleep(long durationMs) |
void |
timestampOrdered(long timestamp) |
long |
timestampVolatile() |
long |
timestampWeak() |
int |
versionVolatile() |
int |
versionWeak() |
static MappedByteBuffer |
waitForFileMapping(Consumer<String> logger,
File markFile,
long deadlineMs,
EpochClock epochClock) |
public MarkFile(File directory, String filename, boolean warnIfDirectoryExists, boolean dirDeleteOnStart, int versionFieldOffset, int timestampFieldOffset, int totalFileLength, long timeoutMs, EpochClock epochClock, IntConsumer versionCheck, Consumer<String> logger)
close()
is called.directory
- for the Mark file.filename
- of the Mark file.warnIfDirectoryExists
- for logging purposes.dirDeleteOnStart
- if desired.versionFieldOffset
- to use for version field access.timestampFieldOffset
- to use for timestamp field access.totalFileLength
- to allocate when creating new Mark file.timeoutMs
- for the activity check (in milliseconds).epochClock
- to use for time checks.versionCheck
- to use for existing Mark file and version field.logger
- to use to signal progress or null.public MarkFile(File markFile, boolean shouldPreExist, int versionFieldOffset, int timestampFieldOffset, int totalFileLength, long timeoutMs, EpochClock epochClock, IntConsumer versionCheck, Consumer<String> logger)
MarkFile
if none present. Checking if an active MarkFile
exists and is active.
Existing MarkFile
is used if not active.
Total length of Mark file will be mapped until close()
is called.markFile
- to use.shouldPreExist
- or not.versionFieldOffset
- to use for version field access.timestampFieldOffset
- to use for timestamp field access.totalFileLength
- to allocate when creating new MarkFile
.timeoutMs
- for the activity check (in milliseconds).epochClock
- to use for time checks.versionCheck
- to use for existing MarkFile
and version field.logger
- to use to signal progress or null.public MarkFile(File directory, String filename, int versionFieldOffset, int timestampFieldOffset, long timeoutMs, EpochClock epochClock, IntConsumer versionCheck, Consumer<String> logger)
MarkFile
if one present and is active.
Total length of MarkFile
will be mapped until close()
is called.directory
- for the MarkFile
file.filename
- of the MarkFile
file.versionFieldOffset
- to use for version field access.timestampFieldOffset
- to use for timestamp field access.timeoutMs
- for the activity check (in milliseconds) and for how long to wait for file to exist.epochClock
- to use for time checks.versionCheck
- to use for existing MarkFile
file and version field.logger
- to use to signal progress or null.public MarkFile(MappedByteBuffer mappedBuffer, int versionFieldOffset, int timestampFieldOffset)
MarkFile
given a mapped file and offsets of version and timestamp.
If mappedBuffer is not null, then it will be unmapped upon close()
.mappedBuffer
- for the MarkFile
fields.versionFieldOffset
- for the version field.timestampFieldOffset
- for the timestamp field.public MarkFile(UnsafeBuffer buffer, int versionFieldOffset, int timestampFieldOffset)
MarkFile
given a buffer and offsets of version and timestamp.buffer
- for the MarkFile
fieldsversionFieldOffset
- for the version fieldtimestampFieldOffset
- for the timestamp fieldpublic boolean isClosed()
public void close()
close
in interface AutoCloseable
public void signalReady(int version)
public int versionVolatile()
public int versionWeak()
public void timestampOrdered(long timestamp)
public long timestampVolatile()
public long timestampWeak()
public void deleteDirectory(boolean ignoreFailures)
public File parentDirectory()
public File markFile()
public MappedByteBuffer mappedByteBuffer()
public UnsafeBuffer buffer()
public static void ensureDirectoryExists(File directory, String filename, boolean warnIfDirectoryExists, boolean dirDeleteOnStart, int versionFieldOffset, int timestampFieldOffset, long timeoutMs, EpochClock epochClock, IntConsumer versionCheck, Consumer<String> logger)
public static MappedByteBuffer waitForFileMapping(Consumer<String> logger, File markFile, long deadlineMs, EpochClock epochClock)
public static MappedByteBuffer mapExistingMarkFile(File markFile, int versionFieldOffset, int timestampFieldOffset, long timeoutMs, EpochClock epochClock, IntConsumer versionCheck, Consumer<String> logger)
public static MappedByteBuffer mapNewOrExistingMarkFile(File markFile, boolean shouldPreExist, int versionFieldOffset, int timestampFieldOffset, long totalFileLength, long timeoutMs, EpochClock epochClock, IntConsumer versionCheck, Consumer<String> logger)
public static MappedByteBuffer mapExistingFile(File markFile, Consumer<String> logger, long offset, long length)
public static boolean isActive(MappedByteBuffer byteBuffer, EpochClock epochClock, long timeoutMs, int versionFieldOffset, int timestampFieldOffset, IntConsumer versionCheck, Consumer<String> logger)
protected static void sleep(long durationMs)
Copyright © 2014-2019 Real Logic Ltd. All Rights Reserved.