Esempio n. 1
0
        /// <summary>
        /// Wrap a <seealso cref="BroadcastReceiver"/> to simplify the API for receiving messages.
        /// </summary>
        /// <param name="receiver"> to be wrapped. </param>
        public CopyBroadcastReceiver(BroadcastReceiver receiver)
        {
            _receiver = receiver;
            _scratchBuffer = new UnsafeBuffer(new byte[ScratchBufferSize]);

            while (receiver.ReceiveNext())
            {
                // If we're reconnecting to a broadcast buffer then we need to
                // scan ourselves up to date, otherwise we risk "falling behind"
                // the buffer due to the time taken to catchup.
            }
        }
Esempio n. 2
0
            /// <summary>
            /// This is called automatically by <seealso cref="Connect()"/> and its overloads.
            /// There is no need to call it from a client application. It is responsible for providing default
            /// values for options that are not individually changed through field setters.
            /// </summary>
            /// <returns> this Aeron.Context for method chaining. </returns>
            public Context Conclude()
            {
                try
                {
                    _cncFile = new FileInfo(Path.Combine(_aeronDirectoryName, CncFileDescriptor.CNC_FILE));

                    if (_epochClock == null)
                    {
                        _epochClock = new SystemEpochClock();
                    }

                    if (_nanoClock == null)
                    {
                        _nanoClock = new SystemNanoClock();
                    }

                    if (_idleStrategy == null)
                    {
                        _idleStrategy = new SleepingIdleStrategy(IdleSleepMs);
                    }

                    if (CncFile() != null)
                    {
                        _cncByteBuffer = IoUtil.MapExistingFile(CncFile().FullName);
                        _cncMetaDataBuffer = CncFileDescriptor.CreateMetaDataBuffer(_cncByteBuffer);

                        var cncVersion = _cncMetaDataBuffer.GetInt(CncFileDescriptor.CncVersionOffset(0));

                        if (CncFileDescriptor.CNC_VERSION != cncVersion)
                        {
                            throw new InvalidOperationException(
                                "aeron cnc file version not understood: version=" + cncVersion);
                        }
                    }

                    if (_toClientBuffer == null)
                    {
                        var receiver =
                            new BroadcastReceiver(CncFileDescriptor.CreateToClientsBuffer(_cncByteBuffer,
                                _cncMetaDataBuffer));
                        _toClientBuffer = new CopyBroadcastReceiver(receiver);
                    }

                    if (_toDriverBuffer == null)
                    {
                        _toDriverBuffer =
                            new ManyToOneRingBuffer(CncFileDescriptor.CreateToDriverBuffer(_cncByteBuffer,
                                _cncMetaDataBuffer));
                    }

                    if (CountersMetaDataBuffer() == null)
                    {
                        CountersMetaDataBuffer(CncFileDescriptor.CreateCountersMetaDataBuffer(_cncByteBuffer,
                            _cncMetaDataBuffer));
                    }

                    if (CountersValuesBuffer() == null)
                    {
                        CountersValuesBuffer(CncFileDescriptor.CreateCountersValuesBuffer(_cncByteBuffer,
                            _cncMetaDataBuffer));
                    }

                    _interServiceTimeout = CncFileDescriptor.ClientLivenessTimeout(_cncMetaDataBuffer);

                    if (_logBuffersFactory == null)
                    {
                        _logBuffersFactory = new MappedLogBuffersFactory();
                    }

                    if (_errorHandler == null)
                    {
                        _errorHandler = DEFAULT_ERROR_HANDLER;
                    }

                    if (_availableImageHandler == null)
                    {
                        _availableImageHandler = image => { };
                    }

                    if (_unavailableImageHandler == null)
                    {
                        _unavailableImageHandler = image => { };
                    }
                }
                catch (
                    Exception ex)
                {
                    Console.WriteLine("***");
                    Console.WriteLine("***");
                    Console.WriteLine("Failed to connect to the Media Driver - is it currently running?");
                    Console.WriteLine("***");
                    Console.WriteLine("***");

                    throw new InvalidOperationException("Could not initialise communication buffers", ex);
                }

                return this;
            }
Esempio n. 3
0
 public void SetUp()
 {
     _buffer = A.Fake<IAtomicBuffer>();
     A.CallTo(() => _buffer.Capacity).Returns(TotalBufferLength);
     _broadcastReceiver = new BroadcastReceiver(_buffer);
 }