private IWireProtocol <TCommandResult> CreateSupportedWireProtocol(IConnection connection) { if (_cachedWireProtocol != null && _cachedConnectionId == connection.ConnectionId) { return(_cachedWireProtocol); } else { _cachedConnectionId = connection.ConnectionId; var serverVersion = connection.Description?.ServerVersion; // If server API versioning has been requested, then we SHOULD send the initial hello command // using OP_MSG. Since this is the first message and buildInfo hasn't been sent yet, // connection.Description will be null and we can't rely on the semver check to determine if // the server supports OP_MSG. // As well since server API versioning is supported on MongoDB 5.0+, we also know that // OP_MSG will be supported regardless and can skip the semver checks for other messages. if (_serverApi != null || (serverVersion != null && Feature.CommandMessage.IsSupported(serverVersion))) { return(_cachedWireProtocol = CreateCommandUsingCommandMessageWireProtocol()); } else { return(_cachedWireProtocol = CreateCommandUsingQueryMessageWireProtocol()); } } }
private IWireProtocol <TCommandResult> CreateSupportedWireProtocol(IConnection connection) { if (_cachedWireProtocol != null && _cachedConnectionId == connection.ConnectionId) { return(_cachedWireProtocol); } else { _cachedConnectionId = connection.ConnectionId; // If server API versioning has been requested, then we SHOULD send the initial hello command // using OP_MSG. Since this is the first message and hello/legacy hello hasn't been sent yet, // connection.Description will be null and we can't rely on the server check to determine if // the server supports OP_MSG. // As well since server API versioning is supported on MongoDB 5.0+, we also know that // OP_MSG will be supported regardless and can skip the server checks for other messages. if (_serverApi != null || connection.Description != null) { return(_cachedWireProtocol = CreateCommandUsingCommandMessageWireProtocol()); } else { // The driver doesn't support servers less than 3.6. However it's still useful to support OP_QUERY for initial handshake. // For pre-3.6 servers, it will allow throwing unsupported wire protocol exception on the driver side. // If we only supported OP_MSG, we would throw a general server error about closing connection without actual reason of why it happened return(_cachedWireProtocol = CreateCommandUsingQueryMessageWireProtocol()); } } }
/// <summary> /// Constructor. /// </summary> protected ClientBase() { _pingTimer = new SimpleConnectionTimer(30000); _pingTimer.Elapsed += PingTimer_Elapsed; ConnectTimeout = DefaultConnectionAttemptTimeout; WireProtocol = WireProtocolManager.GetDefaultWireProtocol(); }
public PotatoServer(IWireProtocol protocol, IPotatoClientFactory factory, ILogger <PotatoServer> logger) { ClientFactory = factory; Logger = logger; Logger.LogTrace("PotatoTcp Server initialized."); }
private async Task <TResult> ExecuteProtocolAsync <TResult>(IWireProtocol <TResult> protocol, CancellationToken cancellationToken) { try { return(await protocol.ExecuteAsync(_connection, cancellationToken).ConfigureAwait(false)); } catch (Exception ex) { _server.HandleChannelException(_connection, ex); throw; } }
private TResult ExecuteProtocol <TResult>(IWireProtocol <TResult> protocol, CancellationToken cancellationToken) { try { return(protocol.Execute(_connection, cancellationToken)); } catch (Exception ex) { _server.HandleChannelException(_connection, ex); throw; } }
private void ExecuteProtocol(IWireProtocol protocol, CancellationToken cancellationToken) { try { protocol.Execute(_connection, cancellationToken); } catch (Exception ex) { _server.HandleChannelException(_connection, ex); throw; } }
private TResult ExecuteProtocol <TResult>(IWireProtocol <TResult> protocol, ICoreSession session, CancellationToken cancellationToken) { try { return(protocol.Execute(_connection, cancellationToken)); } catch (Exception ex) { MarkSessionDirtyIfNeeded(session, ex); _server.HandleChannelException(_connection, ex); throw; } }
public static async Task <TResult> ExecuteAsync <TResult>( this IWireProtocol <TResult> protocol, IConnectionSource connectionSource, TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(protocol, "protocol"); var slidingTimeout = new SlidingTimeout(timeout); using (var connection = await connectionSource.GetConnectionAsync(slidingTimeout, cancellationToken)) { return(await protocol.ExecuteAsync(connection, slidingTimeout, cancellationToken)); } }
private IWireProtocol <TCommandResult> CreateSupportedWireProtocol(IConnection connection) { if (_cachedWireProtocol != null && _cachedConnectionId == connection.ConnectionId) { return(_cachedWireProtocol); } else { _cachedConnectionId = connection.ConnectionId; var serverVersion = connection.Description?.ServerVersion; if (serverVersion != null && Feature.CommandMessage.IsSupported(serverVersion)) { return(_cachedWireProtocol = CreateCommandUsingCommandMessageWireProtocol()); } else { return(_cachedWireProtocol = CreateCommandUsingQueryMessageWireProtocol()); } } }
public PotatoClientFactory(IWireProtocol wireProtocol, ILogger <PotatoClient> logger) { WireProtocol = wireProtocol; Logger = logger; }
public PotatoClientFactory(IWireProtocol wireProtocol) : this(wireProtocol, PotatoClient.DefaultLogger) { }
public PotatoServer(IWireProtocol wireProtocol, ILogger <PotatoServer> logger) : this(wireProtocol, new PotatoClientFactory(wireProtocol), logger) { }
public PotatoServer(IWireProtocol wireProtocol) : this(wireProtocol, new PotatoClientFactory(wireProtocol), DefaultLogger) { }