示例#1
0
 public RootGuardianSupervisor(RootActorPath root, IActorRefProvider provider, TaskCompletionSource<Status> terminationPromise, ILoggingAdapter log)
 {
     _log = log;
     _terminationPromise = terminationPromise;
     _provider = provider;
     _path = root / "_Root-guardian-supervisor";   //In akka this is root / "bubble-walker" 
 }
示例#2
0
 public VirtualPathContainer(IActorRefProvider provider, ActorPath path, IInternalActorRef parent, ILoggingAdapter log)
 {
     _parent   = parent;
     _log      = log;
     _provider = provider;
     _path     = path;
 }
示例#3
0
        private static Task <object> Ask(ICanTell self, object message, IActorRefProvider provider,
                                         TimeSpan?timeout)
        {
            var result = new TaskCompletionSource <object>();

            CancellationTokenSource timeoutCancellation = null;

            timeout = timeout ?? provider.Settings.AskTimeout;

            if (timeout != Timeout.InfiniteTimeSpan && timeout.Value > default(TimeSpan))
            {
                timeoutCancellation = new CancellationTokenSource();
                timeoutCancellation.Token.Register(() => result.TrySetCanceled());
                timeoutCancellation.CancelAfter(timeout.Value);
            }

            //create a new tempcontainer path
            ActorPath path = provider.TempPath();
            //callback to unregister from tempcontainer
            Action unregister =
                () =>
            {
                // cancelling timeout (if any) in order to prevent memory leaks
                // (a reference to 'result' variable in CancellationToken's callback)
                timeoutCancellation?.Cancel();
                provider.UnregisterTempActor(path);
            };

            var future = new FutureActorRef(result, unregister, path);

            //The future actor needs to be registered in the temp container
            provider.RegisterTempActor(future, path);
            self.Tell(message, future);
            return(result.Task);
        }
示例#4
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="root">TBD</param>
 /// <param name="provider">TBD</param>
 /// <param name="terminationPromise">TBD</param>
 /// <param name="log">TBD</param>
 public RootGuardianSupervisor(RootActorPath root, IActorRefProvider provider, TaskCompletionSource <Status> terminationPromise, ILoggingAdapter log)
 {
     _log = log;
     _terminationPromise = terminationPromise;
     _provider           = provider;
     _path = root / "_Root-guardian-supervisor";   //In akka this is root / "bubble-walker"
 }
示例#5
0
        private static Task <object> Ask(ICanTell self, object message, IActorRefProvider provider,
                                         TimeSpan?timeout)
        {
            var result = new TaskCompletionSource <object>();

            timeout = timeout ?? provider.Settings.AskTimeout;

            if (timeout != Timeout.InfiniteTimeSpan && timeout.Value > default(TimeSpan))
            {
                var cancellationSource = new CancellationTokenSource();
                cancellationSource.Token.Register(() => result.TrySetCanceled());
                cancellationSource.CancelAfter(timeout.Value);
            }

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

            //The future actor needs to be registered in the temp container
            provider.RegisterTempActor(future, path);
            self.Tell(message, future);
            return(result.Task);
        }
示例#6
0
 public FunctionRef(ActorPath path, IActorRefProvider provider, EventStream eventStream, Action <IActorRef, object> tell)
 {
     _eventStream = eventStream;
     _tell        = tell;
     Path         = path;
     Provider     = provider;
 }
示例#7
0
        public static AskRefs Create(IActorRefProvider provider, TimeSpan timeout)
        {
            var tcs = new TaskCompletionSource <object>();

            // logic copied from Ask (Akka.Actor -> Futures.cs)

            if (timeout != System.Threading.Timeout.InfiniteTimeSpan && timeout > default(TimeSpan))
            {
                var cancellationSource = new CancellationTokenSource();
                cancellationSource.Token.Register(() => tcs.TrySetCanceled());
                cancellationSource.CancelAfter(timeout);
            }

            //create a new tempcontainer path
            ActorPath path = provider.TempPath();

            //callback to unregister from tempcontainer
            Action unregister = () => provider.UnregisterTempActor(path);
            var    future     = new FutureActorRef(tcs, unregister, path);

            //The future actor needs to be registered in the temp container
            provider.RegisterTempActor(future, path);

            return(new AskRefs(future, tcs));
        }
