Пример #1
0
        public int DoWork()
        {
            int workCount = 0;

            if (CheckForClockTick())
            {
                PollServiceAdapter();
                workCount += 1;
            }

            if (null != logAdapter)
            {
                int polled = logAdapter.Poll();

                if (0 == polled)
                {
                    if (logAdapter.IsConsumed(aeron.CountersReader()))
                    {
                        _consensusModuleProxy.Ack(logAdapter.Position(), ackId++, serviceId);
                        logAdapter.Dispose();
                        logAdapter = null;
                    }
                    else if (logAdapter.IsImageClosed())
                    {
                        logAdapter.Dispose();
                        logAdapter = null;
                    }
                }

                workCount += polled;
            }

            return(workCount);
        }
        public int DoWork()
        {
            int workCount = 0;

            if (CheckForClockTick())
            {
                PollServiceAdapter();
                workCount += 1;
            }

            if (null != logAdapter)
            {
                int polled = logAdapter.Poll();

                if (0 == polled)
                {
                    if (logAdapter.IsDone())
                    {
                        logAdapter.Dispose();
                        logAdapter = null;
                    }
                }

                workCount += polled;
            }

            return(workCount);
        }
Пример #3
0
        public void OnClose()
        {
            if (isServiceActive)
            {
                isServiceActive = false;
                try
                {
                    service.OnTerminate(this);
                }
                catch (Exception ex)
                {
                    ctx.CountedErrorHandler().OnError(ex);
                }
            }

            if (!ctx.OwnsAeronClient())
            {
                foreach (ClientSession session in sessionByIdMap.Values)
                {
                    session.Disconnect();
                }

                logAdapter?.Dispose();
                _consensusModuleProxy?.Dispose();
                _serviceAdapter?.Dispose();
            }

            ctx.Dispose();
        }
Пример #4
0
        public void OnClose()
        {
            if (shouldCloseResources)
            {
                logAdapter?.Dispose();
                serviceControlPublisher?.Dispose();
                serviceControlAdapter?.Dispose();

                foreach (ClientSession session in sessionByIdMap.Values)
                {
                    session.Disconnect();
                }
            }
        }
        public void OnClose()
        {
            if (!ctx.OwnsAeronClient())
            {
                logAdapter?.Dispose();
                _consensusModuleProxy?.Dispose();
                _serviceAdapter?.Dispose();

                foreach (ClientSession session in sessionByIdMap.Values)
                {
                    session.Disconnect();
                }
            }
        }
Пример #6
0
        private void JoinActiveLog()
        {
            if (null != logAdapter)
            {
                if (!logAdapter.IsCaughtUp())
                {
                    return;
                }

                logAdapter.Dispose();
                logAdapter = null;
            }


            CountersReader counters = aeron.CountersReader();

            int commitPositionId = newActiveLogEvent.commitPositionId;

            if (!CommitPos.IsActive(counters, commitPositionId))
            {
                throw new System.InvalidOperationException("CommitPos counter not active: " + commitPositionId);
            }

            int logSessionId = newActiveLogEvent.sessionId;

            leadershipTermId    = newActiveLogEvent.leadershipTermId;
            termBaseLogPosition = CommitPos.GetTermBaseLogPosition(counters, commitPositionId);

            Subscription logSubscription = aeron.AddSubscription(newActiveLogEvent.channel, newActiveLogEvent.streamId);

            if (newActiveLogEvent.ackBeforeImage)
            {
                serviceControlPublisher.AckAction(termBaseLogPosition, leadershipTermId, serviceId, ClusterAction.READY);
            }

            Image image = AwaitImage(logSessionId, logSubscription);

            heartbeatCounter.SetOrdered(epochClock.Time());

            if (!newActiveLogEvent.ackBeforeImage)
            {
                serviceControlPublisher.AckAction(termBaseLogPosition, leadershipTermId, serviceId, ClusterAction.READY);
            }

            newActiveLogEvent = null;
            logAdapter        = new BoundedLogAdapter(image, new ReadableCounter(counters, commitPositionId), this);

            Role((ClusterRole)roleCounter.Get());

            foreach (ClientSession session in sessionByIdMap.Values)
            {
                if (ClusterRole.Leader == role)
                {
                    session.Connect(aeron);
                }
                else
                {
                    session.Disconnect();
                }
            }
        }