GithubHelp home page GithubHelp logo

dlepex / actorish4j Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 432 KB

Asynchronous actorlike entities: Agent, State Machine and more

License: Apache License 2.0

Java 100.00%
java asynchronous concurrency actor-model nonblocking elixir agent akka scheduling erlang

actorish4j's Introduction

Purpose

Actorish4j is a minimalistic library that provides asynchronous (non-blocking), actorlike entities and tries to implement these entities in the most Java-friendly way.

Due to its simplicity and tight integration with Java 8 CompletableFuture/CompletionStage and Queue API, Actorish4j may be the better choice than some bloated Actor frameworks. If you are not interested in supervision hierarchies, actor-based network communication and only need the concurrency part then this library may be the tool for you.

Use JitPack to add dependency in your project:

    // gradle build sample
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
    dependencies {
        compile 'com.github.dlepex:actorish4j:v0.7.4'
    
        // compile 'org.jctools:jctools-core:2.1.1' // optional dependency, 
        // Actorish4j may use JCTools MpmcArrayQueue, if it detects its presence
    }

Overview

Enqueuer<T>

https://dlepex.github.io/actorish4j/io/github/actorish4j/Enqueuer.html

Enqueuer is the most basic and the most useful "actor-like" entity.

Enqueuer implements the multiple-producer single-consumer idiom: anyone can send (offer) a message to the Enqueuer, but only the single consumer can read (poll) the queue. The polling is done asynchronously.

All other actor-like entities in this library are implemented on top of the Enqueuer.

TaskEnqueuer

https://dlepex.github.io/actorish4j/io/github/actorish4j/TaskEnqueuer.html

TaskEnqueuer is the Enqueuer which polls and executes async tasks one by one.

TaskEnqueuer can be used as the direct replacement for the single-threaded ExecutorService, in case your tasks are asynchronous computations. Note that this class doesn't follow ExecutorService API deliberately because it can be misused for blocking tasks.

TaskEnqueuer guarantees that:

  • Async tasks will be executed in the order of their arrival
  • Async tasks will NEVER run concurrently i.e. next AsyncRunnable will wait for the completion of the CompletionStage of the previous AsyncRunnable

Agent<S>

https://dlepex.github.io/actorish4j/io/github/actorish4j/Agent.html

Agent implements the specific form of "state sharing pattern" tailored to asynchronous computations (Basically this library itself only useful for non-blocking code)

Agent is a very simple (thin) wrapper around the TaskEnqueuer class.

Agent interface (method naming) is inspired by Elixir Agent module. See https://hexdocs.pm/elixir/Agent.html

StateMachine<E>

https://dlepex.github.io/actorish4j/io/github/actorish4j/StateMachine.html

Event-Driven State Machine implementation inspired by Erlang gen_statem (gen_fsm) behaviour in a "state functions mode". In this mode each state has (or better say "is") a corresponding function (StateFunc) that handles events in that state.

This test contains two example of state machines: https://github.com/dlepex/actorish4j/blob/master/src/test/java/io/github/actorish4j/StateMachineTest.java

Javadoc

https://dlepex.github.io/actorish4j/overview-summary.html

Showcases

The classes below are the examples of applying Actorish4j to the "real world problems".

NettyChannelWritesEnqueuer

https://github.com/dlepex/actorish4j/blob/master/src/main/java/io/github/actorish4j/applications/NettyChannelWritesEnqueuer.java

NettyChannelWritesEnqueuer orders writes to Netty channel and flushes them when it's appropriate to do so.

ExactDateScheduler

https://github.com/dlepex/actorish4j/blob/master/src/main/java/io/github/actorish4j/applications/ExactDateScheduler.java

ExactDateScheduler schedules task execution at specified LocalDateTime. Tasks are executed sequentially one after another, their order is preserved in case of equal begin dates

actorish4j's People

Contributors

dlepex avatar

Stargazers

 avatar  avatar  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.