示例#8
0
        public static PromiseActorRef Apply(IActorRefProvider provider, TimeSpan timeout, object targetName,
                                            string messageClassName, IActorRef sender = null)
        {
            sender = sender ?? ActorRefs.NoSender;
            var result    = new TaskCompletionSource <object>();
            var a         = new PromiseActorRef(provider, result, messageClassName);
            var scheduler = provider.Guardian.Underlying.System.Scheduler.Advanced;
            var c         = new Cancelable(scheduler, timeout);

            scheduler.ScheduleOnce(timeout, () => result.TrySetResult(new Status.Failure(new AskTimeoutException(
                                                                                             string.Format("Ask timed out on [{0}] after [{1} ms]. Sender[{2}] sent message of type {3}.", targetName, timeout.TotalMilliseconds, sender, messageClassName)))),
                                   c);

            result.Task.ContinueWith(r =>
            {
                try
                {
                    a.Stop();
                }
                finally
                {
                    c.Cancel(false);
                }
            }, TaskContinuationOptions.AttachedToParent & TaskContinuationOptions.ExecuteSynchronously);

            return(a);
        }
示例#9
0
        private static Task <object> Ask(ICanTell self, object message, IActorRefProvider provider,
                                         TimeSpan?timeout, CancellationToken cancellationToken)
        {
            TaskCompletionSource <object> result;

            if (isRunContinuationsAsynchronouslyAvailable)
            {
                result = new TaskCompletionSource <object>((TaskCreationOptions)RunContinuationsAsynchronously);
            }
            else
            {
                result = new TaskCompletionSource <object>();
            }

            CancellationTokenSource timeoutCancellation = null;

            timeout = timeout ?? provider.Settings.AskTimeout;
            List <CancellationTokenRegistration> ctrList = new List <CancellationTokenRegistration>(2);

            if (timeout != Timeout.InfiniteTimeSpan && timeout.Value > default(TimeSpan))
            {
                timeoutCancellation = new CancellationTokenSource();
                ctrList.Add(timeoutCancellation.Token.Register(() => result.TrySetCanceled()));
                timeoutCancellation.CancelAfter(timeout.Value);
            }

            if (cancellationToken.CanBeCanceled)
            {
                ctrList.Add(cancellationToken.Register(() => result.TrySetCanceled()));
            }

            //create a new tempcontainer path
            ActorPath path = provider.TempPath();
            //callback to unregister from tempcontainer
            Action unregister =
                () =>
            {
                // cancelling timeout (if any) in order to prevent memory leaks
                // (a reference to 'result' variable in CancellationToken's callback)
                if (timeoutCancellation != null)
                {
                    timeoutCancellation.Cancel();
                    timeoutCancellation.Dispose();
                }
                for (var i = 0; i < ctrList.Count; i++)
                {
                    ctrList[i].Dispose();
                }
                provider.UnregisterTempActor(path);
            };

            var future = new FutureActorRef(result, unregister, path, isRunContinuationsAsynchronouslyAvailable);

            //The future actor needs to be registered in the temp container
            provider.RegisterTempActor(future, path);
            self.Tell(message, future);
            return(result.Task);
        }
示例#10
0
        /// <summary>
        ///     Configures the provider.
        /// </summary>
        private void ConfigureProvider()
        {
            Type providerType = Type.GetType(_settings.ProviderClass);

            global::System.Diagnostics.Debug.Assert(providerType != null, "providerType != null");
            var provider = (IActorRefProvider)Activator.CreateInstance(providerType, _name, _settings, _eventStream);

            _provider = provider;
        }
示例#11
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <typeparam name="T">TBD</typeparam>
        /// <param name="self">TBD</param>
        /// <param name="messageFactory">Factory method that creates a message that can encapsulate the 'Sender' IActorRef</param>
        /// <param name="timeout">TBD</param>
        /// <param name="cancellationToken">TBD</param>
        /// <exception cref="ArgumentException">
        /// This exception is thrown if the system can't resolve the target provider.
        /// </exception>
        /// <returns>TBD</returns>
        public static Task <T> Ask <T>(this ICanTell self, Func <IActorRef, object> messageFactory, TimeSpan?timeout, CancellationToken cancellationToken)
        {
            IActorRefProvider provider = ResolveProvider(self);

            if (provider == null)
            {
                throw new ArgumentException("Unable to resolve the target Provider", nameof(self));
            }

            var result = TaskEx.NonBlockingTaskCompletionSource <T>();

            CancellationTokenSource timeoutCancellation = null;

            timeout = timeout ?? provider.Settings.AskTimeout;

            CancellationTokenRegistration?ctr1 = null;
            CancellationTokenRegistration?ctr2 = null;

            if (timeout != Timeout.InfiniteTimeSpan && timeout.Value > default(TimeSpan))
            {
                timeoutCancellation = new CancellationTokenSource();

                ctr1 = timeoutCancellation.Token.Register(() =>
                {
                    result.TrySetException(new AskTimeoutException($"Timeout after {timeout} seconds"));
                });

                timeoutCancellation.CancelAfter(timeout.Value);
            }

            if (cancellationToken.CanBeCanceled)
            {
                ctr2 = cancellationToken.Register(() => result.TrySetCanceled());
            }

            var future = provider.CreateFutureRef(result);
            var path   = future.Path;

            //The future actor needs to be unregistered in the temp container
            _ = result.Task.ContinueWith(t =>
            {
                provider.UnregisterTempActor(path);

                ctr1?.Dispose();
                ctr2?.Dispose();
                timeoutCancellation?.Dispose();
            }, TaskContinuationOptions.ExecuteSynchronously);

            //The future actor needs to be registered in the temp container
            provider.RegisterTempActor(future, path);
            var message = messageFactory(future);

            self.Tell(message, future);

            return(result.Task);
        }
