Exemplo n.º 1
0
 public override void Send(object message, ActorRef sender)
 {
     if (sender is LocalActorRef)
     {
         sender.AsInstanceOf<LocalActorRef>().Provider.DeadLetters.Tell(message);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        ///     Processes the failure.
        /// </summary>
        /// <param name="actorCell">The actor cell.</param>
        /// <param name="restart">if set to <c>true</c> [restart].</param>
        /// <param name="child">The child.</param>
        /// <param name="cause">The cause.</param>
        private void ProcessFailure(ActorCell actorCell, bool restart, ActorRef child, Exception cause)
        {
            if (restart)
            {
                RestartChild(child, cause, false);
            }
            else
            {
                child.AsInstanceOf <InternalActorRef>().Stop();
            }

            /*
             * if (children.nonEmpty) {
             * if (restart && children.forall(_.requestRestartPermission(retriesWindow)))
             * children foreach (crs ⇒ restartChild(crs.child, cause, suspendFirst = (crs.child != child)))
             * else
             * for (c ← children) context.stop(c.child)
             * }
             */

            //if (children.Any())
            //{
            //    if (restart)
            //    {

            //    }
            //    else
            //    {
            //        foreach (var child in children)
            //        {
            //            child.Stop();
            //        }
            //    }
            //}
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Restarts the child.
        /// </summary>
        /// <param name="child">The child.</param>
        /// <param name="cause">The cause.</param>
        /// <param name="suspendFirst">if set to <c>true</c> [suspend first].</param>
        protected void RestartChild(ActorRef child, Exception cause, bool suspendFirst)
        {
            var c = child.AsInstanceOf <InternalActorRef>();

            if (suspendFirst)
            {
                c.Suspend();
            }
            c.AsInstanceOf <InternalActorRef>().Restart(cause);
        }
Exemplo n.º 4
0
 protected override void ProcessFailure(ActorCell actorCell, bool restart, ActorRef child, Exception cause)
 {
     if (restart)
     {
         RestartChild(child, cause, false);
     }
     else
     {
         child.AsInstanceOf <InternalActorRef>().Stop();
     }
 }
Exemplo n.º 5
0
 protected override void ProcessFailure(ActorCell actorCell, bool restart, ActorRef child, Exception cause)
 {
     if (restart)
     {
         foreach (var c in actorCell.GetChildren().ToArray())
         {
             RestartChild(child, cause, false);
         }
     }
     else
     {
         foreach (var c in actorCell.GetChildren().ToArray())
         {
             child.AsInstanceOf <InternalActorRef>().Stop();
         }
     }
 }
Exemplo n.º 6
0
        public static Task <bool> GracefulStop(this ActorRef target, TimeSpan timeout, object stopMessage)
        {
            var internalTarget = target.AsInstanceOf <InternalActorRef>();

            if (internalTarget.IsTerminated)
            {
                return(Task.Run(() => true));
            }

            var provider = Futures.ResolveProvider(target);
            var promise  = new TaskCompletionSource <object>();

            //set up the timeout
            var cancellationSource = new CancellationTokenSource();

            cancellationSource.Token.Register(() => promise.TrySetCanceled());
            cancellationSource.CancelAfter(timeout);

            //create a new tempcontainer path
            var path = provider.TempPath();
            //callback to unregister from tempcontainer
            Action unregister = () => provider.UnregisterTempActor(path);

            var fref = new FutureActorRef(promise, ActorRef.NoSender, unregister, path);

            internalTarget.Tell(new Watch(internalTarget, fref));
            target.Tell(stopMessage, ActorRef.NoSender);
            return(promise.Task.ContinueWith(t =>
            {
                var returnResult = false;
                PatternMatch.Match(t.Result)
                .With <Terminated>(terminated =>
                {
                    returnResult = (terminated.ActorRef.Path.Equals(target.Path));
                })
                .Default(m =>
                {
                    returnResult = false;
                });

                internalTarget.Tell(new Unwatch(target, fref));
                return returnResult;
            }, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.AttachedToParent));
        }
Exemplo n.º 7
0
        public static string SerializedActorPath(ActorRef @ref)
        {
            /*
val path = actorRef.path
    val originalSystem: ExtendedActorSystem = actorRef match {
      case a: ActorRefWithCell ⇒ a.underlying.system.asInstanceOf[ExtendedActorSystem]
      case _                   ⇒ null
    }
    Serialization.currentTransportInformation.value match {
      case null ⇒ originalSystem match {
        case null ⇒ path.toSerializationFormat
        case system ⇒
          try path.toSerializationFormatWithAddress(system.provider.getDefaultAddress)
          catch { case NonFatal(_) ⇒ path.toSerializationFormat }
      }
      case Information(address, system) ⇒
        if (originalSystem == null || originalSystem == system)
          path.toSerializationFormatWithAddress(address)
        else {
          val provider = originalSystem.provider
          path.toSerializationFormatWithAddress(provider.getExternalAddressFor(address).getOrElse(provider.getDefaultAddress))
        }
    }*/
            ActorSystem originalSystem = null;
            if (@ref is ActorRefWithCell)
            {
                originalSystem = @ref.AsInstanceOf<ActorRefWithCell>().Underlying.System;
                if (CurrentTransportInformation == null)
                {
                    return @ref.Path.ToSerializationFormat();
                }
                return @ref.Path.ToStringWithAddress(CurrentTransportInformation.Address);
            }
            return @ref.Path.ToSerializationFormat();
        }
Exemplo n.º 8
0
 /// <summary>
 ///     Restarts the child.
 /// </summary>
 /// <param name="child">The child.</param>
 /// <param name="cause">The cause.</param>
 /// <param name="suspendFirst">if set to <c>true</c> [suspend first].</param>
 private void RestartChild(ActorRef child, Exception cause, bool suspendFirst)
 {
     var c = child.AsInstanceOf<InternalActorRef>();
     if (suspendFirst)
         c.Suspend();
     c.AsInstanceOf<InternalActorRef>().Restart(cause);
 }
Exemplo n.º 9
0
 /// <summary>
 ///     Resumes the child.
 /// </summary>
 /// <param name="child">The child.</param>
 /// <param name="exception">The exception.</param>
 private void ResumeChild(ActorRef child, Exception exception)
 {
     child.AsInstanceOf<InternalActorRef>().Resume(exception);
 }
Exemplo n.º 10
0
        /// <summary>
        ///     Processes the failure.
        /// </summary>
        /// <param name="actorCell">The actor cell.</param>
        /// <param name="restart">if set to <c>true</c> [restart].</param>
        /// <param name="child">The child.</param>
        /// <param name="cause">The cause.</param>
        private void ProcessFailure(ActorCell actorCell, bool restart, ActorRef child, Exception cause)
        {
            if (restart)
            {
                RestartChild(child, cause, false);
            }
            else
            {
                child.AsInstanceOf<InternalActorRef>().Stop();
            }
            /*
    if (children.nonEmpty) {
      if (restart && children.forall(_.requestRestartPermission(retriesWindow)))
        children foreach (crs ⇒ restartChild(crs.child, cause, suspendFirst = (crs.child != child)))
      else
        for (c ← children) context.stop(c.child)
    }
             */

            //if (children.Any())
            //{
            //    if (restart)
            //    {

            //    }
            //    else
            //    {
            //        foreach (var child in children)
            //        {
            //            child.Stop();
            //        }
            //    }
            //}
        }
Exemplo n.º 11
0
 /// <summary>
 ///  Resume the previously failed child: <b>do never apply this to a child which
 ///  is not the currently failing child</b>. Suspend/resume needs to be done in
 ///  matching pairs, otherwise actors will wake up too soon or never at all.
 /// </summary>
 /// <param name="child">The child.</param>
 /// <param name="exception">The exception.</param>
 protected void ResumeChild(ActorRef child, Exception exception)
 {
     child.AsInstanceOf <InternalActorRef>().Resume(exception);
 }
Exemplo n.º 12
0
 protected override void ProcessFailure(ActorCell actorCell, bool restart, ActorRef child, Exception cause)
 {
     if (restart)
     {
         foreach (var c in actorCell.GetChildren().ToArray())
         {
             RestartChild(child, cause, false);
         }
     }
     else
     {
         foreach (var c in actorCell.GetChildren().ToArray())
         {
             child.AsInstanceOf<InternalActorRef>().Stop();
         }
     }
 }
Exemplo n.º 13
0
 protected override void ProcessFailure(ActorCell actorCell, bool restart, ActorRef child, Exception cause) 
 {
     if (restart)
     {
         RestartChild(child, cause, false);
     }
     else
     {
         child.AsInstanceOf<InternalActorRef>().Stop();
     }
 }