Ejemplo n.º 1
0
        private void InvokeAll(Ice.OutputStream os, int requestId)
        {
            if (_traceLevels.protocol >= 1)
            {
                FillInValue(os, 10, os.Size);
                if (requestId > 0)
                {
                    FillInValue(os, Protocol.headerSize, requestId);
                }
                TraceUtil.TraceSend(os, _logger, _traceLevels);
            }

            var iss = new Ice.InputStream(os.Communicator, os.Encoding, os.GetBuffer(), false);

            iss.Pos = Protocol.requestHdr.Length;

            int            invokeNum      = 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;
                    }

                    var inS = new Incoming(_reference.GetCommunicator(), this, null, _adapter, _response, 0, requestId);
                    inS.Invoke(servantManager, iss);
                    --invokeNum;
                }
            }
            catch (Ice.LocalException ex)
            {
                InvokeException(requestId, ex, invokeNum, false); // Fatal invocation exception
            }

            _adapter.decDirectCount();
        }
Ejemplo n.º 2
0
        public void SendResponse(int requestId, Ice.OutputStream os, byte status, bool amd)
        {
            OutgoingAsyncBase?outAsync;

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

                if (_traceLevels.Protocol >= 1)
                {
                    FillInValue(os, 10, os.Size);
                }

                // Adopt the OutputStream's buffer.
                var iss = new Ice.InputStream(os.Communicator, os.Encoding, os.GetBuffer(), true);

                iss.Pos = Protocol.replyHdr.Length + 4;

                if (_traceLevels.Protocol >= 1)
                {
                    TraceUtil.TraceRecv(iss, _logger, _traceLevels);
                }

                if (_asyncRequests.TryGetValue(requestId, out outAsync))
                {
                    outAsync.GetIs().Swap(iss);
                    if (!outAsync.Response())
                    {
                        outAsync = null;
                    }
                    _asyncRequests.Remove(requestId);
                }
            }

            if (outAsync != null)
            {
                if (amd)
                {
                    outAsync.InvokeResponseAsync();
                }
                else
                {
                    outAsync.InvokeResponse();
                }
            }
            _adapter.DecDirectCount();
        }
Ejemplo n.º 3
0
        internal static void TraceSend(Ice.OutputStream str, Ice.ILogger logger, TraceLevels tl)
        {
            if (tl.Protocol >= 1)
            {
                int p   = str.Pos;
                var iss = new Ice.InputStream(str.Communicator, str.Encoding, str.GetBuffer(), false);
                iss.Pos = 0;

                using (var s = new System.IO.StringWriter(CultureInfo.CurrentCulture))
                {
                    byte type = PrintMessage(s, iss);

                    logger.Trace(tl.ProtocolCat, "sending " + GetMessageTypeAsString(type) + " " + s.ToString());
                }
                str.Pos = p;
            }
        }
Ejemplo n.º 4
0
        internal static void Trace(string heading, Ice.OutputStream str, Ice.ILogger logger, TraceLevels tl)
        {
            if (tl.protocol >= 1)
            {
                int p   = str.Pos;
                var iss = new Ice.InputStream(str.Communicator, str.Encoding, str.GetBuffer(), false);
                iss.Pos = 0;

                using (var s = new System.IO.StringWriter(CultureInfo.CurrentCulture))
                {
                    s.Write(heading);
                    PrintMessage(s, iss);

                    logger.Trace(tl.protocolCat, s.ToString());
                }
                str.Pos = p;
            }
        }
Ejemplo n.º 5
0
        public EndpointI create(string str, bool oaEndpoint)
        {
            string[]? arr = IceUtilInternal.StringUtil.splitString(str, " \t\r\n");
            if (arr == null)
            {
                throw new System.FormatException("mismatched quote");
            }

            if (arr.Length == 0)
            {
                throw new System.FormatException("value has no non-whitespace characters");
            }

            List <string> v        = new List <string>(arr);
            string        protocol = v[0];

            v.RemoveAt(0);

            if (protocol.Equals("default"))
            {
                protocol = _communicator.defaultsAndOverrides().defaultProtocol;
            }

            EndpointFactory factory = null;

            lock (this)
            {
                for (int i = 0; i < _factories.Count; i++)
                {
                    EndpointFactory f = _factories[i];
                    if (f.protocol().Equals(protocol))
                    {
                        factory = f;
                    }
                }
            }

            if (factory != null)
            {
                EndpointI e = factory.create(v, oaEndpoint);
                if (v.Count > 0)
                {
                    throw new System.FormatException($"unrecognized argument `{v[0]}' in endpoint `{str}'");
                }
                return(e);

                // Code below left in place for debugging.

                /*
                 * EndpointI e = f.create(s.Substring(m.Index + m.Length), oaEndpoint);
                 * BasicStream bs = new BasicStream(_instance, true);
                 * e.streamWrite(bs);
                 * Buffer buf = bs.getBuffer();
                 * buf.b.position(0);
                 * short type = bs.readShort();
                 * EndpointI ue = new IceInternal.OpaqueEndpointI(type, bs);
                 * System.Console.Error.WriteLine("Normal: " + e);
                 * System.Console.Error.WriteLine("Opaque: " + ue);
                 * return e;
                 */
            }

            //
            // If the stringified endpoint is opaque, create an unknown endpoint,
            // then see whether the type matches one of the known endpoints.
            //
            if (protocol.Equals("opaque"))
            {
                EndpointI ue = new OpaqueEndpointI(v);
                if (v.Count > 0)
                {
                    throw new System.FormatException($"unrecognized argument `{v[0]}' in endpoint `{str}'");
                }
                factory = get(ue.type());
                if (factory != null)
                {
                    //
                    // Make a temporary stream, write the opaque endpoint data into the stream,
                    // and ask the factory to read the endpoint data from that stream to create
                    // the actual endpoint.
                    //
                    Ice.OutputStream os = new Ice.OutputStream(_communicator, Ice.Util.currentProtocolEncoding);
                    os.WriteShort(ue.type());
                    ue.streamWrite(os);
                    Ice.InputStream iss =
                        new Ice.InputStream(_communicator, Ice.Util.currentProtocolEncoding, os.GetBuffer(), true);
                    iss.pos(0);
                    iss.ReadShort(); // type
                    iss.StartEncapsulation();
                    EndpointI e = factory.read(iss);
                    iss.EndEncapsulation();
                    return(e);
                }
                return(ue); // Endpoint is opaque, but we don't have a factory for its type.
            }

            return(null);
        }
