Exemple #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static <T> java.util.List<T> await(Iterable<java.util.concurrent.Future<T>> futures) throws InterruptedException, java.util.concurrent.ExecutionException
        public static IList <T> Await <T>(IEnumerable <Future <T> > futures)
        {
            IList <T>         result   = futures is System.Collections.ICollection ? new List <T>(((System.Collections.ICollection)futures).Count) : new List <T>();
            IList <Exception> failures = null;

            foreach (Future <T> future in futures)
            {
                try
                {
                    result.Add(future.get());
                }
                catch (ExecutionException e)
                {
                    if (failures == null)
                    {
                        failures = new List <Exception>();
                    }
                    failures.Add(e.InnerException);
                }
            }
            if (failures != null)
            {
                if (failures.Count == 1)
                {
                    throw new ExecutionException(failures[0]);
                }
                ExecutionException exception = new ExecutionException(null);
                foreach (Exception failure in failures)
                {
                    exception.addSuppressed(failure);
                }
                throw exception;
            }
            return(result);
        }
Exemple #2
0
        /// <inheritdoc/>
        Expression IExpressionVisitor <Expression> .VisitArrayLiteral(ArrayListExpression node)
        {
            var type = node.ArrayType != null?node.ArrayType.ResolveType(Context) : TypeProvider.AnyType;

            node.Type        = typeof(Collections.List <>).MakeGenericType(type);
            node.ElementType = type;
            if (node.Arguments != null)
            {
                var types = node.Arguments.Map(arg => arg.Accept(this).Type);
                if (node.Constructor == null)
                {
                    var ctors = node.Type.GetConstructors(ReflectionUtils.PublicInstance);
                    var ctor  = ReflectionUtils.BindToMethod(ctors, types, out ArgumentConversions conversions);
                    if (ctor == null)
                    {
                        ExecutionException.ThrowMissingMethod(node.Type, "ctor", node);
                    }
                    node.Constructor         = ctor;
                    node.ArgumentConversions = conversions;
                }
            }
            else if (node.Constructor == null)
            {
                node.Constructor = node.Type.GetConstructor(ReflectionUtils.PublicInstance, null, new Type[0], null);
            }
            var items = node.Expressions;

            if (items.Count > 0)
            {
                var arrayConversions = new ArgumentConversions(items.Count);
                for (int index = 0; index < items.Count; index++)
                {
                    var expression = items[index].Accept(this);
                    if (!TypeUtils.AreReferenceAssignable(type, expression.Type) && expression.Type.TryImplicitConvert(type, out System.Reflection.MethodInfo implicitCall))
                    {
                        if (expression.Type.IsValueType &&
                            implicitCall.GetParameters()[0].ParameterType == TypeProvider.ObjectType)
                        {
                            arrayConversions.Append(index, new BoxConversion(index, expression.Type));
                        }
                        arrayConversions.Append(index, new ParamConversion(index, implicitCall));
                    }
                }
                node.ArrayConversions = arrayConversions;
            }
            return(node);
        }
        private async Task StopExecutionWithException(ExecutionException executionException)
        {
            // Kill the process and finalize execution
            await FinalizeExecution(true);

            /*
             * To work around potentially dangerous situation
             * when [ executionException ] is [ null ], but
             * [ _process ] is still running.
             */
            if (executionException == null)
            {
                throw new ArgumentNullException(nameof(executionException));
            }

            // Throw an exception
            throw executionException;
        }
