Skip to content

damian-burke/stateful-relay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Stateful Relay

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:

Initialization

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.

Invalidation

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 in doOnSubscribe, 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 example dirty flag).
  • .invalidate() - Invoking the invalidate() method on the relay, which either marks the object as invalidated or invokes the object's invalidate method if it implements the Invalidatable interface.

Updating

Objects can be update-able. The process may be defined through one of the following.

  • Maybe<T>
  • Callable<T>

Example

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();

License

This software is released under the Apache License v2.

RxJava and RxRelay are also licensed under Apache License v2.

Copyright

Copyright 2017 Damian Burke

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages