Exemple #1
0
        public void invoke(ServantManager servantManager, Ice.InputStream stream)
        {
            _is = stream;

            int start = _is.pos();

            //
            // Read the current.
            //
            _current.id.ice_readMembers(_is);

            //
            // For compatibility with the old FacetPath.
            //
            string[] facetPath = _is.readStringSeq();
            if (facetPath.Length > 0)
            {
                if (facetPath.Length > 1)
                {
                    throw new Ice.MarshalException();
                }
                _current.facet = facetPath[0];
            }
            else
            {
                _current.facet = "";
            }

            _current.operation = _is.readString();
            _current.mode      = (Ice.OperationMode)_is.readByte();
            _current.ctx       = new Dictionary <string, string>();
            int sz = _is.readSize();

            while (sz-- > 0)
            {
                string first  = _is.readString();
                string second = _is.readString();
                _current.ctx[first] = second;
            }

            Ice.Instrumentation.CommunicatorObserver obsv = _communicator.initializationData().observer;
            if (obsv != null)
            {
                // Read the encapsulation size.
                int size = _is.readInt();
                _is.pos(_is.pos() - 4);

                _observer = obsv.getDispatchObserver(_current, _is.pos() - start + size);
                if (_observer != null)
                {
                    _observer.attach();
                }
            }

            //
            // Don't put the code above into the try block below. Exceptions
            // in the code above are considered fatal, and must propagate to
            // the caller of this operation.
            //

            if (servantManager != null)
            {
                _servant = servantManager.findServant(_current.id, _current.facet);
                if (_servant == null)
                {
                    _locator = servantManager.findServantLocator(_current.id.category);
                    if (_locator == null && _current.id.category.Length > 0)
                    {
                        _locator = servantManager.findServantLocator("");
                    }

                    if (_locator != null)
                    {
                        Debug.Assert(_locator != null);
                        try
                        {
                            _servant = _locator.locate(_current, out _cookie);
                        }
                        catch (Exception ex)
                        {
                            skipReadParams(); // Required for batch requests.
                            handleException(ex, false);
                            return;
                        }
                    }
                }
            }

            if (_servant == null)
            {
                try
                {
                    if (servantManager != null && servantManager.hasServant(_current.id))
                    {
                        throw new Ice.FacetNotExistException(_current.id, _current.facet, _current.operation);
                    }
                    else
                    {
                        throw new Ice.ObjectNotExistException(_current.id, _current.facet, _current.operation);
                    }
                }
                catch (Exception ex)
                {
                    skipReadParams(); // Required for batch requests
                    handleException(ex, false);
                    return;
                }
            }

            try
            {
                Task <Ice.OutputStream> task = _servant(this, _current);
                if (task == null)
                {
                    completed(null, false);
                }
                else
                {
                    if (task.IsCompleted)
                    {
                        _os = task.GetAwaiter().GetResult(); // Get the response
                        completed(null, false);
                    }
                    else
                    {
                        task.ContinueWith((Task <Ice.OutputStream> t) =>
                        {
                            try
                            {
                                _os = t.GetAwaiter().GetResult();
                                completed(null, true); // true = asynchronous
                            }
                            catch (Exception ex)
                            {
                                completed(ex, true); // true = asynchronous
                            }
                        },
                                          CancellationToken.None,
                                          TaskContinuationOptions.ExecuteSynchronously,
                                          scheduler: TaskScheduler.Current);
                    }
                }
            }
            catch (Exception ex)
            {
                completed(ex, false);
            }
        }
