Пример #1
0
        public void OnAvailableImage(
            long correlationId,
            int streamId,
            int sessionId,
            long subscriptionRegistrationId,
            int subscriberPositionId,
            string logFileName,
            string sourceIdentity)
        {
            Subscription subscription = (Subscription)_resourceByRegIdMap[subscriptionRegistrationId];

            if (null != subscription && !subscription.ContainsImage(correlationId))
            {
                Image image = new Image(subscription, sessionId,
                                        new UnsafeBufferPosition(_counterValuesBuffer, subscriberPositionId),
                                        LogBuffers(correlationId, logFileName), _ctx.ErrorHandler(), sourceIdentity, correlationId);

                AvailableImageHandler handler = subscription.AvailableImageHandler();
                if (null != handler)
                {
                    try
                    {
                        handler(image);
                    }
                    catch (Exception ex)
                    {
                        HandleError(ex);
                    }
                }

                subscription.AddImage(image);
            }
        }
Пример #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();
            }
        }
Пример #3
0
        internal ClientConductor(Aeron.Context ctx)
        {
            _ctx = ctx;

            _clientLock                     = ctx.ClientLock();
            _epochClock                     = ctx.EpochClock();
            _nanoClock                      = ctx.NanoClock();
            _errorHandler                   = ctx.ErrorHandler();
            _counterValuesBuffer            = ctx.CountersValuesBuffer();
            _driverProxy                    = ctx.DriverProxy();
            _logBuffersFactory              = ctx.LogBuffersFactory();
            _imageMapMode                   = ctx.ImageMapMode();
            _keepAliveIntervalNs            = ctx.KeepAliveInterval();
            _driverTimeoutMs                = ctx.DriverTimeoutMs();
            _driverTimeoutNs                = _driverTimeoutMs * 1000000;
            _interServiceTimeoutNs          = ctx.InterServiceTimeout();
            _publicationConnectionTimeoutMs = ctx.PublicationConnectionTimeout();
            _driverListener                 = new DriverListenerAdapter(ctx.ToClientBuffer(), this);
            _driverAgentInvoker             = ctx.DriverAgentInvoker();

            long nowNs = _nanoClock.NanoTime();

            _timeOfLastKeepaliveNs      = nowNs;
            _timeOfLastCheckResourcesNs = nowNs;
            _timeOfLastWorkNs           = nowNs;
        }
Пример #4
0
        internal ClientConductor(Aeron.Context ctx)
        {
            _clientLock                     = ctx.ClientLock();
            _epochClock                     = ctx.EpochClock();
            _nanoClock                      = ctx.NanoClock();
            _errorHandler                   = ctx.ErrorHandler();
            _counterValuesBuffer            = ctx.CountersValuesBuffer();
            _driverProxy                    = ctx.DriverProxy();
            _logBuffersFactory              = ctx.LogBuffersFactory();
            _imageMapMode                   = ctx.ImageMapMode();
            _keepAliveIntervalNs            = ctx.KeepAliveInterval();
            _driverTimeoutMs                = ctx.DriverTimeoutMs();
            _driverTimeoutNs                = _driverTimeoutMs * 1000000;
            _interServiceTimeoutNs          = ctx.InterServiceTimeout();
            _publicationConnectionTimeoutMs = ctx.PublicationConnectionTimeout();
            _defaultAvailableImageHandler   = ctx.AvailableImageHandler();
            _defaultUnavailableImageHandler = ctx.UnavailableImageHandler();
            _driverEventsAdapter            = new DriverEventsAdapter(ctx.ToClientBuffer(), this);

            long nowNs = _nanoClock.NanoTime();

            _timeOfLastKeepAliveNs      = nowNs;
            _timeOfLastResourcesCheckNs = nowNs;
            _timeOfLastServiceNs        = nowNs;
        }