示例#12
0
        public static async Task <T> AskEx <T>(this ICanTell self, Func <IActorRef, object> messageFactory, TimeSpan?timeout, CancellationToken cancellationToken)
        {
            IActorRefProvider provider = ResolveProvider(self);

            if (provider == null)
            {
                throw new ArgumentException("Unable to resolve the target Provider", nameof(self));
            }

            return((T) await AskEx(self, messageFactory, provider, timeout, cancellationToken));
        }
示例#13
0
文件: Futures.cs 项目: ziez/akka.net
        /// <summary>
        /// TBD
        /// </summary>
        /// <typeparam name="T">TBD</typeparam>
        /// <param name="self">TBD</param>
        /// <param name="message">TBD</param>
        /// <param name="timeout">TBD</param>
        /// <param name="cancellationToken">TBD</param>
        /// <exception cref="ArgumentException">
        /// This exception is thrown if the system can't resolve the target provider.
        /// </exception>
        /// <returns>TBD</returns>
        public static Task <T> Ask <T>(this ICanTell self, object message, TimeSpan?timeout, CancellationToken cancellationToken)
        {
            IActorRefProvider provider = ResolveProvider(self);

            if (provider == null)
            {
                throw new ArgumentException("Unable to resolve the target Provider", nameof(self));
            }

            return(Ask(self, message, provider, timeout, cancellationToken).CastTask <object, T>());
        }
示例#14
0
        public static Task <T> Ask <T>(this ICanTell self, object message, TimeSpan?timeout = null)
        {
            IActorRefProvider provider = ResolveProvider(self);

            if (provider == null)
            {
                throw new NotSupportedException("Unable to resolve the target Provider");
            }

            ResolveReplyTo();
            return(Ask(self, message, provider, timeout).CastTask <object, T>());
        }
示例#15
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <typeparam name="T">TBD</typeparam>
        /// <param name="self">TBD</param>
        /// <param name="message">TBD</param>
        /// <param name="timeout">TBD</param>
        /// <param name="cancellationToken">TBD</param>
        /// <exception cref="ArgumentException">
        /// This exception is thrown if the system can't resolve the target provider.
        /// </exception>
        /// <returns>TBD</returns>
        public static async Task <T> Ask <T>(this ICanTell self, object message, TimeSpan?timeout, CancellationToken cancellationToken)
        {
            await SynchronizationContextManager.RemoveContext;

            IActorRefProvider provider = ResolveProvider(self);

            if (provider == null)
            {
                throw new ArgumentException("Unable to resolve the target Provider", nameof(self));
            }

            return((T) await Ask(self, message, provider, timeout, cancellationToken));
        }
示例#16
0
 private void ConfigureProvider()
 {
     try
     {
         Type providerType = Type.GetType(_settings.ProviderClass);
         global::System.Diagnostics.Debug.Assert(providerType != null, "providerType != null");
         var provider =
             (IActorRefProvider)Activator.CreateInstance(providerType, _name, _settings, _eventStream);
         _provider = provider;
     }
     catch (Exception)
     {
         try { StopScheduler(); }
         catch
         {
             // ignored
         }
         throw;
     }
 }
 public RemoteDeadLetterActorRef(IActorRefProvider provider, ActorPath actorPath, EventStream eventStream)
     : base(provider, actorPath, eventStream)
 {
 }
