private void MakeTransition(State <TState, TData> nextState) { if (!_stateFunctions.ContainsKey(nextState.StateName)) { Terminate(Stay().WithStopReason(new Failure($"Next state {nextState.StateName} does not exist"))); } else { for (int i = nextState.Replies.Count - 1; i >= 0; i--) { Sender.Tell(nextState.Replies[i]); } if (!_currentState.StateName.Equals(nextState.StateName) || nextState.Notifies) { _nextState = nextState; HandleTransition(_currentState.StateName, nextState.StateName); Listeners.Gossip(new Transition <TState>(Self, _currentState.StateName, nextState.StateName)); _nextState = null; } _currentState = nextState; var timeout = _currentState.Timeout ?? _stateTimeouts[_currentState.StateName]; if (timeout.HasValue) { var t = timeout.Value; if (t < TimeSpan.MaxValue) { _timeoutFuture = Context.System.Scheduler.ScheduleTellOnceCancelable(t, Context.Self, new TimeoutMarker(_generation), Context.Self); } } } }
protected override void OnReceive(object message) { PatternMatch.Match(message) .With <ListenerMessage>(l => Listeners.ListenerReceive(l)) .With <string>(s => { if (s.Equals("foo")) { Listeners.Gossip("bar"); } }); }
private void MakeTransition(State <TS, TD> upcomingState) { if (!stateFunctions.ContainsKey(upcomingState.StateName)) { Terminate( Stay() .WithStopReason( new Failure(String.Format((string)"Next state {0} does not exist", (object)upcomingState.StateName)))); } else { var replies = upcomingState.Replies; replies.Reverse(); foreach (var r in replies) { Sender.Tell(r); } if (!currentState.StateName.Equals(upcomingState.StateName)) { nextState = upcomingState; HandleTransition(currentState.StateName, nextState.StateName); Listeners.Gossip(new Transition <TS>(Self, currentState.StateName, nextState.StateName)); nextState = null; } currentState = upcomingState; var timeout = currentState.Timeout ?? stateTimeouts[currentState.StateName]; if (timeout.HasValue) { var t = timeout.Value; if (t < TimeSpan.MaxValue) { timeoutFuture = new CancellationTokenSource(); Context.System.Scheduler.ScheduleOnce(t, Self, new TimeoutMarker(generation), timeoutFuture.Token); } } } }
private void MakeTransition(State <TState, TData> upcomingState) { if (!_stateFunctions.ContainsKey(upcomingState.StateName)) { Terminate( Stay() .WithStopReason( new Failure(String.Format("Next state {0} does not exist", upcomingState.StateName)))); } else { var replies = upcomingState.Replies; replies.Reverse(); foreach (var r in replies) { Sender.Tell(r); } if (!_currentState.StateName.Equals(upcomingState.StateName)) { _nextState = upcomingState; HandleTransition(_currentState.StateName, _nextState.StateName); Listeners.Gossip(new Transition <TState>(Self, _currentState.StateName, _nextState.StateName)); _nextState = null; } _currentState = upcomingState; var timeout = _currentState.Timeout ?? _stateTimeouts[_currentState.StateName]; if (timeout.HasValue) { var t = timeout.Value; if (t < TimeSpan.MaxValue) { _timeoutFuture = Context.System.Scheduler.ScheduleTellOnceCancelable(t, Context.Self, new TimeoutMarker(_generation), Context.Self); } } } }