Exemple #1
0
        void IStateProviderReplica.Initialize(StatefulServiceInitializationParameters initializationParameters)
        {
            this.initiParams = initializationParameters;
            this.traceId     = ActorTrace.GetTraceIdForReplica(this.initiParams.PartitionId, this.initiParams.ReplicaId);

            var statefulServiceContext = new StatefulServiceContext(
                FabricRuntime.GetNodeContext(),
                this.initiParams.CodePackageActivationContext,
                this.initiParams.ServiceTypeName,
                this.initiParams.ServiceName,
                this.initiParams.InitializationData,
                this.initiParams.PartitionId,
                this.initiParams.ReplicaId);

            var stateManagerConfig = this.userDefinedStateManagerConfig;

            if (stateManagerConfig == null)
            {
                var actorImplType = this.actorTypeInformation.ImplementationType;

                stateManagerConfig = new ReliableStateManagerConfiguration(
                    ActorNameFormat.GetConfigPackageName(actorImplType),
                    ActorNameFormat.GetFabricServiceReplicatorSecurityConfigSectionName(actorImplType),
                    ActorNameFormat.GetFabricServiceReplicatorConfigSectionName(actorImplType));
            }

            this.stateManager = new ReliableStateManager(statefulServiceContext, stateManagerConfig);

            ReleaseAssert.AssertIfNull(this.onDataLossAsyncFunc, "onDataLossAsync event handler cannot be null.");
            this.stateManager.OnDataLossAsync = this.onDataLossAsyncFunc;

            this.stateManager.Initialize(this.initiParams);
        }
        /// <summary>
        /// This is used by Kvs and Volatile actor state provider.
        /// </summary>
        /// <param name="codePackage"></param>
        /// <param name="actorImplType"></param>
        /// <returns></returns>
        internal static ReplicatorSettings GetActorReplicatorSettings(CodePackageActivationContext codePackage, Type actorImplType)
        {
            var settings = ReplicatorSettings.LoadFrom(
                codePackage,
                ActorNameFormat.GetConfigPackageName(actorImplType),
                ActorNameFormat.GetFabricServiceReplicatorConfigSectionName(actorImplType));

            settings.SecurityCredentials = SecurityCredentials.LoadFrom(
                codePackage,
                ActorNameFormat.GetConfigPackageName(actorImplType),
                ActorNameFormat.GetFabricServiceReplicatorSecurityConfigSectionName(actorImplType));

            var nodeContext = FabricRuntime.GetNodeContext();
            var endpoint    = codePackage.GetEndpoint(ActorNameFormat.GetFabricServiceReplicatorEndpointName(actorImplType));

            settings.ReplicatorAddress = string.Format(
                CultureInfo.InvariantCulture,
                "{0}:{1}",
                nodeContext.IPAddressOrFQDN,
                endpoint.Port);

            if (!settings.MaxPrimaryReplicationQueueSize.HasValue)
            {
                settings.MaxPrimaryReplicationQueueSize = DefaultMaxPrimaryReplicationQueueSize;
            }

            if (!settings.MaxSecondaryReplicationQueueSize.HasValue)
            {
                settings.MaxSecondaryReplicationQueueSize = DefaultMaxSecondaryReplicationQueueSize;
            }

            return(settings);
        }