Ejemplo n.º 1
0
        /// <summary>
        /// <see cref="ReliableCollectionsActorStateProvider"/> is currently in PREVIEW.
        /// Initializes a new instance of the ReliableDictionaryActorStateProvider class
        /// with specified configuration.
        /// </summary>
        /// <param name="stateManagerConfig">
        /// A <see cref="ReliableStateManagerConfiguration"/> that describes <see cref="IReliableStateManager"/> configuration.
        /// </param>
        /// <param name="actorStateDictionaryCount">
        /// Number of <see cref="IReliableDictionary{TKey, TValue}"/> across which actor states will be partitioned and stored.
        /// </param>
        /// <param name="reminderDictionaryCount">
        /// Number of <see cref="IReliableDictionary{TKey, TValue}"/> across which reminders will be partitioned and stored.
        /// </param>
        /// <remarks>
        /// Values for <paramref name="actorStateDictionaryCount"/> and <paramref name="reminderDictionaryCount"/> can be specified
        /// only once when the Actor Service is created for first time. It cannot be changed after that and
        /// <see cref="ReliableCollectionsActorStateProvider"/> will ignore any values that are different from first time.
        /// </remarks>
        public ReliableCollectionsActorStateProvider(
            ReliableStateManagerConfiguration stateManagerConfig,
            int actorStateDictionaryCount,
            int reminderDictionaryCount)
        {
            if (actorStateDictionaryCount < 1)
            {
                throw new ArgumentException("Value for actorStateDictionaryCount cannot be less than 1.");
            }

            if (reminderDictionaryCount < 1)
            {
                throw new ArgumentException("Value for reminderDictionaryCount cannot be less than 1.");
            }

            this.traceId = string.Empty;
            this.isLogicalTimeManagerInitialized = false;
            this.isDictionariesInitialized       = false;
            this.replicaRole = ReplicaRole.Unknown;
            this.transientErrorRetryDelay             = TimeSpan.FromSeconds(DefaultTransientErrorRetryDelaySeconds);
            this.userDefinedStateManagerConfig        = stateManagerConfig;
            this.userDefinedActorStateDictionaryCount = actorStateDictionaryCount;
            this.userDefinedReminderDictionaryCount   = reminderDictionaryCount;
            this.logicalTimeManager   = new VolatileLogicalTimeManager(this);
            this.actorStateSerializer = new ActorStateProviderSerializer();
            this.stateProviderHelper  = new ActorStateProviderHelper(this);
        }
        Task IActorStateProvider.ActorActivatedAsync(ActorId actorId, CancellationToken cancellationToken)
        {
            var key = ActorStateProviderHelper.CreateActorPresenceStorageKey(actorId);

            this.stateDictionary.TryAdd(key, null);

            return(Task.FromResult(true));
        }
 private ReplicatorSettings GetReplicatorSettings()
 {
     // Even though NullActorStateProvider don't replicate any state, we need
     // to keep the copy stream and the replication stream drained at all times.
     // This is required in order to unblock role changes. Hence we need to
     // specify a valid replicator address in the settings.
     return(ActorStateProviderHelper.GetActorReplicatorSettings(
                this.initParams.CodePackageActivationContext,
                this.actorTypeInformation.ImplementationType));
 }
        protected void LoadFromSettings(
            ICodePackageActivationContext activationContext,
            string configPackageName,
            string sectionName)
        {
            ConfigurationSection section;

            if (ActorStateProviderHelper.TryGetConfigSection(activationContext, configPackageName, sectionName, out section))
            {
                this.LoadFromSection(section);
            }
        }
        protected virtual void LoadFromSection(ConfigurationSection section)
        {
            this.TransientErrorRetryDelay = ActorStateProviderHelper.GetTimeConfigInSecondsAsTimeSpan(
                section,
                TransientErrorRetryDelayParameterName,
                this.TransientErrorRetryDelay);

            this.OperationTimeout = ActorStateProviderHelper.GetTimeConfigInSecondsAsTimeSpan(
                section,
                OperationTimeoutParameterName,
                this.OperationTimeout);
        }
        protected override void LoadFromSection(ConfigurationSection section)
        {
            base.LoadFromSection(section);

            this.BackupCallbackSlowCancellationHealthReportTimeToLive = ActorStateProviderHelper.GetTimeConfigInSecondsAsTimeSpan(
                section,
                BackupCallbackSlowCancellationHealthReportTimeToLiveParameterName,
                this.BackupCallbackSlowCancellationHealthReportTimeToLive);

            this.BackupCallbackExpectedCancellationTime = ActorStateProviderHelper.GetTimeConfigInSecondsAsTimeSpan(
                section,
                BackupCallbackExpectedCancellationTimeParameterName,
                this.BackupCallbackExpectedCancellationTime);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ActorService"/> class.
        /// </summary>
        /// <param name="context">Service context the actor service is operating under.</param>
        /// <param name="actorTypeInfo">The type information of the Actor.</param>
        /// <param name="actorFactory">The factory method to create Actor objects.</param>
        /// <param name="stateManagerFactory">The factory method to create <see cref="IActorStateManager"/></param>
        /// <param name="stateProvider">The state provider to store and access the state of the Actor objects.</param>
        /// <param name="settings">The settings used to configure the behavior of the Actor service.</param>
        public ActorService(
            StatefulServiceContext context,
            ActorTypeInformation actorTypeInfo,
            Func <ActorService, ActorId, ActorBase> actorFactory = null,
            Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
            IActorStateProvider stateProvider = null,
            ActorServiceSettings settings     = null)
            : base(
                context,
                stateProvider ?? ActorStateProviderHelper.CreateDefaultStateProvider(actorTypeInfo))
        {
            this.actorTypeInformation = actorTypeInfo;
            this.stateProvider        = (IActorStateProvider)this.StateProviderReplica;
            this.settings             = ActorServiceSettings.DeepCopyFromOrDefaultOnNull(settings);

            // Set internal components
            this.actorActivator      = new ActorActivator(actorFactory ?? this.DefaultActorFactory);
            this.stateManagerFactory = stateManagerFactory ?? DefaultActorStateManagerFactory;
            this.actorManagerAdapter = new ActorManagerAdapter {
                ActorManager = new MockActorManager(this)
            };
            this.replicaRole = ReplicaRole.Unknown;
        }
        Task IActorStateProvider.RemoveActorAsync(ActorId actorId, CancellationToken cancellationToken)
        {
            var actorStorageKeyPrefix    = CreateActorStorageKeyPrefix(actorId, string.Empty);
            var reminderStorgaeKeyPrefix = CreateReminderStorageKeyPrefix(actorId, string.Empty);

            object value;

            foreach (var kvPair in this.stateDictionary)
            {
                if (kvPair.Key.StartsWith(actorStorageKeyPrefix) ||
                    kvPair.Key.StartsWith(reminderStorgaeKeyPrefix))
                {
                    this.stateDictionary.TryRemove(kvPair.Key, out value);
                }
            }

            // Delete actor presence key
            var key = ActorStateProviderHelper.CreateActorPresenceStorageKey(actorId);

            this.stateDictionary.TryRemove(key, out value);

            return(Task.FromResult(true));
        }
 public NullActorStateProvider()
 {
     this.currentRole              = ReplicaRole.Unknown;
     this.stateDictionary          = new ConcurrentDictionary <string, object>();
     this.actorStateProviderHelper = new ActorStateProviderHelper(this);
 }