Ejemplo n.º 1
0
 public SchedulingActor(IScheduler scheduler)
 {
     _logger.Debug("Scheduling actor started at path {Path}", Self.Path);
     _scheduler = scheduler;
     Receive <ScheduleCommand>(message => Schedule(message));
     Receive <ScheduleMessage>(message => Schedule(message));
     Receive <Unschedule>(message => Unschedule(message));
 }
Ejemplo n.º 2
0
        protected virtual RouterConfig CreateActorRouter(CreateActorRouteMessage msg)
        {
            switch (msg.PoolKind)
            {
            case PoolKind.Random:
                Log.Debug("Created random pool router to pass messages to {actor} ", msg.ActorName);
                return(new RandomPool(Environment.ProcessorCount));

            case PoolKind.ConsistentHash:
                Log.Debug("Created consistent hashing pool router to pass messages to {actor} ", msg.ActorName);

                var routesMap = msg.Routes.ToDictionary(r => CreateHandlerRouteMessage.GetTypeWithoutMetadata(r.MessageType),
                                                        r => r.CorrelationField);

                var pool = new ConsistentHashingPool(Environment.ProcessorCount,
                                                     message =>
                {
                    var idContainer = (message as IMessageMetadataEnvelop)?.Message ?? message;
                    string prop     = null;

                    foreach (var searchType in GetInterfacesAndBaseTypes(idContainer.GetType()))
                    {
                        if (!routesMap.TryGetValue(searchType, out prop))
                        {
                            continue;
                        }
                        var value = idContainer.GetType()
                                    .GetProperty(prop)
                                    .GetValue(idContainer);
                        return(value);
                    }
                    throw new ArgumentException($"Cannot find route for {message.GetType()}");
                }
                                                     );
                return(pool);

            case PoolKind.None:
                Log.Debug("Intentionally use {actor} without router", msg.ActorName);
                return(NoRouter.Instance);

            default:
                Log.Debug("{actor} defaulted to no router", msg.ActorName);

                return(NoRouter.Instance);
            }
        }
Ejemplo n.º 3
0
        public EventSourcedActor(IConstructAggregates aggregateConstructor,
                                 ISnapshotsPersistencePolicy policy,
                                 IPublisher publisher)
        {
            PersistenceId         = Self.Path.Name;
            SnapshotsPolicy       = policy;
            _aggregateConstructor = aggregateConstructor;
            Publisher             = publisher;
            Id      = AggregateActorName.Parse <T>(Self.Path.Name).Id;
            State   = (AggregateBase)aggregateConstructor.Build(typeof(T), Id, null);
            Monitor = new ActorMonitor(Context, typeof(T).Name);
            Command <GracefullShutdownRequest>(req =>
            {
                Monitor.IncrementMessagesReceived();
                DeleteSnapshots(SnapshotsPolicy.GetSnapshotsToDelete());
                Become(Terminating);
            });

            Command <CheckHealth>(s => Sender.Tell(new HealthStatus(s.Payload)));

            Command <SaveSnapshotSuccess>(s =>
            {
                NotifyWatchers(s);
                SnapshotsPolicy.MarkSnapshotSaved(s.Metadata);
            });

            Command <NotifyOnPersistenceEvents>(c =>
            {
                var waiter = c.Waiter ?? Sender;
                if (IsRecoveryFinished)
                {
                    waiter.Tell(RecoveryCompleted.Instance);
                }

                _persistenceWaiters.Add(waiter);
            });

            Recover <DomainEvent>(e =>
            {
                State.ApplyEvent(e);
                SnapshotsPolicy.MarkActivity(e.CreatedTime);
            });

            Recover <SnapshotOffer>(offer =>
            {
                SnapshotsPolicy.MarkSnapshotApplied(offer.Metadata);
                State = _aggregateConstructor.Build(typeof(T), Id, (IMemento)offer.Snapshot);
            });

            Recover <RecoveryCompleted>(message =>
            {
                _log.Debug("Recovery for actor {Id} is completed", PersistenceId);
                NotifyWatchers(message);
            });
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SerilogExtendedLogger"/> class.
 /// </summary>
 public SerilogExtendedLogger()
 {
     Receive <Error>(m => WithSerilog(logger => SetContextFromLogEvent(logger, m).Error(m.Cause, GetFormat(m.Message), GetArgs(m.Message))));
     Receive <Warning>(m => WithSerilog(logger => SetContextFromLogEvent(logger, m).Warn(GetFormat(m.Message), GetArgs(m.Message))));
     Receive <Info>(m => WithSerilog(logger => SetContextFromLogEvent(logger, m).Info(GetFormat(m.Message), GetArgs(m.Message))));
     Receive <Debug>(m => WithSerilog(logger => SetContextFromLogEvent(logger, m).Debug(GetFormat(m.Message), GetArgs(m.Message))));
     Receive <InitializeLogger>(m =>
     {
         _log.Debug("SerilogLogger started");
         Sender.Tell(new LoggerInitialized());
     });
 }
        public bool ShouldRetry(IJobExecutionContext context, JobExecutionException e)
        {
            if (e?.InnerException != null && !_settings.ErrorActions.ShouldContinue(e.InnerException))
            {
                _log.Debug("Job {Key} will not be retried due to special error encoured: {error}",
                           context.JobDetail.Key.Name, e.InnerException);
                return(false);
            }

            int retries     = GetAlreadyPerformedRetries(context);
            var shouldRetry = retries < this._settings.MaxRetries;

            if (shouldRetry)
            {
                _log.Debug("Job {Key} will be retried, {retries} / {maxRetries}", context.JobDetail.Key.Name, retries, _settings.MaxRetries);
            }
            else
            {
                _log.Debug("Job {Key} will not be retried, as retries limit was reached: {maxRetries}", context.JobDetail.Key.Name,
                           _settings.MaxRetries);
            }

            return(shouldRetry);
        }
Ejemplo n.º 6
0
 private void OnSystemTermination()
 {
     _log.Debug("grid node Actor system terminated");
 }
Ejemplo n.º 7
0
 public void JobToBeExecuted(IJobExecutionContext context)
 {
     _log.Debug("Job {JobKey} is about to be executed", context.JobDetail.Key);
 }
Ejemplo n.º 8
0
 public void Handle(CreateAccountCommand msg)
 {
     _log.Debug("Handling command: {Command}", msg.ToPropsString());
     _repository.Save(new Account(msg.AccountId, msg.BusinessId), msg.Id);
 }