Ejemplo n.º 1
0
        internal override async Task <PlacementResult> OnSelectActivation(
            PlacementStrategy strategy, GrainId target, IPlacementContext context)
        {
            List <ActivationAddress> places = await context.Lookup(target);

            if (places.Count <= 0)
            {
                // we return null to indicate that we were unable to select a target from places activations.
                return(null);
            }

            if (places.Count == 1)
            {
                return(PlacementResult.IdentifySelection(places[0]));
            }

            // places.Count > 0
            // Choose randomly if there is one, else make a new activation of the target
            // pick local if available (consider making this a purely random assignment of grains).
            var here  = context.LocalSilo;
            var local = places.Where(a => a.Silo.Equals(here)).ToList();

            if (local.Count > 0)
            {
                return(PlacementResult.IdentifySelection(local[random.Next(local.Count)]));
            }
            if (places.Count > 0)
            {
                return(PlacementResult.IdentifySelection(places[random.Next(places.Count)]));
            }
            // we return null to indicate that we were unable to select a target from places activations.
            return(null);
        }
Ejemplo n.º 2
0
        public virtual async Task <PlacementResult> OnSelectActivation(
            PlacementStrategy strategy, GrainId target, IPlacementContext context)
        {
            List <ActivationAddress> places = (await context.Lookup(target)).Addresses;

            return(ChooseRandomActivation(places, context));
        }
Ejemplo n.º 3
0
        internal override async Task<PlacementResult> OnSelectActivation(
            PlacementStrategy strategy, GrainId target, IPlacementContext context)
        {
            List<ActivationAddress> places = await context.Lookup(target);
            if (places.Count <= 0)
            {
                // we return null to indicate that we were unable to select a target from places activations.
                return null;
            }

            if (places.Count == 1) return PlacementResult.IdentifySelection(places[0]);

            // places.Count > 0
            // Choose randomly if there is one, else make a new activation of the target
            // pick local if available (consider making this a purely random assignment of grains).
            var here = context.LocalSilo;
            var local = places.Where(a => a.Silo.Equals(here)).ToList();
            if (local.Count > 0) 
                return PlacementResult.IdentifySelection(local[random.Next(local.Count)]);
            if (places.Count > 0)
                return PlacementResult.IdentifySelection(places[random.Next(places.Count)]);
            // we return null to indicate that we were unable to select a target from places activations.
            return null;
        }
Ejemplo n.º 4
0
 internal override async Task<PlacementResult> OnSelectActivation(
     PlacementStrategy strategy, GrainId target, IPlacementContext context)
 {
     List<ActivationAddress> places = (await context.Lookup(target)).Addresses;
     return ChooseRandomActivation(places, context);
 }