public Task <TChannel> CreateChannelAsync <TChannel>( INiftyClientConnector <TChannel> connector, TimeSpan?connectTimeout, TimeSpan?receiveTimeout, TimeSpan?readTimeout, TimeSpan?writeTimeout, int maxFrameSize, ClientSslConfig sslConfig = null, EndPoint socksProxy = null) where TChannel : INiftyClientChannel { this.ThrowIfDisposed(); Guard.ArgumentNotNull(connector, nameof(connector)); var connectFuture = niftyClient.ConnectAsync( connector, connectTimeout, receiveTimeout, readTimeout, writeTimeout, maxFrameSize, sslConfig, socksProxy); return(connectFuture); }
public Task <TNiftyClientChannelTransport> ConnectAsync <TChannel, TClient>( INiftyClientConnector <TChannel> clientChannelConnector, TimeSpan?connectTimeout, TimeSpan?receiveTimeout, TimeSpan?readTimeout, TimeSpan?sendTimeout, int maxFrameSize, ClientSslConfig sslConfig, EndPoint socksProxyAddress) where TChannel : INiftyClientChannel { return(ConnectAsync( clientChannelConnector, connectTimeout, receiveTimeout, readTimeout, sendTimeout, maxFrameSize, sslConfig, socksProxyAddress) .ContinueWith(t => { try { return new TNiftyClientChannelTransport(typeof(TClient), t.GetAwaiter().GetResult()); } catch (Exception e) { throw new ThriftyTransportException($"Failed to establish client connection.{Environment.NewLine}{e.Message}", e, ThriftyTransportException.ExceptionType.NotOpen); } })); }
public Task <TChannel> CreateChannelAsync <TChannel>(INiftyClientConnector <TChannel> connector, ClientSslConfig sslConfig = null) where TChannel : INiftyClientChannel { return(CreateChannelAsync(connector, DEFAULT_CONNECT_TIMEOUT, DEFAULT_RECEIVE_TIMEOUT, DEFAULT_READ_TIMEOUT, DEFAULT_WRITE_TIMEOUT, DEFAULT_MAX_FRAME_SIZE, sslConfig, this.DefaultSocksProxy)); }
public Task <TClient> CreateClientAsync <TClient, TChannel>( INiftyClientConnector <TChannel> connector, ThriftClientConfig config = null, String clientName = null, ClientSslConfig sslConfig = null, IEnumerable <ThriftClientEventHandler> eventHandlers = null) where TClient : class where TChannel : INiftyClientChannel { return(this.CreateClientAsync(connector, typeof(TClient), config, clientName, sslConfig, eventHandlers) .ContinueWith(t => t.Result as TClient)); }
//private IChannelGroup allChannels = new DefaultChannelGroup(); public Task <T> ConnectAsync <T>( INiftyClientConnector <T> clientChannelConnector, ClientSslConfig sslConfig) where T : INiftyClientChannel { return(this.ConnectAsync(clientChannelConnector, DefaultConnectTimeout, DefaultReceiveTimeout, DefaultReadTimeout, DefaultSendTimeout, DefaultMaxFrameSize, sslConfig, this.DefaultSocksProxyAddress)); }
public Task <Object> CreateClientAsync <TChannel>( INiftyClientConnector <TChannel> connector, Type clientType, TimeSpan?connectTimeout, TimeSpan?receiveTimeout, TimeSpan?readTimeout, TimeSpan?writeTimeout, int maxFrameSize, string clientName, ClientSslConfig sslConfig, IEnumerable <ThriftClientEventHandler> eventHandlers, EndPoint socksProxy) where TChannel : INiftyClientChannel { this.ThrowIfDisposed(); Guard.ArgumentNotNull(connector, nameof(connector)); Guard.ArgumentNotNull(clientType, nameof(clientType)); eventHandlers = eventHandlers ?? Enumerable.Empty <ThriftClientEventHandler>(); var connectFuture = this.CreateChannelAsync( connector, connectTimeout, receiveTimeout, readTimeout, writeTimeout, maxFrameSize, sslConfig, socksProxy); return(connectFuture.ContinueWith(t => { String name = String.IsNullOrWhiteSpace(clientName) ? DefaultClientName : clientName; INiftyClientChannel channel = null; try { channel = t.Result; return this.CreateClient(channel, clientType, name, eventHandlers); } catch (AggregateException ex) { _logger.LogError(0, ex, $"create clinet channel fault."); // The channel was created successfully, but client creation failed so the // channel must be closed now channel?.CloseAsync(); throw; } })); }
/// <summary> /// Asynchronously connect to a service to create a new client. /// </summary> /// <typeparam name="TChannel"></typeparam> /// <param name="connector">Connector used to establish the new connection</param> /// <returns>Future that will be set to the client once the connection is established</returns> public Task <Object> OpenAsync <TChannel>(INiftyClientConnector <TChannel> connector) where TChannel : INiftyClientChannel { return(_clientManager.CreateClientAsync( connector, this.ClientType, ConnectTimeout, ReceiveTimeout, ReadTimeout, WriteTimeout, MaxFrameSize, ClientName, this.SslConfig, this._eventHandlers, GetSocksProxyOrDefault())); }
public Task <T> ConnectAsync <T>( INiftyClientConnector <T> clientChannelConnector, TimeSpan?connectTimeout, TimeSpan?receiveTimeout, TimeSpan?readTimeout, TimeSpan?sendTimeout, ClientSslConfig sslConfig, int maxFrameSize) where T : INiftyClientChannel { return(ConnectAsync(clientChannelConnector, connectTimeout, receiveTimeout, readTimeout, sendTimeout, maxFrameSize, sslConfig, this.DefaultSocksProxyAddress)); }
public Task <T> ConnectAsync <T>( INiftyClientConnector <T> clientChannelConnector, TimeSpan?connectTimeout, TimeSpan?receiveTimeout, TimeSpan?readTimeout, TimeSpan?sendTimeout, int maxFrameSize, ClientSslConfig sslConfig, EndPoint socksProxyAddress) where T : INiftyClientChannel { this.ThrowIfDisposed(); Guard.ArgumentNotNull(clientChannelConnector, nameof(clientChannelConnector)); Bootstrap bootstrap = new Bootstrap(); bootstrap.Group(this.WorkerExecutor) .Channel <TcpSocketChannel>() .Option(ChannelOption.TcpNodelay, true); if (connectTimeout != null) { bootstrap.Option(ChannelOption.ConnectTimeout, connectTimeout.Value); } bootstrap.Handler(new ActionChannelInitializer <ISocketChannel>(channel => { clientChannelConnector.ConfigureChannelPipeline(channel.Pipeline, maxFrameSize, this.NettyClientConfig, sslConfig); })); Task <IChannel> connectTask = clientChannelConnector.ConnectAsync(bootstrap); return(connectTask.ContinueWith(t => { if (t.Exception == null && t.Result != null && t.Result.Open) { _allChannel.Add(t.GetAwaiter().GetResult()); } if (t.Exception != null) { _logger.LogError(nameof(EventId), t.Exception, "Failed to establish client connection."); } return CreateNiftyClientChannel(clientChannelConnector, receiveTimeout, readTimeout, sendTimeout, t); })); }
public Task <TNiftyClientChannelTransport> ConnectAsync <T, TClient>( INiftyClientConnector <T> clientChannelConnector, TimeSpan?connectTimeout, TimeSpan?receiveTimeout, TimeSpan?readTimeout, TimeSpan?sendTimeout, int maxFrameSize, ClientSslConfig sslConfig) where T : INiftyClientChannel { return(ConnectAsync <T, TClient>( clientChannelConnector, connectTimeout, receiveTimeout, readTimeout, sendTimeout, maxFrameSize, sslConfig, (EndPoint)null)); }
public Task <Object> CreateClientAsync <TChannel>( INiftyClientConnector <TChannel> connector, Type clientType, ThriftClientConfig config = null, String clientName = null, ClientSslConfig sslConfig = null, IEnumerable <ThriftClientEventHandler> eventHandlers = null) where TChannel : INiftyClientChannel { config = config ?? new ThriftClientConfig(); return(this.CreateClientAsync(connector, clientType, config.ConnectTimeout, config.ReceiveTimeout, config.ReceiveTimeout, config.WriteTimeout, config.MaxFrameSize, clientName, sslConfig, eventHandlers, null)); }
private T CreateNiftyClientChannel <T>(INiftyClientConnector <T> clientChannelConnector, TimeSpan?receiveTimeout, TimeSpan?readTimeout, TimeSpan?sendTimeout, Task <IChannel> future) where T : INiftyClientChannel { this.ThrowIfDisposed(); try { if (future.Status == TaskStatus.RanToCompletion) { IChannel nettyChannel = future.GetAwaiter().GetResult(); var channel = clientChannelConnector.NewThriftClientChannel(nettyChannel, this.NettyClientConfig); channel.ReceiveTimeout = receiveTimeout; channel.ReadTimeout = readTimeout; channel.SendTimeout = sendTimeout; return(channel); } else if (future.IsCanceled) { throw new ThriftyTransportException($"Unable to cancel client channel connection ( server: {clientChannelConnector.ServerAddress} ).", ThriftyTransportException.ExceptionType.NotOpen); } else if (future.Exception != null) { throw new ThriftyTransportException($"Unable to open client channel connection ( server: {clientChannelConnector.ServerAddress} ).", future.Exception, ThriftyTransportException.ExceptionType.NotOpen); } else { throw new ThriftyTransportException($"Unable to open client channel connection ( server: {clientChannelConnector.ServerAddress} ) . connection task status is '{future.Status}' .", ThriftyTransportException.ExceptionType.NotOpen); } } catch (AggregateException t) { throw new ThriftyTransportException($"Failed to establish client connection ( server: {clientChannelConnector.ServerAddress} ).", t, ThriftyTransportException.ExceptionType.Unknown); } }