Exemple #4
0
        /// <inheritdoc/>
        Expression IExpressionVisitor <Expression> .VisitAssignment(AssignmentExpression node)
        {
            var            right    = node.Right.Accept(this);
            var            left     = node.Left;
            string         name     = null;
            ExpressionType nodeType = left.NodeType;
            IBinder        binder   = null;

            if (nodeType == ExpressionType.Identifier)
            {
                var exp = (NameExpression)left;
                name = exp.Name;
                var bindingAttr = ReflectionUtils.AnyPublic;
                name = exp.Name;
                if (TryGetLocalVariable(name, out binder) ||
                    Method.DeclaringType.TryFindMember(name, bindingAttr, out binder))
                {
                    exp.Binder = binder;
                }
                else
                {
                    ExecutionException.ThrowMissingMember(Method.DeclaringType, name, left, node);
                }
            }
            else if (nodeType == ExpressionType.MemberAccess)
            {
                var exp    = (MemberExpression)left;
                var target = exp.Target.Accept(this);
                name = exp.Name;
                if (exp.Binder is null && target.Type.TryFindMember(name, ReflectionUtils.AnyPublic, out binder))
                {
                    exp.Binder = binder;
                }
                else if (target.Type.IsDynamicInvocable())
                {
                    binder = new DynamicMemberBinder(name);
                }
                else
                {
                    throw ExecutionException.ThrowMissingMember(target.Type, name, node);
                }
            }
Exemple #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertLockAcquisitionFailed(LockAcquisition lockAcquisition) throws Exception
        private void AssertLockAcquisitionFailed(LockAcquisition lockAcquisition)
        {
            ExecutionException executionException = null;

            for (int i = 0; i < 30; i++)
            {
                try
                {
                    lockAcquisition.Result();
                    fail("Transaction termination expected");
                }
                catch (ExecutionException e)
                {
                    executionException = e;
                }
                catch (TimeoutException)
                {
                }
            }
            assertNotNull("execution should fail", executionException);
            assertThat(executionException.InnerException, instanceOf(typeof(LockClientStoppedException)));
            assertTrue("locking thread seem to be still in progress", lockAcquisition.Completed());
        }
Exemple #6
0
        static System.Reflection.MethodInfo VisitPow(BinaryExpression node, Expression left, Expression right, ArgumentConversions conversions)
        {
            var types = new Type[2] {
                left.Type, right.Type
            };

            System.Reflection.MethodInfo method = ReflectionHelpers.MathPow;
            if (left.Type.IsPrimitive || right.Type.IsPrimitive)
            {
                var initial = ReflectionUtils.FromSystemType(ref types);
                if (!method.MatchesArgumentTypes(types, conversions))
                {
                    ExecutionException.ThrowArgumentMisMatch(node);
                }
                conversions.SetInitial(initial);
                return(method);
            }
            if (!method.MatchesArgumentTypes(types, conversions))
            {
                ExecutionException.ThrowArgumentMisMatch(node);
            }
            return(method);
        }
 public override void ExecutionException(Session ssn, ExecutionException exc)
 {
     ssn.AddException(exc);
 }
Exemple #8
0
 private void OnExecutionException(Exception exception)
 {
     ExecutionException?.Invoke(this, new EventArgs <Exception>(exception));
 }
 protected internal abstract void Handle(ExecutionException executionException, LogRegistry logRegistry);
        internal async Task StartSubscribe()
        {
            var reader = TaskQueueReader;

            SubscriberStarted?.Invoke(this);
            while (true)
            {
                T newPayload;
                try
                {
                    newPayload = await reader.ReadAsync(TaskManagerCancellationToken.Token).ConfigureAwait(false);
                }
                catch (OperationCanceledException)
                {
                    break;
                }
                catch (Exception e)
                {
                    TaskPayloadFetchException?.Invoke(this, e);
                    continue;
                }

                var cts = TaskManagerCancellationToken;
                CancellationTokenSource localCts = null;
                var timeout = ExecutionTimeout;
                if (timeout.HasValue)
                {
                    localCts = new CancellationTokenSource(timeout.Value);
                    cts      = CancellationTokenSource.CreateLinkedTokenSource(
                        TaskManagerCancellationToken.Token,
                        localCts.Token);
                }
                try
                {
                    ExecutionStarting?.Invoke(this);
                    await Execution(newPayload, cts).ConfigureAwait(false);

                    ExecutionFinished?.Invoke(this);
                }
                catch (OperationCanceledException ex)
                {
                    if (localCts?.IsCancellationRequested ?? false)
                    {
                        ExecutionTimeoutEvent?.Invoke(this);
                    }
                    else
                    {
                        SubscriberCancelled?.Invoke(this, ex);
                        break;
                    }
                }
                catch (ObjectDisposedException ed)
                {
                    SubscriberCancelled?.Invoke(this, ed);
                    break;
                }
                catch (Exception e)
                {
                    ExecutionException?.Invoke(this, e);
                }

                if (TaskManagerCancellationToken.IsCancellationRequested)
                {
                    break;
                }
            }
            TaskSubscriberFinalized?.Invoke(this);
        }
Exemple #11
0
 public void AddException(ExecutionException exc)
 {
     lock (_exceptions)
     {
         _exceptions.Add(exc);
     }
 }
Exemple #12
0
 public virtual void ExecutionException(C context, ExecutionException mystruct)
 {
 }
 protected override void Handle(ExecutionException executionException, LogRegistry logRegistry)
 {
     var logExtensions = executionException.Call.GetActionAs<TestActions.LogExtensions>();
     logExtensions.SetExceptionHandlerLog();
 }
Exemple #14
0
 private void Given_subject_IsConstructedWith(string message)
 {
     subject = new ExecutionException(message);
 }
Exemple #15
0
 public void SetUp()
 {
     subject = null;
 }
Exemple #16
0
 private void Given_subject_IsConstructedWith()
 {
     subject = new ExecutionException();
 }