internal static IActorStateProvider GetActorStateProviderOverride()
        {
            IActorStateProvider stateProvider = null;

            try
            {
                var configurationPackageName         = ActorNameFormat.GetConfigPackageName();
                var stateProviderOverrideSectionName = ActorNameFormat.GetActorStateProviderOverrideSectionName();
                var attributeTypeKey = ActorNameFormat.GetActorStateProviderOverrideKeyName();

                // Load the ActorStateProviderAttribute Type from the Configuration settings
                var context = FabricRuntime.GetActivationContext();
                var config  = context.GetConfigurationPackageObject(configurationPackageName);

                if ((config.Settings.Sections != null) &&
                    (config.Settings.Sections.Contains(stateProviderOverrideSectionName)))
                {
                    var section           = config.Settings.Sections[stateProviderOverrideSectionName];
                    var stateProviderType = section.Parameters[attributeTypeKey].Value;
                    stateProvider = Activator.CreateInstance(Type.GetType(stateProviderType)) as IActorStateProvider;
                }
            }
            catch (Exception)
            {
                // ignore
            }

            return(stateProvider);
        }
        public async Task <TState> Migrate(int currentStateVersion, IActorStateProvider stateProvider, ActorId actorId, string stateKey, string versionKey)
        {
            if (currentStateVersion == _version)
            {
                if (await stateProvider.ContainsStateAsync(actorId, stateKey, CancellationToken.None))
                {
                    var state = await stateProvider.LoadStateAsync <TState>(actorId, stateKey, CancellationToken.None);

                    return(state);
                }
            }
            else if (currentStateVersion < _version)
            {
                var oldState = await MigratePredecessor(currentStateVersion, stateProvider, actorId, stateKey, versionKey);

                var state = MigrateUp(oldState);

                await stateProvider.SaveStateAsync(actorId,
                                                   new ActorStateChange[] { new ActorStateChange(stateKey, typeof(TState), state, StateChangeKind.Update) },
                                                   CancellationToken.None);

                return(state);
            }
            await stateProvider.SaveStateAsync(actorId,
                                               new ActorStateChange[] { new ActorStateChange(stateKey, typeof(int), _version, StateChangeKind.Update) },
                                               CancellationToken.None);

            return(default(TState));
        }
Exemple #3
0
 public void RegisterActorFactory <TActor>(
     ILifetimeScope container,
     Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
     IActorStateProvider stateProvider = null,
     ActorServiceSettings settings     = null) where TActor : ActorBase
 {
     ActorRuntime.RegisterActorAsync <TActor>((context, actorTypeInfo) =>
     {
         return(new ActorService(context, actorTypeInfo, (actorService, actorId) =>
         {
             var lifetimeScope = container.BeginLifetimeScope(builder =>
             {
                 builder.RegisterInstance(context)
                 .As <StatefulServiceContext>()
                 .As <ServiceContext>();
                 builder.RegisterInstance(actorService)
                 .As <ActorService>();
                 builder.RegisterInstance(actorId)
                 .As <ActorId>();
             });
             var actor = lifetimeScope.Resolve <TActor>();
             return actor;
         }, stateManagerFactory, stateProvider, settings));
     }).GetAwaiter().GetResult();
 }
        RegisterActor <TActor>(
            this ContainerBuilder builder,
            Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
            IActorStateProvider stateProvider = null,
            ActorServiceSettings settings     = null)
            where TActor : ActorBase
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var actorType = typeof(TActor);

            if (!actorType.CanBeProxied())
            {
                throw new ArgumentException(actorType.GetInvalidProxyTypeErrorMessage());
            }

            var registration = builder.RegisterServiceWithInterception <TActor, ActorInterceptor>();

            registration.EnsureRegistrationIsInstancePerLifetimeScope();

            var creator = new ServiceFabricRegistrationCreator(c => c.Resolve <IActorFactoryRegistration>().RegisterActorFactory <TActor>(
                                                                   c, stateManagerFactory, stateProvider, settings));

            builder.RegisterInstance(creator)
            .As <IServiceFabricRegistrationCreator>();

            // builder.RegisterBuildCallback(
            //    c => c.Resolve<IActorFactoryRegistration>().RegisterActorFactory<TActor>(
            //        c, stateManagerFactory, stateProvider, settings));
            return(registration);
        }
        public MockActorService(
            ICodePackageActivationContext codePackageActivationContext,
            IServiceProxyFactory serviceProxyFactory,
            IActorProxyFactory actorProxyFactory,
            NodeContext nodeContext,
            StatefulServiceContext statefulServiceContext,
            ActorTypeInformation actorTypeInfo,
            Func <ActorService, ActorId, ActorBase> actorFactory = null,
            Func <ActorBase, IActorStateProvider,
                  IActorStateManager> stateManagerFactory = null,
            IActorStateProvider stateProvider             = null,
            ActorServiceSettings settings = null

            ) :
            base(
                context: statefulServiceContext,
                actorTypeInfo: actorTypeInfo,
                actorFactory: actorFactory,
                stateManagerFactory: stateManagerFactory,
                stateProvider: stateProvider,
                settings: settings)
        {
            _codePackageActivationContext = codePackageActivationContext;
            _serviceProxyFactory          = serviceProxyFactory;
            _actorProxyFactory            = actorProxyFactory;
            _nodeContext = nodeContext;
        }
