Example #1
0
        /// <summary>
        ///     Gets the logger.
        /// </summary>
        /// <param name="cell">The cell.</param>
        /// <returns>LoggingAdapter.</returns>
        public static LoggingAdapter GetLogger(IActorContext cell)
        {
            string logSource = cell.Self.ToString();
            Type logClass = cell.Props.Type;

            return new BusLogging(cell.System.EventStream, logSource, logClass);
        }
Example #2
0
 public override Task ReplayMessagesAsync(IActorContext context, string persistenceId, long fromSequenceNr, long toSequenceNr, long max,
     Action<IPersistentRepresentation> recoveryCallback)
 {
     var highest = HighestSequenceNr(persistenceId);
     if (highest != 0L && max != 0L)
         Read(persistenceId, fromSequenceNr, Math.Min(toSequenceNr, highest), max).ForEach(recoveryCallback);
     return Task.FromResult(new object());
 }
Example #3
0
 private static Tuple<IActorRef, Type>[] CreateInitialActor(IActorContext context, Socket socket)
 {
     return new[]
     {
         Tuple.Create(context.ActorOf(Props.Create(() => new ServerActor())),
                      typeof(IServer))
     };
 }
Example #4
0
 /// <summary>
 /// Creates a new stash for specified <paramref name="actor"/> if it has not been initialized already.
 /// </summary>
 public override void AfterIncarnated(ActorBase actor, IActorContext context)
 {
     var stashed = actor as IActorStash;
     if (stashed != null && stashed.Stash == null)
     {
         stashed.Stash = context.CreateStash(actor.GetType());
     }
 }
Example #5
0
 /// <summary>
 /// Ensures, that all stashed messages inside <paramref name="actor"/> stash have been unstashed.
 /// </summary>
 public override void BeforeIncarnated(ActorBase actor, IActorContext context)
 {
     var actorStash = actor as IActorStash;
     if (actorStash != null)
     {
         actorStash.Stash.UnstashAll();
     }
 }
Example #6
0
 /// <summary>
 /// Creates cluster sharding proxy actor from config
 /// </summary>
 /// <param name="context">Current actor context (will create child actor)</param>
 /// <param name="actorConfig">Configuration to create from</param>
 /// <param name="windsorContainer">Dependency resolver</param>
 /// <param name="pathName">New actor's path name</param>
 protected virtual void CreateShardingProxyActor(
     IActorContext context,
     Config actorConfig,
     IWindsorContainer windsorContainer,
     string pathName)
 {
     context.ActorOf(Props.Create(() => new ShardingProxyWrappperActor(windsorContainer, actorConfig)), pathName);
 }
Example #7
0
 private Tuple<IActorRef, TaggedType[], ActorBindingFlags>[] CreateInitialActor(IActorContext context) =>
     new[]
     {
         Tuple.Create(
             context.ActorOf(Props.Create(() =>
                 new UserLoginActor(_clusterContext, context.Self.Cast<ActorBoundChannelRef>(), new IPEndPoint(IPAddress.None, 0)))),
             new TaggedType[] { typeof(IUserLogin) },
             (ActorBindingFlags)0)
     };
 private Tuple<IActorRef, TaggedType[], ActorBindingFlags>[] CreateInitialActor(IActorContext context)
 {
     return new[]
     {
         Tuple.Create(
             context.ActorOf(Props.Create(() => new UserLoginActor(context.Self))),
             new TaggedType[] { typeof(IUserLogin) },
             ActorBindingFlags.CloseThenStop)
     };
 }
 private IActorRef LookupOrCreateTodoChildActor(IActorContext context, string name)
 {
     var child = context.Child(name);
     if (child.Equals(ActorRefs.Nobody)) //child doesn't exist
     {
         return Context.ActorOf(Props.Create(() => new MessageProducerChildActor()),
             name);
     }
     return child;
 }
        public override Task ReplayMessagesAsync(IActorContext context, string persistenceId, long fromSequenceNr, long toSequenceNr, long max,
            Action<IPersistentRepresentation> recoveryCallback)
        {
            Console.WriteLine("Replaying messages for Persistence Id:" + persistenceId);
            var persistentRepresentations = repository.GetData<JournalEntry>(persistenceId, fromSequenceNr, toSequenceNr, max);

            foreach (var persistentRepresentation in persistentRepresentations)
            {
                recoveryCallback((IPersistentRepresentation)persistentRepresentation.Payload);
            }
            return Task.FromResult(false);
        }
