/// <summary>
        /// Adds CancellationToken to the grain extension
        /// so that it can be cancelled through remote call to the CancellationSourcesExtension.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="request"></param>
        /// <param name="logger"></param>
        /// <param name="siloRuntimeClient"></param>
        internal static void RegisterCancellationTokens(
            IAddressable target,
            InvokeMethodRequest request,
            Logger logger,
            ISiloRuntimeClient siloRuntimeClient)
        {
            for (var i = 0; i < request.Arguments.Length; i++)
            {
                var arg = request.Arguments[i];
                if (!(arg is GrainCancellationToken))
                {
                    continue;
                }
                var grainToken = ((GrainCancellationToken)request.Arguments[i]);

                CancellationSourcesExtension cancellationExtension;
                if (!siloRuntimeClient.TryGetExtensionHandler(out cancellationExtension))
                {
                    cancellationExtension = new CancellationSourcesExtension();
                    if (!siloRuntimeClient.TryAddExtension(cancellationExtension))
                    {
                        logger.Error(
                            ErrorCode.CancellationExtensionCreationFailed,
                            $"Could not add cancellation token extension to: {target}");
                        return;
                    }
                }

                // Replacing the half baked GrainCancellationToken that came from the wire with locally fully created one.
                request.Arguments[i] = cancellationExtension.RecordCancellationToken(grainToken.Id, grainToken.IsCancellationRequested);
            }
        }
        /// <summary>
        /// Adds CancellationToken to the grain extension
        /// so that it can be cancelled through remote call to the CancellationSourcesExtension.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="request"></param>
        /// <param name="logger"></param>
        /// <param name="siloRuntimeClient"></param>
        internal static void RegisterCancellationTokens(
            IAddressable target,
            InvokeMethodRequest request,
            Logger logger,
            ISiloRuntimeClient siloRuntimeClient)
        {
            for (var i = 0; i < request.Arguments.Length; i++)
            {
                var arg = request.Arguments[i];
                if (!(arg is GrainCancellationToken)) continue;
                var grainToken = ((GrainCancellationToken) request.Arguments[i]);

                CancellationSourcesExtension cancellationExtension;
                if (!siloRuntimeClient.TryGetExtensionHandler(out cancellationExtension))
                {
                    cancellationExtension = new CancellationSourcesExtension();
                    if (!siloRuntimeClient.TryAddExtension(cancellationExtension))
                    {
                        logger.Error(
                            ErrorCode.CancellationExtensionCreationFailed,
                            $"Could not add cancellation token extension to: {target}");
                        return;
                    }
                }

                // Replacing the half baked GrainCancellationToken that came from the wire with locally fully created one.
                request.Arguments[i] = cancellationExtension.RecordCancellationToken(grainToken.Id, grainToken.IsCancellationRequested);
            }
        }
 public Task InstallExtension(T name)
 {
     if (extender == null)
     {
         extender = new GenericTestExtension <T>(this, this.GrainFactory);
         if (!runtimeClient.TryAddExtension(extender))
         {
             throw new SystemException("Unable to add new extension");
         }
     }
     ExtensionProperty = name;
     return(Task.CompletedTask);
 }
        public override Task OnActivateAsync()
        {
            if (extender == null)
            {
                extender = new SimpleExtension("A");
                if (!runtimeClient.TryAddExtension(extender))
                {
                    throw new SystemException("Unable to add new extension");
                }
            }

            return(base.OnActivateAsync());
        }
示例#5
0
 public Task InstallExtension(string name)
 {
     if (extender == null)
     {
         extender = new TestExtension(this, GrainFactory);
         if (!runtimeClient.TryAddExtension(extender))
         {
             throw new SystemException("Unable to add new extension");
         }
     }
     ExtensionProperty = name;
     return(TaskDone.Done);
 }
示例#6
0
 public Task InstallExtension(T name)
 {
     if (extender == null)
     {
         extender = new GenericTestExtension <T>(this);
         if (!runtimeClient.TryAddExtension(extender))
         {
             throw new SystemException("Unable to add new extension");
         }
     }
     ExtensionProperty = name;
     return(TaskDone.Done);
 }