Esempio n. 1
0
 /// <summary>
 /// Unmap a <seealso cref="MappedByteBuffer"/> without waiting for the next GC cycle.
 /// </summary>
 /// <param name="wrapper"> to be unmapped. </param>
 public static void Unmap(MappedByteBuffer wrapper)
 {
     wrapper?.Dispose();
 }
Esempio n. 2
0
        public static UnsafeBuffer CreateErrorLogBuffer(MappedByteBuffer buffer, IDirectBuffer metaDataBuffer)
        {
            var offset = END_OF_METADATA_OFFSET + metaDataBuffer.GetInt(ToDriverBufferLengthOffset(0)) + metaDataBuffer.GetInt(ToClientsBufferLengthOffset(0)) + metaDataBuffer.GetInt(CountersMetaDataBufferLengthOffset(0)) + metaDataBuffer.GetInt(CountersValuesBufferLengthOffset(0));

            return new UnsafeBuffer(buffer.Pointer, offset, metaDataBuffer.GetInt(ErrorLogBufferLengthOffset(0)));
        }
Esempio n. 3
0
 public static UnsafeBuffer CreateMetaDataBuffer(MappedByteBuffer buffer)
 {
     return new UnsafeBuffer(buffer.Pointer, 0, BitUtil.SIZE_OF_INT + META_DATA_LENGTH);
 }
Esempio n. 4
0
 public static UnsafeBuffer CreateToDriverBuffer(MappedByteBuffer buffer, IDirectBuffer metaDataBuffer)
 {
     return new UnsafeBuffer(buffer.Pointer, END_OF_METADATA_OFFSET, metaDataBuffer.GetInt(ToDriverBufferLengthOffset(0)));
 }
Esempio n. 5
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;
            }