Example #11
0
        /// <summary>
        /// Creates simple actor from config
        /// </summary>
        /// <param name="context">Current actor context (will create child actor)</param>
        /// <param name="actorConfig">Configuration to create from</param>
        /// <param name="windsorContainer">Dependency resolver</param>
        /// <param name="currentPath">Parent (current) actor path</param>
        /// <param name="pathName">New actor's path name</param>
        protected override void CreateSimpleActor(
                    IActorContext context,
                    Config actorConfig,
                    IWindsorContainer windsorContainer,
                    string currentPath,
                    string pathName)
        {
            var childTypeName = actorConfig.GetString("type");
            if (string.IsNullOrWhiteSpace(childTypeName))
            {
                return;
            }

            var type = Type.GetType(childTypeName);
            if (type != null)
            {
                context.GetLogger()
                    .Info(
                        // ReSharper disable FormatStringProblem
                        "{Type}: {NameSpaceName} initializing {ActorType} on {PathString}",
                        // ReSharper restore FormatStringProblem
                        typeof(NameSpaceActor).Name,
                        currentPath,
                        type.Name,
                        pathName);

                if (type == typeof(NameSpaceActor) || type == typeof(NameSpaceForwarder))
                {
                    // this is done for tests, otherwise it would lead to CircularDependencyException
                    context.ActorOf(Props.Create(() => new NameSpaceForwarder(windsorContainer, this.testActor)), pathName);
                }
                else
                {
                    context.ActorOf(Context.System.DI().Props(type), pathName);
                }
            }
            else
            {
                context.GetLogger()
                    .Error(
                        // ReSharper disable FormatStringProblem
                        "{Type}: {ClassTypeString} was not found for actor {NameSpaceName}/{PathString}",
                        // ReSharper restore FormatStringProblem
                        typeof(NameSpaceActor).Name,
                        childTypeName,
                        currentPath,
                        pathName);
            }
        }
Example #12
0
            public override Task ReplayMessagesAsync(IActorContext context, string persistenceId, long fromSequenceNr,
                long toSequenceNr, long max,
                Action<IPersistentRepresentation> recoveryCallback)
            {
                var highest = HighestSequenceNr(persistenceId);
                var readFromStore =
                    Read(persistenceId, fromSequenceNr, toSequenceNr, max).ToArray();

                if (readFromStore.Length == 0) return Task.FromResult(new object());
                if (IsCorrupt(readFromStore))
                {
                    var promise = new TaskCompletionSource<object>();
                    promise.SetException( new SimulatedException(string.Format("blahonga {0} {1}", fromSequenceNr, toSequenceNr)));
                    return promise.Task;
                }
                readFromStore.ForEach(recoveryCallback);
                return Task.FromResult(new object());
            }
Example #13
0
        /// <summary>INTERNAL
        /// Abstract base class for stash support
        /// <remarks>Note! Part of internal API. Breaking changes may occur without notice. Use at own risk.</remarks>
        /// </summary>
        /// <exception cref="NotSupportedException">This exception is thrown if the actor's mailbox isn't deque-based (e.g. <see cref="UnboundedDequeBasedMailbox"/>).</exception>
        protected AbstractStash(IActorContext context, int capacity = 100)
        {
            var actorCell = (ActorCell)context;
            Mailbox = actorCell.Mailbox.MessageQueue as IDequeBasedMessageQueueSemantics;
            if(Mailbox == null)
            {
                string message = $@"DequeBasedMailbox required, got: {actorCell.Mailbox.GetType().Name}
An (unbounded) deque-based mailbox can be configured as follows:
    my-custom-mailbox {{
        mailbox-type = ""Akka.Dispatch.UnboundedDequeBasedMailbox""
    }}";
                throw new NotSupportedException(message);
            }
            _theStash = new LinkedList<Envelope>();
            _actorCell = actorCell;

            // TODO: capacity needs to come from dispatcher or mailbox config
            // https://github.com/akka/akka/blob/master/akka-actor/src/main/scala/akka/actor/Stash.scala#L126
            _capacity = capacity;
        }
