public ConnectionInfo(ConnectionInfo underlying, bool incoming, string adapterName, string connectionId) { Underlying = underlying; Incoming = incoming; AdapterName = adapterName; ConnectionId = connectionId; }
private static void Warning(UnhandledException ex, Current current) { Debug.Assert(current.Adapter.Communicator != null); var output = new System.Text.StringBuilder(); output.Append("dispatch exception:"); output.Append("\nidentity: ").Append(current.Identity.ToString(current.Adapter.Communicator.ToStringMode)); output.Append("\nfacet: ").Append(StringUtil.EscapeString(current.Facet, "", current.Adapter.Communicator.ToStringMode)); output.Append("\noperation: ").Append(current.Operation); if (current.Connection != null) { try { for (ConnectionInfo?p = current.Connection.GetConnectionInfo(); p != null; p = p.Underlying) { if (p is IPConnectionInfo ipinfo) { output.Append("\nremote host: ").Append(ipinfo.RemoteAddress) .Append(" remote port: ") .Append(ipinfo.RemotePort); break; } } } catch (Exception) { } } output.Append("\n"); output.Append(ex.ToString()); current.Adapter.Communicator.Logger.Warning(output.ToString()); }
public ConnectionInfo(ConnectionInfo underlying, bool incoming, string adapterName, string connectionId) { this.underlying = underlying; this.incoming = incoming; this.adapterName = adapterName; this.connectionId = connectionId; ice_initialize(); }
private static TCPConnectionInfo?getTCPConnectionInfo(ConnectionInfo?info) { for (; info != null; info = info.Underlying) { if (info is TCPConnectionInfo) { return((TCPConnectionInfo)info); } } return(null); }
private IPConnectionInfo?GetIPConnectionInfo() { for (ConnectionInfo?p = _connectionInfo; p != null; p = p.Underlying) { if (p is IPConnectionInfo) { return((IPConnectionInfo)p); } } return(null); }
private static IPConnectionInfo?getIPConnectionInfo(ConnectionInfo info) { for (ConnectionInfo?i = info; i != null; i = i.Underlying) { if (i is IPConnectionInfo) { return((IPConnectionInfo)i); } } return(null); }
private static TCPConnectionInfo?getTCPConnectionInfo(ConnectionInfo info) { ConnectionInfo?underlying = info; for (; underlying != null; underlying = underlying.Underlying) { if (info is TCPConnectionInfo) { return((TCPConnectionInfo)underlying); } } return(null); }
public ValueTask <ConnectionInfo> InitConnectAsync(CancellationToken cancellationToken) { if (_connectionInfo is not null) { return(new ValueTask <ConnectionInfo>(_connectionInfo)); } return(StartConnectAsync(cancellationToken)); async ValueTask <ConnectionInfo> StartConnectAsync(CancellationToken ct) { if (_initTask is null) { await _initSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); try { if (_initTask is null) { _initTask = DoConnectAsync(ct); } } finally { _initSemaphore.Release(); } } return(await _initTask.ConfigureAwait(false)); } async Task <ConnectionInfo> DoConnectAsync(CancellationToken ct) { await ConnectAsync(ct).ConfigureAwait(false); QueryMessage?connectRequest = CreateQueryRequest(_initialDocument); var configMessage = await SendQueryAsync <BsonDocument>(connectRequest, ct).ConfigureAwait(false); QueryMessage?buildInfoRequest = CreateQueryRequest(new BsonDocument("buildInfo", 1)); var hell = await SendQueryAsync <BsonDocument>(buildInfoRequest, ct).ConfigureAwait(false); _connectionInfo = new ConnectionInfo(configMessage[0], hell[0]); Init = true; return(_connectionInfo); } }
public RabbitMqConnectionStatusMonitor(IRabbitMqConnection connection, ILoggerFactory?loggerFactory = null) { _rabbitMqConnection = connection; _logger = loggerFactory?.CreateLogger(nameof(RabbitMqConnectionStatusMonitor)); _isConnected = new BehaviorSubject <bool>(false); _rabbitMqConnection.Connect(); var blocked = Observable.FromEventPattern <ConnectionBlockedEventArgs>(h => connection.AutoRecoveringConnection.ConnectionBlocked += h, h => connection.AutoRecoveringConnection.ConnectionBlocked -= h).Select(e => { _logger?.LogInformation($"AMQP connection blocked - {nameof(ShutdownEventArgs)} => {e.EventArgs?.ToJson()}"); return(ConnectionStatus.Disconnected); }); var unblocked = Observable.FromEventPattern <EventArgs>(h => connection.AutoRecoveringConnection.ConnectionUnblocked += h, h => connection.AutoRecoveringConnection.ConnectionUnblocked -= h).Select(e => { _logger?.LogInformation($"AMQP connection unblocked - {nameof(EventArgs)} => {e.EventArgs?.ToJson()}"); return(ConnectionStatus.Connected); }); var shutdowned = Observable.FromEventPattern <ShutdownEventArgs>(h => connection.AutoRecoveringConnection.ConnectionShutdown += h, h => connection.AutoRecoveringConnection.ConnectionShutdown -= h).Select(e => { _logger?.LogInformation($"AMQP connection shutdown - {nameof(ShutdownEventArgs)} => {e.EventArgs?.ToJson()}"); return(ConnectionStatus.Disconnected); }); var closed = Observable.FromEventPattern <CallbackExceptionEventArgs>(h => connection.AutoRecoveringConnection.CallbackException += h, h => connection.AutoRecoveringConnection.CallbackException -= h).Select(e => { _logger?.LogError(e.EventArgs.Exception, $"An exception occured in a callback process - {nameof(CallbackExceptionEventArgs)} => {e.EventArgs?.ToJson()}"); return(ConnectionStatus.ErrorOccurred); }); var errorOccurred = Observable.FromEventPattern <EventArgs>(h => connection.AutoRecoveringConnection.RecoverySucceeded += h, h => connection.AutoRecoveringConnection.RecoverySucceeded -= h).Select(e => { _logger?.LogInformation($"AMQP connection recovery success - {nameof(EventArgs)} => {e.EventArgs?.ToJson()}"); return(ConnectionStatus.Connected); }); var connectionRecoveryError = Observable.FromEventPattern <ConnectionRecoveryErrorEventArgs>(h => connection.AutoRecoveringConnection.ConnectionRecoveryError += h, h => connection.AutoRecoveringConnection.ConnectionRecoveryError -= h).Select(e => { _logger?.LogError(e.EventArgs.Exception, $"AMQP connection recovery error - {nameof(ConnectionRecoveryErrorEventArgs)} => {e.EventArgs?.ToJson()}"); return(ConnectionStatus.Disconnected); }); _connectionInfoChanged = Observable.Merge(blocked, unblocked, shutdowned, closed, errorOccurred, connectionRecoveryError) .Scan(ConnectionInfo.InitialConnected, UpdateConnectionInfo) .StartWith(ConnectionInfo.InitialConnected) .Do(connectionInfo => { ConnectionInfo = connectionInfo; _logger?.LogInformation($"{nameof(RabbitMqConnectionStatusMonitor)} => ConnectionInfo - {connectionInfo}"); _isConnected.OnNext(connectionInfo.Status == ConnectionStatus.Connected); }) .Replay(1); _cleanUp = _connectionInfoChanged.Connect(); }
public EventStoreConnectionStatusMonitor(IEventStoreConnection connection, ILoggerFactory?loggerFactory = null) { _eventStoreConnection = connection; _logger = loggerFactory?.CreateLogger(nameof(EventStoreConnectionStatusMonitor)); _isConnected = new BehaviorSubject <bool>(false); var connected = Observable.FromEventPattern <ClientConnectionEventArgs>(h => connection.Connected += h, h => connection.Connected -= h).Select(_ => { return(ConnectionStatus.Connected); }); var disconnected = Observable.FromEventPattern <ClientConnectionEventArgs>(h => connection.Disconnected += h, h => connection.Disconnected -= h).Select(arg => { _logger?.LogInformation($"{nameof(EventStoreConnectionStatusMonitor)} => Connection lost - [{arg.EventArgs.RemoteEndPoint}]"); return(ConnectionStatus.Disconnected); }); var reconnecting = Observable.FromEventPattern <ClientReconnectingEventArgs>(h => connection.Reconnecting += h, h => connection.Reconnecting -= h).Select(_ => { return(ConnectionStatus.Connecting); }); var closed = Observable.FromEventPattern <ClientClosedEventArgs>(h => connection.Closed += h, h => connection.Closed -= h).Select(arg => { _logger?.LogInformation($"{nameof(EventStoreConnectionStatusMonitor)} => Connection closed - [{arg.EventArgs.Reason}]"); return(ConnectionStatus.Closed); }); var errorOccurred = Observable.FromEventPattern <ClientErrorEventArgs>(h => connection.ErrorOccurred += h, h => connection.ErrorOccurred -= h).Select(arg => { _logger?.LogError(arg.EventArgs.Exception, $"{nameof(EventStoreConnectionStatusMonitor)} => An error occured while connected to EventStore"); return(ConnectionStatus.ErrorOccurred); }); var authenticationFailed = Observable.FromEventPattern <ClientAuthenticationFailedEventArgs>(h => connection.AuthenticationFailed += h, h => connection.AuthenticationFailed -= h).Select(arg => { _logger?.LogError($"{nameof(EventStoreConnectionStatusMonitor)} => Authentication failed while connecting to EventStore - [{arg.EventArgs.Reason}]"); return(ConnectionStatus.AuthenticationFailed); }); _connectionInfoChanged = Observable.Merge(connected, disconnected, reconnecting, closed, errorOccurred, authenticationFailed) .Scan(ConnectionInfo.InitialDisconnected, UpdateConnectionInfo) .StartWith(ConnectionInfo.InitialDisconnected) .Do(connectionInfo => { ConnectionInfo = connectionInfo; _logger?.LogInformation($"{nameof(EventStoreConnectionStatusMonitor)} => ConnectionInfo - {connectionInfo}"); _isConnected.OnNext(connectionInfo.Status == ConnectionStatus.Connected); }) .Replay(1); _cleanUp = _connectionInfoChanged.Connect(); _eventStoreConnection.ConnectAsync().Wait(); }