Example #1
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);

            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));
        }
 public PlacementDirectorsManager(
     IServiceProvider services,
     PlacementStrategy defaultPlacementStrategy,
     ClientObserversPlacementDirector clientObserversPlacementDirector)
 {
     this.serviceProvider                  = services;
     this.defaultPlacementStrategy         = defaultPlacementStrategy;
     this.clientObserversPlacementDirector = clientObserversPlacementDirector;
     this.ResolveBuiltInStrategies();
     // TODO: Make default selector configurable
     this.defaultActivationSelector = ResolveSelector(RandomPlacement.Singleton, true);
 }
Example #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));
        }