當前位置: 首頁>>代碼示例>>C#>>正文


C# ActivationData.SetGrainInstance方法代碼示例

本文整理匯總了C#中Orleans.Runtime.ActivationData.SetGrainInstance方法的典型用法代碼示例。如果您正苦於以下問題:C# ActivationData.SetGrainInstance方法的具體用法?C# ActivationData.SetGrainInstance怎麽用?C# ActivationData.SetGrainInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Orleans.Runtime.ActivationData的用法示例。


在下文中一共展示了ActivationData.SetGrainInstance方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CreateGrainInstance

        /// <summary>
        /// Perform just the prompt, local part of creating an activation object
        /// Caller is responsible for registering locally, registering with store and calling its activate routine
        /// </summary>
        /// <param name="grainTypeName"></param>
        /// <param name="data"></param>
        /// <param name="genericArguments"></param>
        /// <returns></returns>
        private void CreateGrainInstance(string grainTypeName, ActivationData data, string genericArguments)
        {
            string grainClassName;
            var interfaceToClassMap = GrainTypeManager.GetGrainInterfaceToClassMap();
            if (!interfaceToClassMap.TryGetValue(grainTypeName, out grainClassName))
            {
                // Lookup from grain type code
                var typeCode = data.Grain.GetTypeCode();
                if (typeCode != 0)
                {
                    PlacementStrategy unused;
                    GetGrainTypeInfo(typeCode, out grainClassName, out unused, genericArguments);
                }
                else
                {
                    grainClassName = grainTypeName;
                }
            }

            GrainTypeData grainTypeData = GrainTypeManager[grainClassName];

            Type grainType = grainTypeData.Type;
            Type stateObjectType = grainTypeData.StateObjectType;
            lock (data)
            {
                var grain = (Grain) Activator.CreateInstance(grainType);
                grain.Identity = data.Identity;
                grain.Runtime = grainRuntime;
                data.SetGrainInstance(grain);

                if (stateObjectType != null)
                {
                    SetupStorageProvider(data);

                    var state = (GrainState)Activator.CreateInstance(stateObjectType);
                    state.InitState(null);
                    data.GrainInstance.GrainState = state;
                    data.GrainInstance.Storage = new GrainStateStorageBridge(data.GrainTypeName, data.GrainInstance, data.StorageProvider);
                }
            }

            activations.IncrementGrainCounter(grainClassName);

            data.GrainInstance.Data = data;

            if (logger.IsVerbose) logger.Verbose("CreateGrainInstance {0}{1}", data.Grain, data.ActivationId);
        }
開發者ID:kucheruk,項目名稱:orleans,代碼行數:55,代碼來源:Catalog.cs

示例2: UnregisterMessageTarget

        /// <summary>
        /// Unregister message target and stop delivering messages to it
        /// </summary>
        /// <param name="activation"></param>
        public void UnregisterMessageTarget(ActivationData activation)
        {
            activations.RemoveTarget(activation);

            // this should be removed once we've refactored the deactivation code path. For now safe to keep.
            ActivationCollector.TryCancelCollection(activation);
            activationsDestroyed.Increment();

            scheduler.UnregisterWorkContext(new SchedulingContext(activation));

            if (activation.GrainInstance == null) return;

            var grainTypeName = TypeUtils.GetFullName(activation.GrainInstanceType);
            activations.DecrementGrainCounter(grainTypeName);
            activation.SetGrainInstance(null);
        }
開發者ID:kucheruk,項目名稱:orleans,代碼行數:20,代碼來源:Catalog.cs

示例3: CreateGrainInstance

        /// <summary>
        /// Perform just the prompt, local part of creating an activation object
        /// Caller is responsible for registering locally, registering with store and calling its activate routine
        /// </summary>
        /// <param name="grainTypeName"></param>
        /// <param name="data"></param>
        /// <param name="genericArguments"></param>
        /// <returns></returns>
        private void CreateGrainInstance(string grainTypeName, ActivationData data, string genericArguments)
        {
            string grainClassName;
            var interfaceToClassMap = GrainTypeManager.GetGrainInterfaceToClassMap();
            if (!interfaceToClassMap.TryGetValue(grainTypeName, out grainClassName))
            {
                // Lookup from grain type code
                var typeCode = data.Grain.GetTypeCode();
                if (typeCode != 0)
                {
                    PlacementStrategy unused;
                    GetGrainTypeInfo(typeCode, out grainClassName, out unused, genericArguments);
                }
                else
                {
                    grainClassName = grainTypeName;
                }
            }

            GrainTypeData grainTypeData = GrainTypeManager[grainClassName];

            Type grainType = grainTypeData.Type;

            // TODO: Change back to GetRequiredService after stable Microsoft.Framework.DependencyInjection is released and can be referenced here
            var services = Runtime.Silo.CurrentSilo.Services;
            var grain = services != null
                ? (Grain) services.GetService(grainType)
                : (Grain) Activator.CreateInstance(grainType);

            // Inject runtime hooks into grain instance
            grain.Runtime = grainRuntime;
            grain.Data = data;

            Type stateObjectType = grainTypeData.StateObjectType;
            object state = null;
            if (stateObjectType != null)
            {
                state = Activator.CreateInstance(stateObjectType);
            }
            
            lock (data)
            {
                grain.Identity = data.Identity;
                data.SetGrainInstance(grain);
                var statefulGrain = grain as IStatefulGrain;
                if (statefulGrain != null)
                {
                    if (state != null)
                    {
                        SetupStorageProvider(data);
                        statefulGrain.GrainState.State = state;
                        statefulGrain.SetStorage(new GrainStateStorageBridge(data.GrainTypeName, statefulGrain,
                            data.StorageProvider));
                    }
                }
            }

            activations.IncrementGrainCounter(grainClassName);

            if (logger.IsVerbose) logger.Verbose("CreateGrainInstance {0}{1}", data.Grain, data.ActivationId);
        }