Example #14
0
 public override Task ReplayMessagesAsync(IActorContext context, string persistenceId, long fromSequenceNr, long toSequenceNr, long max, Action<IPersistentRepresentation> recoveryCallback)
 {
     var promise = new TaskCompletionSource<object>();
     if (ChaosSupportExtensions.ShouldFail(_replayFailureRate))
     {
         var replays = Read(persistenceId, fromSequenceNr, toSequenceNr, max).ToArray();
         var top = replays.Take(_random.Next(replays.Length + 1)).ToArray();
         foreach (var persistentRepresentation in top)
         {
             recoveryCallback(persistentRepresentation);
         }
         promise.SetException(new ReplayFailedException(top));
     }
     else
     {
         foreach (var p in Read(persistenceId, fromSequenceNr, toSequenceNr, max))
         {
             recoveryCallback(p);
         }
         promise.SetResult(new object());
     }
     return promise.Task;
 }
Example #15
0
 public ActorSelection Select(IActorContext context = null)
 {
     return(context == null?
            ActorSystem.ActorSelection(ActorMetaData.Path) :
                context.ActorSelection(ActorMetaData.Path));
 }
 public ActorRefConverter(IActorContext context)
 {
     this.context = context;
 }
 /// <inheritdoc/>
 public abstract Task ReplayMessagesAsync(IActorContext context, string persistenceId, long fromSequenceNr, long toSequenceNr, long max, Action <IPersistentRepresentation> recoveryCallback);
Example #18
0
 public Routee NewRoutee(Props routeeProps, IActorContext context)
 {
     var routee = new ActorRefRoutee(context.ActorOf(EnrichWithPoolDispatcher(routeeProps, context)));
     return routee;
 }
 public override Routee NewRoutee(Props routeeProps, IActorContext context)
 {
     var name = "c" + _childNameCounter.GetAndIncrement();
     var actorRef = context.ActorOf(EnrichWithPoolDispatcher(routeeProps, context), name);
     return new ActorRefRoutee(actorRef);
 }
 public IActorRef CreateResourceHarvesterActor(IActorContext actorContext, IActorRef villagerActor)
 {
     var props = Props.Create<ResourceHarvesterActor>(actorContext.System.Scheduler, villagerActor);
     var resourceHarvesterRoutine = actorContext.ActorOf(props);
     return resourceHarvesterRoutine;
 }
Example #21
0
        /// <summary>
        /// Creates child actors according to current config
        /// </summary>
        /// <param name="context">Current actor's context</param>
        /// <param name="actorPath">Current actor's path</param>
        /// <param name="container">Dependency resolver</param>
        private void InitChildActorsFromConfig(IActorContext context, ActorPath actorPath, IWindsorContainer container)
        {
            var config = Context.System.Settings.Config.GetConfig("akka.actor.deployment");
            if (config == null)
            {
                return;
            }

            var namespacePathElements = actorPath.Elements.Skip(1).ToList();
            foreach (var pair in config.AsEnumerable())
            {
                var key = pair.Key;

                var path = key.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                if (path.Length != namespacePathElements.Count + 1)
                {
                    continue;
                }

                if (namespacePathElements.Where((t, i) => path[i] != t).Any())
                {
                    continue;
                }

                var actorConfig = config.GetConfig(key);
                EnActorType actorType;
                if (!Enum.TryParse(actorConfig.GetString("actor-type"), out actorType))
                {
                    actorType = EnActorType.Simple;
                }

                var currentPath = "/" + string.Join("/", namespacePathElements);

                switch (actorType)
                {
                    case EnActorType.Singleton:
                        this.CreateSingletonActor(context, actorConfig, currentPath, path.Last());
                        break;

                    case EnActorType.SingletonProxy:
                        this.CreateSingletonProxyActor(context, actorConfig, currentPath, path.Last());
                        break;

                    case EnActorType.Sharding:
                        this.CreateShardingActor(context, actorConfig, container, path.Last());
                        break;

                    case EnActorType.ShardingProxy:
                        this.CreateShardingProxyActor(context, actorConfig, container, path.Last());
                        break;

                    default:
                        this.CreateSimpleActor(context, actorConfig, container, currentPath, path.Last());
                        break;
                }
            }
        }
