public void OnMessage(int msgTypeId, IMutableDirectBuffer buffer, int index, int length) { switch (msgTypeId) { case ControlProtocolEvents.ON_ERROR: { _errorResponse.Wrap(buffer, index); int correlationId = (int) _errorResponse.OffendingCommandCorrelationId(); int errorCodeValue = _errorResponse.ErrorCodeValue(); var errorCode = GetErrorCode(_errorResponse.ErrorCodeValue()); var message = _errorResponse.ErrorMessage(); if (ErrorCode.CHANNEL_ENDPOINT_ERROR == errorCode) { _listener.OnChannelEndpointError(correlationId, message); } else if (correlationId == _activeCorrelationId) { _receivedCorrelationId = correlationId; _listener.OnError(correlationId, errorCodeValue, errorCode, message); } break; } case ControlProtocolEvents.ON_AVAILABLE_IMAGE: { _imageReady.Wrap(buffer, index); _listener.OnAvailableImage( _imageReady.CorrelationId(), _imageReady.StreamId(), _imageReady.SessionId(), _imageReady.SubscriptionRegistrationId(), _imageReady.SubscriberPositionId(), _imageReady.LogFileName(), _imageReady.SourceIdentity()); break; } case ControlProtocolEvents.ON_PUBLICATION_READY: { _publicationReady.Wrap(buffer, index); long correlationId = _publicationReady.CorrelationId(); if (correlationId == _activeCorrelationId) { _receivedCorrelationId = correlationId; _listener.OnNewPublication( correlationId, _publicationReady.RegistrationId(), _publicationReady.StreamId(), _publicationReady.SessionId(), _publicationReady.PublicationLimitCounterId(), _publicationReady.ChannelStatusCounterId(), _publicationReady.LogFileName()); } break; } case ControlProtocolEvents.ON_SUBSCRIPTION_READY: { _subscriptionReady.Wrap(buffer, index); long correlationId = _subscriptionReady.CorrelationId(); if (correlationId == _activeCorrelationId) { _receivedCorrelationId = correlationId; _listener.OnNewSubscription(correlationId, _subscriptionReady.ChannelStatusCounterId()); } break; } case ControlProtocolEvents.ON_OPERATION_SUCCESS: { _operationSucceeded.Wrap(buffer, index); long correlationId = _operationSucceeded.CorrelationId(); if (correlationId == _activeCorrelationId) { _receivedCorrelationId = correlationId; } break; } case ControlProtocolEvents.ON_UNAVAILABLE_IMAGE: { _imageMessage.Wrap(buffer, index); _listener.OnUnavailableImage( _imageMessage.CorrelationId(), _imageMessage.SubscriptionRegistrationId(), _imageMessage.StreamId()); break; } case ControlProtocolEvents.ON_EXCLUSIVE_PUBLICATION_READY: { _publicationReady.Wrap(buffer, index); long correlationId = _publicationReady.CorrelationId(); if (correlationId == _activeCorrelationId) { _receivedCorrelationId = correlationId; _listener.OnNewExclusivePublication( correlationId, _publicationReady.RegistrationId(), _publicationReady.StreamId(), _publicationReady.SessionId(), _publicationReady.PublicationLimitCounterId(), _publicationReady.ChannelStatusCounterId(), _publicationReady.LogFileName()); } break; } case ControlProtocolEvents.ON_COUNTER_READY: { _counterUpdate.Wrap(buffer, index); int counterId = _counterUpdate.CounterId(); long correlationId = _counterUpdate.CorrelationId(); if (correlationId == _activeCorrelationId) { _receivedCorrelationId = correlationId; _listener.OnNewCounter(correlationId, counterId); } else { _listener.OnAvailableCounter(correlationId, counterId); } break; } case ControlProtocolEvents.ON_UNAVAILABLE_COUNTER: { _counterUpdate.Wrap(buffer, index); _listener.OnUnavailableCounter(_counterUpdate.CorrelationId(), _counterUpdate.CounterId()); break; } } }
public void SetUp() { MockClientErrorHandler = A.Fake <ErrorHandler>(options => options.Wrapping(throwable => { if (!SuppressPrintError) { Console.WriteLine(throwable.ToString()); Console.Write(throwable.StackTrace); } })); PublicationReady = new PublicationBuffersReadyFlyweight(); SubscriptionReady = new SubscriptionReadyFlyweight(); OperationSuccess = new OperationSucceededFlyweight(); ErrorResponse = new ErrorResponseFlyweight(); ClientTimeout = new ClientTimeoutFlyweight(); PublicationReadyBuffer = new UnsafeBuffer(new byte[SEND_BUFFER_CAPACITY]); SubscriptionReadyBuffer = new UnsafeBuffer(new byte[SEND_BUFFER_CAPACITY]); OperationSuccessBuffer = new UnsafeBuffer(new byte[SEND_BUFFER_CAPACITY]); ErrorMessageBuffer = new UnsafeBuffer(new byte[SEND_BUFFER_CAPACITY]); ClientTimeoutBuffer = new UnsafeBuffer(new byte[SEND_BUFFER_CAPACITY]); CounterValuesBuffer = new UnsafeBuffer(new byte[COUNTER_BUFFER_LENGTH]); MockToClientReceiver = A.Fake <CopyBroadcastReceiver>(); MockAvailableImageHandler = A.Fake <AvailableImageHandler>(); MockUnavailableImageHandler = A.Fake <UnavailableImageHandler>(); MockCloseHandler = A.Fake <Action>(); LogBuffersFactory = A.Fake <ILogBuffersFactory>(); DriverProxy = A.Fake <DriverProxy>(); MockAeron = A.Fake <Aeron>(); A.CallTo(() => mockClientLock.TryLock()).Returns(true); A.CallTo(() => DriverProxy.AddPublication(CHANNEL, STREAM_ID_1)).Returns(CORRELATION_ID); A.CallTo(() => DriverProxy.AddPublication(CHANNEL, STREAM_ID_2)).Returns(CORRELATION_ID_2); A.CallTo(() => DriverProxy.RemovePublication(CORRELATION_ID)).Returns(CLOSE_CORRELATION_ID); A.CallTo(() => DriverProxy.AddSubscription(A <string> ._, A <int> ._)).Returns(CORRELATION_ID); A.CallTo(() => DriverProxy.RemoveSubscription(CORRELATION_ID)).Returns(CLOSE_CORRELATION_ID); Aeron.Context ctx = new Aeron.Context() .ClientLock(mockClientLock) .EpochClock(EpochClock) .NanoClock(NanoClock) .ToClientBuffer(MockToClientReceiver) .DriverProxy(DriverProxy) .LogBuffersFactory(LogBuffersFactory) .ErrorHandler(MockClientErrorHandler) .AvailableImageHandler(MockAvailableImageHandler) .UnavailableImageHandler(MockUnavailableImageHandler) .CloseHandler(MockCloseHandler) .KeepAliveIntervalNs(KEEP_ALIVE_INTERVAL) .DriverTimeoutMs(AWAIT_TIMEOUT) .InterServiceTimeoutNs(INTER_SERVICE_TIMEOUT_MS * 1000000) .CountersValuesBuffer(CounterValuesBuffer); Conductor = new ClientConductor(ctx, MockAeron); PublicationReady.Wrap(PublicationReadyBuffer, 0); SubscriptionReady.Wrap(SubscriptionReadyBuffer, 0); OperationSuccess.Wrap(OperationSuccessBuffer, 0); ErrorResponse.Wrap(ErrorMessageBuffer, 0); ClientTimeout.Wrap(ClientTimeoutBuffer, 0); PublicationReady.CorrelationId(CORRELATION_ID); PublicationReady.RegistrationId(CORRELATION_ID); PublicationReady.SessionId(SESSION_ID_1); PublicationReady.StreamId(STREAM_ID_1); PublicationReady.LogFileName(SESSION_ID_1 + "-log"); OperationSuccess.CorrelationId(CLOSE_CORRELATION_ID); var termBuffersSession1 = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT]; var termBuffersSession2 = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT]; for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++) { termBuffersSession1[i] = new UnsafeBuffer(new byte[TERM_BUFFER_LENGTH]); termBuffersSession2[i] = new UnsafeBuffer(new byte[TERM_BUFFER_LENGTH]); } UnsafeBuffer logMetaDataSession1 = new UnsafeBuffer(new byte[TERM_BUFFER_LENGTH]); UnsafeBuffer logMetaDataSession2 = new UnsafeBuffer(new byte[TERM_BUFFER_LENGTH]); IMutableDirectBuffer header1 = DataHeaderFlyweight.CreateDefaultHeader(SESSION_ID_1, STREAM_ID_1, 0); IMutableDirectBuffer header2 = DataHeaderFlyweight.CreateDefaultHeader(SESSION_ID_2, STREAM_ID_2, 0); LogBufferDescriptor.StoreDefaultFrameHeader(logMetaDataSession1, header1); LogBufferDescriptor.StoreDefaultFrameHeader(logMetaDataSession2, header2); var logBuffersSession1 = A.Fake <LogBuffers>(); var logBuffersSession2 = A.Fake <LogBuffers>(); A.CallTo(() => LogBuffersFactory.Map(SESSION_ID_1 + "-log")).Returns(logBuffersSession1); A.CallTo(() => LogBuffersFactory.Map(SESSION_ID_2 + "-log")).Returns(logBuffersSession2); A.CallTo(() => logBuffersSession1.DuplicateTermBuffers()).Returns(termBuffersSession1); A.CallTo(() => logBuffersSession2.DuplicateTermBuffers()).Returns(termBuffersSession2); A.CallTo(() => logBuffersSession1.MetaDataBuffer()).Returns(logMetaDataSession1); A.CallTo(() => logBuffersSession2.MetaDataBuffer()).Returns(logMetaDataSession2); A.CallTo(() => logBuffersSession1.TermLength()).Returns(TERM_BUFFER_LENGTH); A.CallTo(() => logBuffersSession2.TermLength()).Returns(TERM_BUFFER_LENGTH); }