Example #1
0
        public void AddSubscriptionShouldNotifyMediaDriver()
        {
            WhenReceiveBroadcastOnMessage(ControlProtocolEvents.ON_SUBSCRIPTION_READY, SubscriptionReadyBuffer, buffer =>
            {
                SubscriptionReady.CorrelationId(CORRELATION_ID);
                return(SubscriptionReadyFlyweight.LENGTH);
            });

            Conductor.AddSubscription(CHANNEL, STREAM_ID_1);

            A.CallTo(() => DriverProxy.AddSubscription(CHANNEL, STREAM_ID_1)).MustHaveHappened();
        }
Example #2
0
        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;
                }
            }
        }