Exemple #6
0
 public TestObservableObserverActorService(StatefulServiceContext context,
                                           ActorTypeInformation actorTypeInfo,
                                           Func <ActorBase> actorFactory     = null,
                                           IActorStateProvider stateProvider = null,
                                           ActorServiceSettings settings     = null)
     : base(context, actorTypeInfo, actorFactory, stateProvider, settings)
 {
 }
        public TransactionManagerActorGarbageCollector(IActorStateProvider actorStateProvider, TimeSpan scanInterval, CancellationToken cancellationToken)
        {
            this.actorStateProvider = actorStateProvider;
            this.scanInterval       = scanInterval;
            this.cancellationToken  = cancellationToken;

            this.StartScanning();
        }
        public DeviceActorService(
            StatefulServiceContext context,
            ActorTypeInformation typeInfo,
            Func <ActorBase> actorFactory     = null,
            IActorStateProvider stateProvider = null,
            ActorServiceSettings settings     = null)
            : base(context, typeInfo, actorFactory, stateProvider, settings)
        {
            // Read settings from the DeviceActorServiceConfig section in the Settings.xml file
            ICodePackageActivationContext activationContext = context.CodePackageActivationContext;
            ConfigurationPackage          config            = activationContext.GetConfigurationPackageObject(ConfigurationPackage);
            ConfigurationSection          section           = config.Settings.Sections[ConfigurationSection];

            // Read the ServiceBusConnectionString setting from the Settings.xml file
            ConfigurationProperty parameter = section.Parameters[ServiceBusConnectionStringParameter];

            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                this.ServiceBusConnectionString = parameter.Value;
            }
            else
            {
                throw new ArgumentException(
                          string.Format(ParameterCannotBeNullFormat, ServiceBusConnectionStringParameter),
                          ServiceBusConnectionStringParameter);
            }

            // Read the EventHubName setting from the Settings.xml file
            parameter = section.Parameters[EventHubNameParameter];
            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                this.EventHubName = parameter.Value;
            }
            else
            {
                throw new ArgumentException(
                          string.Format(ParameterCannotBeNullFormat, EventHubNameParameter),
                          EventHubNameParameter);
            }

            // Read the QueueLength setting from the Settings.xml file
            parameter = section.Parameters[QueueLengthParameter];
            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                this.QueueLength = DefaultQueueLength;
                int queueLength;
                if (int.TryParse(parameter.Value, out queueLength))
                {
                    this.QueueLength = queueLength;
                }
            }
            else
            {
                throw new ArgumentException(
                          string.Format(ParameterCannotBeNullFormat, QueueLengthParameter),
                          QueueLengthParameter);
            }
        }
Exemple #9
0
 protected ObservableObserverActorServiceBase(StatefulServiceContext context,
                                              ActorTypeInformation actorTypeInfo,
                                              Func <ActorBase> actorFactory     = null,
                                              IActorStateProvider stateProvider = null,
                                              ActorServiceSettings settings     = null)
     : base(context, actorTypeInfo, actorFactory, stateProvider, settings)
 {
     ConfigurationHelper.Initialize(this.Context);
 }
