From f40b72ecffb23365819afe2cc1b21d2f8c2b926d Mon Sep 17 00:00:00 2001 From: Denis Lepekhin Date: Mon, 13 Nov 2017 21:25:46 +0300 Subject: [PATCH] + state machine (gen_fsm) impl, multiple doc fix. --- README.md | 10 + docs/allclasses-frame.html | 11 +- docs/allclasses-noframe.html | 11 +- docs/github/jcext/Enqueuer.Conf.html | 21 +- docs/github/jcext/Enqueuer.html | 66 +-- docs/github/jcext/Poller.html | 4 +- docs/github/jcext/StateMachine.Conf.html | 304 ++++++++++ ...ceive.html => StateMachine.NextState.html} | 105 ++-- ...rFunc.html => StateMachine.StateFunc.html} | 84 ++- docs/github/jcext/StateMachine.html | 540 ++++++++++++++++++ docs/github/jcext/TaskEnqueuer.Conf.html | 4 +- .../jcext/TaskEnqueuer.RejectsListener.html | 4 +- docs/github/jcext/TaskEnqueuer.html | 25 +- docs/github/jcext/Timer.DefaultImpl.html | 5 +- docs/github/jcext/Timer.html | 48 +- .../applications/ErlangActor.SpecialMsg.html | 330 ----------- .../jcext/applications/ErlangActor.html | 325 ----------- .../applications/ExactDateScheduler.Conf.html | 6 +- .../applications/ExactDateScheduler.html | 4 +- .../NettyChannelWritesEnqueuer.Conf.html | 4 +- .../NettyChannelWritesEnqueuer.html | 21 +- .../jcext/applications/Timer.DefaultImpl.html | 2 +- .../jcext/applications/package-frame.html | 8 - .../jcext/applications/package-summary.html | 35 +- .../jcext/applications/package-tree.html | 17 - docs/github/jcext/package-frame.html | 6 + docs/github/jcext/package-summary.html | 32 +- docs/github/jcext/package-tree.html | 6 + docs/index-all.html | 121 ++-- docs/index.html | 11 +- docs/overview-tree.html | 23 +- src/main/java/github/jcext/Enqueuer.java | 27 +- .../github/jcext/EnqueuerBasedEntity.java | 2 + src/main/java/github/jcext/StateMachine.java | 191 +++++++ src/main/java/github/jcext/Timer.java | 34 ++ .../jcext/applications/ErlangActor.java | 133 ----- .../applications/ExactDateScheduler.java | 3 +- .../java/github/jcext/applications/Timer.java | 26 - .../github/jcext/ExactDateSchedulerTest.java | 1 - .../java/github/jcext/StateMachineTest.java | 175 ++++++ 40 files changed, 1570 insertions(+), 1215 deletions(-) create mode 100644 docs/github/jcext/StateMachine.Conf.html rename docs/github/jcext/{applications/ErlangActor.Receive.html => StateMachine.NextState.html} (50%) rename docs/github/jcext/{applications/ErlangActor.ReceiverFunc.html => StateMachine.StateFunc.html} (54%) create mode 100644 docs/github/jcext/StateMachine.html delete mode 100644 docs/github/jcext/applications/ErlangActor.SpecialMsg.html delete mode 100644 docs/github/jcext/applications/ErlangActor.html create mode 100644 src/main/java/github/jcext/StateMachine.java create mode 100644 src/main/java/github/jcext/Timer.java delete mode 100644 src/main/java/github/jcext/applications/ErlangActor.java delete mode 100644 src/main/java/github/jcext/applications/Timer.java create mode 100644 src/test/java/github/jcext/StateMachineTest.java diff --git a/README.md b/README.md index 12f5fab..43e3bbc 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,16 @@ 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 +#### github.jcext.StateMachine<E> + +https://dlepex.github.io/jcext/github/jcext/StateMachine.html + +Experimental implementation of Erlang gen_statem (gen_fsm) behaviour in a "state functions mode". In this mode +each state has a corresponding function (StateFunc) that handles events in that state. + +This test contains two example of state machines: +https://github.com/dlepex/jcext/blob/master/src/main/java/github/jcext/StateMachineTest.java + #### Javadoc diff --git a/docs/allclasses-frame.html b/docs/allclasses-frame.html index 3a4c9c3..8e7fd45 100644 --- a/docs/allclasses-frame.html +++ b/docs/allclasses-frame.html @@ -18,9 +18,6 @@

