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); }
public virtual async Task <PlacementResult> OnSelectActivation( PlacementStrategy strategy, GrainId target, IPlacementContext context) { List <ActivationAddress> places = (await context.Lookup(target)).Addresses; return(ChooseRandomActivation(places, context)); }
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; }
internal override async Task<PlacementResult> OnSelectActivation( PlacementStrategy strategy, GrainId target, IPlacementContext context) { List<ActivationAddress> places = (await context.Lookup(target)).Addresses; return ChooseRandomActivation(places, context); }