Exemple #10
0
 public ActorBaseService(
     StatefulServiceContext context,
     ActorTypeInformation actorTypeInfo,
     Func <ActorService, ActorId, ActorBase> actorFactory,
     Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
     IActorStateProvider stateProvider = null,
     ActorServiceSettings settings     = null) : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
 }
 public ActorDemoActorService(
     StatefulServiceContext context,
     ActorTypeInformation actorTypeInfo,
     Func <ActorService, ActorId, Actors.Runtime.ActorBase> actorFactory = null,
     Func <Microsoft.ServiceFabric.Actors.Runtime.ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
     IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) :
     base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
 }
 public NodeManagerService(
     StatefulServiceContext context,
     ActorTypeInformation actorTypeInfo,
     Func <ActorService, ActorId, ActorBase> actorFactory = null,
     Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
     IActorStateProvider stateProvider = null, ActorServiceSettings settings = null)
     : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     this.nodeManagerSettings = new NodeManagerSettings(context.CodePackageActivationContext.GetConfigurationPackageObject(this.configurationPackageName).Settings);
 }
Exemple #13
0
 public CommonActorService(StatefulServiceContext context, ActorTypeInformation actorTypeInfo,
                           ILoggerFactory loggerFactory,
                           LoggerConfiguration loggerConfiguration = null,
                           Func <ActorService, ActorId, ActorBase> actorFactory = null,
                           Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
                           IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) : base(context,
                                                                                                                  actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     Logger = loggerFactory.CreateLogger(GetType());
 }
 public ActorServiceEapBase(StatefulServiceContext context,
                            ActorTypeInformation actorTypeInfo,
                            DiagnosticPipeline diagnosticPipeline,
                            Func <ActorService, ActorId, ActorBase> actorFactory = null,
                            Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
                            IActorStateProvider stateProvider = null, ActorServiceSettings settings = null)
     : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     CreateSerilog(diagnosticPipeline);
 }
