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

            int templateId = messageHeaderDecoder.TemplateId();

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

                long typeId = snapshotMarkerDecoder.TypeId();
                if (typeId != ClusteredServiceContainer.SNAPSHOT_TYPE_ID)
                {
                    throw new InvalidOperationException("unexpected snapshot type: " + typeId);
                }

                switch (snapshotMarkerDecoder.Mark())
                {
                case SnapshotMark.BEGIN:
                    if (inSnapshot)
                    {
                        throw new InvalidOperationException("already in snapshot");
                    }

                    inSnapshot = true;
                    return(ControlledFragmentHandlerAction.CONTINUE);

                case SnapshotMark.END:
                    if (!inSnapshot)
                    {
                        throw new InvalidOperationException("missing begin snapshot");
                    }

                    isDone = true;
                    return(ControlledFragmentHandlerAction.BREAK);
                }

                break;

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

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

                agent.AddSession(
                    clientSessionDecoder.ClusterSessionId(),
                    clientSessionDecoder.ResponseStreamId(),
                    responseChannel,
                    encodedPrincipal);
                break;

            default:
                throw new InvalidOperationException("unknown template id: " + templateId);
            }

            return(ControlledFragmentHandlerAction.CONTINUE);
        }
示例#2
0
        public ControlledFragmentHandlerAction OnFragment(IDirectBuffer buffer, int offset, int length, Header header)
        {
            messageHeaderDecoder.Wrap(buffer, offset);

            int schemaId = messageHeaderDecoder.SchemaId();

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

            int templateId = messageHeaderDecoder.TemplateId();

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

                long typeId = snapshotMarkerDecoder.TypeId();
                if (typeId != ClusteredServiceContainer.Configuration.SNAPSHOT_TYPE_ID)
                {
                    throw new ClusterException("unexpected snapshot type: " + typeId);
                }

                switch (snapshotMarkerDecoder.Mark())
                {
                case SnapshotMark.BEGIN:
                    if (inSnapshot)
                    {
                        throw new ClusterException("already in snapshot");
                    }

                    inSnapshot = true;
                    appVersion = snapshotMarkerDecoder.AppVersion();
                    timeUnit   = snapshotMarkerDecoder.TimeUnit() == ClusterTimeUnit.NULL_VALUE
                                ? ClusterTimeUnit.MILLIS
                                : snapshotMarkerDecoder.TimeUnit();

                    return(ControlledFragmentHandlerAction.CONTINUE);

                case SnapshotMark.END:
                    if (!inSnapshot)
                    {
                        throw new ClusterException("missing begin snapshot");
                    }

                    isDone = true;
                    return(ControlledFragmentHandlerAction.BREAK);
                }

                break;

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

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

                agent.AddSession(
                    clientSessionDecoder.ClusterSessionId(),
                    clientSessionDecoder.ResponseStreamId(),
                    responseChannel,
                    encodedPrincipal);
                break;
            }

            return(ControlledFragmentHandlerAction.CONTINUE);
        }