예제 #1
0
        private async Task <PlacementResult> AddActivation(
            PlacementTarget target,
            IPlacementRuntime context,
            PlacementStrategy strategy)
        {
            if (target.IsClient)
            {
                throw new InvalidOperationException("Client grains are not activated using the placement subsystem.");
            }

            var director    = ResolveDirector(strategy);
            var siloAddress = await director.OnAddActivation(strategy, target, context);

            var grainTypeName = context.GetGrainTypeName(((LegacyGrainId)target.GrainIdentity).TypeCode);

            ActivationId activationId;

            if (strategy.IsDeterministicActivationId)
            {
                // Use the grain id as the activation id.
                activationId = ActivationId.GetDeterministic(target.GrainIdentity);
            }
            else
            {
                activationId = ActivationId.NewId();
            }

            return(PlacementResult.SpecifyCreation(
                       siloAddress,
                       activationId,
                       strategy,
                       grainTypeName));
        }
예제 #2
0
        private async Task <PlacementResult> AddActivation(
            PlacementTarget target,
            IPlacementRuntime context,
            PlacementStrategy strategy)
        {
            if (target.IsClient)
            {
                throw new InvalidOperationException("Client grains are not activated using the placement subsystem.");
            }

            var director = ResolveDirector(strategy);

            return(PlacementResult.SpecifyCreation(
                       await director.OnAddActivation(strategy, target, context),
                       strategy,
                       context.GetGrainTypeName(target.GrainIdentity.TypeCode)));
        }
예제 #3
0
        private async ValueTask <PlacementResult> GetOrPlaceActivationAsync(
            PlacementTarget target,
            PlacementStrategy strategy,
            IPlacementRuntime placementRuntime,
            IActivationSelector selector,
            IPlacementDirector director)
        {
            var placementResult = await selector.OnSelectActivation(strategy, target.GrainIdentity, placementRuntime);

            if (placementResult is object)
            {
                return(placementResult);
            }

            var siloAddress = await director.OnAddActivation(strategy, target, placementRuntime);

            string grainTypeName;

            if (LegacyGrainId.TryConvertFromGrainId(target.GrainIdentity, out var legacyId))
            {
                grainTypeName = placementRuntime.GetGrainTypeName(legacyId.TypeCode);
            }
            else
            {
                grainTypeName = null;
            }

            ActivationId activationId;

            if (strategy.IsDeterministicActivationId)
            {
                // Use the grain id as the activation id.
                activationId = ActivationId.GetDeterministic(target.GrainIdentity);
            }
            else
            {
                activationId = ActivationId.NewId();
            }

            return(PlacementResult.SpecifyCreation(
                       siloAddress,
                       activationId,
                       strategy,
                       grainTypeName));
        }
예제 #4
0
 public static string GetGrainTypeName(this IPlacementRuntime @this, GrainId grainId, string genericArguments = null)
 {
     return(@this.GetGrainTypeName(grainId.TypeCode, genericArguments));
 }