示例#1
0
        private async Task InjectDependencies()
        {
            catalog.SiloStatusOracle = this.siloStatusOracle;
            this.siloStatusOracle.SubscribeToSiloStatusEvents(localGrainDirectory);

            // consistentRingProvider is not a system target per say, but it behaves like the localGrainDirectory, so it is here
            this.siloStatusOracle.SubscribeToSiloStatusEvents((ISiloStatusListener)RingProvider);

            this.siloStatusOracle.SubscribeToSiloStatusEvents(typeManager);

            this.siloStatusOracle.SubscribeToSiloStatusEvents(Services.GetRequiredService <DeploymentLoadPublisher>());

            var reminderTable = Services.GetService <IReminderTable>();

            if (reminderTable != null)
            {
                logger.Info($"Creating reminder grain service for type={reminderTable.GetType()}");

                // Start the reminder service system target
                var timerFactory = this.Services.GetRequiredService <IAsyncTimerFactory>();
                reminderService = new LocalReminderService(this, reminderTable, this.initTimeout, this.loggerFactory, timerFactory);
                RegisterSystemTarget((SystemTarget)reminderService);
            }

            RegisterSystemTarget(catalog);
            await scheduler.QueueActionAsync(catalog.Start, catalog)
            .WithTimeout(initTimeout, $"Starting Catalog failed due to timeout {initTimeout}");

            // SystemTarget for provider init calls
            this.fallbackScheduler = Services.GetRequiredService <FallbackSystemTarget>();
            RegisterSystemTarget(fallbackScheduler);
        }
示例#2
0
文件: Silo.cs 项目: dotnet/orleans
        private void InjectDependencies()
        {
            catalog.SiloStatusOracle = this.siloStatusOracle;
            this.siloStatusOracle.SubscribeToSiloStatusEvents(localGrainDirectory);

            // consistentRingProvider is not a system target per say, but it behaves like the localGrainDirectory, so it is here
            this.siloStatusOracle.SubscribeToSiloStatusEvents((ISiloStatusListener)RingProvider);

            this.siloStatusOracle.SubscribeToSiloStatusEvents(Services.GetRequiredService <DeploymentLoadPublisher>());

            var reminderTable = Services.GetService <IReminderTable>();

            if (reminderTable != null)
            {
                logger.LogInformation("Creating reminder grain service for type {ReminderTableType}", reminderTable.GetType());

                // Start the reminder service system target
                var timerFactory = this.Services.GetRequiredService <IAsyncTimerFactory>();
                reminderService = new LocalReminderService(this, reminderTable, this.initTimeout, this.loggerFactory, timerFactory);
                RegisterSystemTarget((SystemTarget)reminderService);
            }

            // SystemTarget for provider init calls
            this.fallbackScheduler = Services.GetRequiredService <FallbackSystemTarget>();
            RegisterSystemTarget(fallbackScheduler);
        }
示例#3
0
 public void RecordNewSystemTarget(SystemTarget target)
 {
     systemTargets.TryAdd(target.ActivationId, target);
     if (!Constants.IsSingletonSystemTarget(target.GrainId))
     {
         FindSystemTargetCounter(Constants.SystemTargetName(target.GrainId)).Increment();
     }
 }
