public class MarkFile
extends java.lang.Object
implements java.lang.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(java.io.File markFile,
boolean shouldPreExist,
int versionFieldOffset,
int timestampFieldOffset,
int totalFileLength,
long timeoutMs,
EpochClock epochClock,
java.util.function.IntConsumer versionCheck,
java.util.function.Consumer<java.lang.String> logger)
Create a
MarkFile if none present. |
MarkFile(java.io.File directory,
java.lang.String filename,
boolean warnIfDirectoryExists,
boolean dirDeleteOnStart,
int versionFieldOffset,
int timestampFieldOffset,
int totalFileLength,
long timeoutMs,
EpochClock epochClock,
java.util.function.IntConsumer versionCheck,
java.util.function.Consumer<java.lang.String> logger)
Create a directory and mark file if none present.
|
MarkFile(java.io.File directory,
java.lang.String filename,
int versionFieldOffset,
int timestampFieldOffset,
long timeoutMs,
EpochClock epochClock,
java.util.function.IntConsumer versionCheck,
java.util.function.Consumer<java.lang.String> logger)
Map a pre-existing
MarkFile if one present and is active. |
MarkFile(java.nio.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(java.io.File directory,
java.lang.String filename,
boolean warnIfDirectoryExists,
boolean dirDeleteOnStart,
int versionFieldOffset,
int timestampFieldOffset,
long timeoutMs,
EpochClock epochClock,
java.util.function.IntConsumer versionCheck,
java.util.function.Consumer<java.lang.String> logger) |
static boolean |
isActive(java.nio.MappedByteBuffer byteBuffer,
EpochClock epochClock,
long timeoutMs,
int versionFieldOffset,
int timestampFieldOffset,
java.util.function.IntConsumer versionCheck,
java.util.function.Consumer<java.lang.String> logger) |
boolean |
isClosed() |
static java.nio.MappedByteBuffer |
mapExistingFile(java.io.File markFile,
java.util.function.Consumer<java.lang.String> logger,
long offset,
long length) |
static java.nio.MappedByteBuffer |
mapExistingMarkFile(java.io.File markFile,
int versionFieldOffset,
int timestampFieldOffset,
long timeoutMs,
EpochClock epochClock,
java.util.function.IntConsumer versionCheck,
java.util.function.Consumer<java.lang.String> logger) |
static java.nio.MappedByteBuffer |
mapNewOrExistingMarkFile(java.io.File markFile,
boolean shouldPreExist,
int versionFieldOffset,
int timestampFieldOffset,
long totalFileLength,
long timeoutMs,
EpochClock epochClock,
java.util.function.IntConsumer versionCheck,
java.util.function.Consumer<java.lang.String> logger) |
java.nio.MappedByteBuffer |
mappedByteBuffer() |
java.io.File |
markFile() |
java.io.File |
parentDirectory() |
void |
signalReady(int version) |
void |
timestampOrdered(long timestamp) |
long |
timestampVolatile() |
long |
timestampWeak() |
int |
versionVolatile() |
int |
versionWeak() |
static java.nio.MappedByteBuffer |
waitForFileMapping(java.util.function.Consumer<java.lang.String> logger,
java.io.File markFile,
long deadlineMs,
EpochClock epochClock) |
public MarkFile(java.io.File directory, java.lang.String filename, boolean warnIfDirectoryExists, boolean dirDeleteOnStart, int versionFieldOffset, int timestampFieldOffset, int totalFileLength, long timeoutMs, EpochClock epochClock, java.util.function.IntConsumer versionCheck, java.util.function.Consumer<java.lang.String> logger)
close()
is called.directory
- for the Mark filefilename
- of the Mark filewarnIfDirectoryExists
- for logging purposesdirDeleteOnStart
- if desiredversionFieldOffset
- to use for version field accesstimestampFieldOffset
- to use for timestamp field accesstotalFileLength
- to allocate when creating new Mark filetimeoutMs
- for the activity check (in milliseconds)epochClock
- to use for time checksversionCheck
- to use for existing Mark file and version fieldlogger
- to use to signal progress or nullpublic MarkFile(java.io.File markFile, boolean shouldPreExist, int versionFieldOffset, int timestampFieldOffset, int totalFileLength, long timeoutMs, EpochClock epochClock, java.util.function.IntConsumer versionCheck, java.util.function.Consumer<java.lang.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 useshouldPreExist
- or notversionFieldOffset
- to use for version field accesstimestampFieldOffset
- to use for timestamp field accesstotalFileLength
- to allocate when creating new MarkFile
timeoutMs
- for the activity check (in milliseconds)epochClock
- to use for time checksversionCheck
- to use for existing MarkFile
and version fieldlogger
- to use to signal progress or nullpublic MarkFile(java.io.File directory, java.lang.String filename, int versionFieldOffset, int timestampFieldOffset, long timeoutMs, EpochClock epochClock, java.util.function.IntConsumer versionCheck, java.util.function.Consumer<java.lang.String> logger)
MarkFile
if one present and is active.
Total length of MarkFile
will be mapped until close()
is called.directory
- for the MarkFile
filefilename
- of the MarkFile
fileversionFieldOffset
- to use for version field accesstimestampFieldOffset
- to use for timestamp field accesstimeoutMs
- for the activity check (in milliseconds) and for how long to wait for file to existepochClock
- to use for time checksversionCheck
- to use for existing MarkFile
file and version fieldlogger
- to use to signal progress or nullpublic MarkFile(java.nio.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
fieldsversionFieldOffset
- for the version fieldtimestampFieldOffset
- for the timestamp fieldpublic 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 java.lang.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 java.io.File parentDirectory()
public java.io.File markFile()
public java.nio.MappedByteBuffer mappedByteBuffer()
public UnsafeBuffer buffer()
public static void ensureDirectoryExists(java.io.File directory, java.lang.String filename, boolean warnIfDirectoryExists, boolean dirDeleteOnStart, int versionFieldOffset, int timestampFieldOffset, long timeoutMs, EpochClock epochClock, java.util.function.IntConsumer versionCheck, java.util.function.Consumer<java.lang.String> logger)
public static java.nio.MappedByteBuffer waitForFileMapping(java.util.function.Consumer<java.lang.String> logger, java.io.File markFile, long deadlineMs, EpochClock epochClock)
public static java.nio.MappedByteBuffer mapExistingMarkFile(java.io.File markFile, int versionFieldOffset, int timestampFieldOffset, long timeoutMs, EpochClock epochClock, java.util.function.IntConsumer versionCheck, java.util.function.Consumer<java.lang.String> logger)
public static java.nio.MappedByteBuffer mapNewOrExistingMarkFile(java.io.File markFile, boolean shouldPreExist, int versionFieldOffset, int timestampFieldOffset, long totalFileLength, long timeoutMs, EpochClock epochClock, java.util.function.IntConsumer versionCheck, java.util.function.Consumer<java.lang.String> logger)
public static java.nio.MappedByteBuffer mapExistingFile(java.io.File markFile, java.util.function.Consumer<java.lang.String> logger, long offset, long length)
public static boolean isActive(java.nio.MappedByteBuffer byteBuffer, EpochClock epochClock, long timeoutMs, int versionFieldOffset, int timestampFieldOffset, java.util.function.IntConsumer versionCheck, java.util.function.Consumer<java.lang.String> logger)
Copyright © 2014-2019 Real Logic Ltd. All Rights Reserved.