예제 #1
0
        public static void dumpStream(BasicStream stream)
        {
            int pos = stream.pos();

            stream.pos(0);

            byte[] data = new byte[stream.size()];
            stream.readBlob(data);
            dumpOctets(data);

            stream.pos(pos);
        }
예제 #2
0
        internal static void traceRecv(BasicStream str, Ice.Logger logger, TraceLevels tl)
        {
            if (tl.protocol >= 1)
            {
                int p = str.pos();
                str.pos(0);

                using (System.IO.StringWriter s = new System.IO.StringWriter(CultureInfo.CurrentCulture))
                {
                    byte type = printMessage(s, str);

                    logger.trace(tl.protocolCat, "received " + getMessageTypeAsString(type) + " " + s.ToString());
                }
                str.pos(p);
            }
        }
예제 #3
0
        internal static void trace(string heading, BasicStream str, Ice.Logger logger, TraceLevels tl)
        {
            if (tl.protocol >= 1)
            {
                int p = str.pos();
                str.pos(0);

                using (System.IO.StringWriter s = new System.IO.StringWriter(CultureInfo.CurrentCulture))
                {
                    s.Write(heading);
                    printMessage(s, str);

                    logger.trace(tl.protocolCat, s.ToString());
                }
                str.pos(p);
            }
        }
예제 #4
0
 //
 // Writeable stream constructor
 //
 public StreamWrapper(BasicStream s)
 {
     type_   = StreamType.Write;
     s_      = s;
     spos_   = s.pos();
     bytes_  = new byte[254];
     pos_    = 0;
     length_ = 0;
 }
예제 #5
0
        public void sendResponse(int requestId, BasicStream os, byte status, bool amd)
        {
            Ice.AsyncCallback cb = null;
            OutgoingAsyncBase outAsync;

            lock (this)
            {
                Debug.Assert(_response);

                os.pos(Protocol.replyHdr.Length + 4);

                if (_traceLevels.protocol >= 1)
                {
                    fillInValue(os, 10, os.size());
                    TraceUtil.traceRecv(os, _logger, _traceLevels);
                }

                if (_asyncRequests.TryGetValue(requestId, out outAsync))
                {
                    _asyncRequests.Remove(requestId);
                    outAsync.getIs().swap(os);
                    cb = outAsync.completed();
                }
            }

            if (cb != null)
            {
                if (amd)
                {
                    outAsync.invokeCompletedAsync(cb);
                }
                else
                {
                    outAsync.invokeCompleted(cb);
                }
            }
            _adapter.decDirectCount();
        }
예제 #6
0
파일: Incoming.cs 프로젝트: stick/zeroc-ice
        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;
        }
예제 #7
0
        private void invokeAll(BasicStream os, int requestId, int batchRequestNum)
        {
            if (batchRequestNum > 0)
            {
                os.pos(Protocol.requestBatchHdr.Length);
            }
            else
            {
                os.pos(Protocol.requestHdr.Length);
            }

            if (_traceLevels.protocol >= 1)
            {
                fillInValue(os, 10, os.size());
                if (requestId > 0)
                {
                    fillInValue(os, Protocol.headerSize, requestId);
                }
                else if (batchRequestNum > 0)
                {
                    fillInValue(os, Protocol.headerSize, batchRequestNum);
                }
                TraceUtil.traceSend(os, _logger, _traceLevels);
            }

            int            invokeNum      = batchRequestNum > 0 ? batchRequestNum : 1;
            ServantManager servantManager = _adapter.getServantManager();

            try
            {
                while (invokeNum > 0)
                {
                    //
                    // Increase the direct count for the dispatch. We increase it again here for
                    // each dispatch. It's important for the direct count to be > 0 until the last
                    // collocated request response is sent to make sure the thread pool isn't
                    // destroyed before.
                    //
                    try
                    {
                        _adapter.incDirectCount();
                    }
                    catch (Ice.ObjectAdapterDeactivatedException ex)
                    {
                        handleException(requestId, ex, false);
                        break;
                    }

                    Incoming @in = new Incoming(_reference.getInstance(), this, null, _adapter, _response, (byte)0,
                                                requestId);
                    @in.invoke(servantManager, os);
                    --invokeNum;
                }
            }
            catch (Ice.LocalException ex)
            {
                invokeException(requestId, ex, invokeNum, false); // Fatal invocation exception
            }

            _adapter.decDirectCount();
        }