public override void PostStop()
 {
     if (!_completionSignalled)
     {
         StageActorRef.Tell(_stage._onFailureMessage(new AbruptStageTerminationException(this)));
     }
 }
Ejemplo n.º 2
0
            private StageActorRef.Receive Connecting(Outbound outbound)
            {
                return(args =>
                {
                    var sender = args.Item1;
                    var msg = args.Item2;

                    msg.Match()
                    .With <Terminated>(() => FailStage(new StreamTcpException("The IO manager actor (TCP) has terminated. Stopping now.")))
                    .With <Tcp.CommandFailed>(failed => FailStage(new StreamTcpException($"Tcp command {failed.Cmd} failed")))
                    .With <Tcp.Connected>(c =>
                    {
                        ((Outbound)_role).LocalAddressPromise.TrySetResult(c.LocalAddress);
                        _connection = sender;
                        SetHandler(_bytesOut, _readHandler);
                        StageActorRef.Unwatch(outbound.Manager);
                        StageActorRef.Become(Connected);
                        StageActorRef.Watch(_connection);
                        _connection.Tell(new Tcp.Register(StageActorRef, keepOpenonPeerClosed: true, useResumeWriting: false), StageActorRef);

                        if (IsAvailable(_bytesOut))
                        {
                            _connection.Tell(Tcp.ResumeReading.Instance, StageActorRef);
                        }

                        Pull(_bytesIn);
                    });
                });
            }
Ejemplo n.º 3
0
            private void Receive(Tuple <IActorRef, object> args)
            {
                var sender = args.Item1;
                var msg    = args.Item2;

                msg.Match()
                .With <Tcp.Bound>(bound =>
                {
                    _listener = sender;
                    StageActorRef.Watch(_listener);

                    if (IsAvailable(_stage._out))
                    {
                        _listener.Tell(new Tcp.ResumeAccepting(1), StageActorRef);
                    }

                    var target = StageActorRef;
                    _bindingPromise.TrySetResult(new StreamTcp.ServerBinding(bound.LocalAddress, () =>
                    {
                        target.Tell(Tcp.Unbind.Instance, StageActorRef);
                        return(_unbindPromise.Task);
                    }));
                })
                .With <Tcp.CommandFailed>(() =>
                {
                    var ex = BindFailedException.Instance;
                    _bindingPromise.TrySetException(ex);
                    _unbindPromise.TrySetResult(NotUsed.Instance);
                    FailStage(ex);
                })
                .With <Tcp.Connected>(c =>
                {
                    Push(_stage._out, ConnectionFor(c, sender));
                })
                .With <Tcp.Unbind>(() =>
                {
                    if (!IsClosed(_stage._out) && _listener != null)
                    {
                        TryUnbind();
                    }
                })
                .With <Tcp.Unbound>(() =>    // If we're unbound then just shut down
                {
                    if (_stage._connectionFlowsAwaitingInitialization.Current == 0)
                    {
                        CompleteStage();
                    }
                    else
                    {
                        ScheduleOnce(BindShutdownTimer, _stage._bindShutdownTimeout);
                    }
                })
                .With <Terminated>(terminated =>
                {
                    if (Equals(terminated.ActorRef, _listener))
                    {
                        FailStage(new IllegalStateException("IO Listener actor terminated unexpectedly"));
                    }
                });
            }
Ejemplo n.º 4
0
            private void Receive(Tuple <IActorRef, object> args)
            {
                var sender = args.Item1;
                var msg    = args.Item2;

                if (msg is Tcp.Bound)
                {
                    var bound = (Tcp.Bound)msg;
                    _listener = sender;
                    StageActorRef.Watch(_listener);

                    if (IsAvailable(_stage._out))
                    {
                        _listener.Tell(new Tcp.ResumeAccepting(1), StageActorRef);
                    }

                    var thisStage = StageActorRef;
                    _bindingPromise.TrySetResult(new StreamTcp.ServerBinding(bound.LocalAddress, () =>
                    {
                        // Beware, sender must be explicit since stageActor.ref will be invalid to access after the stage stopped
                        thisStage.Tell(Tcp.Unbind.Instance, thisStage);
                        return(_unbindPromise.Task);
                    }));
                }
                else if (msg is Tcp.CommandFailed)
                {
                    var ex = BindFailedException.Instance;
                    _bindingPromise.TrySetException(ex);
                    _unbindPromise.TrySetResult(NotUsed.Instance);
                    FailStage(ex);
                }
                else if (msg is Tcp.Connected)
                {
                    var connected = (Tcp.Connected)msg;
                    Push(_stage._out, ConnectionFor(connected, sender));
                }
                else if (msg is Tcp.Unbind)
                {
                    if (!IsClosed(_stage._out) && !ReferenceEquals(_listener, null))
                    {
                        TryUnbind();
                    }
                }
                else if (msg is Tcp.Unbound)
                {
                    UnbindCompleted();
                }
                else if (msg is Terminated)
                {
                    if (_unbindStarted)
                    {
                        UnbindCompleted();
                    }
                    else
                    {
                        FailStage(new IllegalStateException("IO Listener actor terminated unexpectedly"));
                    }
                }
            }
 public override void PreStart()
 {
     SetKeepGoing(true);
     _self = GetStageActorRef(Receive);
     _self.Watch(_stage._actorRef);
     _stage._actorRef.Tell(_stage._onInitMessage, _self);
     Pull(_stage._inlet);
 }
Ejemplo n.º 6
0
            private void TryUnbind()
            {
                if (_listener == null)
                {
                    return;
                }

                StageActorRef.Unwatch(_listener);
                SetKeepGoing(true);
                _listener.Tell(Tcp.Unbind.Instance, StageActorRef);
            }
Ejemplo n.º 7
0
 private void UnbindCompleted()
 {
     StageActorRef.Unwatch(_listener);
     if (_connectionFlowsAwaitingInitialization.Current == 0)
     {
         CompleteStage();
     }
     else
     {
         ScheduleOnce(BindShutdownTimer, _stage._bindShutdownTimeout);
     }
 }
Ejemplo n.º 8
0
 public override void PreStart()
 {
     Pull(_stage._inlet);
     _self = GetStageActorRef(Behaviour);
     _stage._probe.Tell(_self);
 }