예제 #1
0
        /// <summary>
        /// Gets or places an activation.
        /// </summary>
        public ValueTask <PlacementResult> GetOrPlaceActivation(PlacementTarget target, IPlacementRuntime placementRuntime)
        {
            var strategy = _strategyResolver.GetPlacementStrategy(target.GrainIdentity.Type);
            var director = _directorResolver.GetPlacementDirector(strategy);
            var selector = director as IActivationSelector ?? _defaultActivationSelector;

            if (selector.TrySelectActivationSynchronously(strategy, target.GrainIdentity, placementRuntime, out var placementResult))
            {
                return(new ValueTask <PlacementResult>(placementResult));
            }

            return(GetOrPlaceActivationAsync(target, strategy, placementRuntime, selector, director));
        }
예제 #2
0
        /// <summary>
        /// Gets or places an activation.
        /// </summary>
        public ValueTask <PlacementResult> GetOrPlaceActivation(PlacementTarget target, IPlacementRuntime placementRuntime)
        {
            var strategy = _strategyResolver.GetPlacementStrategy(target.GrainIdentity.Type);
            var director = _directorResolver.GetPlacementDirector(strategy);
            var selector = director as IActivationSelector ?? _defaultActivationSelector;

            var selectActivationTask = selector.OnSelectActivation(strategy, target.GrainIdentity, placementRuntime);

            if (selectActivationTask.IsCompletedSuccessfully && selectActivationTask.Result is object)
            {
                return(selectActivationTask);
            }

            return(GetOrPlaceActivationAsync(selectActivationTask, target, strategy, placementRuntime, director));
        }