Ejemplo n.º 6
0
        private async ValueTask InvokeAllAsync(Ice.OutputStream os, int requestId)
        {
            // The object adapter DirectCount was incremented by the caller and we are responsible to decrement it
            // upon completion.

            Ice.Instrumentation.IDispatchObserver?dispatchObserver = null;
            try
            {
                if (_traceLevels.Protocol >= 1)
                {
                    FillInValue(os, 10, os.Size);
                    if (requestId > 0)
                    {
                        FillInValue(os, Protocol.headerSize, requestId);
                    }
                    TraceUtil.TraceSend(os, _logger, _traceLevels);
                }

                var requestFrame = new Ice.InputStream(os.Communicator, os.Encoding, os.GetBuffer(), false);
                requestFrame.Pos = Protocol.requestHdr.Length;

                int start   = requestFrame.Pos;
                var current = Protocol.CreateCurrent(requestId, requestFrame, _adapter);

                // Then notify and set dispatch observer, if any.
                Ice.Instrumentation.ICommunicatorObserver?communicatorObserver = _adapter.Communicator.Observer;
                if (communicatorObserver != null)
                {
                    int encapsSize = requestFrame.GetEncapsulationSize();

                    dispatchObserver = communicatorObserver.GetDispatchObserver(current,
                                                                                requestFrame.Pos - start + encapsSize);
                    dispatchObserver?.Attach();
                }

                bool amd = true;
                try
                {
                    Ice.IObject?servant = current.Adapter.Find(current.Id, current.Facet);

                    if (servant == null)
                    {
                        amd = false;
                        throw new Ice.ObjectNotExistException(current.Id, current.Facet, current.Operation);
                    }

                    ValueTask <Ice.OutputStream> vt = servant.DispatchAsync(requestFrame, current);
                    amd = !vt.IsCompleted;
                    if (requestId != 0)
                    {
                        var responseFrame = await vt.ConfigureAwait(false);

                        dispatchObserver?.Reply(responseFrame.Size - Protocol.headerSize - 4);
                        SendResponse(requestId, responseFrame, amd);
                    }
                }
                catch (Ice.SystemException ex)
                {
                    Incoming.ReportException(ex, dispatchObserver, current);
                    // Forward the exception to the caller without marshaling
                    HandleException(requestId, ex, amd);
                }
                catch (System.Exception ex)
                {
                    Incoming.ReportException(ex, dispatchObserver, current);
                    if (requestId != 0)
                    {
                        // For now, marshal it
                        // TODO: revisit during exception refactoring.
                        var responseFrame = Protocol.CreateFailureResponseFrame(ex, current);
                        dispatchObserver?.Reply(responseFrame.Size - Protocol.headerSize - 4);
                        SendResponse(requestId, responseFrame, amd);
                    }
                }
            }
            catch (Ice.LocalException ex)
            {
                HandleException(requestId, ex, false);
            }
            finally
            {
                dispatchObserver?.Detach();
                _adapter.DecDirectCount();
            }
        }
Ejemplo n.º 7
0
        internal static void trace(string heading, Ice.OutputStream str, Ice.Logger logger, TraceLevels tl)
        {
            if (tl.protocol >= 1)
            {
                int             p   = str.pos();
                Ice.InputStream iss = new Ice.InputStream(str.communicator(), str.GetEncoding(), str.GetBuffer(), false);
                iss.pos(0);

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

                    logger.trace(tl.protocolCat, s.ToString());
                }
                str.pos(p);
            }
        }
Ejemplo n.º 8
0
        internal static void traceSend(Ice.OutputStream str, Ice.Logger logger, TraceLevels tl)
        {
            if (tl.protocol >= 1)
            {
                int             p   = str.pos();
                Ice.InputStream iss = new Ice.InputStream(str.communicator(), str.GetEncoding(), str.GetBuffer(), false);
                iss.pos(0);

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

                    logger.trace(tl.protocolCat, "sending " + getMessageTypeAsString(type) + " " + s.ToString());
                }
                str.pos(p);
            }
        }