public ControlledFragmentHandlerAction OnFragment(IDirectBuffer buffer, int offset, int length, Header header) { if (isDispatchComplete) { return(ABORT); } messageHeaderDecoder.Wrap(buffer, offset); int schemaId = messageHeaderDecoder.SchemaId(); if (schemaId != MessageHeaderDecoder.SCHEMA_ID) { throw new ArchiveException("expected schemaId=" + MessageHeaderDecoder.SCHEMA_ID + ", actual=" + schemaId); } int templateId = messageHeaderDecoder.TemplateId(); switch (templateId) { case ControlResponseDecoder.TEMPLATE_ID: { controlResponseDecoder .Wrap(buffer, offset + MessageHeaderEncoder.ENCODED_LENGTH, messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version()); if (controlResponseDecoder.ControlSessionId() == controlSessionId) { ControlResponseCode code = controlResponseDecoder.Code(); long correlationId = controlResponseDecoder.CorrelationId(); if (ControlResponseCode.SUBSCRIPTION_UNKNOWN == code && correlationId == this.correlationId) { isDispatchComplete = true; return(BREAK); } if (ControlResponseCode.ERROR == code) { ArchiveException ex = new ArchiveException( "response for correlationId=" + this.correlationId + ", error: " + controlResponseDecoder.ErrorMessage(), (int)controlResponseDecoder.RelevantId(), correlationId); if (correlationId == this.correlationId) { throw ex; } else { errorHandler?.Invoke(ex); } } } } break; case RecordingSubscriptionDescriptorDecoder.TEMPLATE_ID: { recordingSubscriptionDescriptorDecoder.Wrap( buffer, offset + MessageHeaderEncoder.ENCODED_LENGTH, messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version()); long correlationId = recordingSubscriptionDescriptorDecoder.CorrelationId(); if (recordingSubscriptionDescriptorDecoder.ControlSessionId() == controlSessionId && correlationId == this.correlationId) { consumer.OnSubscriptionDescriptor( controlSessionId, correlationId, recordingSubscriptionDescriptorDecoder.SubscriptionId(), recordingSubscriptionDescriptorDecoder.StreamId(), recordingSubscriptionDescriptorDecoder.StrippedChannel()); if (0 == --remainingSubscriptionCount) { isDispatchComplete = true; return(BREAK); } } } break; } return(CONTINUE); }
public ControlledFragmentHandlerAction OnFragment(IDirectBuffer buffer, int offset, int length, Header header) { if (isDispatchComplete) { return(ControlledFragmentHandlerAction.ABORT); } messageHeaderDecoder.Wrap(buffer, offset); int schemaId = messageHeaderDecoder.SchemaId(); if (schemaId != MessageHeaderDecoder.SCHEMA_ID) { throw new ArchiveException("expected schemaId=" + MessageHeaderDecoder.SCHEMA_ID + ", actual=" + schemaId); } int templateId = messageHeaderDecoder.TemplateId(); switch (templateId) { case ControlResponseDecoder.TEMPLATE_ID: { controlResponseDecoder.Wrap( buffer, offset + MessageHeaderEncoder.ENCODED_LENGTH, messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version()); if (controlResponseDecoder.ControlSessionId() == controlSessionId) { ControlResponseCode code = controlResponseDecoder.Code(); long correlationId = controlResponseDecoder.CorrelationId(); if (ControlResponseCode.RECORDING_UNKNOWN == code && correlationId == this.correlationId) { isDispatchComplete = true; return(ControlledFragmentHandlerAction.BREAK); } if (ControlResponseCode.ERROR == code) { ArchiveException ex = new ArchiveException( "response for correlationId=" + this.correlationId + ", error: " + controlResponseDecoder.ErrorMessage(), (int)controlResponseDecoder.RelevantId(), correlationId); if (correlationId == this.correlationId) { throw ex; } else { errorHandler?.Invoke(ex); } } } break; } case RecordingDescriptorDecoder.TEMPLATE_ID: { recordingDescriptorDecoder.Wrap( buffer, offset + MessageHeaderEncoder.ENCODED_LENGTH, messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version()); long correlationId = recordingDescriptorDecoder.CorrelationId(); if (controlSessionId == recordingDescriptorDecoder.ControlSessionId() && correlationId == this.correlationId) { consumer.OnRecordingDescriptor( controlSessionId, correlationId, recordingDescriptorDecoder.RecordingId(), recordingDescriptorDecoder.StartTimestamp(), recordingDescriptorDecoder.StopTimestamp(), recordingDescriptorDecoder.StartPosition(), recordingDescriptorDecoder.StopPosition(), recordingDescriptorDecoder.InitialTermId(), recordingDescriptorDecoder.SegmentFileLength(), recordingDescriptorDecoder.TermBufferLength(), recordingDescriptorDecoder.MtuLength(), recordingDescriptorDecoder.SessionId(), recordingDescriptorDecoder.StreamId(), recordingDescriptorDecoder.StrippedChannel(), recordingDescriptorDecoder.OriginalChannel(), recordingDescriptorDecoder.SourceIdentity()); if (0 == --remainingRecordCount) { isDispatchComplete = true; return(ControlledFragmentHandlerAction.BREAK); } } break; } } return(ControlledFragmentHandlerAction.CONTINUE); }