示例#4
0
 private ExtensionInvoker GetCurrentExtensionInvoker()
 {
     return(RuntimeContext.CurrentGrainContext switch
     {
         SystemTarget systemTarget => systemTarget.ExtensionInvoker,
         ActivationData activation => activation.ExtensionInvoker,
         _ => throw new InvalidOperationException("Attempting to GetCurrentExtensionInvoker when not in an activation scope")
     });
示例#5
0
        public void RecordNewSystemTarget(SystemTarget target)
        {
            var systemTarget = (ISystemTargetBase)target;

            systemTargets.TryAdd(target.ActivationId, target);
            if (!Constants.IsSingletonSystemTarget(systemTarget.GrainId.Type))
            {
                FindSystemTargetCounter(Constants.SystemTargetName(systemTarget.GrainId.Type)).Increment();
            }
        }
示例#6
0
        public void RemoveSystemTarget(SystemTarget target)
        {
            var systemTarget = (ISystemTargetBase)target;

            systemTargets.TryRemove(target.ActivationId, out _);
            if (!Constants.IsSingletonSystemTarget(systemTarget.GrainId.Type))
            {
                FindSystemTargetCounter(Constants.SystemTargetName(systemTarget.GrainId.Type)).DecrementBy(1);
            }
        }
示例#7
0
        public void RemoveSystemTarget(SystemTarget target)
        {
            SystemTarget ignore;

            systemTargets.TryRemove(target.ActivationId, out ignore);
            if (!Constants.IsSingletonSystemTarget(target.GrainId))
            {
                FindSystemTargetCounter(Constants.SystemTargetName(target.GrainId)).DecrementBy(1);
            }
        }
示例#8
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            // SystemTarget for provider init calls
            this.lifecycleSchedulingSystemTarget = Services.GetRequiredService <LifecycleSchedulingSystemTarget>();
            this.fallbackScheduler = Services.GetRequiredService <FallbackSystemTarget>();
            RegisterSystemTarget(lifecycleSchedulingSystemTarget);

            try
            {
                await this.scheduler.QueueTask(() => this.siloLifecycle.OnStart(cancellationToken), this.lifecycleSchedulingSystemTarget.SchedulingContext);
            }
            catch (Exception exc)
            {
                logger.Error(ErrorCode.SiloStartError, "Exception during Silo.Start", exc);
                throw;
            }
        }
示例#9
0
        private async Task InjectDependencies()
        {
            healthCheckParticipants.Add(membershipOracle);

            catalog.SiloStatusOracle = this.membershipOracle;
            this.membershipOracle.SubscribeToSiloStatusEvents(localGrainDirectory);
            messageCenter.SiloDeadOracle = this.membershipOracle.IsDeadSilo;

            // consistentRingProvider is not a system target per say, but it behaves like the localGrainDirectory, so it is here
            this.membershipOracle.SubscribeToSiloStatusEvents((ISiloStatusListener)RingProvider);

            this.membershipOracle.SubscribeToSiloStatusEvents(typeManager);

            this.membershipOracle.SubscribeToSiloStatusEvents(Services.GetRequiredService <DeploymentLoadPublisher>());

            this.membershipOracle.SubscribeToSiloStatusEvents(Services.GetRequiredService <ClientObserverRegistrar>());

            var reminderTable = Services.GetService <IReminderTable>();

            if (reminderTable != null)
            {
                logger.Info($"Creating reminder grain service for type={reminderTable.GetType()}");

                // Start the reminder service system target
                reminderService = new LocalReminderService(this, reminderTable, this.initTimeout, this.loggerFactory);;
                RegisterSystemTarget((SystemTarget)reminderService);
            }

            RegisterSystemTarget(catalog);
            await scheduler.QueueAction(catalog.Start, catalog.SchedulingContext)
            .WithTimeout(initTimeout, $"Starting Catalog failed due to timeout {initTimeout}");

            // SystemTarget for provider init calls
            this.fallbackScheduler = Services.GetRequiredService <FallbackSystemTarget>();
            RegisterSystemTarget(fallbackScheduler);

            // SystemTarget for startup tasks
            var startupTaskTarget = Services.GetRequiredService <StartupTaskSystemTarget>();

            RegisterSystemTarget(startupTaskTarget);
        }
示例#10
0
文件: Silo.cs 项目: wmhang/orleans
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            StartTaskWithPerfAnalysis("Start Scheduler", scheduler.Start, new Stopwatch());

            // SystemTarget for provider init calls
            this.lifecycleSchedulingSystemTarget = Services.GetRequiredService <LifecycleSchedulingSystemTarget>();
            this.fallbackScheduler = Services.GetRequiredService <FallbackSystemTarget>();
            RegisterSystemTarget(lifecycleSchedulingSystemTarget);

            try
            {
                await this.scheduler.QueueTask(() => this.siloLifecycle.OnStart(cancellationToken), this.lifecycleSchedulingSystemTarget.SchedulingContext);

                this.logger.LogInformation((int)ErrorCode.SiloStarted, "Silo started");
            }
            catch (Exception exc)
            {
                logger.Error(ErrorCode.SiloStartError, "Exception during Silo.Start", exc);
                throw;
            }
        }
