public bool TrySelectActivationSynchronously(
            PlacementStrategy strategy, GrainId target, IPlacementRuntime context, out PlacementResult placementResult)
        {
            AddressesAndTag addressesAndTag;

            if (context.FastLookup(target, out addressesAndTag))
            {
                placementResult = ChooseRandomActivation(addressesAndTag.Addresses, context);
                return(true);
            }

            placementResult = null;
            return(false);
        }
Esempio n. 2
0
        public virtual ValueTask <PlacementResult> OnSelectActivation(
            PlacementStrategy strategy,
            GrainId target,
            IPlacementRuntime context)
        {
            if (context.FastLookup(target, out var addresses))
            {
                var placementResult = ChooseRandomActivation(addresses, context);
                return(new ValueTask <PlacementResult>(placementResult));
            }

            return(SelectActivationAsync(target, context));

            async ValueTask <PlacementResult> SelectActivationAsync(GrainId target, IPlacementRuntime context)
            {
                var places = await context.FullLookup(target);

                return(ChooseRandomActivation(places, context));
            }
        }
Esempio n. 3
0
        public override ValueTask <PlacementResult> OnSelectActivation(PlacementStrategy strategy, GrainId target, IPlacementRuntime context)
        {
            if (!ClientGrainId.TryParse(target, out var clientId))
            {
                throw new InvalidOperationException($"Unsupported id format: {target}");
            }

            var grainId = clientId.GrainId;

            if (context.FastLookup(grainId, out var addresses))
            {
                var placementResult = ChooseRandomActivation(addresses, context);
                return(new ValueTask <PlacementResult>(placementResult));
            }

            return(SelectActivationAsync(grainId, context));

            async ValueTask <PlacementResult> SelectActivationAsync(GrainId target, IPlacementRuntime context)
            {
                var places = await context.FullLookup(target);

                return(ChooseRandomActivation(places, context));
            }
        }
Esempio n. 4
0
        public static Task <AddressesAndTag> Lookup(this IPlacementRuntime @this, GrainId grainId)
        {
            AddressesAndTag l;

            return(@this.FastLookup(grainId, out l) ? Task.FromResult(l) : @this.FullLookup(grainId));
        }