コード例 #1
0
ファイル: BoundedLogAdapter.cs プロジェクト: shekky/Aeron.NET
        public ControlledFragmentHandlerAction OnFragment(IDirectBuffer buffer, int offset, int length, Header header)
        {
            messageHeaderDecoder.Wrap(buffer, offset);

            switch (messageHeaderDecoder.TemplateId())
            {
            case SessionHeaderDecoder.TEMPLATE_ID:
            {
                sessionHeaderDecoder.Wrap(buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH, messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version());

                agent.OnSessionMessage(sessionHeaderDecoder.ClusterSessionId(), sessionHeaderDecoder.CorrelationId(), sessionHeaderDecoder.Timestamp(), buffer, offset + ClientSession.SESSION_HEADER_LENGTH, length - ClientSession.SESSION_HEADER_LENGTH, header);

                break;
            }

            case TimerEventDecoder.TEMPLATE_ID:
            {
                timerEventDecoder.Wrap(buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH, messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version());

                agent.OnTimerEvent(timerEventDecoder.CorrelationId(), timerEventDecoder.Timestamp());
                break;
            }

            case SessionOpenEventDecoder.TEMPLATE_ID:
            {
                openEventDecoder.Wrap(buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH, messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version());

                string responseChannel  = openEventDecoder.ResponseChannel();
                byte[] encodedPrincipal = new byte[openEventDecoder.EncodedPrincipalLength()];
                openEventDecoder.GetEncodedPrincipal(encodedPrincipal, 0, encodedPrincipal.Length);

                agent.OnSessionOpen(openEventDecoder.ClusterSessionId(), openEventDecoder.Timestamp(), openEventDecoder.ResponseStreamId(), responseChannel, encodedPrincipal);
                break;
            }

            case SessionCloseEventDecoder.TEMPLATE_ID:
            {
                closeEventDecoder.Wrap(buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH, messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version());

                agent.OnSessionClose(closeEventDecoder.ClusterSessionId(), closeEventDecoder.Timestamp(), closeEventDecoder.CloseReason());
                break;
            }

            case ClusterActionRequestDecoder.TEMPLATE_ID:
            {
                actionRequestDecoder.Wrap(buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH, messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version());

                agent.OnServiceAction(header.Position(), actionRequestDecoder.Timestamp(), actionRequestDecoder.Action());
                break;
            }
            }

            return(ControlledFragmentHandlerAction.CONTINUE);
        }
コード例 #2
0
        public ControlledFragmentHandlerAction OnFragment(IDirectBuffer buffer, int offset, int length, Header header)
        {
            messageHeaderDecoder.Wrap(buffer, offset);
            int templateId = messageHeaderDecoder.TemplateId();

            if (templateId == SessionHeaderDecoder.TEMPLATE_ID)
            {
                sessionHeaderDecoder.Wrap(
                    buffer,
                    offset + MessageHeaderDecoder.ENCODED_LENGTH,
                    messageHeaderDecoder.BlockLength(),
                    messageHeaderDecoder.Version());

                agent.OnSessionMessage(
                    sessionHeaderDecoder.ClusterSessionId(),
                    sessionHeaderDecoder.Timestamp(),
                    buffer,
                    offset + SESSION_HEADER_LENGTH,
                    length - SESSION_HEADER_LENGTH,
                    header);

                return(ControlledFragmentHandlerAction.CONTINUE);
            }


            switch (templateId)
            {
            case TimerEventDecoder.TEMPLATE_ID:
                timerEventDecoder.Wrap(
                    buffer,
                    offset + MessageHeaderDecoder.ENCODED_LENGTH,
                    messageHeaderDecoder.BlockLength(),
                    messageHeaderDecoder.Version());

                agent.OnTimerEvent(timerEventDecoder.CorrelationId(), timerEventDecoder.Timestamp());
                break;

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

                string responseChannel  = openEventDecoder.ResponseChannel();
                byte[] encodedPrincipal = new byte[openEventDecoder.EncodedPrincipalLength()];
                openEventDecoder.GetEncodedPrincipal(encodedPrincipal, 0, encodedPrincipal.Length);

                agent.OnSessionOpen(
                    openEventDecoder.ClusterSessionId(),
                    openEventDecoder.Timestamp(),
                    openEventDecoder.ResponseStreamId(),
                    responseChannel,
                    encodedPrincipal);
                break;

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

                agent.OnSessionClose(
                    closeEventDecoder.ClusterSessionId(),
                    closeEventDecoder.Timestamp(),
                    closeEventDecoder.CloseReason());
                break;

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

                agent.OnServiceAction(
                    actionRequestDecoder.LogPosition(),
                    actionRequestDecoder.LeadershipTermId(),
                    actionRequestDecoder.Timestamp(),
                    actionRequestDecoder.Action());
                break;

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

                agent.OnNewLeadershipTermEvent(
                    newLeadershipTermEventDecoder.LeadershipTermId(),
                    newLeadershipTermEventDecoder.LogPosition(),
                    newLeadershipTermEventDecoder.Timestamp(),
                    newLeadershipTermEventDecoder.LeaderMemberId(),
                    newLeadershipTermEventDecoder.LogSessionId());
                break;

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

                agent.OnClusterChange(
                    clusterChangeEventDecoder.LeadershipTermId(),
                    clusterChangeEventDecoder.LogPosition(),
                    clusterChangeEventDecoder.Timestamp(),
                    clusterChangeEventDecoder.LeaderMemberId(),
                    clusterChangeEventDecoder.ClusterSize(),
                    clusterChangeEventDecoder.EventType(),
                    clusterChangeEventDecoder.MemberId(),
                    clusterChangeEventDecoder.ClusterMembers());
                break;
            }

            return(ControlledFragmentHandlerAction.CONTINUE);
        }
