nu.jibe:jibe-tools-fsm

Annotation-driven FSM

Лицензия

Лицензия

Группа

Группа

nu.jibe
Идентификатор

Идентификатор

jibe-tools-fsm
Последняя версия

Последняя версия

0.9.11
Дата

Дата

Тип

Тип

jar
Описание

Описание

nu.jibe:jibe-tools-fsm
Annotation-driven FSM
Ссылка на сайт

Ссылка на сайт

https://github.com/joachimbjorklund/jibe-tools-fsm
Система контроля версий

Система контроля версий

https://github.com/joachimbjorklund/jibe-tools-fsm.git

Скачать jibe-tools-fsm

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/nu.jibe/jibe-tools-fsm/ -->
<dependency>
    <groupId>nu.jibe</groupId>
    <artifactId>jibe-tools-fsm</artifactId>
    <version>0.9.11</version>
</dependency>
// https://jarcasting.com/artifacts/nu.jibe/jibe-tools-fsm/
implementation 'nu.jibe:jibe-tools-fsm:0.9.11'
// https://jarcasting.com/artifacts/nu.jibe/jibe-tools-fsm/
implementation ("nu.jibe:jibe-tools-fsm:0.9.11")
'nu.jibe:jibe-tools-fsm:jar:0.9.11'
<dependency org="nu.jibe" name="jibe-tools-fsm" rev="0.9.11">
  <artifact name="jibe-tools-fsm" type="jar" />
</dependency>
@Grapes(
@Grab(group='nu.jibe', module='jibe-tools-fsm', version='0.9.11')
)
libraryDependencies += "nu.jibe" % "jibe-tools-fsm" % "0.9.11"
[nu.jibe/jibe-tools-fsm "0.9.11"]

Зависимости

compile (5)

Идентификатор библиотеки Тип Версия
org.apache.commons : commons-lang3 jar 3.3.2
org.javassist : javassist jar 3.18.1-GA
org.reflections : reflections jar 0.9.9
joda-time : joda-time jar 2.7
org.slf4j : slf4j-api jar 1.7.10

test (4)

Идентификатор библиотеки Тип Версия
org.mockito : mockito-all jar 1.9.5
org.slf4j : slf4j-log4j12 jar 1.7.10
com.jayway.awaitility : awaitility jar 1.6.3
junit : junit jar 4.12

Модули Проекта

Данный проект не имеет модулей.

Jibe Tools Fsm

Annotation-driven StateMachine (FSM)

With annotations you define your state-machine. No interfaces to implement... Just plain Java...

###Install Add Jibe Tools Fsm to your project. for maven projects just add this dependency:

<dependency>
    <groupId>nu.jibe</groupId>
    <artifactId>jibe-tools-fsm</artifactId>
    <version>0.9.10</version>
</dependency>

Or clone with

git clone https://github.com/joachimbjorklund/jibe-tools-fsm.git

And build it your self... (much more fun)

###Usage This should get you started...:

package jibe.tools.fsm.api.test.trafficlight;

import jibe.tools.fsm.annotations.Action;
import jibe.tools.fsm.annotations.StartState;
import jibe.tools.fsm.annotations.State;
import jibe.tools.fsm.annotations.StateMachine;
import jibe.tools.fsm.annotations.Transition;
import jibe.tools.fsm.annotations.TransitionOnTimeout;
import jibe.tools.fsm.api.ActionType;
import jibe.tools.fsm.api.Engine;
import jibe.tools.fsm.core.EngineFactory;

import static java.util.concurrent.TimeUnit.SECONDS;

/**
 *
 */
@StateMachine
public class TrafficLightFSM {

    private Object currentState;

    public static void main(String[] args) throws InterruptedException {

        Engine engine = EngineFactory.newInstance().newEngine(new TrafficLightFSM());
        engine.start();

        Thread.sleep(30000);
        engine.event("error");

        Thread.sleep(10000);
        engine.event("fixed");

        Thread.sleep(30000);
        engine.stop();
    }

    @StartState
    private class RedLight {
        @Action(ActionType.OnEnter)
        public void onEnter() {
            System.out.println("RED");
            currentState = this;
        }

        @TransitionOnTimeout(period = 10, timeUnit = SECONDS)
        public RedAndYellowLight timeout() {
            return new RedAndYellowLight();
        }

        @Transition
        public BlinkingYellowLight event(String s) {
            if ("error".equals(s)) {
                return new BlinkingYellowLight();
            }
            return null;
        }
    }

    @State
    private class RedAndYellowLight {
        @Action(ActionType.OnEnter)
        public void onEnter() {
            System.out.println("RED_AND_YELLOW");
            currentState = this;
        }

        @TransitionOnTimeout(period = 2, timeUnit = SECONDS)
        public GreenLight timeout() {
            return new GreenLight();
        }

        @Transition
        public BlinkingYellowLight event(String s) {
            if ("error".equals(s)) {
                return new BlinkingYellowLight();
            }
            return null;
        }
    }

    @State
    private class YellowLight {
        @Action(ActionType.OnEnter)
        public void onEnter() {
            System.out.println("YELLOW");
            currentState = this;
        }

        @TransitionOnTimeout(period = 2, timeUnit = SECONDS)
        public RedLight timeout() {
            return new RedLight();
        }

        @Transition
        public BlinkingYellowLight event(String s) {
            if ("error".equals(s)) {
                return new BlinkingYellowLight();
            }
            return null;
        }
    }

    @State
    private class GreenLight {
        @Action(ActionType.OnEnter)
        public void onEnter() {
            System.out.println("GREEN");
            currentState = this;
        }

        @TransitionOnTimeout(period = 2, timeUnit = SECONDS)
        public YellowLight timeout() {
            return new YellowLight();
        }

        @Transition
        public BlinkingYellowLight event(String s) {
            if ("error".equals(s)) {
                return new BlinkingYellowLight();
            }
            return null;
        }
    }

    @State
    private class BlinkingYellowLight {
        @Action(ActionType.OnEnter)
        public void onEnter() {
            System.out.println("BLINKING_YELLOW");
            currentState = this;
        }

        @Transition
        public RedLight event(String s) {
            if ("fixed".equals(s)) {
                return new RedLight();
            }
            return null;
        }
    }
}

That's all folks!

Cheers

Версии библиотеки

Версия
0.9.11
0.9.10
0.9.8