Example #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AtLeastOnceDeliverySemantic"/> class.
 /// </summary>
 /// <param name="context">TBD</param>
 /// <param name="settings">TBD</param>
 public AtLeastOnceDeliverySemantic(IActorContext context, PersistenceSettings.AtLeastOnceDeliverySettings settings)
 {
     _context            = context;
     _settings           = settings;
     _deliverySequenceNr = 0;
 }
 public override void Action(IActorContext <IBartender> context)
 {
     context.Out.WriteLine("Press ENTER");
     context.In.ReadLine();
     throw new NotImplementedException();
 }
Example #24
0
 public override void HandleChildTerminated(IActorContext actorContext, IActorRef child, IEnumerable <IInternalActorRef> children)
 {
     Delegates.Remove(child);
 }
Example #25
0
 /// <summary>
 /// Creates a new <see cref="Routee"/> configured to use the provided <paramref name="routeeProps"/>
 /// and the pool dispatcher if enabled.
 /// </summary>
 /// <param name="routeeProps">The <see cref="Actor.Props"/> to configure with the pool dispatcher.</param>
 /// <param name="context">The context for the provided <paramref name="routeeProps"/>.</param>
 /// <returns>
 /// A new <see cref="Routee"/> configured to use the provided <paramref name="routeeProps"/>
 /// and the pool dispatcher if enabled.
 /// </returns>
 internal virtual Routee NewRoutee(Props routeeProps, IActorContext context)
 {
     return(new ActorRefRoutee(context.ActorOf(EnrichWithPoolDispatcher(routeeProps, context))));
 }
Example #26
0
 public override void ProcessFailure(IActorContext context, bool restart, IActorRef child, Exception cause, ChildRestartStats stats,
                                     IReadOnlyCollection <ChildRestartStats> children)
 {
     Delegates[child].ProcessFailure(context, restart, child, cause, stats, children);
 }
 /// <summary>
 /// Plugin behavior applied to <paramref name="actor"/> instance before the actor is being recycled.
 /// </summary>
 public virtual void BeforeIncarnated(ActorBase actor, IActorContext context)
 {
 }
 /// <summary>
 /// Plugin behavior applied to <paramref name="actor"/> instance when the new one is being created.
 /// </summary>
 public virtual void AfterIncarnated(ActorBase actor, IActorContext context)
 {
 }
 public ActorRefConverter(IActorContext context)
 {
     _context = context;
 }
Example #30
0
 /// <summary>
 /// This method is called to act on the failure of a child: restart if the flag is true, stop otherwise.
 /// </summary>
 /// <param name="context">The actor context.</param>
 /// <param name="restart">if set to <c>true</c> restart, stop otherwise.</param>
 /// <param name="child">The child actor</param>
 /// <param name="cause">The exception that caused the child to fail.</param>
 /// <param name="stats">The stats for the child that failed. The ActorRef to the child can be obtained via the <see cref="ChildRestartStats.Child"/> property</param>
 /// <param name="children">The stats for all children</param>
 protected abstract void ProcessFailure(IActorContext context, bool restart, IActorRef child, Exception cause, ChildRestartStats stats, IReadOnlyCollection <ChildRestartStats> children);
Example #31
0
 /// <summary>INTERNAL
 /// A stash implementation that is bounded
 /// <remarks>Note! Part of internal API. Breaking changes may occur without notice. Use at own risk.</remarks>
 /// </summary>
 public BoundedStashImpl(IActorContext context, int capacity = 100)
     : base(context, capacity)
 {
 }
