Ejemplo n.º 1
0
        public static bool MayInterleave(IInvokable req)
        {
            // not interested
            if (req.ArgumentCount == 0)
            {
                return(false);
            }

            string arg = null;

            // assume single argument message
            if (req.ArgumentCount == 1)
            {
                arg = (string)UnwrapImmutable(req.GetArgument <object>(0));
            }

            // assume stream message
            if (req.ArgumentCount == 2)
            {
                arg = (string)UnwrapImmutable(req.GetArgument <object>(1));
            }

            if (arg == "err")
            {
                throw new ApplicationException("boom");
            }

            return(arg == "reentrant");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets target grain to the found instances of type GrainCancellationToken
        /// </summary>
        private void SetGrainCancellationTokensTarget(GrainReference target, IInvokable request)
        {
            for (var i = 0; i < request.ArgumentCount; i++)
            {
                var arg = request.GetArgument <object>(i);
                if (arg is not GrainCancellationToken grainToken)
                {
                    continue;
                }

                grainToken.AddGrainReference(this.cancellationTokenRuntime, target);
            }
        }
        /// <summary>
        /// Adds CancellationToken to the grain extension
        /// so that it can be canceled through remote call to the CancellationSourcesExtension.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="request"></param>
        internal static void RegisterCancellationTokens(
            IGrainContext target,
            IInvokable request)
        {
            for (var i = 0; i < request.ArgumentCount; i++)
            {
                var arg = request.GetArgument <object>(i);
                if (arg is not GrainCancellationToken grainToken)
                {
                    continue;
                }

                var cancellationExtension = (CancellationSourcesExtension)target.GetGrainExtension <ICancellationSourcesExtension>();

                // Replacing the half baked GrainCancellationToken that came from the wire with locally fully created one.
                request.SetArgument(i, cancellationExtension.RecordCancellationToken(grainToken.Id, grainToken.IsCancellationRequested));
            }
        }