예제 #1
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;
            }
예제 #2
0
 /// <summary>
 /// This method is used for testing and debugging.
 /// </summary>
 /// <param name="toClientBuffer"> Injected CopyBroadcastReceiver </param>
 /// <returns> this Aeron.Context for method chaining. </returns>
 public Context ToClientBuffer(CopyBroadcastReceiver toClientBuffer)
 {
     _toClientBuffer = toClientBuffer;
     return this;
 }
예제 #3
0
 internal DriverListenerAdapter(CopyBroadcastReceiver broadcastReceiver, IDriverListener listener)
 {
     _broadcastReceiver = broadcastReceiver;
     _listener = listener;
 }