using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Orleans.Runtime.Placement { /// /// Interface for placement directors. /// public interface IPlacementDirector { /// /// Gets the key used to store the placement hint, if present. /// public const string PlacementHintKey = nameof(PlacementHintKey); /// /// Picks an appropriate silo to place the specified target on. /// /// The target's placement strategy. /// The grain being placed as well as information about the request which triggered the placement. /// The placement context. /// An appropriate silo to place the specified target on. Task OnAddActivation( PlacementStrategy strategy, PlacementTarget target, IPlacementContext context); /// /// Gets the placement hint from the provided request context data, if present and valid. /// /// The request context data. /// The compatible silos. /// The placement hint, if present and valid, or otherwise. public static SiloAddress? GetPlacementHint(Dictionary requestContextData, SiloAddress[] compatibleSilos) { if (requestContextData is { Count: > 0 } data && data.TryGetValue(PlacementHintKey, out var value) && value is SiloAddress placementHint && compatibleSilos.Contains(placementHint)) { return placementHint; } return null; } } }