The stateful relay is based on RxJava and RxRelay.
The Stateful Relay is a test to simplify the creation of managed objects with a reactive lifecycle. Objects wrapped within may have
the following attributes:
Objects can be created with an initial state. Initial state can be one of the following.
T- Object reference.Maybe<T>- Maybe provides an initial state.Callable<T>- Provide an initial state through a custom callable.
Objects can be invalidated. Invalidation can be triggered in different ways.
TTL- A time to live can be assigned to the object to force a refresh after a certain time. (TTL is only checked indoOnSubscribe, i.e. when accessing the object. TTL is not checked via background timer.)Invalidator<T>- Custom invalidator to check for properties of the object (for exampledirtyflag)..invalidate()- Invoking theinvalidate()method on the relay, which either marks the object as invalidated or invokes the object'sinvalidatemethod if it implements theInvalidatableinterface.
Objects can be update-able. The process may be defined through one of the following.
Maybe<T>Callable<T>
StatefulRelay<String> relay = new StatefulRelay.Builder<String>()
.withInitialization("Initial Value")
.withTTL(5, TimeUnit.SECONDS)
.withUpdater(new Callable<String>() {
@Override
public String call() throws Exception {
return "Updated at " + new Date().toGMTString();
}
})
.withInvalidator(new Invalidator<String>() {
@Override
public boolean isInvalidated(String s) {
return s != null && s.contains("invalid");
}
})
.build();
Invalidation can be triggered by calling
relay.invalidate();
This software is released under the Apache License v2.
RxJava and RxRelay are also licensed under Apache License v2.
Copyright 2017 Damian Burke