public class PersistentAtomicReference<T> extends Object
AtomicReference but is backed by a file, so can be
persisted across a server restart. Assumes the underlying type can be serialized by Jackson.
Strangely, this is not actually atomic in the AtomicReference way; i.e. not
threadsafe, nor does it do CAS.
| Modifier and Type | Method and Description |
|---|---|
static <T> PersistentAtomicReference<T> |
create(Path filename,
com.fasterxml.jackson.databind.JavaType javaType,
com.google.common.base.Supplier<? extends T> initialValue) |
static <T> PersistentAtomicReference<T> |
create(Path filename,
com.fasterxml.jackson.core.type.TypeReference<T> typeReference,
com.google.common.base.Supplier<? extends T> initialValue) |
static <T> PersistentAtomicReference<T> |
create(String filename,
com.fasterxml.jackson.databind.JavaType javaType,
com.google.common.base.Supplier<? extends T> initialValue) |
static <T> PersistentAtomicReference<T> |
create(String filename,
com.fasterxml.jackson.core.type.TypeReference<T> typeReference,
com.google.common.base.Supplier<? extends T> initialValue) |
T |
get()
Returns the value stored.
|
void |
set(T newValue)
Set the reference to
newValue. |
void |
setUnchecked(T newValue)
|
String |
toString() |
public void set(T newValue) throws IOException, InterruptedException
newValue.newValue - The value to set.IOException - If an error occurs working with the file on disk.InterruptedException - If the thread is interrupted.public void setUnchecked(T newValue) throws InterruptedException
newValue - The value to set.InterruptedException - If the thread is interrupted.public T get()
public static <T> PersistentAtomicReference<T> create(Path filename, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, com.google.common.base.Supplier<? extends T> initialValue) throws IOException, InterruptedException
IOExceptionInterruptedExceptionpublic static <T> PersistentAtomicReference<T> create(String filename, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, com.google.common.base.Supplier<? extends T> initialValue) throws IOException, InterruptedException
IOExceptionInterruptedExceptionpublic static <T> PersistentAtomicReference<T> create(Path filename, com.fasterxml.jackson.databind.JavaType javaType, com.google.common.base.Supplier<? extends T> initialValue) throws IOException, InterruptedException
IOExceptionInterruptedExceptionpublic static <T> PersistentAtomicReference<T> create(String filename, com.fasterxml.jackson.databind.JavaType javaType, com.google.common.base.Supplier<? extends T> initialValue) throws IOException, InterruptedException
IOExceptionInterruptedExceptionCopyright © 2017. All rights reserved.