예제 #1
0
        public void OnClose()
        {
            _clientLock.Lock();

            try
            {
                if (!_isClosed)
                {
                    _isClosed = true;

                    int lingeringResourcesSize = _lingeringResources.Count;
                    ForceCloseResources();
                    _driverProxy.ClientClose();

                    if (_lingeringResources.Count > lingeringResourcesSize)
                    {
                        Aeron.Sleep(1);
                    }

                    for (int i = 0, size = _lingeringResources.Count; i < size; i++)
                    {
                        _lingeringResources[i].Delete();
                    }
                }
            }
            finally
            {
                _clientLock.Unlock();
            }
        }
예제 #2
0
        private void AwaitResponse(long correlationId, string expectedChannel)
        {
            _driverException = null;
            var deadlineNs = _nanoClock.NanoTime() + _driverTimeoutNs;

            do
            {
                if (null == _driverAgentInvoker)
                {
                    Aeron.Sleep(1);
                }
                else
                {
                    _driverAgentInvoker.Invoke();
                }

                DoWork(correlationId, expectedChannel);

                if (_driverListener.LastReceivedCorrelationId() == correlationId)
                {
                    if (null != _driverException)
                    {
                        throw _driverException;
                    }

                    return;
                }
            } while (_nanoClock.NanoTime() < deadlineNs);

            throw new DriverTimeoutException("No response from driver wihtout timeout");
        }
예제 #3
0
        private AeronClient(ClientServerConfig config)
        {
            _config = config;
            AeronDriver.DriverContext    driverContext = config.ToDriverContext();
            Adaptive.Aeron.Aeron.Context clientContext = config.ToClientContext();

            driverContext
            .LoggerInfo(_driverLog.Info)
            .LoggerWarning(_driverLog.Warn)
            .LoggerWarning(_driverLog.Error);

            _driver = AeronDriver.Start(driverContext);

            clientContext
            .ErrorHandler(OnError)
            .AvailableImageHandler(ConnectionOnImageAvailable)
            .UnavailableImageHandler(ConnectionOnImageUnavailable);

            _client = Adaptive.Aeron.Aeron.Connect(clientContext);

            const int sessionsLen =
#if DEBUG
                1;
#else
                64;
#endif

            _clientSessions = new AeronClientSession[sessionsLen];
        }
예제 #4
0
        private void checkServiceInterval(long nowNs)
        {
            if (nowNs > (_timeOfLastServiceNs + _interServiceTimeoutNs))
            {
                int lingeringResourcesSize = _lingeringResources.Count;

                ForceCloseResources();

                if (_lingeringResources.Count > lingeringResourcesSize)
                {
                    Aeron.Sleep(1000);
                }

                OnClose();

                throw new ConductorServiceTimeoutException("Exceeded (ns): " + _interServiceTimeoutNs);
            }
        }
        private void CheckServiceInterval(long nowNs)
        {
            if ((_timeOfLastServiceNs + _interServiceTimeoutNs) - nowNs < 0)
            {
                int lingeringResourcesSize = _lingeringResources.Count;

                ForceCloseResources();

                if (_lingeringResources.Count > lingeringResourcesSize)
                {
                    Aeron.Sleep(NanoUtil.ToMillis(_ctx.ResourceLingerDurationNs()));
                }

                OnClose();

                throw new ConductorServiceTimeoutException("service interval exceeded (ns): " + _interServiceTimeoutNs);
            }
        }
예제 #6
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;
        }
예제 #7
0
        public void OnClose()
        {
            if (!_isClosed)
            {
                _isClosed = true;

                int lingeringResourcesSize = _lingeringResources.Count;
                ForceClosePublicationsAndSubscriptions();

                if (_lingeringResources.Count > lingeringResourcesSize)
                {
                    Aeron.Sleep(1);
                }

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

                _lingeringResources.Clear();
            }
        }
예제 #8
0
        private void AwaitResponse(long correlationId)
        {
            _driverException = null;
            var deadlineNs = _nanoClock.NanoTime() + _driverTimeoutNs;

            do
            {
                Aeron.Sleep(1);

                Service(correlationId);

                if (_driverEventsAdapter.LastReceivedCorrelationId() == correlationId)
                {
                    if (null != _driverException)
                    {
                        throw _driverException;
                    }

                    return;
                }
            } while (_nanoClock.NanoTime() < deadlineNs);

            throw new DriverTimeoutException("No response from MediaDriver within (ms):" + _driverTimeoutMs);
        }
        public AeronServer(int serverPort, ClientServerConfig config)
        {
            _config        = config;
            _driverContext = config.ToDriverContext();
            _clientContext = config.ToClientContext();

            _driverContext
            .LoggerInfo(_driverLog.Info)
            .LoggerWarning(_driverLog.Warn)
            .LoggerWarning(_driverLog.Error);

            _driver = AeronDriver.Start(_driverContext);

            _clientContext
            .ErrorHandler(OnError)
            .AvailableImageHandler(ConnectionOnImageAvailable)
            .UnavailableImageHandler(ConnectionOnImageUnavailable);

            _client = Adaptive.Aeron.Aeron.Connect(_clientContext);

            _publicationIdleStrategy = _config.ClientIdleStrategy.GetClientIdleStrategy();

            _subscription = _client.AddSubscription($"aeron:udp?endpoint=0.0.0.0:{serverPort}", ServerStreamId);
        }