public override async Task <PlacementResult> OnSelectActivation(PlacementStrategy strategy, GrainId target, IPlacementRuntime context)
        {
            // no need to check if we can find an activation for this client in the cache or local directory partition
            // as TrySelectActivationSynchronously which checks for that should have been called before
            AddressesAndTag addresses;

            // we need to look up the directory entry for this grain on a remote silo
            switch (target.Category)
            {
            case UniqueKey.Category.Client:
            {
                addresses = await context.FullLookup(target);

                return(ChooseRandomActivation(addresses.Addresses, context));
            }

            case UniqueKey.Category.GeoClient:
            {
                // we need to look up the activations in the remote cluster
                addresses = await context.LookupInCluster(target, target.Key.ClusterId);

                return(ChooseRandomActivation(addresses.Addresses, context));
            }

            default:
                throw new InvalidOperationException("Unsupported client type. Grain " + target);
            }
        }
        public virtual async Task <PlacementResult> OnSelectActivation(
            PlacementStrategy strategy, GrainId target, IPlacementRuntime context)
        {
            List <ActivationAddress> places = (await context.FullLookup(target)).Addresses;

            return(ChooseRandomActivation(places, context));
        }
Esempio n. 3
0
        public override async Task <PlacementResult> OnSelectActivation(PlacementStrategy strategy, GrainId target, IPlacementRuntime context)
        {
            // no need to check if we can find an activation for this client in the cache or local directory partition
            // as TrySelectActivationSynchronously which checks for that should have been called before
            List <ActivationAddress> addresses;

            // we need to look up the directory entry for this grain on a remote silo
            if (!ClientGrainId.TryParse(target, out var clientId))
            {
                throw new InvalidOperationException($"Unsupported id format: {target}");
            }

            addresses = await context.FullLookup(clientId.GrainId);

            return(ChooseRandomActivation(addresses, context));
        }
Esempio n. 4
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. 5
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. 6
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));
        }