Example #32
0
 /// <summary>
 /// This method is called after the child has been removed from the set of children.
 /// It does not need to do anything special. Exceptions thrown from this method
 /// do NOT make the actor fail if this happens during termination.
 /// </summary>
 /// <param name="actorContext">TBD</param>
 /// <param name="child">TBD</param>
 /// <param name="children">TBD</param>
 public abstract void HandleChildTerminated(IActorContext actorContext, IActorRef child, IEnumerable <IInternalActorRef> children);
Example #33
0
        /// <summary>
        /// Creates cluster singleton actor from config
        /// </summary>
        /// <param name="context">Current actor context (will create child actor)</param>
        /// <param name="actorConfig">Configuration to create from</param>
        /// <param name="currentPath">Parent (current) actor path</param>
        /// <param name="pathName">New actor's path name</param>
        protected virtual void CreateSingletonActor(
            IActorContext context,
            Config actorConfig,
            string currentPath,
            string pathName)
        {
            var childTypeName = actorConfig.GetString("type");
            if (string.IsNullOrWhiteSpace(childTypeName))
            {
                return;
            }

            var type = Type.GetType(childTypeName);
            if (type == null)
            {
                context.GetLogger()
                    .Error(
                        "{Type}: {ClassTypeString} was not found for actor {NameSpaceName}/{PathString}",
                        typeof(NameSpaceActor).Name,
                        childTypeName,
                        currentPath,
                        pathName);
                return;
            }

            var singletonName = actorConfig.GetString("singleton-name");
            if (string.IsNullOrEmpty(singletonName))
            {
                context.GetLogger()
                    .Error(
                        "{Type}: singleton-name was not defined for{NameSpaceName}/ {PathString}",
                        typeof(NameSpaceActor).Name,
                        currentPath,
                        pathName);
                return;
            }

            var role = actorConfig.GetString("singleton-node-role");
            if (string.IsNullOrEmpty(role))
            {
                context.GetLogger()
                    .Error(
                        "{Type}: singleton-node-role was not defined for {NameSpaceName}/{PathString}",
                        typeof(NameSpaceActor).Name,
                        currentPath,
                        pathName);
                return;
            }

            context.GetLogger()
                .Info(
                    "{Type}: {NameSpaceName} initializing singleton {SingletonName} of type {ActorType} on {PathString}",
                    typeof(NameSpaceActor).Name,
                    currentPath,
                    singletonName,
                    type.Name,
                    pathName);

            context.ActorOf(
                ClusterSingletonManager.Props(
                    context.System.DI().Props(type),
                    new ClusterSingletonManagerSettings(
                        singletonName,
                        role,
                        actorConfig.GetTimeSpan("removal-margin", TimeSpan.FromSeconds(1), false),
                        actorConfig.GetTimeSpan("handover-retry-interval", TimeSpan.FromSeconds(5), false))),
                pathName);
        }
Example #34
0
        protected override void ProcessFailure(IActorContext context, bool restart, Exception cause, ChildRestartStats failedChildStats, IReadOnlyCollection <ChildRestartStats> allChildren)
        {
            // for compatibility, since 1.1.2

            ProcessFailure(context, restart, failedChildStats.Child, cause, failedChildStats, allChildren);
        }
Example #35
0
 private Tuple <IActorRef, TaggedType[], ActorBindingFlags>[] CreateInitialActor(IActorContext context) =>
 new[]
 {
     Tuple.Create(
         context.ActorOf(Props.Create(() =>
                                      new UserLoginActor(_clusterContext, context.Self.Cast <ActorBoundChannelRef>(), new IPEndPoint(IPAddress.None, 0)))),
         new TaggedType[] { typeof(IUserLogin) },
         (ActorBindingFlags)0)
 };
Example #36
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="actorContext">TBD</param>
 /// <param name="child">TBD</param>
 /// <param name="children">TBD</param>
 public override void HandleChildTerminated(IActorContext actorContext, IActorRef child, IEnumerable <IInternalActorRef> children)
 {
     //Intentionally left blank
 }