開發者ID:sbambach,項目名稱:orleans,代碼行數:69,代碼來源:Catalog.cs

示例4: CreateGrainInstance

        /// <summary>
        /// Perform just the prompt, local part of creating an activation object
        /// Caller is responsible for registering locally, registering with store and calling its activate routine
        /// </summary>
        /// <param name="grainTypeName"></param>
        /// <param name="data"></param>
        /// <param name="genericArguments"></param>
        /// <returns></returns>
        private void CreateGrainInstance(string grainTypeName, ActivationData data, string genericArguments)
        {
            string grainClassName;
            if (!GrainTypeManager.TryGetPrimaryImplementation(grainTypeName, out grainClassName))
            {
                // Lookup from grain type code
                var typeCode = data.Grain.GetTypeCode();
                if (typeCode != 0)
                {
                    PlacementStrategy unused;
                    MultiClusterRegistrationStrategy unusedActivationStrategy;
                    GetGrainTypeInfo(typeCode, out grainClassName, out unused, out unusedActivationStrategy, genericArguments);
                }
                else
                {
                    grainClassName = grainTypeName;
                }
            }

            GrainTypeData grainTypeData = GrainTypeManager[grainClassName];

            //Get the grain's type
            Type grainType = grainTypeData.Type;

            //Gets the type for the grain's state
            Type stateObjectType = grainTypeData.StateObjectType;
            
            lock (data)
            {
                Grain grain;

                //Create a new instance of a stateless grain
                if (stateObjectType == null)
                {
                    //Create a new instance of the given grain type
                    grain = grainCreator.CreateGrainInstance(grainType, data.Identity);
                }
                //Create a new instance of a stateful grain
                else
                {
                    SetupStorageProvider(grainType, data);
                    grain = grainCreator.CreateGrainInstance(grainType, data.Identity, stateObjectType, data.StorageProvider);
                }
                grain.Data = data;
                data.SetGrainInstance(grain);
            }

            activations.IncrementGrainCounter(grainClassName);

            if (logger.IsVerbose) logger.Verbose("CreateGrainInstance {0}{1}", data.Grain, data.ActivationId);
        }
開發者ID:Carlm-MS,項目名稱:orleans,代碼行數:59,代碼來源:Catalog.cs

示例5: CreateGrainInstance

        /// <summary>
        /// Perform just the prompt, local part of creating an activation object
        /// Caller is responsible for registering locally, registering with store and calling its activate routine
        /// </summary>
        /// <param name="grainTypeName"></param>
        /// <param name="data"></param>
        /// <param name="genericArguments"></param>
        /// <returns></returns>
        private void CreateGrainInstance(string grainTypeName, ActivationData data, string genericArguments)
        {
            string grainClassName;
            var interfaceToClassMap = GrainTypeManager.GetGrainInterfaceToClassMap();
            if (!interfaceToClassMap.TryGetValue(grainTypeName, out grainClassName))
            {
                // Lookup from grain type code
                var typeCode = data.Grain.GetTypeCode();
                if (typeCode != 0)
                {
                    PlacementStrategy unused;
                    MultiClusterRegistrationStrategy unusedActivationStrategy;
                    GetGrainTypeInfo(typeCode, out grainClassName, out unused, out unusedActivationStrategy, genericArguments);
                }
                else
                {
                    grainClassName = grainTypeName;
                }
            }

            GrainTypeData grainTypeData = GrainTypeManager[grainClassName];

            Type grainType = grainTypeData.Type;

            //Create a new instance of the given grain type
            var grain = grainCreator.CreateGrainInstance(grainType, data.Identity);
            grain.Data = data;

            Type stateObjectType = grainTypeData.StateObjectType;
            object state = null;
            if (stateObjectType != null)
            {
                state = Activator.CreateInstance(stateObjectType);
            }
            
            lock (data)
            {
                data.SetGrainInstance(grain);
                var statefulGrain = grain as IStatefulGrain;
                if (statefulGrain != null)
                {
                    if (state != null)
                    {
                        SetupStorageProvider(data);
                        statefulGrain.GrainState.State = state;
                        statefulGrain.SetStorage(new GrainStateStorageBridge(data.GrainTypeName, statefulGrain,
                            data.StorageProvider));
                    }
                }
            }

            activations.IncrementGrainCounter(grainClassName);

            if (logger.IsVerbose) logger.Verbose("CreateGrainInstance {0}{1}", data.Grain, data.ActivationId);
        }
開發者ID:gaoshoufenmu,項目名稱:orleans,代碼行數:63,代碼來源:Catalog.cs


注:本文中的Orleans.Runtime.ActivationData.SetGrainInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。