示例#18
0
 /// <summary>
 /// INTERNAL API
 /// </summary>
 /// <param name="result">TBD</param>
 /// <param name="path">TBD</param>
 /// <param name="provider">TBD</param>
 public FutureActorRef(TaskCompletionSource <T> result, ActorPath path, IActorRefProvider provider)
 {
     _result   = result;
     _path     = path;
     _provider = provider;
 }
示例#19
0
 public DeadLetterActorRef(IActorRefProvider provider, ActorPath path, EventStream eventStream)
     : base(provider, path, eventStream)
 {
     _eventStream = eventStream;
 }
示例#20
0
        private static async Task <object> Ask(ICanTell self, Func <IActorRef, object> messageFactory, IActorRefProvider provider,
                                               TimeSpan?timeout, CancellationToken cancellationToken)
        {
            TaskCompletionSource <object> result = TaskEx.NonBlockingTaskCompletionSource <object>();

            CancellationTokenSource timeoutCancellation = null;

            timeout = timeout ?? provider.Settings.AskTimeout;
            var ctrList = new List <CancellationTokenRegistration>(2);

            if (timeout != Timeout.InfiniteTimeSpan && timeout.Value > default(TimeSpan))
            {
                timeoutCancellation = new CancellationTokenSource();

                ctrList.Add(timeoutCancellation.Token.Register(() =>
                {
                    result.TrySetException(new AskTimeoutException($"Timeout after {timeout} seconds"));
                }));

                timeoutCancellation.CancelAfter(timeout.Value);
            }

            if (cancellationToken.CanBeCanceled)
            {
                ctrList.Add(cancellationToken.Register(() => result.TrySetCanceled()));
            }

            //create a new tempcontainer path
            ActorPath path = provider.TempPath();

            var future = new FutureActorRef(result, () => { }, path, TaskEx.IsRunContinuationsAsynchronouslyAvailable);

            //The future actor needs to be registered in the temp container
            provider.RegisterTempActor(future, path);
            var message = messageFactory(future);

            self.Tell(message, future);

            try
            {
                return(await result.Task);
            }
            finally
            {
                //callback to unregister from tempcontainer

                provider.UnregisterTempActor(path);

                for (var i = 0; i < ctrList.Count; i++)
                {
                    ctrList[i].Dispose();
                }

                if (timeoutCancellation != null)
                {
                    timeoutCancellation.Dispose();
                }
            }
        }
示例#21
0
 public IgnoreActorRef(IActorRefProvider provider)
 {
     Provider = provider;
 }
示例#22
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="provider">TBD</param>
 /// <param name="path">TBD</param>
 /// <param name="eventStream">TBD</param>
 public EmptyLocalActorRef(IActorRefProvider provider, ActorPath path, EventStream eventStream)
 {
     _provider    = provider;
     _path        = path;
     _eventStream = eventStream;
 }
示例#23
0
 internal TracedActorRef(IActorRefProvider provider, IActorRef @delegate, IAkkaTracer tracer)
 {
     _provider = provider;
     _delegate = @delegate;
     _tracer   = tracer;
 }
 public EmptyLocalActorRef(IActorRefProvider provider, ActorPath path, EventStream eventStream)
 {
     _provider = provider;
     _path = path;
     _eventStream = eventStream;
 }
示例#25
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="provider">TBD</param>
 /// <param name="path">TBD</param>
 /// <param name="eventStream">TBD</param>
 public DeadLetterActorRef(IActorRefProvider provider, ActorPath path, EventStream eventStream)
     : base(provider, path, eventStream)
 {
     _eventStream = eventStream;
 }
示例#26
0
 public PromiseActorRef(IActorRefProvider provider, TaskCompletionSource <object> result, string mcn)
 {
     _provider = provider;
     Result    = result;
     _mcn      = mcn;
 }
示例#27
0
 /// <summary>
 /// Can't access constructor directly - use <see cref="Apply"/> instead.
 /// </summary>
 private PromiseActorRef(IActorRefProvider provider, TaskCompletionSource <object> promise, string mcn)
 {
     _provider = provider;
     _promise  = promise;
     _mcn      = mcn;
 }
示例#28
0
 public TraceActorRefProvider(string systemName, Settings settings, EventStream eventStream)
 {
     _delegate = new LocalActorRefProvider(systemName, settings, eventStream);
 }
示例#29
0
 public TraceActorRefProvider(IActorRefProvider @delegate)
 {
     _delegate = @delegate;
 }
 public OmnetActorRefProvider(string systemName, Settings settings, EventStream eventStream)
 {
     _localActorRefProvider = new LocalActorRefProvider(systemName, settings, eventStream);
 }