Exemple #15
0
 public ActorBackendRemotingV1Service(
     StatefulServiceContext context,
     ActorTypeInformation actorTypeInfo,
     Func <ActorService, ActorId, ActorBase> actorFactory = null,
     Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
     IActorStateProvider stateProvider = null,
     ActorServiceSettings settings     = null)
     : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     FabricTelemetryInitializerExtension.SetServiceCallContext(context);
 }
        public void RegisterActorFactory <TActor>(
            ILifetimeScope container,
            Type actorServiceType,
            Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
            IActorStateProvider stateProvider     = null,
            ActorServiceSettings settings         = null,
            object lifetimeScopeTag               = null,
            Action <ILifetimeScope> scopeCallback = null)
            where TActor : ActorBase
        {
            ActorRuntime.RegisterActorAsync <TActor>((context, actorTypeInfo) =>
            {
                ActorBase ActorFactory(ActorService actorService, ActorId actorId)
                {
                    var tag = lifetimeScopeTag ?? Constants.DefaultLifetimeScopeTag;

                    var lifetimeScope = container.BeginLifetimeScope(tag, builder =>
                    {
                        builder.RegisterInstance(context)
                        .As <StatefulServiceContext>()
                        .As <ServiceContext>();
                        builder.RegisterInstance(actorService)
                        .As <ActorService>();
                        builder.RegisterInstance(actorId)
                        .As <ActorId>();
                    });

                    scopeCallback?.Invoke(lifetimeScope);

                    try
                    {
                        var actor = lifetimeScope.Resolve <TActor>();
                        return(actor);
                    }
                    catch (Exception ex)
                    {
                        // Proactively dispose lifetime scope as interceptor will not be called.
                        lifetimeScope.Dispose();

                        this.ConstructorExceptionCallback(ex);
                        throw;
                    }
                }

                return((ActorService)container.Resolve(
                           actorServiceType,
                           new TypedParameter(typeof(StatefulServiceContext), context),
                           new TypedParameter(typeof(ActorTypeInformation), actorTypeInfo),
                           new TypedParameter(typeof(Func <ActorService, ActorId, ActorBase>), (Func <ActorService, ActorId, ActorBase>)ActorFactory),
                           new TypedParameter(typeof(Func <ActorBase, IActorStateProvider, IActorStateManager>), stateManagerFactory),
                           new TypedParameter(typeof(IStateProvider), stateProvider),
                           new TypedParameter(typeof(ActorServiceSettings), settings)));
            }).GetAwaiter().GetResult();
        }
        public DeviceActorService(StatefulServiceContext context, 
                                  ActorTypeInformation typeInfo,
                                  Func<ActorBase> actorFactory = null, 
                                  IActorStateProvider stateProvider = null, 
                                  ActorServiceSettings settings = null)
            : base(context, typeInfo, actorFactory, stateProvider, settings)
        {
            // Read settings from the DeviceActorServiceConfig section in the Settings.xml file
            var activationContext = Context.CodePackageActivationContext;
            var config = activationContext.GetConfigurationPackageObject(ConfigurationPackage);
            var section = config.Settings.Sections[ConfigurationSection];

            // Read the ServiceBusConnectionString setting from the Settings.xml file
            var parameter = section.Parameters[ServiceBusConnectionStringParameter];
            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                ServiceBusConnectionString = parameter.Value;
            }
            else
            {
                throw new ArgumentException(
                    string.Format(ParameterCannotBeNullFormat, ServiceBusConnectionStringParameter),
                                  ServiceBusConnectionStringParameter);
            }

            // Read the EventHubName setting from the Settings.xml file
            parameter = section.Parameters[EventHubNameParameter];
            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                EventHubName = parameter.Value;
            }
            else
            {
                throw new ArgumentException(string.Format(ParameterCannotBeNullFormat, EventHubNameParameter),
                                            EventHubNameParameter);
            }

            // Read the QueueLength setting from the Settings.xml file
            parameter = section.Parameters[QueueLengthParameter];
            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                QueueLength = DefaultQueueLength;
                int queueLength;
                if (int.TryParse(parameter.Value, out queueLength))
                {
                    QueueLength = queueLength;
                }
            }
            else
            {
                throw new ArgumentException(string.Format(ParameterCannotBeNullFormat, QueueLengthParameter),
                                            QueueLengthParameter);
            }
        }
 protected BackupRestoreActorService(StatefulServiceContext context,
                                     ActorTypeInformation actorTypeInfo,
                                     IFileStore fileStore,
                                     IServiceEventSource serviceEventSource, Func <ActorService, ActorId, ActorBase> actorFactory = null,
                                     Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
                                     IActorStateProvider stateProvider = null,
                                     ActorServiceSettings settings     = null)
     : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     this._serviceEventSource = serviceEventSource;
     this._fileStore          = fileStore;
 }
 public StudentActorService
 (
     StatefulServiceContext context,
     ActorTypeInformation actorTypeInfo,
     Func <ActorService, ActorId, ActorBase> actorFactory = null,
     Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
     IActorStateProvider stateProvider = null,
     ActorServiceSettings settings     = null) :
     base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     _stateProviderEventStreamReader = new ActorStateProviderEventStreamReader(StateProvider, StudentActor.EventStreamStateKey);
 }
 /// <summary>
 /// Creates a new instance, using the provided arguments.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="actorTypeInfo"></param>
 /// <param name="centralBackupStore"></param>
 /// <param name="logCallback"></param>
 /// <param name="actorFactory"></param>
 /// <param name="stateManagerFactory"></param>
 /// <param name="stateProvider"></param>
 /// <param name="settings"></param>
 protected BackupRestoreActorService(StatefulServiceContext context,
                                     ActorTypeInformation actorTypeInfo,
                                     ICentralBackupStore centralBackupStore,
                                     Action <string> logCallback, Func <ActorService, ActorId, ActorBase> actorFactory = null,
                                     Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory     = null,
                                     IActorStateProvider stateProvider = null,
                                     ActorServiceSettings settings     = null)
     : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     _centralBackupStore = centralBackupStore ?? throw new ArgumentNullException(nameof(centralBackupStore));
     _logCallback        = logCallback;
 }
        public static async Task <string> GetActorsInPartition(IActorStateProvider actorStateProvider, CancellationToken cancellationToken)
        {
            List <ActorId> actorsInPartition = await GetAllActorsInCurrentPartitionAsync(actorStateProvider, cancellationToken);

            var actorPartitionMetadata = new ActorPartitionMetadata
            {
                count  = actorsInPartition.Count,
                actors = actorsInPartition
            };

            return(actorPartitionMetadata.ToString());
        }
