Пример #1
0
        /// <summary></summary>
        /// <exception cref="TaskCanceledException">
        /// This exception is thrown if the underlying task is <see cref="TaskStatus.Canceled"/>.
        /// </exception>
        public static Task<bool> GracefulStop(this IActorRef target, TimeSpan timeout, object stopMessage)
        {
            var internalTarget = target.AsInstanceOf<IInternalActorRef>();

            var promiseRef = PromiseActorRef.Apply(internalTarget.Provider, timeout, target, stopMessage.GetType().Name);
            internalTarget.SendSystemMessage(new Watch(internalTarget, promiseRef));
            target.Tell(stopMessage, ActorRefs.NoSender);
            return promiseRef.Result.ContinueWith(t =>
            {
                if (t.Status == TaskStatus.RanToCompletion)
                {
                    var returnResult = false;
                    PatternMatch.Match(t.Result)
                        .With<Terminated>(terminated =>
                        {
                            returnResult = (terminated.ActorRef.Path.Equals(target.Path));
                        })
                        .Default(m =>
                        {
                            internalTarget.SendSystemMessage(new Unwatch(internalTarget, promiseRef));
                            returnResult = false;
                        });
                    return returnResult;
                }
                else
                {
                    internalTarget.SendSystemMessage(new Unwatch(internalTarget, promiseRef));
                    if (t.Status == TaskStatus.Canceled)
                        throw new TaskCanceledException();
                    else
                        throw t.Exception;
                }
            }, TaskContinuationOptions.ExecuteSynchronously);
        }
Пример #2
0
        public static FluentConfig LogLevel(this FluentConfig self, LogLevel logLevel)
        {
            self.AsInstanceOf<FluentConfigInternals>()
                .AppendLine(string.Format("akka.loglevel = {0}", logLevel.StringFor()));

            return self;
        }
Пример #3
0
 private static FluentConfig LogSentMessages(this FluentConfig self, bool on)
 {
     if (on)
     {
         self.AsInstanceOf<FluentConfigInternals>().AppendLine("akka.remote.log-sent-messages = on");
     }
     return self;
 }
Пример #4
0
 private static FluentConfig DebugReceive(this FluentConfig self, bool on)
 {
     if (on)
     {
         self.AsInstanceOf<FluentConfigInternals>().AppendLine("akka.actor.debug.receive = on");
     }
     return self;
 }
Пример #5
0
        /*
    log-config-on-start = on
    stdout-loglevel = DEBUG
    loglevel = ERROR
    actor {
        provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""
        
        debug {  
          receive = on 
          autoreceive = on
          lifecycle = on
          event-stream = on
          unhandled = on
        }
*/
        public static FluentConfig LogConfigOnStart(this FluentConfig self, bool on)
        {
            if (on)
            {
                self.AsInstanceOf<FluentConfigInternals>().AppendLine("akka.log-config-on-start = on");
            }
            return self;
        }
Пример #6
0
        public static FluentConfig StartRemotingOn(this FluentConfig self, string hostname,int port)
        {
            string remoteConfig = @"
akka.actor.provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""
akka.remote.helios.tcp.transport-class = ""Akka.Remote.Transport.Helios.HeliosTcpTransport, Akka.Remote""
akka.remote.helios.tcp.applied-adapters = []
akka.remote.helios.tcp.transport-protocol = tcp
akka.remote.helios.tcp.port = {0}
akka.remote.helios.tcp.hostname = 0.0.0.0 #listens on ALL ips for this machine
akka.remote.helios.tcp.public-hostname = {1} #but only accepts connections on localhost (usually 127.0.0.1)
";
            self.AsInstanceOf<FluentConfigInternals>().AppendLine(string.Format(remoteConfig,port,hostname));

            return self;
        }
Пример #7
0
        public static Task<bool> GracefulStop(this IActorRef target, TimeSpan timeout, object stopMessage)
        {
            var internalTarget = target.AsInstanceOf<IInternalActorRef>();
            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, unregister, path);
            internalTarget.Tell(new Watch(internalTarget, fref));
            target.Tell(stopMessage, ActorRefs.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);
        }
Пример #8
0
        private static FluentConfig LogRemoteLifecycleEvents(this FluentConfig self, LogLevel logLevel)
        {
            self.AsInstanceOf<FluentConfigInternals>().AppendLine(string.Format("akka.remote.log-remote-lifecycle-events = {0}", logLevel.StringFor()));

            return self;
        }
Пример #9
0
 private static void ConfigureDispatcher(this FluentConfig self, string type, int throughput,
     TimeSpan? throughputDeadlineTimeout)
 {
     self.AsInstanceOf<FluentConfigInternals>()
         .AppendLine(string.Format("akka.actor.default-dispatcher.type = '{0}'", type));
     self.AsInstanceOf<FluentConfigInternals>()
         .AppendLine(string.Format("akka.actor.default-dispatcher.throughput = {0}", throughput));
     self.AsInstanceOf<FluentConfigInternals>()
         .AppendLine(string.Format("akka.actor.default-dispatcher.throughput-deadline-time = {0}ms",
             throughputDeadlineTimeout.GetValueOrDefault(TimeSpan.FromSeconds(0)).TotalMilliseconds));
 }
Пример #10
0
 public static FluentConfig DebugUnhandled(this FluentConfig self, bool on)
 {
     if (on)
     {
         self.AsInstanceOf<FluentConfigInternals>().AppendLine("akka.actor.debug.unhandled = on");
     }
     return self;
 }
Пример #11
0
 private static FluentConfig DebugEventStream(this FluentConfig self, bool on)
 {
     if (on)
     {
         self.AsInstanceOf<FluentConfigInternals>().AppendLine("akka.actor.debug.event-stream = on");
     }
     return self;
 }
Пример #12
0
        public static IStash GetStash(this IActorContext context)
        {
            var actorCell = context.AsInstanceOf<ActorCell>();
            var actor = actorCell.Actor;
            if (!(actor is IActorStash))
            {
                throw new NotSupportedException(string.Format("Cannot create stash for Actor {0} - needs to implement IActorStash interface", actor));
            }

            if (actor is WithBoundedStash)
            {
                return new BoundedStashImpl(context);
            }

            if (actor is WithUnboundedStash)
            {
                return new UnboundedStashImpl(context);
            }

            throw new ArgumentException(string.Format("Actor {0} implements unrecognized subclass of IActorStash - cannot instantiate", actor));
        }