コード例 #1
0
        public LinkChannel(LinkConfiguration configuration, ILinkConnection connection)
        {
            if (configuration == null)
                throw new ArgumentNullException(nameof(configuration));

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

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

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

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

            Connection = connection;

            Connection.Disposed += ConnectionOnDisposed;
            Connection.Connected += ConnectionOnConnected;

            _logger.Debug($"Created(connectionId: {Connection.Id:D})");

            ScheduleReopen(false);
        }
コード例 #2
0
ファイル: LinkChannel.cs プロジェクト: YouDoCom/rabbit-link
        public LinkChannel(ILinkConnection connection, LinkStateHandler <LinkChannelState> stateHandler,
                           TimeSpan recoveryInterval)
            : base(LinkChannelState.Init)
        {
            _connection = connection ?? throw new ArgumentNullException(nameof(connection));
            _logger     =
                connection.Configuration.LoggerFactory.CreateLogger($"{GetType().Name}({Id:D})")
                ?? throw new ArgumentException("Cannot create logger", nameof(connection.Configuration.LoggerFactory));

            if (recoveryInterval <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(recoveryInterval), "Must be greater than zero");
            }

            _stateHandler = stateHandler ?? throw new ArgumentNullException(nameof(stateHandler));

            _recoveryInterval = recoveryInterval;

            _disposeCts          = new CancellationTokenSource();
            _disposeCancellation = _disposeCts.Token;

            _connection.Disposed += ConnectionOnDisposed;

            _logger.Debug($"Created(connectionId: {_connection.Id:D})");
        }
コード例 #3
0
 public static void Debug(this ILinkLogger logger, string message)
 {
     if (logger == null)
     {
         throw new ArgumentNullException(nameof(logger));
     }
     logger.Write(LinkLoggerLevel.Debug, message);
 }
コード例 #4
0
        /// <summary>
        ///     Creates new instance of <see cref="BufferedLinkLogger" />
        /// </summary>
        /// <param name="undelyingLogger">Underlying logger to write messages</param>
        /// <param name="maxMessages">Maximum number of messages in buffer, after buffer overflow it will blocks next writes</param>
        public BufferedLinkLogger(ILinkLogger undelyingLogger, int? maxMessages = 1000)
        {
            if (undelyingLogger == null)
                throw new ArgumentNullException(nameof(undelyingLogger));
            if (maxMessages <= 0)
                throw new ArgumentException("Must be greater than zero", nameof(maxMessages));

            UnderlyingLogger = undelyingLogger;

            _eventLoop = maxMessages == null
                ? new EventLoop(EventLoop.DisposingStrategy.Wait)
                : new EventLoop(maxMessages.Value, EventLoop.DisposingStrategy.Wait);
        }
コード例 #5
0
ファイル: LinkConsumer.cs プロジェクト: YouDoCom/rabbit-link
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        public LinkConnection(LinkConfiguration configuration) : base(LinkConnectionState.Init)
        {
            _configuration = configuration;

            _logger = _configuration.LoggerFactory.CreateLogger($"{GetType().Name}({Id:D})")
                      ?? throw new ArgumentException("Cannot create logger", nameof(configuration.LoggerFactory));

            _connectionFactory = new LinkConnectionFactory(
                _configuration.ConnectionName,
                _configuration.AppId,
                _configuration.ConnectionString,
                _configuration.Timeout,
                _configuration.UseBackgroundThreadsForConnection
                );

            _disposeCts          = new CancellationTokenSource();
            _disposeCancellation = _disposeCts.Token;

            _logger.Debug($"Created ( name: {_configuration.ConnectionName})");
            if (_configuration.AutoStart)
            {
                Initialize();
            }
        }
コード例 #8
0
 public LinkTopologyConfig(ILinkLogger logger, IActionInvoker <IModel> invoker)
 {
     _invoker = invoker ?? throw new ArgumentNullException(nameof(invoker));
     _logger  = logger ?? throw new ArgumentNullException(nameof(logger));
 }
コード例 #9
0
 public LinkTopologyRunner(ILinkLogger logger, Func <ILinkTopologyConfig, Task <T> > configureFunc)
 {
     _configureFunc = configureFunc;
     _logger        = logger ?? throw new ArgumentNullException(nameof(logger));
 }
コード例 #10
0
 public LinkLoggerHandler(IMemberDirectory directory, ILinkLogger linkLogger)
 {
     _linkLogger = linkLogger;
     _directory = directory;
     _regEx = new Regex(URL_PATTERN, RegexOptions.IgnoreCase);
 }
コード例 #11
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="communicator"></param>
 /// <param name="directory"></param>
 /// <param name="linkLogger"></param>
 public LinksCommand(ICommunicator communicator, IMemberDirectory directory, ILinkLogger linkLogger)
 {
     _communicator = communicator;
     _directory = directory;
     _linkLogger = linkLogger;
 }