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(); } }
internal ClientConductor(Aeron.Context ctx, Aeron aeron) { _ctx = ctx; _aeron = aeron; _clientLock = ctx.ClientLock(); _epochClock = ctx.EpochClock(); _nanoClock = ctx.NanoClock(); _driverProxy = ctx.DriverProxy(); _logBuffersFactory = ctx.LogBuffersFactory(); _keepAliveIntervalNs = ctx.KeepAliveIntervalNs(); _driverTimeoutMs = ctx.DriverTimeoutMs(); _driverTimeoutNs = _driverTimeoutMs * 1000000; _closeLingerDurationMs = (int)ctx.CloseLingerDurationNs() / 1000000; _interServiceTimeoutNs = ctx.InterServiceTimeoutNs(); _defaultAvailableImageHandler = ctx.AvailableImageHandler(); _defaultUnavailableImageHandler = ctx.UnavailableImageHandler(); _driverEventsAdapter = new DriverEventsAdapter(ctx.ToClientBuffer(), ctx.ClientId(), this); _counterValuesBuffer = ctx.CountersValuesBuffer(); _countersReader = new CountersReader(ctx.CountersMetaDataBuffer(), ctx.CountersValuesBuffer(), Encoding.ASCII); if (null != ctx.AvailableCounterHandler()) { _availableCounterHandlers.Add(ctx.AvailableCounterHandler()); } if (null != ctx.UnavailableCounterHandler()) { _unavailableCounterHandlers.Add(ctx.UnavailableCounterHandler()); } if (null != ctx.CloseHandler()) { _closeHandlers.Add(ctx.CloseHandler()); } long nowNs = _nanoClock.NanoTime(); _timeOfLastKeepAliveNs = nowNs; _timeOfLastServiceNs = nowNs; }