示例#11
0
文件: Silo.cs 项目: sunnycase/orleans
        private async Task InjectDependencies()
        {
            healthCheckParticipants.Add(membershipOracle);

            catalog.SiloStatusOracle = this.membershipOracle;
            this.membershipOracle.SubscribeToSiloStatusEvents(localGrainDirectory);
            messageCenter.SiloDeadOracle = this.membershipOracle.IsDeadSilo;

            // consistentRingProvider is not a system target per say, but it behaves like the localGrainDirectory, so it is here
            this.membershipOracle.SubscribeToSiloStatusEvents((ISiloStatusListener)RingProvider);

            this.membershipOracle.SubscribeToSiloStatusEvents(typeManager);

            this.membershipOracle.SubscribeToSiloStatusEvents(Services.GetRequiredService <DeploymentLoadPublisher>());

            this.membershipOracle.SubscribeToSiloStatusEvents(Services.GetRequiredService <ClientObserverRegistrar>());

            IOptions <ReminderOptions> reminderOptions = this.Services.GetRequiredService <IOptions <ReminderOptions> >();

            if (!reminderOptions.Value.ReminderService.Equals(ReminderOptions.BuiltIn.Disabled))
            {
                // start the reminder service system target
                reminderService = Services.GetRequiredService <LocalReminderServiceFactory>()
                                  .CreateReminderService(this, initTimeout, this.runtimeClient);
                var reminderServiceSystemTarget = this.reminderService as SystemTarget;
                if (reminderServiceSystemTarget != null)
                {
                    RegisterSystemTarget(reminderServiceSystemTarget);
                }
            }

            RegisterSystemTarget(catalog);
            await scheduler.QueueAction(catalog.Start, catalog.SchedulingContext)
            .WithTimeout(initTimeout, $"Starting Catalog failed due to timeout {initTimeout}");

            // SystemTarget for provider init calls
            this.fallbackScheduler = Services.GetRequiredService <FallbackSystemTarget>();

            RegisterSystemTarget(fallbackScheduler);
        }
示例#12
0
 internal void RegisterSystemTarget(SystemTarget target)
 {
     scheduler.RegisterWorkContext(target.SchedulingContext);
     activationDirectory.RecordNewSystemTarget(target);
 }
 /// <summary>
 /// Schedules the provided <paramref name="action"/> on the <see cref="SystemTarget"/>.
 /// </summary>
 /// <param name="self">The <see cref="SystemTarget"/>.</param>
 /// <param name="action">The action.</param>
 /// <returns>A <see cref="Task"/> which completes when the <paramref name="action"/> has completed.</returns>
 public static Task ScheduleTask(this SystemTarget self, Action action)
 {
     return(self.RuntimeClient.Scheduler.RunOrQueueAction(action, self));
 }
示例#14
0
 /// <summary>
 /// Schedules the provided <paramref name="action"/> on the <see cref="SystemTarget"/>.
 /// </summary>
 /// <param name="self">The <see cref="SystemTarget"/>.</param>
 /// <param name="action">The action.</param>
 /// <returns>A <see cref="Task"/> which completes when the <paramref name="action"/> has completed.</returns>
 public static Task <T> ScheduleTask <T>(this SystemTarget self, Func <Task <T> > action)
 {
     return(self.RuntimeClient.Scheduler.RunOrQueueTask(action, self));
 }