Exemple #22
0
 protected EventStoredActorService
     (StatefulServiceContext context,
     ActorTypeInformation actorTypeInfo,
     Func <Microsoft.ServiceFabric.Actors.Runtime.ActorService, ActorId, ActorBase> actorFactory = null,
     Func <Microsoft.ServiceFabric.Actors.Runtime.ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
     IActorStateProvider stateProvider = null,
     ActorServiceSettings settings     = null,
     IReliableStateManagerReplica reliableStateManagerReplica = null,
     IEventStreamReader <TEventStream> eventStreamReader      = null)
     : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings, reliableStateManagerReplica)
 {
     StateProviderEventStreamReader = eventStreamReader ?? new EventStreamReader <TEventStream>(StateProvider, EventStoredActor <TAggregateRoot, TEventStream> .EventStreamStateKey);
 }
Exemple #23
0
 public PipelineRunnerActorService(
     StatefulServiceContext context, ActorTypeInformation actorTypeInfo,
     Func <ActorService, ActorId, ActorBase> actorFactory, Func <ActorBase, IActorStateProvider,
                                                                 IActorStateManager> stateManagerFactory = null,
     IActorStateProvider stateProvider = null)
     : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, new ActorServiceSettings
 {
     ActorGarbageCollectionSettings = new ActorGarbageCollectionSettings(300, 60)
     {
     }
 })
 {
 }
 public Actor1Service(StatefulServiceContext context, ActorTypeInformation actorTypeInfo,
                      Func <ActorService, ActorId, ActorBase> actorFactory = null,
                      Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
                      IActorStateProvider stateProvider = null, ActorServiceSettings settings = null)
     : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     _connectionString = context
                         .CodePackageActivationContext
                         .GetConfigurationPackageObject("Config")
                         .Settings
                         .Sections["BusConfig"]
                         .Parameters["AzureServiceBusConnectionString"].Value;
 }
Exemple #25
0
 public DefaultFtpActionService(StatefulServiceContext context, ActorTypeInformation actorTypeInfo,
                                ILoggerFactory loggerFactory,
                                string scalerActorServiceName,
                                string scalerActorId,
                                LoggerConfiguration loggerConfiguration = null,
                                Func <ActorService, ActorId, ActorBase> actorFactory = null,
                                Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
                                IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) : base(context,
                                                                                                                       actorTypeInfo, loggerFactory, loggerConfiguration, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     _scalerActorServiceName = scalerActorServiceName;
     _scalerActorId          = scalerActorId;
 }
Exemple #26
0
 public ActorService(
     StatefulServiceContext context,
     ActorTypeInformation actorTypeInfo,
     Func <Microsoft.ServiceFabric.Actors.Runtime.ActorService, ActorId, ActorBase> actorFactory = null,
     Func <Microsoft.ServiceFabric.Actors.Runtime.ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
     IActorStateProvider stateProvider = null,
     ActorServiceSettings settings     = null,
     IReliableStateManagerReplica reliableStateManagerReplica = null) :
     base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     StateManager = reliableStateManagerReplica ??
                    (IReliableStateManagerReplica) new ReliableStateManager(context, (ReliableStateManagerConfiguration)null);
 }
        public static async Task <string> GetActorDetails(IActorStateProvider actorStateProvider, ActorId actorId, CancellationToken cancellationToken)
        {
            IEnumerable <string> stateKeys = await actorStateProvider.EnumerateStateNamesAsync(actorId, cancellationToken);

            var actorDetails = new Dictionary <string, object>();

            foreach (var stateKey in stateKeys)
            {
                object value = await actorStateProvider.LoadStateAsync <object>(actorId, stateKey, cancellationToken);

                actorDetails.Add(stateKey, value);
            }

            return(JsonConvert.SerializeObject(actorDetails));
        }