Example #37
0
 private Props EnrichWithPoolDispatcher(Props routeeProps, IActorContext context)
 {
     //        if (usePoolDispatcher && routeeProps.dispatcher == Dispatchers.DefaultDispatcherId)
     //  routeeProps.withDispatcher("akka.actor.deployment." + context.self.path.elements.drop(1).mkString("/", "/", "")
     //    + ".pool-dispatcher")
     //else
     //  routeeProps
     if (UsePoolDispatcher && routeeProps.Dispatcher == Dispatchers.DefaultDispatcherId)
     {
         return
             routeeProps.WithDispatcher("akka.actor.deployment." + context.Self.Path.Elements.Drop(1).Join("/") +
                                        ".pool-dispatcher");
     }
     return routeeProps;
 }
Example #38
0
        public virtual Routee NewRoutee(Props routeeProps, IActorContext context)
        {
            var routee = new ActorRefRoutee(context.ActorOf(EnrichWithPoolDispatcher(routeeProps, context)));

            return(routee);
        }
        public override async Task ReplayMessagesAsync(
            IActorContext context,
            string persistenceId,
            long fromSequenceNr,
            long toSequenceNr,
            long max,
            Action <IPersistentRepresentation> recoveryCallback)
        {
            try
            {
                if (toSequenceNr < fromSequenceNr || max == 0)
                {
                    return;
                }

                if (fromSequenceNr == toSequenceNr)
                {
                    max = 1;
                }

                if (toSequenceNr > fromSequenceNr && max == toSequenceNr)
                {
                    max = toSequenceNr - fromSequenceNr + 1;
                }

                var count          = 0L;
                var start          = (int)fromSequenceNr - 1;
                var localBatchSize = batchSize;

                StreamEventsSlice slice;
                do
                {
                    if (max == long.MaxValue && toSequenceNr > fromSequenceNr)
                    {
                        max = toSequenceNr - fromSequenceNr + 1;
                    }

                    if (max < localBatchSize)
                    {
                        localBatchSize = (int)max;
                    }

                    try
                    {
                        slice = await connection.ReadStreamEventsForwardAsync(persistenceId, start, localBatchSize, false);
                    }
                    catch (Exception e)
                    {
                        throw;
                    }

                    foreach (var @event in slice.Events)
                    {
                        var jsonText       = Encoding.UTF8.GetString(@event.OriginalEvent.Data);
                        var representation = JsonConvert.DeserializeObject <IPersistentRepresentation>(jsonText, serializerSettings);

                        recoveryCallback(representation);
                        count++;

                        if (count == max)
                        {
                            return;
                        }
                    }

                    start = slice.NextEventNumber;
                } while (!slice.IsEndOfStream);
            }
            catch (Exception e)
            {
                log.Error(e, "Error replaying messages for: {0}", persistenceId);
                throw;
            }
        }
Example #40
0
 public abstract Task ReplayMessagesAsync(IActorContext context, string persistenceId, long fromSequenceNr, long toSequenceNr, long max, Action<IPersistentRepresentation> recoveryCallback);
Example #41
0
 public static DIActorContextAdapter DI(this IActorContext context)
 {
     return(new DIActorContextAdapter(context));
 }
Example #42
0
 public override ValueTask <Behavior <TMessage> > ReceiveSignal(IActorContext <TMessage> context, ISignal signal) =>
 _onSignal(context, signal);
Example #43
0
        public override Routee NewRoutee(Props routeeProps, IActorContext context)
        {
            _nodeAddrEnumerator.MoveNext();
            var name = "c" + _childNameCounter.GetAndIncrement();
            var deploy = new Deploy(routeeProps.RouterConfig, new RemoteScope(_nodeAddrEnumerator.Current));
            

            var actorRef = context.AsInstanceOf<ActorCell>()
                .AttachChild(Local.EnrichWithPoolDispatcher(routeeProps, context).WithDeploy(deploy), false, name);
            return new ActorRefRoutee(actorRef);
        }
 public ActorNameEventMetadataProvider(IActorContext actorContext)
 {
     this.actorContext = actorContext;
 }