示例#15
0
        public void ReceiveMessage(Message msg)
        {
            this.messagingTrace.OnIncomingMessageAgentReceiveMessage(msg);

            // Find the activation it targets; first check for a system activation, then an app activation
            if (msg.TargetGrain.IsSystemTarget())
            {
                SystemTarget target = this.activationDirectory.FindSystemTarget(msg.TargetActivation);
                if (target == null)
                {
                    MessagingStatisticsGroup.OnRejectedMessage(msg);
                    Message response = this.messageFactory.CreateRejectionResponse(msg, Message.RejectionTypes.Unrecoverable,
                                                                                   string.Format("SystemTarget {0} not active on this silo. Msg={1}", msg.TargetGrain, msg));
                    this.messageCenter.SendMessage(response);
                    this.logger.LogWarning(
                        (int)ErrorCode.MessagingMessageFromUnknownActivation,
                        "Received a message {Message} for an unknown SystemTarget: {Target}",
                        msg,
                        msg.TargetAddress);
                    return;
                }

                target.ReceiveMessage(msg);
            }
            else if (messageCenter.TryDeliverToProxy(msg))
            {
                return;
            }
            else
            {
                try
                {
                    var targetActivation = catalog.GetOrCreateActivation(
                        msg.TargetAddress,
                        msg.IsNewPlacement,
                        msg.RequestContextData);

                    if (targetActivation is null)
                    {
                        // Activation does not exists and is not a new placement.
                        if (msg.Direction == Message.Directions.Response)
                        {
                            logger.LogWarning(
                                (int)ErrorCode.Dispatcher_NoTargetActivation,
                                "No target activation {Activation} for response message: {Message}",
                                msg.TargetActivation,
                                msg);
                            return;
                        }
                        else
                        {
                            logger.LogInformation(
                                (int)ErrorCode.Dispatcher_Intermediate_GetOrCreateActivation,
                                "Intermediate NonExistentActivation for message {Message}",
                                msg);

                            var nonExistentActivation = msg.TargetAddress;
                            ProcessRequestToInvalidActivation(msg, nonExistentActivation, null, "Non-existent activation");
                            return;
                        }
                    }

                    targetActivation.ReceiveMessage(msg);
                }
                catch (Exception ex)
                {
                    MessagingProcessingStatisticsGroup.OnDispatcherMessageProcessedError(msg);
                    logger.LogError(
                        (int)ErrorCode.Dispatcher_ErrorCreatingActivation,
                        ex,
                        "Error creating activation for grain {TargetGrain} (interface: {InterfaceType}). Message {Message}",
                        msg.TargetGrain,
                        msg.InterfaceType,
                        msg);

                    this.RejectMessage(msg, Message.RejectionTypes.Transient, ex);
                }
            }
        }
示例#16
0
 internal void RegisterSystemTarget(SystemTarget target) => this.catalog.RegisterSystemTarget(target);
示例#17
0
文件: Silo.cs 项目: Carlm-MS/orleans
 internal void UnregisterSystemTarget(SystemTarget target)
 {
     activationDirectory.RemoveSystemTarget(target);
     scheduler.UnregisterWorkContext(target.SchedulingContext);
 }
示例#18
0
文件: Silo.cs 项目: Carlm-MS/orleans
 internal void RegisterSystemTarget(SystemTarget target)
 {
     scheduler.RegisterWorkContext(target.SchedulingContext);
     activationDirectory.RecordNewSystemTarget(target);
 }
示例#19
0
 internal void UnregisterSystemTarget(SystemTarget target)
 {
     activationDirectory.RemoveSystemTarget(target);
     scheduler.UnregisterWorkContext(target.SchedulingContext);
 }
示例#20
0
        internal void RegisterSystemTarget(SystemTarget target)
        {
            var providerRuntime = this.Services.GetRequiredService <SiloProviderRuntime>();

            providerRuntime.RegisterSystemTarget(target);
        }
示例#21
0
 /// <summary>
 /// Schedules the provided <paramref name="action"/> on the <see cref="SystemTarget"/>'s <see cref="ISchedulingContext"/>.
 /// </summary>
 /// <param name="self">The <see cref="SystemTarget"/>.</param>
 /// <param name="action">The action.</param>
 /// <returns>A <see cref="Task"/> which completes when the <paramref name="action"/> has completed.</returns>
 public static Task ScheduleTask(this SystemTarget self, Func <Task> action)
 {
     return(self.RuntimeClient.Scheduler.RunOrQueueTask(action, self.SchedulingContext));
 }