public LinkTopology(LinkConfiguration configuration, ILinkChannel channel, ILinkTopologyHandler handler,
            bool once)
        {
            if (configuration == null)
                throw new ArgumentNullException(nameof(configuration));

            if (channel == null)
                throw new ArgumentNullException(nameof(channel));

            if (handler == null)
                throw new ArgumentNullException(nameof(handler));

            _configuration = configuration;
            _logger = _configuration.LoggerFactory.CreateLogger($"{GetType().Name}({Id:D})");

            if (_logger == null)
                throw new ArgumentException("Cannot create logger", nameof(configuration.LoggerFactory));

            _handler = handler;
            _isOnce = once;

            _disposedCancellationSource = new CancellationTokenSource();
            _disposedCancellation = _disposedCancellationSource.Token;

            Channel = channel;
            Channel.Disposed += ChannelOnDisposed;
            Channel.Ready += ChannelOnReady;

            _logger.Debug($"Created(channelId: {Channel.Id}, once: {once})");

#pragma warning disable 4014
            ScheduleConfiguration(false);
#pragma warning restore 4014           
        }
Exemple #2
0
        public LinkConsumer(
            LinkConsumerConfiguration configuration,
            ILinkChannel channel
            ) : base(LinkConsumerState.Init)
        {
            _configuration = configuration;

            _channel = channel ?? throw new ArgumentNullException(nameof(channel));

            _logger = _channel.Connection.Configuration.LoggerFactory.CreateLogger($"{GetType().Name}({Id:D})")
                      ?? throw new InvalidOperationException("Cannot create logger");

            _topologyRunner = new LinkTopologyRunner <ILinkQueue>(_logger, configuration.TopologyHandler.Configure);
            _appId          = _channel.Connection.Configuration.AppId;

            _channel.Disposed += ChannelOnDisposed;

            _channel.Initialize(this);
        }
        public LinkTopology(ILinkChannel channel, LinkTopologyConfiguration configuration)
            : base(LinkTopologyState.Init)
        {
            _channel       = channel ?? throw new ArgumentNullException(nameof(channel));
            _configuration = configuration;

            _logger = _channel.Connection.Configuration.LoggerFactory.CreateLogger($"{GetType().Name}({Id:D})")
                      ?? throw new InvalidOperationException("Cannot create logger");

            _topologyRunner = new LinkTopologyRunner <object>(_logger, async cfg =>
            {
                await _configuration.TopologyHandler.Configure(cfg)
                .ConfigureAwait(false);
                return(null);
            });

            _channel.Disposed += ChannelOnDisposed;

            _logger.Debug($"Created(channelId: {_channel.Id})");

            _channel.Initialize(this);
        }