Example #45
0
 public static IServiceScope CreateScope(this IActorContext context)
 {
     return(ServiceScopeExtensionIdProvider.Instance.Get(context.System).CreateScope());
 }
Example #46
0
 public override ValueTask <Behavior <TMessage> > Receive(IActorContext <TMessage> context, TMessage message) =>
 _onMessage(message);
Example #47
0
 public override async Task ReplayMessagesAsync(IActorContext context, string persistenceId, long fromSequenceNr, long toSequenceNr, long max,
     Action<IPersistentRepresentation> recoveryCallback)
 {
     NotifyNewPersistenceIdAdded(persistenceId);
     using (var connection = CreateDbConnection())
     {
         await connection.OpenAsync();
         await QueryExecutor.SelectByPersistenceIdAsync(connection, _pendingRequestsCancellation.Token, persistenceId, fromSequenceNr, toSequenceNr, max, recoveryCallback);
     }
 }
 public ActorSelectionVariable(IActorContext context, IActorRef self, IActorRef sender, IOutVariable actorPath, IOutVariable <IActorRef> anchorRef = null)
     : base(context, self, sender)
 {
     ActorPath = actorPath;
     AnchorRef = anchorRef;
 }
 /// <summary>INTERNAL
 /// A stash implementation that is bounded
 /// <remarks>Note! Part of internal API. Breaking changes may occur without notice. Use at own risk.</remarks>
 /// </summary>
 public UnboundedStashImpl(IActorContext context)
     : base(context, int.MaxValue)
 {
 }
 public ActorSelectionVariable(IActorContext context, IActorRef self, IActorRef sender)
     : base(context, self, sender)
 {
 }
Example #51
0
 protected override void ProcessFailure(IActorContext context, bool restart, Exception cause, ChildRestartStats failedChildStats, IReadOnlyCollection<ChildRestartStats> allChildren)
 {
     var child = failedChildStats.Child;
     TestActor.Tell(new FF(new Failed(child, cause, failedChildStats.Uid)), child);
     base.ProcessFailure(context, restart, cause, failedChildStats, allChildren);
 }
Example #52
0
 /// <summary>INTERNAL
 /// A stash implementation that is bounded
 /// <remarks>Note! Part of internal API. Breaking changes may occur without notice. Use at own risk.</remarks>
 /// </summary>
 public UnboundedStashImpl(IActorContext context)
     : base(context, int.MaxValue)
 {
 }
Example #53
0
        /// <summary>
        /// Creates cluster singleton proxy actor from config
        /// </summary>
        /// <param name="context">Current actor context (will create child actor)</param>
        /// <param name="actorConfig">Configuration to create from</param>
        /// <param name="currentPath">Parent (current) actor path</param>
        /// <param name="pathName">New actor's path name</param>
        protected virtual void CreateSingletonProxyActor(
            IActorContext context,
            Config actorConfig,
            string currentPath,
            string pathName)
        {
            var singletonName = actorConfig.GetString("singleton-name");
            if (string.IsNullOrEmpty(singletonName))
            {
                context.GetLogger()
                    .Error(
                        "{Type}: singleton-name was not defined for {NameSpaceName}/{PathString}",
                        typeof(NameSpaceActor).Name,
                        currentPath,
                        pathName);
                return;
            }

            var singletonManagerPath = actorConfig.GetString("singleton-path");
            if (string.IsNullOrEmpty(singletonName))
            {
                context.GetLogger()
                    .Error(
                        "{Type}: singleton-path was not defined for {NameSpaceName}/{PathString}",
                        typeof(NameSpaceActor).Name,
                        currentPath,
                        pathName);
                return;
            }

            var role = actorConfig.GetString("singleton-node-role");
            if (string.IsNullOrEmpty(role))
            {
                context.GetLogger()
                    .Error(
                        "{Type}: singleton-node-role was not defined for {NameSpaceName}/{PathString}",
                        typeof(NameSpaceActor).Name,
                        currentPath,
                        pathName);
                return;
            }

            context.GetLogger()
                .Info(
                    "{Type}: {NameSpaceName} initializing singleton proxy {SingletonManagerPath} / {SingletonName} for {PathString}",
                    typeof(NameSpaceActor).Name,
                    currentPath,
                    singletonManagerPath,
                    singletonName,
                    pathName);

            context.ActorOf(
                ClusterSingletonProxy.Props(
                    singletonManagerPath: singletonManagerPath,
                    settings:
                        new ClusterSingletonProxySettings(
                            singletonName,
                            role,
                            actorConfig.GetTimeSpan("singleton-identification-interval", TimeSpan.FromSeconds(1), false),
                            actorConfig.GetInt("buffer-size", 2048))),
                name: pathName);
        }
 public override void HandleChildTerminated(IActorContext actorContext, ActorRef child, IEnumerable<InternalActorRef> children)
 {
     //Intentionally left blank
 }
