Examples of UntypedStateMachine


Examples of org.squirrelframework.foundation.fsm.UntypedStateMachine

        UntypedStateMachineBuilder builder = StateMachineBuilderFactory.create(StateMachineSample.class);
        builder.externalTransition().from("A").to("B").on(FSMEvent.ToB).callMethod("fromAToB");
        builder.onEntry("B").callMethod("ontoB");
       
        // 4. Use State Machine
        UntypedStateMachine fsm = builder.newStateMachine("A");
        fsm.fire(FSMEvent.ToB, 10);
       
        System.out.println("Current state is "+fsm.getCurrentState());
    }
View Full Code Here

Examples of org.squirrelframework.foundation.fsm.UntypedStateMachine

                }
                logger.append("AToBOnFIRST");
            }
        });
        builder.transition().from("A").to("B").on("SECOND");
        final UntypedStateMachine fsm = builder.newStateMachine("A");
        fsm.addDeclarativeListener(new Object() {
            @OnTransitionDecline
            public void onTransitionDeclined() {
                fail();
            }
        });
        fsm.start();
        try {
            TimeUnit.MILLISECONDS.sleep(500);
        } catch (InterruptedException e) {
        }
        fsm.fire("SECOND");
        fsm.terminate();
        assertEquals("AToBOnFIRST.AToBOnFIRST.AToBOnFIRST.AToBOnFIRST.AToBOnFIRST", logger.toString());
    }
View Full Code Here

Examples of org.squirrelframework.foundation.fsm.UntypedStateMachine

                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                UntypedStateMachine fsm2 = (UntypedStateMachine)context;
                System.out.println("fsm2 current state: "+fsm2.getCurrentState());
            }
        });
       
        UntypedStateMachineBuilder builder2 = StateMachineBuilderFactory.create(ConcurrentSimpleStateMachine.class);
        builder2.transition().from("C").to("D").on("SECOND").perform(
                new AnonymousAction<UntypedStateMachine, Object, Object, Object>() {
            @Override
            public void execute(Object from, Object to, Object event,
                    Object context, UntypedStateMachine stateMachine) {
                UntypedStateMachine fsm1 = (UntypedStateMachine)context;
                System.out.println("fsm1 current state: "+fsm1.getCurrentState());
            }
        });
       
        final UntypedStateMachine fsm1 = builder1.newStateMachine("A");
        fsm1.start();
        final UntypedStateMachine fsm2 = builder2.newStateMachine("C");
        fsm2.start();
       
        return new UntypedStateMachine[]{fsm1, fsm2};
    }
View Full Code Here

Examples of org.squirrelframework.foundation.fsm.UntypedStateMachine

        builder.transition().from("B").to("C").on("SECOND");
       
        builder.transition().from("A").to("D").on("SECOND");
        builder.transition().from("C").to("E").on("SECOND");
       
        final UntypedStateMachine fsm = builder.newStateMachine("A");
       
        // thread 1 start process event "FIRST"
        new Thread(new Runnable() {
            @Override
            public void run() {
                fsm.fire("FIRST");
                eventCondition.countDown();
            }
        }, "Test-Thread-1").start();
       
        // thread 2 read fsm state while processing event "FIRST"
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    actionCondition.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                readStateRef.set(fsm.getCurrentState());
                eventCondition.countDown();
            }
        }, "Test-Thread-2").start();
       
        // thread 3 test event "SECOND" while processing event "FIRST"
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    actionCondition.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                testStateRef.set(fsm.test("SECOND"));
                eventCondition.countDown();
            }
        }, "Test-Thread-3").start();
       
        // thread 4 dump data while processing event "FIRST"
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    actionCondition.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                dumpDataRef.set(fsm.dumpSavedData());
                eventCondition.countDown();
            }
        }, "Test-Thread-4").start();
       
        // thread 5 process event "SECOND" while processing event "FIRST"
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    actionCondition.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                fsm.fire("SECOND");
                eventCondition.countDown();
            }
        }, "Test-Thread-5").start();
       
        // wait for all threads finish processing events then check result
        try {
            eventCondition.await(1000, TimeUnit.MILLISECONDS);
            TimeUnit.MILLISECONDS.sleep(TIME_INTERVAL);
        } catch (InterruptedException e) {
            fail();
        }
       
        assertEquals(fsm.getCurrentState(), "C");
        assertEquals(readStateRef.get(), "C");
        assertEquals(testStateRef.get(), "E");
        assertNotNull(dumpDataRef.get());
        assertEquals(((StateMachineData.Reader)dumpDataRef.get()).currentState(), "C");
       
        Object testAgain = fsm.test("SECOND");
        assertEquals(testAgain, "E");
    }
View Full Code Here

Examples of org.squirrelframework.foundation.fsm.UntypedStateMachine

        l3.callSequence = callSequence;
        MockitoAnnotations.initMocks(callSequence);
       
        builder.transition().from("A").to("B").on("FIRST");
        builder.transition().from("B").to("C").on("SECOND");
        final UntypedStateMachine fsm = builder.newStateMachine("A");
        fsm.addDeclarativeListener(l1);
        fsm.addDeclarativeListener(l2);
       
        InOrder inOrder = Mockito.inOrder(callSequence.mock);
        // thread 1 fire event "FIRST"
        new Thread(new Runnable() {
            @Override
            public void run() {
                fsm.fire("FIRST");
                eventCondition.countDown();
            }
        }, "Test-Thread-1").start();
       
        // thread 2 add listener and fire event "SECOND" during thread 1 processing event "FIRST"
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    l3Condition.await();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                fsm.addDeclarativeListener(l3);
                l1Condition.countDown();
                fsm.fire("SECOND");
                eventCondition.countDown();
            }
        }, "Test-Thread-2").start();
       
        // wait for all threads finish processing events then check result
View Full Code Here

Examples of org.squirrelframework.foundation.fsm.UntypedStateMachine

        final Listener3 l3 = new Listener3();
        l3.callSequence = callSequence;
        MockitoAnnotations.initMocks(callSequence);
       
        builder.transition().from("A").to("B").on("FIRST");
        final UntypedStateMachine fsm = builder.newStateMachine("A");
        fsm.addDeclarativeListener(l1);
        fsm.addDeclarativeListener(l2);
        fsm.addDeclarativeListener(l3);
       
        InOrder inOrder = Mockito.inOrder(callSequence.mock);
        fsm.fire("FIRST");
        try {
            lCondition.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.