コード例 #1
0
ファイル: PlacementService.cs プロジェクト: oising/orleans
        /// <summary>
        /// Gets or places an activation.
        /// </summary>
        public Task AddressMessage(Message message)
        {
            if (message.IsFullyAddressed)
            {
                return(Task.CompletedTask);
            }
            if (message.TargetGrain.IsDefault)
            {
                ThrowMissingAddress();
            }

            var grainId = message.TargetGrain;

            if (_grainLocator.TryLocalLookup(grainId, out var result))
            {
                SetMessageTargetPlacement(message, result.Activation, result.Silo, false);
                return(Task.CompletedTask);
            }

            return(GetOrPlaceActivationAsync(message));
コード例 #2
0
ファイル: ManagementGrain.cs プロジェクト: richorama/orleans
        public ValueTask <SiloAddress> GetActivationAddress(IAddressable reference)
        {
            var grainReference = reference as GrainReference;
            var grainId        = grainReference.GrainId;

            GrainProperties grainProperties = default;

            if (!siloManifest.Grains.TryGetValue(grainId.Type, out grainProperties))
            {
                var grainManifest = clusterManifest.AllGrainManifests
                                    .SelectMany(m => m.Grains.Where(g => g.Key == grainId.Type))
                                    .FirstOrDefault();
                if (grainManifest.Value != null)
                {
                    grainProperties = grainManifest.Value;
                }
                else
                {
                    throw new ArgumentException($"Unable to find Grain type '{grainId.Type}'. Make sure it is added to the Application Parts Manager at the Silo configuration.");
                }
            }

            if (grainProperties != default &&
                grainProperties.Properties.TryGetValue(WellKnownGrainTypeProperties.PlacementStrategy, out string placementStrategy))
            {
                if (placementStrategy == nameof(StatelessWorkerPlacement))
                {
                    throw new InvalidOperationException(
                              $"Grain '{grainReference.ToString()}' is a Stateless Worker. This type of grain can't be looked up by this method"
                              );
                }
            }

            if (grainLocator.TryLocalLookup(grainId, out var result))
            {
                return(new ValueTask <SiloAddress>(result?.Silo));
            }

            return(LookupAsync(grainId, grainLocator));