All Classes

  • Enqueuer
  • Enqueuer.Conf
  • Enqueuer.QueueFactory
  • -
  • ErlangActor
  • -
  • ErlangActor.ReceiverFunc
  • -
  • ErlangActor.SpecialMsg
  • ExactDateScheduler
  • ExactDateScheduler.Conf
  • ExactDateScheduler.Task
  • @@ -31,11 +28,15 @@

    All Classes

  • NettyChannelWritesEnqueuer
  • NettyChannelWritesEnqueuer.Conf
  • Poller
  • +
  • StateMachine
  • +
  • StateMachine.Conf
  • +
  • StateMachine.NextState
  • +
  • StateMachine.StateFunc
  • TaskEnqueuer
  • TaskEnqueuer.Conf
  • TaskEnqueuer.RejectsListener
  • -
  • Timer
  • -
  • Timer.DefaultImpl
  • +
  • Timer
  • +
  • Timer.DefaultImpl
  • diff --git a/docs/allclasses-noframe.html b/docs/allclasses-noframe.html index fd4c698..e0ef747 100644 --- a/docs/allclasses-noframe.html +++ b/docs/allclasses-noframe.html @@ -18,9 +18,6 @@

    All Classes

  • Enqueuer
  • Enqueuer.Conf
  • Enqueuer.QueueFactory
  • -
  • ErlangActor
  • -
  • ErlangActor.ReceiverFunc
  • -
  • ErlangActor.SpecialMsg
  • ExactDateScheduler
  • ExactDateScheduler.Conf
  • ExactDateScheduler.Task
  • @@ -31,11 +28,15 @@

    All Classes

  • NettyChannelWritesEnqueuer
  • NettyChannelWritesEnqueuer.Conf
  • Poller
  • +
  • StateMachine
  • +
  • StateMachine.Conf
  • +
  • StateMachine.NextState
  • +
  • StateMachine.StateFunc
  • TaskEnqueuer
  • TaskEnqueuer.Conf
  • TaskEnqueuer.RejectsListener
  • -
  • Timer
  • -
  • Timer.DefaultImpl
  • +
  • Timer
  • +
  • Timer.DefaultImpl
  • diff --git a/docs/github/jcext/Enqueuer.Conf.html b/docs/github/jcext/Enqueuer.Conf.html index c3b1562..275e1d8 100644 --- a/docs/github/jcext/Enqueuer.Conf.html +++ b/docs/github/jcext/Enqueuer.Conf.html @@ -107,7 +107,7 @@

    Class Enqueuer.Conf

  • Direct Known Subclasses:
    -
    ExactDateScheduler.Conf, NettyChannelWritesEnqueuer.Conf, TaskEnqueuer.Conf
    +
    ExactDateScheduler.Conf, NettyChannelWritesEnqueuer.Conf, StateMachine.Conf, TaskEnqueuer.Conf
    Enclosing class:
    @@ -117,7 +117,13 @@

    Class Enqueuer.Conf


    public static class Enqueuer.Conf
     extends java.lang.Object
    -
    Configuration object.
    +
    Configuration object. + Most users will use either setBoundedQueue(int) or setUnboundedQueue() method

    + By default the queue is unbounded

    +
    +
    See Also:
    +
    setUnboundedQueue()
    +
  • @@ -167,9 +173,7 @@

    Method Summary

    void -setBoundedQueue(int capacity) -
    By default the queue is bounded and its max size equal to Enqueuer.defaultCapacity
    - +setBoundedQueue(int capacity)  <T> void @@ -196,7 +200,7 @@

    Method Summary

    void setUnboundedQueue() -
    This option is discouraged, most users should use bounded queues.
    +
    Be careful and prefer bounded queues for the cases where you deal with external untrusted user input (heap overflow exploit).
    @@ -257,7 +261,6 @@

    Method Detail

  • setBoundedQueue

    public void setBoundedQueue(int capacity)
    -
    By default the queue is bounded and its max size equal to Enqueuer.defaultCapacity
    Parameters:
    capacity - max queue size.
    @@ -271,7 +274,9 @@

    setBoundedQueue

  • setUnboundedQueue

    public void setUnboundedQueue()
    -
    This option is discouraged, most users should use bounded queues.
    +
    Be careful and prefer bounded queues for the cases where you deal with external untrusted user input (heap overflow exploit).

    + Unbounded queues are the right choice when you can't afford item (or event) loss because it will lead to the state corruption + of your actor-like entity. However such entities should not be directly available to the untrusted party.

  • diff --git a/docs/github/jcext/Enqueuer.html b/docs/github/jcext/Enqueuer.html index a0c420d..96dbede 100644 --- a/docs/github/jcext/Enqueuer.html +++ b/docs/github/jcext/Enqueuer.html @@ -17,7 +17,7 @@ catch(err) { } //--> -var methods = {"i0":10,"i1":10,"i2":6,"i3":10,"i4":10}; +var methods = {"i0":10,"i1":10,"i2":6,"i3":10,"i4":10,"i5":10}; var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],4:["t3","Abstract Methods"],8:["t4","Concrete Methods"]}; var altColor = "altColor"; var rowColor = "rowColor"; @@ -73,13 +73,13 @@ @@ -162,27 +162,6 @@

    Nested Class Summary

  • - -

    Interface Hierarchy

    -

    Enum Hierarchy

    - diff --git a/docs/github/jcext/package-frame.html b/docs/github/jcext/package-frame.html index 583cad9..15fafc6 100644 --- a/docs/github/jcext/package-frame.html +++ b/docs/github/jcext/package-frame.html @@ -16,7 +16,9 @@

    Interfaces

  • AsyncRunnable
  • Enqueuer.QueueFactory
  • Poller
  • +
  • StateMachine.StateFunc
  • TaskEnqueuer.RejectsListener
  • +
  • Timer
  • Classes

    diff --git a/docs/github/jcext/package-summary.html b/docs/github/jcext/package-summary.html index 0a95dc7..6cca57a 100644 --- a/docs/github/jcext/package-summary.html +++ b/docs/github/jcext/package-summary.html @@ -101,12 +101,22 @@

    Package github.jcext

    +StateMachine.StateFunc<E> +  + + TaskEnqueuer.RejectsListener
    This hook may be helpful if you need to count how many times RejectedExecutionException was thrown in mustOffer-methods of TaskEnqueuer.
    + +Timer + +
    Experimental API, cancellation may be added in the future.
    + + @@ -146,17 +156,37 @@

    Package github.jcext

      +StateMachine<E> + +
    Experimental implementation of Erlang gen_statem (gen_fsm) in a "state functions mode".
    + + + +StateMachine.Conf +  + + +StateMachine.NextState + +
    This class exists to enforce the rule that the last statement in StateFunc must be goTo(...)
    + + + TaskEnqueuer
    TaskEnqueuer is the Enqueuer that polls and executes async tasks AsyncRunnable one by one
    - + TaskEnqueuer.Conf
    Configuration object.
    + +Timer.DefaultImpl +  + diff --git a/docs/github/jcext/package-tree.html b/docs/github/jcext/package-tree.html index f74e824..4ac69d8 100644 --- a/docs/github/jcext/package-tree.html +++ b/docs/github/jcext/package-tree.html @@ -88,10 +88,14 @@

    Class Hierarchy

  • github.jcext.Enqueuer.Conf
  • github.jcext.JcExt
  • +
  • github.jcext.StateMachine<E>
  • +
  • github.jcext.StateMachine.NextState
  • +
  • github.jcext.Timer.DefaultImpl
  • @@ -101,7 +105,9 @@

    Interface Hierarchy

  • github.jcext.AsyncRunnable
  • github.jcext.Enqueuer.QueueFactory<T>
  • github.jcext.Poller<T>
  • +
  • github.jcext.StateMachine.StateFunc<E>
  • github.jcext.TaskEnqueuer.RejectsListener
  • +
  • github.jcext.Timer
  • diff --git a/docs/index-all.html b/docs/index-all.html index 408f8e4..7d465a0 100644 --- a/docs/index-all.html +++ b/docs/index-all.html @@ -67,15 +67,11 @@ -
    A B C D E F G J M N O P R S T U V W  +
    A B C D E F G I J M N O P R S T U V W 

    A

    -
    after() - Method in interface github.jcext.applications.ErlangActor.ReceiverFunc
    -
    -
    Erlang receive after-clause.
    -
    Agent<S> - Class in github.jcext
    Agents provide access to shared state in async fashion.
    @@ -88,6 +84,8 @@

    A

     
    Agent.StateValuePair<S,V> - Class in github.jcext
     
    +
    apply(E) - Method in interface github.jcext.StateMachine.StateFunc
    +
     
    associatedId() - Method in class github.jcext.Enqueuer
    User associated id, can be anything having good toString() method.
    @@ -122,6 +120,8 @@

    C

     
    Conf() - Constructor for class github.jcext.Enqueuer.Conf
     
    +
    Conf() - Constructor for class github.jcext.StateMachine.Conf
    +
     
    Conf() - Constructor for class github.jcext.TaskEnqueuer.Conf
     
    create(int) - Method in interface github.jcext.Enqueuer.QueueFactory
    @@ -132,15 +132,17 @@

    C

    D

    -
    defaultCapacity - Static variable in class github.jcext.Enqueuer
    +
    DefaultImpl() - Constructor for class github.jcext.Timer.DefaultImpl
    +
     
    +
    defaultInstance() - Static method in interface github.jcext.Timer
    -
    Default bounded queue capacity.
    +
    If you use Netty, it's good idea to implement Timer interface on top of HashWheelTimer, so avoid defaultInstance() in that case.
    -
    DefaultImpl() - Constructor for class github.jcext.applications.Timer.DefaultImpl
    +
    delay() - Method in interface github.jcext.applications.ExactDateScheduler.Task.Info
     
    -
    defaultInstance() - Static method in interface github.jcext.applications.Timer
    +
    delay(Runnable, long, TimeUnit) - Method in interface github.jcext.Timer
     
    -
    delay() - Method in interface github.jcext.applications.ExactDateScheduler.Task.Info
    +
    delayValue(T, long, TimeUnit) - Method in interface github.jcext.Timer
     
    disableSameThreadOptimization() - Method in class github.jcext.Enqueuer.Conf
    @@ -165,16 +167,6 @@

    E

    Enqueuer.QueueFactory<T> - Interface in github.jcext
     
    -
    ErlangActor - Class in github.jcext.applications
    -
     
    -
    ErlangActor(Timer) - Constructor for class github.jcext.applications.ErlangActor
    -
     
    -
    ErlangActor.Receive - Class in github.jcext.applications
    -
     
    -
    ErlangActor.ReceiverFunc - Interface in github.jcext.applications
    -
     
    -
    ErlangActor.SpecialMsg - Enum in github.jcext.applications
    -
     
    ExactDateScheduler - Class in github.jcext.applications
    Experimental, Enqueuer application to exact-date scheduling.
    @@ -197,6 +189,10 @@

    E

    F

    +
    finalState() - Method in class github.jcext.StateMachine
    +
     
    +
    finalStateReached() - Method in class github.jcext.StateMachine
    +
     
    fromRunnable(Runnable) - Static method in interface github.jcext.applications.ExactDateScheduler.Task
     
    @@ -221,6 +217,24 @@

    G

     
    github.jcext.internal - package github.jcext.internal
     
    +
    goTo(CompletionStage<StateMachine.StateFunc<E>>) - Method in class github.jcext.StateMachine
    +
     
    +
    goTo(CompletionStage<StateMachine.StateFunc<E>>, long, TimeUnit) - Method in class github.jcext.StateMachine
    +
     
    +
    goTo(StateMachine.StateFunc<E>, long, TimeUnit) - Method in class github.jcext.StateMachine
    +
     
    +
    goTo(StateMachine.StateFunc<E>, int) - Method in class github.jcext.StateMachine
    +
     
    +
    goTo(StateMachine.StateFunc<E>) - Method in class github.jcext.StateMachine
    +
     
    +
    + + + +

    I

    +
    +
    initialState() - Method in class github.jcext.StateMachine
    +
     
    @@ -335,14 +349,6 @@

    R

    realBegin() - Method in interface github.jcext.applications.ExactDateScheduler.Task.Info
     
    -
    receive(ErlangActor.ReceiverFunc) - Method in class github.jcext.applications.ErlangActor
    -
     
    -
    receive(ErlangActor.ReceiverFunc, int) - Method in class github.jcext.applications.ErlangActor
    -
     
    -
    Receive() - Constructor for class github.jcext.applications.ErlangActor.Receive
    -
     
    -
    receive(Object) - Method in interface github.jcext.applications.ErlangActor.ReceiverFunc
    -
     
    run(ExactDateScheduler.Task.Info) - Method in interface github.jcext.applications.ExactDateScheduler.Task
     
    runAsync() - Method in interface github.jcext.AsyncRunnable
    @@ -355,26 +361,34 @@

    R

    S

    +
    sameState() - Method in class github.jcext.StateMachine
    +
     
    schedule(LocalDateTime, ExactDateScheduler.Task) - Method in class github.jcext.applications.ExactDateScheduler
     
    schedule(LocalDateTime, Runnable) - Method in class github.jcext.applications.ExactDateScheduler
     
    schedule(LocalDateTime, Callable<T>) - Method in class github.jcext.applications.ExactDateScheduler
     
    +
    send(E) - Method in class github.jcext.StateMachine
    +
    +
    Descendant classes may override this method to be public, or define their own business specific methods which call send().
    +
    setAssociatedId(Object) - Method in class github.jcext.Enqueuer.Conf
    Optional user associated id, it is used for exception logging, and in toString()
    setBoundedQueue(int) - Method in class github.jcext.Enqueuer.Conf
    -
    -
    By default the queue is bounded and its max size equal to Enqueuer.defaultCapacity
    -
    +
     
    setCustomQueue(Enqueuer.QueueFactory<T>) - Method in class github.jcext.Enqueuer.Conf
    Most users should be happy with default queues, but if you need something very special...
    setCustomQueue(Supplier<Queue<?>>) - Method in class github.jcext.Enqueuer.Conf
     
    +
    setFinalStateEventHandler(Consumer<Object>) - Method in class github.jcext.StateMachine.Conf
    +
    +
    Use it only for logging or monitoring, if you're not happy with default behaviour.
    +
    setPlannedTasksLimit(int) - Method in class github.jcext.applications.ExactDateScheduler.Conf
     
    setQueueWrapper(UnaryOperator<Queue<T>>) - Method in class github.jcext.Enqueuer.Conf
    @@ -389,16 +403,30 @@

    S

    Default pool is FJP.
    -
    setTimer(Timer) - Method in class github.jcext.applications.ExactDateScheduler.Conf
    +
    setTimer(Timer) - Method in class github.jcext.applications.ExactDateScheduler.Conf
    +
     
    +
    setTimer(Timer) - Method in class github.jcext.StateMachine.Conf
     
    setUnboundedQueue() - Method in class github.jcext.Enqueuer.Conf
    -
    This option is discouraged, most users should use bounded queues.
    +
    Be careful and prefer bounded queues for the cases where you deal with external untrusted user input (heap overflow exploit).
    -
    start() - Method in class github.jcext.applications.ErlangActor
    -
     
    state - Variable in class github.jcext.Agent.StateValuePair
     
    +
    StateMachine<E> - Class in github.jcext
    +
    +
    Experimental implementation of Erlang gen_statem (gen_fsm) in a "state functions mode".
    +
    +
    StateMachine(StateMachine.Conf) - Constructor for class github.jcext.StateMachine
    +
     
    +
    StateMachine.Conf - Class in github.jcext
    +
     
    +
    StateMachine.NextState - Class in github.jcext
    +
    +
    This class exists to enforce the rule that the last statement in StateFunc must be goTo(...)
    +
    +
    StateMachine.StateFunc<E> - Interface in github.jcext
    +
     
    StateValuePair(S, V) - Constructor for class github.jcext.Agent.StateValuePair
     
    @@ -428,13 +456,15 @@

    T

    This hook may be helpful if you need to count how many times RejectedExecutionException was thrown in mustOffer-methods of TaskEnqueuer.
    -
    timeout(Runnable, long, TimeUnit) - Method in interface github.jcext.applications.Timer
    +
    threadPool() - Method in class github.jcext.Enqueuer
     
    -
    Timer - Interface in github.jcext.applications
    +
    timer - Variable in class github.jcext.StateMachine
    +
     
    +
    Timer - Interface in github.jcext
    -
    Unstable API.
    +
    Experimental API, cancellation may be added in the future.
    -
    Timer.DefaultImpl - Class in github.jcext.applications
    +
    Timer.DefaultImpl - Class in github.jcext
     
    @@ -446,6 +476,8 @@

    U

     
    underlyingEnq() - Method in class github.jcext.Enqueuer
     
    +
    underlyingEnq() - Method in class github.jcext.StateMachine
    +
     
    update(Function<? super S, ? extends S>) - Method in class github.jcext.Agent
     
    updateAsync(Function<? super S, ? extends CompletionStage<? extends S>>) - Method in class github.jcext.Agent
    @@ -466,15 +498,6 @@

    V

    value - Variable in class github.jcext.Agent.StateValuePair
     
    -
    valueOf(String) - Static method in enum github.jcext.applications.ErlangActor.SpecialMsg
    -
    -
    Returns the enum constant of this type with the specified name.
    -
    -
    values() - Static method in enum github.jcext.applications.ErlangActor.SpecialMsg
    -
    -
    Returns an array containing the constants of this enum type, in -the order they are declared.
    -
    @@ -484,7 +507,7 @@

    W

    with(T, Consumer<? super T>) - Static method in class github.jcext.JcExt
     
    -A B C D E F G J M N O P R S T U V W 
    +A B C D E F G I J M N O P R S T U V W 
    diff --git a/docs/index.html b/docs/index.html index 6b218a0..45d3ed3 100644 --- a/docs/index.html +++ b/docs/index.html @@ -5,11 +5,12 @@ jcext API