Exemple #28
0
 private ActorService GetMockActorService(
     StatefulServiceContext serviceContext,
     ActorTypeInformation actorTypeInformation,
     IActorStateProvider actorStateProvider,
     Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory)
 {
     return((ActorService) new MockActorService(
                codePackageActivationContext: _fabricRuntime.CodePackageContext,
                serviceProxyFactory: _fabricRuntime.ServiceProxyFactory,
                actorProxyFactory: _fabricRuntime.ActorProxyFactory,
                nodeContext: _fabricRuntime.BuildNodeContext(),
                statefulServiceContext: serviceContext,
                actorTypeInfo: actorTypeInformation,
                stateManagerFactory: stateManagerFactory,
                stateProvider: actorStateProvider));
 }
Exemple #29
0
 public FtpSchedulerActorService(StatefulServiceContext context,
                                 ActorTypeInformation actorTypeInfo,
                                 ILoggerFactory loggerFactory,
                                 IServiceConfiguration serviceConfiguration,
                                 string schedulerActorServiceName,
                                 string sectionKeyName = null,
                                 LoggerConfiguration loggerConfiguration = null,
                                 Func <ActorService, ActorId, ActorBase> actorFactory = null,
                                 Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
                                 IActorStateProvider stateProvider = null,
                                 ActorServiceSettings settings     = null) : base(context, actorTypeInfo, loggerFactory, loggerConfiguration, actorFactory, stateManagerFactory, stateProvider, settings)
 {
     ServiceConfiguration      = serviceConfiguration;
     SectionKeyName            = sectionKeyName ?? this.GetType().Name;
     SchedulerActorServiceName = schedulerActorServiceName;
 }
        RegisterActor <TActor>(
            this ContainerBuilder builder,
            Type actorServiceType = null,
            Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
            IActorStateProvider stateProvider     = null,
            ActorServiceSettings settings         = null,
            object lifetimeScopeTag               = null,
            Action <ILifetimeScope> scopeCallback = null)
            where TActor : ActorBase
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var actorType = typeof(TActor);

            if (!actorType.CanBeProxied())
            {
                throw new ArgumentException(actorType.GetInvalidProxyTypeErrorMessage());
            }

            if (actorServiceType == null)
            {
                actorServiceType = typeof(ActorService);
            }
            else
            {
                builder.RegisterType(actorServiceType).AsSelf().IfNotRegistered(actorServiceType);
            }

            if (!typeof(ActorService).IsAssignableFrom(actorServiceType))
            {
                throw new ArgumentException(actorServiceType.GetInvalidActorServiceTypeErrorMessage());
            }

            var registration = builder.RegisterServiceWithInterception <TActor, ActorInterceptor>(lifetimeScopeTag);

            registration.EnsureRegistrationIsInstancePerLifetimeScope();

            builder.RegisterBuildCallback(
                c => c.Resolve <IActorFactoryRegistration>().RegisterActorFactory <TActor>(
                    c, actorServiceType, stateManagerFactory, stateProvider, settings, lifetimeScopeTag, scopeCallback));

            return(registration);
        }
Exemple #31
0
        public WorkerActorService(StatefulServiceContext context,
                                  ActorTypeInformation typeInfo,
                                  Func <ActorService, ActorId, ActorBase> actorFactory,
                                  Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory,
                                  IActorStateProvider stateProvider = null,
                                  ActorServiceSettings settings     = null)
            : base(context, typeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
        {
            // Read Settings
            ReadSettings(context.CodePackageActivationContext.GetConfigurationPackageObject(ConfigurationPackage));

            // Creates event handlers for configuration changes
            context.CodePackageActivationContext.ConfigurationPackageAddedEvent +=
                CodePackageActivationContext_ConfigurationPackageAddedEvent;
            context.CodePackageActivationContext.ConfigurationPackageModifiedEvent +=
                CodePackageActivationContext_ConfigurationPackageModifiedEvent;
            context.CodePackageActivationContext.ConfigurationPackageRemovedEvent +=
                CodePackageActivationContext_ConfigurationPackageRemovedEvent;
        }
 public TelemetryEnabledActorService(StatefulServiceContext context, ActorTypeInformation actorTypeInfo, Func<ActorBase> actorFactory = null, IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) : base(context, actorTypeInfo, actorFactory, stateProvider, settings)
 {}