예제 #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();
        }
예제 #2
0
        private async ValueTask InvokeAllAsync(OutgoingRequestFrame outgoingRequest, 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)
                {
                    // TODO we need a better API for tracing
                    List <System.ArraySegment <byte> > requestData =
                        Ice1Definitions.GetRequestData(outgoingRequest, requestId);
                    TraceUtil.TraceSend(_adapter.Communicator, VectoredBufferExtensions.ToArray(requestData), _logger,
                                        _traceLevels);
                }

                var incomingRequest = new IncomingRequestFrame(_adapter.Communicator, outgoingRequest);
                var current         = new Current(_adapter, incomingRequest, requestId);

                // Then notify and set dispatch observer, if any.
                Ice.Instrumentation.ICommunicatorObserver?communicatorObserver = _adapter.Communicator.Observer;
                if (communicatorObserver != null)
                {
                    dispatchObserver = communicatorObserver.GetDispatchObserver(current, incomingRequest.Size);
                    dispatchObserver?.Attach();
                }

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

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

                    ValueTask <OutgoingResponseFrame> vt = servant.DispatchAsync(incomingRequest, current);
                    amd = !vt.IsCompleted;
                    if (requestId != 0)
                    {
                        OutgoingResponseFrame response = await vt.ConfigureAwait(false);

                        dispatchObserver?.Reply(response.Size);
                        SendResponse(requestId, response, amd);
                    }
                }
                catch (System.Exception ex)
                {
                    if (requestId != 0)
                    {
                        RemoteException actualEx;
                        if (ex is RemoteException remoteEx && !remoteEx.ConvertToUnhandled)
                        {
                            actualEx = remoteEx;
                        }
                        else
                        {
                            actualEx = new UnhandledException(current.Identity, current.Facet, current.Operation, ex);
                        }

                        Incoming.ReportException(actualEx, dispatchObserver, current);
                        var response = new OutgoingResponseFrame(current, actualEx);
                        dispatchObserver?.Reply(response.Size);
                        SendResponse(requestId, response, amd);
                    }
                }
            }
예제 #3
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();
            }
        }
예제 #4
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, new Ice.OutputStream.Position(0, 10), os.Size);
                    if (requestId > 0)
                    {
                        FillInValue(os, new Ice.OutputStream.Position(0, Ice1Definitions.HeaderSize), requestId);
                    }
                    TraceUtil.TraceSend(os, _logger, _traceLevels);
                }

                // TODO Avoid copy OutputStream buffer
                var requestFrame = new Ice.InputStream(os.Communicator, os.Encoding, os.ToArray());
                requestFrame.Pos = Ice1Definitions.RequestHeader.Length;

                int start   = requestFrame.Pos;
                var current = new Ice.Current(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)
                    {
                        Ice.OutputStream responseFrame = await vt.ConfigureAwait(false);

                        dispatchObserver?.Reply(responseFrame.Size - Ice1Definitions.HeaderSize - 4);
                        SendResponse(requestId, responseFrame, amd);
                    }
                }
                catch (System.Exception ex)
                {
                    if (requestId != 0)
                    {
                        Ice.RemoteException actualEx;
                        if (ex is Ice.RemoteException remoteEx && !remoteEx.ConvertToUnhandled)
                        {
                            actualEx = remoteEx;
                        }
                        else
                        {
                            actualEx = new UnhandledException(current.Id, current.Facet, current.Operation, ex);
                        }

                        Incoming.ReportException(actualEx, dispatchObserver, current);
                        var responseFrame = new Ice.OutgoingResponseFrame(current, actualEx);
                        dispatchObserver?.Reply(responseFrame.Size - Ice1Definitions.HeaderSize - 4);
                        SendResponse(requestId, responseFrame, amd);
                    }
                }
            }