Пример #1
0
        internal ClientConductor(Aeron.Context ctx, Aeron aeron)
        {
            _ctx   = ctx;
            _aeron = aeron;

            _clientLock                     = ctx.ClientLock();
            _epochClock                     = ctx.EpochClock();
            _nanoClock                      = ctx.NanoClock();
            _awaitingIdleStrategy           = ctx.AwaitingIdleStrategy();
            _driverProxy                    = ctx.DriverProxy();
            _logBuffersFactory              = ctx.LogBuffersFactory();
            _keepAliveIntervalNs            = ctx.KeepAliveIntervalNs();
            _driverTimeoutMs                = ctx.DriverTimeoutMs();
            _driverTimeoutNs                = _driverTimeoutMs * 1000000;
            _interServiceTimeoutNs          = ctx.InterServiceTimeoutNs();
            _defaultAvailableImageHandler   = ctx.AvailableImageHandler();
            _defaultUnavailableImageHandler = ctx.UnavailableImageHandler();
            _driverEventsAdapter            =
                new DriverEventsAdapter(ctx.ToClientBuffer(), ctx.ClientId(), this, _asyncCommandIdSet);
            _driverAgentInvoker  = ctx.DriverAgentInvoker();
            _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;
        }
Пример #2
0
        private int CheckLiveness(long nowNs)
        {
            if ((_timeOfLastKeepAliveNs + _keepAliveIntervalNs) - nowNs < 0)
            {
                long lastKeepAliveMs = _driverProxy.TimeOfLastDriverKeepaliveMs();
                var  nowMs           = _epochClock.Time();

                if (nowMs > (lastKeepAliveMs + _driverTimeoutMs))
                {
                    _isTerminating = true;
                    ForceCloseResources();

                    throw new DriverTimeoutException("MediaDriver keepalive age exceeded (ms): timeout= " +
                                                     _driverTimeoutMs + ", actual=" + (nowMs - lastKeepAliveMs));
                }

                if (null == _heartbeatTimestamp)
                {
                    int counterId = HeartbeatTimestamp.FindCounterIdByRegistrationId(_countersReader, HeartbeatTimestamp.CLIENT_HEARTBEAT_TYPE_ID, _ctx.ClientId());

                    if (counterId != Agrona.Concurrent.Status.CountersReader.NULL_COUNTER_ID)
                    {
                        _heartbeatTimestamp = new AtomicCounter(_counterValuesBuffer, counterId);
                        _heartbeatTimestamp.SetOrdered(nowMs);
                        _timeOfLastKeepAliveNs = nowNs;
                    }
                }
                else
                {
                    int counterId = _heartbeatTimestamp.Id;
                    if (!HeartbeatTimestamp.IsActive(_countersReader, counterId, HeartbeatTimestamp.CLIENT_HEARTBEAT_TYPE_ID, _ctx.ClientId()))
                    {
                        _isTerminating = true;
                        ForceCloseResources();

                        throw new AeronException("unexpected close of heartbeat timestamp counter: " + counterId);
                    }

                    _heartbeatTimestamp.SetOrdered(nowMs);
                    _timeOfLastKeepAliveNs = nowNs;
                }

                return(1);
            }

            return(0);
        }
Пример #3
0
        internal ClientConductor(Aeron.Context ctx)
        {
            _ctx = ctx;

            _clientLock = ctx.ClientLock();
            _epochClock = ctx.EpochClock();
            _nanoClock  = ctx.NanoClock();

            _driverProxy       = ctx.DriverProxy();
            _logBuffersFactory = ctx.LogBuffersFactory();

            _keepAliveIntervalNs            = ctx.KeepAliveInterval();
            _driverTimeoutMs                = ctx.DriverTimeoutMs();
            _driverTimeoutNs                = _driverTimeoutMs * 1000000;
            _interServiceTimeoutNs          = ctx.InterServiceTimeout();
            _defaultAvailableImageHandler   = ctx.AvailableImageHandler();
            _defaultUnavailableImageHandler = ctx.UnavailableImageHandler();
            _availableCounterHandler        = ctx.AvailableCounterHandler();
            _unavailableCounterHandler      = ctx.UnavailableCounterHandler();
            _driverEventsAdapter            = new DriverEventsAdapter(ctx.ToClientBuffer(), ctx.ClientId(), this);
            _counterValuesBuffer            = ctx.CountersValuesBuffer();
            _countersReader =
                new CountersReader(ctx.CountersMetaDataBuffer(), ctx.CountersValuesBuffer(), Encoding.ASCII);

            long nowNs = _nanoClock.NanoTime();

            _timeOfLastKeepAliveNs = nowNs;
            _timeOfLastServiceNs   = nowNs;
        }