Пример #1
0
        /// <summary>
        /// Evaluates the Union
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            //Create a copy of the evaluation context for the RHS
            SparqlEvaluationContext context2 = new SparqlEvaluationContext(context.Query, context.Data, context.Processor);

            if (!(context.InputMultiset is IdentityMultiset))
            {
                context2.InputMultiset = new Multiset();
                foreach (ISet s in context.InputMultiset.Sets)
                {
                    context2.InputMultiset.Add(s.Copy());
                }
            }

            List <Uri> activeGraphs  = context.Data.ActiveGraphUris.ToList();
            List <Uri> defaultGraphs = context.Data.DefaultGraphUris.ToList();

            ParallelEvaluateDelegate d   = new ParallelEvaluateDelegate(this.ParallelEvaluate);
            IAsyncResult             lhs = d.BeginInvoke(this._lhs, context, activeGraphs, defaultGraphs, null, null);
            IAsyncResult             rhs = d.BeginInvoke(this._rhs, context2, activeGraphs, defaultGraphs, null, null);

            WaitHandle.WaitAll(new WaitHandle[] { lhs.AsyncWaitHandle, rhs.AsyncWaitHandle });

            bool rhsOk = false;

            try
            {
                BaseMultiset lhsResult = d.EndInvoke(lhs);
                rhsOk = true;
                BaseMultiset rhsResult = d.EndInvoke(rhs);
                context.CheckTimeout();

                context.OutputMultiset = lhsResult.Union(rhsResult);
                context.CheckTimeout();

                context.InputMultiset = context.OutputMultiset;
                return(context.OutputMultiset);
            }
            catch
            {
                if (!rhsOk)
                {
                    //Clean up the RHS evaluation call if the LHS has errored
                    try
                    {
                        d.EndInvoke(rhs);
                    }
                    catch
                    {
                        //Ignore this error as we're already going to throw the other error
                    }
                }
                throw;
            }
        }
Пример #2
0
 private void RhsCallback(IAsyncResult result)
 {
     try
     {
         _rhsResult = _d.EndInvoke(result);
     }
     catch (Exception ex)
     {
         _rhsError  = ex;
         _rhsResult = null;
     }
 }
Пример #3
0
        /// <summary>
        /// Evaluates the Union
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            //Create a copy of the evaluation context for the RHS
            SparqlEvaluationContext context2 = new SparqlEvaluationContext(context.Query, context.Data, context.Processor);
            if (!(context.InputMultiset is IdentityMultiset))
            {
                context2.InputMultiset = new Multiset();
                foreach (ISet s in context.InputMultiset.Sets)
                {
                    context2.InputMultiset.Add(s.Copy());
                }
            }

            IGraph activeGraph = context.Data.ActiveGraph;
            IGraph defaultGraph = context.Data.DefaultGraph;

            ParallelEvaluateDelegate d = new ParallelEvaluateDelegate(this.ParallelEvaluate);
            IAsyncResult lhs = d.BeginInvoke(this._lhs, context, activeGraph, defaultGraph, null, null);
            IAsyncResult rhs = d.BeginInvoke(this._rhs, context2, activeGraph, defaultGraph, null, null);

            WaitHandle.WaitAll(new WaitHandle[] { lhs.AsyncWaitHandle, rhs.AsyncWaitHandle });

            bool rhsOk = false;
            try 
            {
                BaseMultiset lhsResult = d.EndInvoke(lhs);
                rhsOk = true;
                BaseMultiset rhsResult = d.EndInvoke(rhs);
                context.CheckTimeout();

                context.OutputMultiset = lhsResult.Union(rhsResult);
                context.CheckTimeout();

                context.InputMultiset = context.OutputMultiset;
                return context.OutputMultiset;
            }
            catch 
            {
                if (!rhsOk)
                {
                    //Clean up the RHS evaluation call if the LHS has errored
                    try
                    {
                        d.EndInvoke(rhs);
                    }
                    catch
                    {
                        //Ignore this error as we're already going to throw the other error
                    }
                }
                throw;
            }
        }
        /// <summary>
        /// Evalutes a Join
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <returns></returns>
        public BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            // Create a copy of the evaluation context for the RHS
            SparqlEvaluationContext context2 = new SparqlEvaluationContext(context.Query, context.Data, context.Processor);

            if (!(context.InputMultiset is IdentityMultiset))
            {
                context2.InputMultiset = new Multiset();
                foreach (ISet s in context.InputMultiset.Sets)
                {
                    context2.InputMultiset.Add(s.Copy());
                }
            }

            List <Uri> activeGraphs  = context.Data.ActiveGraphUris.ToList();
            List <Uri> defaultGraphs = context.Data.DefaultGraphUris.ToList();

            // Start both executing asynchronously
            IAsyncResult lhs = _d.BeginInvoke(_lhs, context, activeGraphs, defaultGraphs, null, null);
            IAsyncResult rhs = _d.BeginInvoke(_rhs, context2, activeGraphs, defaultGraphs, new AsyncCallback(RhsCallback), null);

            // Wait on the LHS
            if (context.RemainingTimeout > 0)
            {
                lhs.AsyncWaitHandle.WaitOne(new TimeSpan(0, 0, 0, 0, (int)context.RemainingTimeout));
            }
            else
            {
                lhs.AsyncWaitHandle.WaitOne();
            }
            context.CheckTimeout();

            // Get the LHS result
            BaseMultiset lhsResult;

            try
            {
                lhsResult = _d.EndInvoke(lhs);
            }
            catch
            {
                throw;
            }

            // If LHS came back as null/empty no need to wait for RHS to complete
            if (lhsResult is NullMultiset)
            {
                context.OutputMultiset = lhsResult;
            }
            else if (lhsResult.IsEmpty)
            {
                context.OutputMultiset = new NullMultiset();
            }
            else
            {
                // Wait for RHS to complete
                if (!rhs.IsCompleted)
                {
                    if (context.RemainingTimeout > 0)
                    {
                        rhs.AsyncWaitHandle.WaitOne(new TimeSpan(0, 0, 0, 0, (int)context.RemainingTimeout));
                    }
                    else
                    {
                        rhs.AsyncWaitHandle.WaitOne();
                    }
                    context.CheckTimeout();
                }

                if (_rhsResult == null)
                {
                    if (_rhsError != null)
                    {
                        throw _rhsError;
                    }
                    Thread.Sleep(10);
                }
                if (_rhsResult == null)
                {
                    throw new RdfQueryException("Unknown error in parallel join evaluation, RHS is reported completed without errors but no result is available");
                }

                // Compute the product of the two sides
                context.OutputMultiset = lhsResult.Product(_rhsResult);
            }
            return(context.OutputMultiset);
        }