Пример #1
0
        public void OnClose()
        {
            _clientLock.Lock();
            try
            {
                if (!_isClosed)
                {
                    _isClosed = true;
                    if (_isTerminating)
                    {
                        _aeron.InternalClose();
                    }

                    ForceCloseResources();

                    for (int i = _closeHandlers.Count - 1; i >= 0; i--)
                    {
                        try
                        {
                            _closeHandlers[i].Invoke();
                        }
                        catch (Exception ex)
                        {
                            HandleError(ex);
                        }
                    }

                    try
                    {
                        if (_isTerminating)
                        {
                            Thread.Sleep(Aeron.Configuration.IdleSleepMs);
                        }

                        Thread.Sleep(_closeLingerDurationMs);
                    }
                    catch (ThreadInterruptedException)
                    {
                        Thread.CurrentThread.Interrupt();
                    }

                    for (int i = 0, size = _lingeringResources.Count; i < size; i++)
                    {
                        _lingeringResources[i].Delete();
                    }

                    _driverProxy.ClientClose();
                    _ctx.Dispose();
                }
            }
            finally
            {
                _clientLock.Unlock();
            }
        }
Пример #2
0
        public void OnClose()
        {
            bool isInterrupted = false;

            _clientLock.Lock();
            try
            {
                if (!_isClosed)
                {
                    if (!_aeron.IsClosed)
                    {
                        _aeron.InternalClose();
                    }

                    ForceCloseResources();
                    NotifyCloseHandlers();

                    try
                    {
                        if (_isTerminating)
                        {
                            Thread.Sleep(Aeron.Configuration.IdleSleepMs);
                        }

                        Thread.Sleep((int)TimeUnit.NANOSECONDS.toMillis(_ctx.CloseLingerDurationNs()));
                    }
                    catch (ThreadInterruptedException)
                    {
                        isInterrupted = true;
                    }

                    for (int i = 0, size = _lingeringLogBuffers.Count; i < size; i++)
                    {
                        CloseHelper.Dispose(_ctx.ErrorHandler(), _lingeringLogBuffers[i]);
                    }

                    _driverProxy.ClientClose();
                    _ctx.Dispose();
                }
            }
            finally
            {
                _isClosed = true;

                if (isInterrupted)
                {
                    Thread.CurrentThread.Interrupt();
                }

                _clientLock.Unlock();
            }
        }