public virtual ControlledFragmentHandlerAction OnFragment(IDirectBuffer buffer, int offset, int length, Header header) { messageHeaderDecoder.Wrap(buffer, offset); 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) { break; } ControlResponseCode code = controlResponseDecoder.Code(); if (ControlResponseCode.RECORDING_UNKNOWN == code) { isDispatchComplete = true; return(ControlledFragmentHandlerAction.BREAK); } if (ControlResponseCode.ERROR == code) { throw new System.InvalidOperationException("response for expectedCorrelationId=" + expectedCorrelationId + ", error: " + controlResponseDecoder.ErrorMessage()); } 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 != expectedCorrelationId) { break; } 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; default: throw new System.InvalidOperationException("Unknown templateId: " + templateId); } return(ControlledFragmentHandlerAction.CONTINUE); }
/// <summary> /// Dispatch a descriptor message to a consumer by reading the fields in the correct order. /// </summary> /// <param name="decoder"> which wraps the encoded message ready for reading. </param> /// <param name="consumer"> to which the decoded fields should be passed. </param> public static void DispatchDescriptor(RecordingDescriptorDecoder decoder, IRecordingDescriptorConsumer consumer) { consumer.OnRecordingDescriptor( decoder.ControlSessionId(), decoder.CorrelationId(), decoder.RecordingId(), decoder.StartTimestamp(), decoder.StopTimestamp(), decoder.StartPosition(), decoder.StopPosition(), decoder.InitialTermId(), decoder.SegmentFileLength(), decoder.TermBufferLength(), decoder.MtuLength(), decoder.SessionId(), decoder.StreamId(), decoder.StrippedChannel(), decoder.OriginalChannel(), decoder.SourceIdentity()); }
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); }