示例#1
0
        private static void PrintRequestHeader(System.IO.StringWriter s, Ice.InputStream str)
        {
            PrintIdentityFacetOperation(s, str);

            try
            {
                byte mode = str.ReadByte();
                s.Write("\noperation mode = " + (int)mode + ' ');
                switch (mode)
                {
                case 0:
                {
                    s.Write("(non-idempotent)");
                    break;
                }

                case 1:
                {
                    s.Write("(idempotent/nonmutating)");
                    break;
                }

                case 2:
                {
                    s.Write("(idempotent)");
                    break;
                }

                default:
                {
                    s.Write("(unknown)");
                    break;
                }
                }

                int sz = str.ReadSize();
                s.Write("\ncontext = ");
                while (sz-- > 0)
                {
                    string key = str.ReadString();
                    string val = str.ReadString();
                    s.Write(key + '/' + val);
                    if (sz > 0)
                    {
                        s.Write(", ");
                    }
                }

                Ice.EncodingVersion v = str.SkipEncapsulation();
                if (!v.Equals(Ice.Util.Encoding_1_0))
                {
                    s.Write("\nencoding = ");
                    s.Write(Ice.Util.EncodingVersionToString(v));
                }
            }
            catch (System.IO.IOException)
            {
                Debug.Assert(false);
            }
        }
示例#2
0
文件: Incoming.cs 项目: bailudata/ice
        public void invoke(ServantManager servantManager, Ice.InputStream stream)
        {
            _is = stream;

            int start = _is.pos();
            //
            // Read the current.
            //
            var id = new Ice.Identity();

            id.ice_readMembers(_is);

            //
            // For compatibility with the old FacetPath.
            //
            string[] facetPath = _is.ReadStringSeq();
            string   facet;

            if (facetPath.Length > 0)
            {
                if (facetPath.Length > 1)
                {
                    throw new Ice.MarshalException();
                }
                facet = facetPath[0];
            }
            else
            {
                facet = "";
            }

            string operation = _is.ReadString();
            byte   mode      = _is.ReadByte();
            Dictionary <string, string> context = new Dictionary <string, string>();
            int sz = _is.ReadSize();

            while (sz-- > 0)
            {
                string first  = _is.ReadString();
                string second = _is.ReadString();
                context[first] = second;
            }
            _current = new Ice.Current(_adapter, id, facet, operation, (Ice.OperationMode)mode, context, _requestId, _connection);
            Ice.Instrumentation.CommunicatorObserver?obsv = _communicator.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);
            }
        }
示例#3
0
文件: Incoming.cs 项目: yzun/ice
        public void Invoke(Ice.InputStream stream)
        {
            _is = stream;

            int start = _is.Pos;
            //
            // Read the current.
            //
            var id = new Ice.Identity(_is);

            //
            // For compatibility with the old FacetPath.
            //
            string[] facetPath = _is.ReadStringArray();
            string   facet;

            if (facetPath.Length > 0)
            {
                if (facetPath.Length > 1)
                {
                    throw new Ice.MarshalException();
                }
                facet = facetPath[0];
            }
            else
            {
                facet = "";
            }

            string operation = _is.ReadString();
            byte   mode      = _is.ReadByte();
            var    context   = new Dictionary <string, string>();
            int    sz        = _is.ReadSize();

            while (sz-- > 0)
            {
                string first  = _is.ReadString();
                string second = _is.ReadString();
                context[first] = second;
            }
            _current = new Ice.Current(_adapter, id, facet, operation, (Ice.OperationMode)mode, context, _requestId, _connection);
            Ice.Instrumentation.ICommunicatorObserver?obsv = _communicator.Observer;
            if (obsv != null)
            {
                // Read the encapsulation size.
                int size = _is.ReadInt();
                _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.
            //
            _servant = _adapter.Find(_current.Id, _current.Facet);

            if (_servant == null)
            {
                try
                {
                    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.Dispatch(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);
            }
        }