示例#1
0
        public void Execute(Action callback)
        {
            _connectionHandler.Connect();

            _policyChain.Pop(this);
            _policyChain.Next(callback);
        }
示例#2
0
 private IStreamReader GetStreamReader()
 {
     if (_connection.IsConnected == false)
     {
         _connection.Connect();
     }
     return(_connection.GetStreamReader());
 }
示例#3
0
        // ----------------Connection----------------
        public async void Connect()
        {
            await connectionHandler.Connect(this);

            if (connectionHandler.ConnectionEstablished)
            {
                //label1.Text = "Connected";
            }
        }
示例#4
0
        public async Task MainAsync()
        {
            _config.LoadConfig();
            await _connectionManager.Connect();

            await _messageHandler.Handle();

            await Task.Delay(-1);
        }
示例#5
0
        /// <summary>
        /// Creates new connection handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="socket"></param>
        private void CreateNewConnection(object sender, Socket socket)
        {
            IConnectionHandler connectionHandler = this.factory.GetNewConnection(socket);

            connectionHandler.MessageReceived += this.HandleIncomingMessage;
            connectionHandler.Disposing       += this.HandleConnectionDispose;
            connectionHandler.Connect();

            this.connectionHandlers.TryAdd(connectionHandler.Name, connectionHandler);
        }
示例#6
0
        public void SendXyz_ConnectionHandler_DisconnectAndConnectAreCalled_ForCertainHttpStatusCodes(HttpStatusCode statusCode)
        {
            _connectionManager = new ConnectionManager(_connectionHandler, _scheduler);
            _disposableCollection.Add(_dataTransportService = new DataTransportService(_connectionManager, _dateTimeStatic, _agentHealthReporter));

            Mock.Arrange(() => _connectionHandler.SendDataRequest <object>(Arg.IsAny <string>(), Arg.IsAny <object[]>()))
            .Throws(new HttpException(statusCode, null));

            _dataTransportService.Send(Arg.IsAny <EventHarvestData>(), Enumerable.Empty <TransactionEventWireModel>());

            Mock.Assert(() => _connectionHandler.Disconnect(), Occurs.Once());
            Mock.Assert(() => _connectionHandler.Connect(), Occurs.Once());
        }
        public void AttemptAutoStart_CallsConnectSynchronously_IfAutoStartAndSyncStartupIsOn()
        {
            Mock.Arrange(() => _configuration.CollectorSyncStartup).Returns(true);
            Mock.Arrange(() => _configuration.AutoStartAgent).Returns(true);

            // Act
            using (var connectionManager = new ConnectionManager(_connectionHandler, _scheduler))
            {
                connectionManager.AttemptAutoStart();
                Mock.Assert(() => _connectionHandler.Connect());
            }
        }
示例#8
0
        public void Execute(Action callback)
        {
            _connectionHandler.Disconnect();

            if (_reconnectDelay > TimeSpan.Zero)
            {
                Thread.Sleep(_reconnectDelay);
            }

            _connectionHandler.Connect();

            _policyChain.Pop(this);
            _policyChain.Next(callback);
        }
示例#9
0
        void Reconnect()
        {
            if (_connectionLock.TryEnterWriteLock((int)_reconnectDelay.TotalMilliseconds / 2))
            {
                try
                {
                    if (_log.IsDebugEnabled)
                    {
                        _log.Debug("Disconnecting connection handler.");
                    }
                    _connectionHandler.Disconnect();

                    if (_reconnectDelay > TimeSpan.Zero)
                    {
                        Thread.Sleep(_reconnectDelay);
                    }

                    if (_log.IsDebugEnabled)
                    {
                        _log.Debug("Re-connecting connection handler...");
                    }
                    _connectionHandler.Connect();
                }
                catch (Exception)
                {
                    _log.Warn("Failed to reconnect, deferring to connection policy for reconnection");
                    _connectionHandler.ForceReconnect(_reconnectDelay);
                }
                finally
                {
                    _connectionLock.ExitWriteLock();
                }
            }
            else
            {
                try
                {
                    _connectionLock.EnterReadLock();
                    if (_log.IsDebugEnabled)
                    {
                        _log.Debug("Waiting for reconnect in another thread.");
                    }
                }
                finally
                {
                    _connectionLock.ExitReadLock();
                }
            }
        }
示例#10
0
        public void Login()
        {
            var result = _connectionHandler.Connect(Username, Password);

            result.ContinueWith(task =>
            {
                switch (task.Result)
                {
                case LoginStatus.Successful:
                    OnLoginSuccessful();
                    return;
                }

                LoginResponseText = "Login failed";
                OnPropertyChanged(nameof(LoginResponseText));
            });
        }
        private void Connect()
        {
            try
            {
                lock (_syncObject)
                {
                    _connectionHandler.Connect();
                }

                _connectionAttempt = 0;
            }
            // This exception is thrown when the agent receives an unexpected HTTP error
            // This is also the parent type of some of the more specific HTTP errors that we handle
            catch (HttpException ex)
            {
                HandleHttpErrorResponse(ex);
            }
            // Occurs when the agent connects to APM but the connection gets aborted by the collector
            catch (SocketException)
            {
                ScheduleRestart();
            }
            // Occurs when the agent is unable to read data from the transport connection (this might occur when a socket exception happens - in that case the exception will be caught above)
            catch (IOException)
            {
                ScheduleRestart();
            }
            // Occurs when no network connection is available, DNS unavailable, etc.
            catch (WebException)
            {
                ScheduleRestart();
            }
            // Usually occurs when a request times out but did not get far enough along to trigger a timeout exception
            catch (OperationCanceledException)
            {
                ScheduleRestart();
            }
            // This catch all is in place so that we avoid doing harm for all of the potentially destructive things that could happen during a connect.
            // We want to error on the side of doing no harm to our customers
            catch (Exception ex)
            {
                ImmediateShutdown(ex.Message);
            }
        }
示例#12
0
 public bool SendLine(string value)
 {
     if (_connection.IsConnected == false)
     {
         _connection.Connect();
     }
     if (_streamWriter == null)
     {
         _streamWriter = _connection.GetStreamWriter();
     }
     try
     {
         _streamWriter.WriteLine(value);
         _streamWriter.Flush();
         _logger.Trace($"Sended: {value}");
         return(true);
     }
     catch
     {
         _streamWriter = null;
         return(false);
     }
 }
示例#13
0
 private ClientWebSocket Connect()
 {
     return(_connectionHandler.Connect(Glossary.DataServerConnectionString).Result);
 }