本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}