コード例 #3
0
        public ControlledFragmentHandlerAction OnFragment(IDirectBuffer buffer, int offset, int length, Header header)
        {
            messageHeaderDecoder.Wrap(buffer, offset);
            int templateId = messageHeaderDecoder.TemplateId();

            int schemaId = messageHeaderDecoder.SchemaId();

            if (schemaId != MessageHeaderDecoder.SCHEMA_ID)
            {
                throw new ClusterException("expected schemaId=" + MessageHeaderDecoder.SCHEMA_ID + ", actual=" +
                                           schemaId);
            }

            if (templateId == SessionMessageHeaderEncoder.TEMPLATE_ID)
            {
                sessionHeaderDecoder.Wrap(
                    buffer,
                    offset + MessageHeaderDecoder.ENCODED_LENGTH,
                    messageHeaderDecoder.BlockLength(),
                    messageHeaderDecoder.Version());

                agent.OnSessionMessage(
                    header.Position,
                    sessionHeaderDecoder.ClusterSessionId(),
                    sessionHeaderDecoder.Timestamp(),
                    buffer,
                    offset + SESSION_HEADER_LENGTH,
                    length - SESSION_HEADER_LENGTH,
                    header);

                return(ControlledFragmentHandlerAction.CONTINUE);
            }


            switch (templateId)
            {
            case TimerEventDecoder.TEMPLATE_ID:
                timerEventDecoder.Wrap(
                    buffer,
                    offset + MessageHeaderDecoder.ENCODED_LENGTH,
                    messageHeaderDecoder.BlockLength(),
                    messageHeaderDecoder.Version());

                agent.OnTimerEvent(
                    header.Position,
                    timerEventDecoder.CorrelationId(),
                    timerEventDecoder.Timestamp()
                    );
                break;

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

                string responseChannel  = openEventDecoder.ResponseChannel();
                byte[] encodedPrincipal = new byte[openEventDecoder.EncodedPrincipalLength()];
                openEventDecoder.GetEncodedPrincipal(encodedPrincipal, 0, encodedPrincipal.Length);

                agent.OnSessionOpen(
                    openEventDecoder.LeadershipTermId(),
                    header.Position,
                    openEventDecoder.ClusterSessionId(),
                    openEventDecoder.Timestamp(),
                    openEventDecoder.ResponseStreamId(),
                    responseChannel,
                    encodedPrincipal);
                break;

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

                agent.OnSessionClose(
                    closeEventDecoder.LeadershipTermId(),
                    header.Position,
                    closeEventDecoder.ClusterSessionId(),
                    closeEventDecoder.Timestamp(),
                    closeEventDecoder.CloseReason());
                break;

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

                agent.OnServiceAction(
                    actionRequestDecoder.LeadershipTermId(),
                    actionRequestDecoder.LogPosition(),
                    actionRequestDecoder.Timestamp(),
                    actionRequestDecoder.Action());
                break;

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

                var clusterTimeUnit = newLeadershipTermEventDecoder.TimeUnit() == ClusterTimeUnit.NULL_VALUE
                        ? ClusterTimeUnit.MILLIS
                        : newLeadershipTermEventDecoder.TimeUnit();

                agent.OnNewLeadershipTermEvent(
                    newLeadershipTermEventDecoder.LeadershipTermId(),
                    newLeadershipTermEventDecoder.LogPosition(),
                    newLeadershipTermEventDecoder.Timestamp(),
                    newLeadershipTermEventDecoder.TermBaseLogPosition(),
                    newLeadershipTermEventDecoder.LeaderMemberId(),
                    newLeadershipTermEventDecoder.LogSessionId(),
                    clusterTimeUnit,
                    newLeadershipTermEventDecoder.AppVersion()
                    );
                break;

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

                agent.OnMembershipChange(
                    membershipChangeEventDecoder.LeadershipTermId(),
                    membershipChangeEventDecoder.LogPosition(),
                    membershipChangeEventDecoder.Timestamp(),
                    membershipChangeEventDecoder.LeaderMemberId(),
                    membershipChangeEventDecoder.ClusterSize(),
                    membershipChangeEventDecoder.ChangeType(),
                    membershipChangeEventDecoder.MemberId(),
                    membershipChangeEventDecoder.ClusterMembers());
                break;
            }

            return(ControlledFragmentHandlerAction.CONTINUE);
        }