public class AccessSafely extends Object
afterCompleting() is used to determine how many times the
writeUsing() behavior is employed before the readUsing() can complete.| Modifier and Type | Method and Description |
|---|---|
static AccessSafely |
afterCompleting(int happenings)
Answer a new
AccessSafely with a completion count of happenings. |
static AccessSafely |
immediately()
Answer a new
AccessSafely with immediate readFrom() results. |
<T> T |
readFrom(String name)
Answer the value associated with
name. |
<T,R> R |
readFrom(String name,
T parameter)
Answer the value associated with
name. |
<T> T |
readFromExpecting(String name,
T expected)
Answer the value associated with
name but not until
it reaches the expected value. |
<T> T |
readFromExpecting(String name,
T expected,
long retries)
Answer the value associated with
name but not until
it reaches the expected value or the total number
of retries is reached. |
<T> T |
readFromNow(String name)
Answer the value associated with
name immediately. |
<T,R> R |
readFromNow(String name,
T parameter)
Answer the value associated with
name immediately. |
<T,R> AccessSafely |
readingWith(String name,
Function<T,R> function)
Answer me with
function registered for reading. |
<T> AccessSafely |
readingWith(String name,
Supplier<T> supplier)
Answer me with
supplier registered for reading. |
AccessSafely |
resetAfterCompletingTo(int happenings)
Answer a new AccessSafely with my existing reads and writes functionality.
|
int |
totalWrites()
Answer the total of writes completed.
|
int |
totalWritesGreaterThan(int lesser,
long retries)
Answer the total of writes completed after ensuring that it surpasses
lesser,
or if retries is reached first throw IllegalStateException. |
<T> void |
writeUsing(String name,
T value)
Set the value associated with
name to the parameter value. |
<T1,T2> void |
writeUsing(String name,
T1 value1,
T2 value2)
Set the values associated with
name using the parameters value1 and value2. |
<T1,T2> AccessSafely |
writingWith(String name,
BiConsumer<T1,T2> consumer)
Answer me with
consumer registered for writing. |
<T> AccessSafely |
writingWith(String name,
Consumer<T> consumer)
Answer me with
consumer registered for writing. |
public static AccessSafely afterCompleting(int happenings)
AccessSafely with a completion count of happenings. This construct
provides a reliable barrier/fence around data access between two or more threads, given that the
number of happenings is accurately predicted.happenings - the int number of times that writeUsing() is employed prior to readFrom() answeringpublic static AccessSafely immediately()
AccessSafely with immediate readFrom() results. Note
that this is not recommended due to highly probably inconsistencies in the data
seen by the reader as opposed to that written by the writer. See the Java memory
model literature for details.public AccessSafely resetAfterCompletingTo(int happenings)
happenings - the int number of times that writeUsing() is employed prior to readFrom() answeringpublic <T,R> AccessSafely readingWith(String name, Function<T,R> function)
function registered for reading.T - the type of the Function parameterR - the type of the Function return valuename - the String name of the Function<T,R> to registerfunction - the Function<T,R> to registerpublic <T> AccessSafely readingWith(String name, Supplier<T> supplier)
supplier registered for reading.T - the type of the Supplier to registername - the String name of the Supplier<T> to registersupplier - the Supplier<T> to registerpublic <T> AccessSafely writingWith(String name, Consumer<T> consumer)
consumer registered for writing.T - the type of the Consumer to registername - the String name of the Consumer<T> to registerconsumer - the Consumer<T> to registerpublic <T1,T2> AccessSafely writingWith(String name, BiConsumer<T1,T2> consumer)
consumer registered for writing.T1 - the type of the first BiConsumer parameter to registerT2 - the type of the second BiConsumer parameter to registername - the String name of the Consumer<T> to registerconsumer - the Consumer<T> to registerpublic <T> T readFrom(String name)
name.T - the type of the value associated with namename - the String name of the value to answerpublic <T,R> R readFrom(String name, T parameter)
name.T - the type of the parameter to the Function<T,R>R - the type of the return value associated with namename - the String name of the value to answerparameter - the T typed function parameterpublic <T> T readFromExpecting(String name, T expected)
name but not until
it reaches the expected value.T - the type of the value associated with namename - the String name of the value to answerexpected - the T typed expected valuepublic <T> T readFromExpecting(String name, T expected, long retries)
name but not until
it reaches the expected value or the total number
of retries is reached.T - the type of the value associated with namename - the String name of the value to answerexpected - the T typed expected valueretries - the long number of retriespublic <T> T readFromNow(String name)
name immediately.T - the type of the value associated with namename - the String name of the value to answerpublic <T,R> R readFromNow(String name, T parameter)
name immediately.T - the type of the parameter to the Function<T,R>R - the type of the return value associated with namename - the String name of the value to answerparameter - the T typed function parameterpublic <T> void writeUsing(String name, T value)
name to the parameter value.T - the type of the value associated with name that is to be writtenname - the String name of the value to answervalue - the T typed value to writepublic <T1,T2> void writeUsing(String name, T1 value1, T2 value2)
name using the parameters value1 and value2.T1 - the type of the first value associated with name that is to be writtenT2 - the type of the second value associated with name that is to be writtenname - the String name of the value to answervalue1 - the T1 typed value to writevalue2 - the T2 typed value to writepublic int totalWrites()
public int totalWritesGreaterThan(int lesser,
long retries)
lesser,
or if retries is reached first throw IllegalStateException.lesser - the int value that must be surpassedretries - the int number of retries before failingIllegalStateException - when the total is not surpassed before the maximum retriesCopyright © 2021. All rights reserved.