Esempio n. 1
0
        public ControlledFragmentHandlerAction OnFragment(IDirectBuffer buffer, int offset, int length, Header header)
        {
            messageHeaderDecoder.Wrap(buffer, offset);

            templateId = messageHeaderDecoder.TemplateId();
            switch (templateId)
            {
            case SessionEventDecoder.TEMPLATE_ID:
                sessionEventDecoder.Wrap(buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH,
                                         messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version());

                clusterSessionId = sessionEventDecoder.ClusterSessionId();
                correlationId    = sessionEventDecoder.CorrelationId();
                leadershipTermId = sessionEventDecoder.LeadershipTermId();
                leaderMemberId   = sessionEventDecoder.LeaderMemberId();
                eventCode        = sessionEventDecoder.Code();
                detail           = sessionEventDecoder.Detail();
                break;

            case NewLeaderEventDecoder.TEMPLATE_ID:
                newLeaderEventDecoder.Wrap(buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH,
                                           messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version());

                clusterSessionId = newLeaderEventDecoder.ClusterSessionId();
                leadershipTermId = newLeaderEventDecoder.LeadershipTermId();
                leaderMemberId   = newLeaderEventDecoder.LeaderMemberId();
                detail           = newLeaderEventDecoder.MemberEndpoints();
                break;

            case EgressMessageHeaderDecoder.TEMPLATE_ID:
                egressMessageHeaderDecoder.Wrap(buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH,
                                                messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version());

                leadershipTermId = EgressMessageHeaderDecoder.LeadershipTermIdId();
                clusterSessionId = egressMessageHeaderDecoder.ClusterSessionId();
                break;

            case ChallengeDecoder.TEMPLATE_ID:
                challengeDecoder.Wrap(buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH,
                                      messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version());

                encodedChallenge = new byte[challengeDecoder.EncodedChallengeLength()];
                challengeDecoder.GetEncodedChallenge(encodedChallenge, 0, challengeDecoder.EncodedChallengeLength());

                clusterSessionId = challengeDecoder.ClusterSessionId();
                correlationId    = challengeDecoder.CorrelationId();
                break;

            default:
                throw new ClusterException("unknown templateId: " + templateId);
            }

            pollComplete = true;

            return(ControlledFragmentHandlerAction.BREAK);
        }
Esempio n. 2
0
        public void OnFragment(IDirectBuffer buffer, int offset, int length, Header header)
        {
            _messageHeaderDecoder.Wrap(buffer, offset);

            int templateId = _messageHeaderDecoder.TemplateId();

            if (EgressMessageHeaderDecoder.TEMPLATE_ID == templateId)
            {
                _egressMessageHeaderDecoder.Wrap(
                    buffer,
                    offset + MessageHeaderDecoder.ENCODED_LENGTH,
                    _messageHeaderDecoder.BlockLength(),
                    _messageHeaderDecoder.Version());

                var sessionId = _egressMessageHeaderDecoder.ClusterSessionId();
                if (sessionId == _clusterSessionId)
                {
                    _listener.OnMessage(
                        sessionId,
                        _egressMessageHeaderDecoder.Timestamp(),
                        buffer,
                        offset + SESSION_HEADER_LENGTH,
                        length - SESSION_HEADER_LENGTH,
                        header);
                }

                return;
            }

            switch (templateId)
            {
            case SessionEventDecoder.TEMPLATE_ID:
            {
                _sessionEventDecoder.Wrap(
                    buffer,
                    offset + MessageHeaderDecoder.ENCODED_LENGTH,
                    _messageHeaderDecoder.BlockLength(),
                    _messageHeaderDecoder.Version());

                var sessionId = _sessionEventDecoder.ClusterSessionId();
                if (sessionId == _clusterSessionId)
                {
                    _listener.SessionEvent(
                        _sessionEventDecoder.CorrelationId(),
                        sessionId,
                        _sessionEventDecoder.LeadershipTermId(),
                        _sessionEventDecoder.LeaderMemberId(),
                        _sessionEventDecoder.Code(),
                        _sessionEventDecoder.Detail());
                }

                break;
            }

            case NewLeaderEventDecoder.TEMPLATE_ID:
            {
                _newLeaderEventDecoder.Wrap(
                    buffer,
                    offset + MessageHeaderDecoder.ENCODED_LENGTH,
                    _messageHeaderDecoder.BlockLength(),
                    _messageHeaderDecoder.Version());

                var sessionId = _newLeaderEventDecoder.ClusterSessionId();
                if (sessionId == _clusterSessionId)
                {
                    _listener.NewLeader(
                        sessionId,
                        _sessionEventDecoder.LeadershipTermId(),
                        _newLeaderEventDecoder.LeaderMemberId(),
                        _newLeaderEventDecoder.MemberEndpoints());
                }

                break;
            }

            case ChallengeDecoder.TEMPLATE_ID:
                break;

            default:
                throw new ClusterException("unknown templateId: " + templateId);
            }
        }