Ejemplo n.º 1
0
        public Consumer() : base()
        {
            var bhv = new FsmBehaviors <string, Work <T> >();

            bhv
            .AddRule("SleepState", null, (Work <T> t) => t.SendMessage(this), "BusyState")
            .AddRule("BusyState", null, (Work <T> t) => Buffer.SendMessage(this), "SleepState")
            .AddBehavior(new Behavior <Work <T> >(
                             (Work <T> t) =>
            {
                (this).SendMessage(GetCurrentState().Result(), t);
            }));

            Become(bhv);
        }
Ejemplo n.º 2
0
        public Buffer(IEnumerable <Consumer <T> > someConsumers) : base()
        {
            CheckArg.IEnumerable(someConsumers);
            foreach (Consumer <T> item in someConsumers)
            {
                _consList.Enqueue(item);
                item.Buffer = this;
            }

            FsmBehaviors <string, Work <T> > bhv = new FsmBehaviors <string, Work <T> >();

            bhv
            .AddRule("BufferEmpty", null,
                     t =>
            {
                if (_consList.Count != 0)
                {
                    Consumer <T> cons = _consList.Dequeue();
                    cons.SendMessage(t);
                }
                else
                {
                    _workList.Enqueue(t);
                }
            }, "BufferNotEmpty")
            .AddRule("BufferNotEmpty", _ => _workList.Count != 0,
                     t =>
            {
                if (_consList.Count != 0)
                {
                    Consumer <T> cons = _consList.Dequeue();
                    cons.SendMessage(t);
                }
                else
                {
                    _workList.Enqueue(t);
                }
            },
                     "BufferNotEmpty");
        }
Ejemplo n.º 3
0
 public FsmActor(FsmBehaviors <TState, TEvent> someBehaviors) : base()
 {
     Become(someBehaviors);
 }