Example #55
0
 /// <summary>
 /// INTERNAL API
 /// </summary>
 internal Routee RouteeFor(string path, IActorContext context)
 {
     return(new ActorSelectionRoutee(context.ActorSelection(path)));
 }
Example #56
0
        public override async Task ReplayMessagesAsync(IActorContext context,
                                                       string persistenceId,
                                                       long fromSequenceNr,
                                                       long toSequenceNr,
                                                       long max,
                                                       Action <IPersistentRepresentation> recoveryCallback)
        {
            try
            {
                if (toSequenceNr < fromSequenceNr || max == 0)
                {
                    return;
                }

                if (fromSequenceNr == toSequenceNr)
                {
                    max = 1;
                }

                if (toSequenceNr > fromSequenceNr && max == toSequenceNr)
                {
                    max = toSequenceNr - fromSequenceNr + 1;
                }

                var count = 0L;

                var start = fromSequenceNr <= 0
                    ? 0
                    : fromSequenceNr - 1;

                var localBatchSize = _settings.ReadBatchSize;

                StreamEventsSlice slice;
                do
                {
                    if (max == long.MaxValue && toSequenceNr > fromSequenceNr)
                    {
                        max = toSequenceNr - fromSequenceNr + 1;
                    }

                    if (max < localBatchSize)
                    {
                        localBatchSize = (int)max;
                    }

                    slice = await _eventStoreConnection.ReadStreamEventsForwardAsync(persistenceId, start, localBatchSize, false);

                    foreach (var @event in slice.Events)
                    {
                        var representation = _adapter.Adapt(@event, s =>
                        {
                            //TODO: Is this correct?
                            var selection = context.ActorSelection(s);
                            return(selection.Anchor);
                        });

                        recoveryCallback(representation);
                        count++;

                        if (count == max)
                        {
                            return;
                        }
                    }

                    start = slice.NextEventNumber;
                } while (!slice.IsEndOfStream);
            }
            catch (Exception e)
            {
                _log.Error(e, "Error replaying messages for: {0}", persistenceId);
                throw;
            }
        }
Example #57
0
        public static IStash CreateStash <T>(this IActorContext context) where T : ActorBase
        {
            var actorType = typeof(T);

            return(CreateStash(context, actorType));
        }
Example #58
0
 public static IStash CreateStash(this IActorContext context, IActorStash actorInstance)
 {
     return(CreateStash(context, actorInstance.GetType()));
 }
 public void CreateTable(IActorContext context, Guid gameToken)
 {
     Table = context.ActorOf(Props.Create(() => new GameTableActor(Player.Token, gameToken)), Player.Token.ToString());
 }
Example #60
0
        /// <summary>
        /// Creates a new logging adapter using the specified context's event stream.
        /// </summary>
        /// <param name="context">The context used to configure the logging adapter.</param>
        /// <param name="logMessageFormatter">The formatter used to format log messages.</param>
        /// <returns>The newly created logging adapter.</returns>
        public static ILoggingAdapter GetLogger(this IActorContext context, ILogMessageFormatter logMessageFormatter = null)
        {
            var logSource = LogSource.Create(context, context.System);

            return(new BusLogging(context.System.EventStream, logSource.Source, logSource.Type, logMessageFormatter ?? new DefaultLogMessageFormatter()));
        }