Git Product home page Git Product logo

stateful-relay's Introduction

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

stateful-relay's People

Contributors

damian-burke avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.