Exemple #2
0
        public void invoke(ServantManager servantManager, BasicStream stream)
        {
            _is = stream;

            int start = _is.pos();

            //
            // Read the current.
            //
            current_.id.read__(_is);

            //
            // For compatibility with the old FacetPath.
            //
            string[] facetPath = _is.readStringSeq();
            if (facetPath.Length > 0)
            {
                if (facetPath.Length > 1)
                {
                    throw new Ice.MarshalException();
                }
                current_.facet = facetPath[0];
            }
            else
            {
                current_.facet = "";
            }

            current_.operation = _is.readString();
            current_.mode      = (Ice.OperationMode)(int) _is.readByte();
            current_.ctx       = new Dictionary <string, string>();
            int sz = _is.readSize();

            while (sz-- > 0)
            {
                string first  = _is.readString();
                string second = _is.readString();
                current_.ctx[first] = second;
            }

            Ice.Instrumentation.CommunicatorObserver obsv = instance_.getObserver();
            if (obsv != null)
            {
                // Read the encapsulation size.
                int size = _is.readInt();
                _is.pos(_is.pos() - 4);

                observer_ = obsv.getDispatchObserver(current_, _is.pos() - start + size);
                if (observer_ != null)
                {
                    observer_.attach();
                }
            }

            //
            // Don't put the code above into the try block below. Exceptions
            // in the code above are considered fatal, and must propagate to
            // the caller of this operation.
            //

            if (servantManager != null)
            {
                servant_ = servantManager.findServant(current_.id, current_.facet);
                if (servant_ == null)
                {
                    locator_ = servantManager.findServantLocator(current_.id.category);
                    if (locator_ == null && current_.id.category.Length > 0)
                    {
                        locator_ = servantManager.findServantLocator("");
                    }

                    if (locator_ != null)
                    {
                        try
                        {
                            servant_ = locator_.locate(current_, out cookie_);
                        }
                        catch (Ice.UserException ex)
                        {
                            Ice.EncodingVersion encoding = _is.skipEncaps(); // Required for batch requests.

                            if (observer_ != null)
                            {
                                observer_.userException();
                            }

                            if (response_)
                            {
                                os_.writeByte(ReplyStatus.replyUserException);
                                os_.startWriteEncaps(encoding, Ice.FormatType.DefaultFormat);
                                os_.writeUserException(ex);
                                os_.endWriteEncaps();
                                if (observer_ != null)
                                {
                                    observer_.reply(os_.size() - Protocol.headerSize - 4);
                                }
                                connection_.sendResponse(os_, compress_);
                            }
                            else
                            {
                                connection_.sendNoResponse();
                            }

                            if (observer_ != null)
                            {
                                observer_.detach();
                                observer_ = null;
                            }
                            connection_ = null;
                            return;
                        }
                        catch (System.Exception ex)
                        {
                            _is.skipEncaps(); // Required for batch requests.
                            handleException__(ex);
                            return;
                        }
                    }
                }
            }

            try
            {
                if (servant_ != null)
                {
                    //
                    // DispatchAsync is a "pseudo dispatch status", used internally only
                    // to indicate async dispatch.
                    //
                    if (servant_.dispatch__(this, current_) == Ice.DispatchStatus.DispatchAsync)
                    {
                        //
                        // If this was an asynchronous dispatch, we're done here.
                        //
                        return;
                    }

                    if (locator_ != null && !servantLocatorFinished__())
                    {
                        return;
                    }
                }
                else
                {
                    //
                    // Skip the input parameters, this is required for reading
                    // the next batch request if dispatching batch requests.
                    //
                    _is.skipEncaps();

                    if (servantManager != null && servantManager.hasServant(current_.id))
                    {
                        throw new Ice.FacetNotExistException(current_.id, current_.facet, current_.operation);
                    }
                    else
                    {
                        throw new Ice.ObjectNotExistException(current_.id, current_.facet, current_.operation);
                    }
                }
            }
            catch (System.Exception ex)
            {
                if (servant_ != null && locator_ != null && !servantLocatorFinished__())
                {
                    return;
                }
                handleException__(ex);
                return;
            }

            //
            // Don't put the code below into the try block above. Exceptions
            // in the code below are considered fatal, and must propagate to
            // the caller of this operation.
            //

            Debug.Assert(connection_ != null);

            if (response_)
            {
                if (observer_ != null)
                {
                    observer_.reply(os_.size() - Protocol.headerSize - 4);
                }
                connection_.sendResponse(os_, compress_);
            }
            else
            {
                connection_.sendNoResponse();
            }

            if (observer_ != null)
            {
                observer_.detach();
                observer_ = null;
            }
            connection_ = null;
        }