public ThriftClient( ThriftClientManager clientManager, Type clientType, String clientName, TimeSpan connectTimeout, TimeSpan receiveTimeout, TimeSpan readTimeout, TimeSpan writeTimeout, EndPoint socksProxy, int maxFrameSize, ClientSslConfig sslConfig, IEnumerable <ThriftClientEventHandler> eventHandlers) { Guard.ArgumentNotNull(clientManager, nameof(clientManager)); Guard.ArgumentNotNull(clientType, nameof(clientType)); Guard.ArgumentNotNull(clientName, nameof(clientName)); Guard.ArgumentNotNull(connectTimeout, nameof(connectTimeout)); Guard.ArgumentNotNull(receiveTimeout, nameof(receiveTimeout)); Guard.ArgumentNotNull(readTimeout, nameof(readTimeout)); Guard.ArgumentNotNull(writeTimeout, nameof(writeTimeout)); Guard.ArgumentCondition(maxFrameSize >= 0, "maxFrameSize cannot be negative"); Guard.ArgumentNotNull(eventHandlers, nameof(clientManager)); this._clientManager = clientManager; this.ClientType = clientType; this.ClientName = clientName; this.ConnectTimeout = connectTimeout; this.ReceiveTimeout = receiveTimeout; this.ReadTimeout = readTimeout; this.WriteTimeout = writeTimeout; this.SocksProxy = socksProxy; this.MaxFrameSize = maxFrameSize; this.SslConfig = sslConfig; this._eventHandlers = eventHandlers; }
public ThriftClient( ThriftClientManager clientManager, Type clientType, ThriftClientConfig clientConfig, String clientName, IEnumerable <ThriftClientEventHandler> eventHandlers = null) : this(clientManager, clientType, clientName, clientConfig.ConnectTimeout, clientConfig.ReceiveTimeout, clientConfig.ReadTimeout, clientConfig.WriteTimeout, clientConfig.SocksProxy, clientConfig.MaxFrameSize, clientConfig.SslConfig, eventHandlers ?? Enumerable.Empty <ThriftClientEventHandler>()) { }
public ThriftClient(ThriftClientManager clientManager, Type clientType) : this(clientManager, clientType, new ThriftClientConfig(), ThriftClientManager.DefaultClientName) { }
public Task AsynchronousInvoke( IRequestChannel channel, TChannelBufferInputTransport inputTransport, TChannelBufferOutputTransport outputTransport, TProtocol inputProtocol, TProtocol outputProtocol, int sequenceId, ClientContextChain contextChain, Object[] args) { //Mark: 微软没有提供 TaskCompletionSource 的非泛型类型,只能使用动态类型处理。 TaskCompletionSourceEx future; if (_successCodec.Type != ThriftType.Void) { future = new TaskCompletionSourceEx(_successCodec.Type.CSharpType); } else { future = new TaskCompletionSourceEx(typeof(Object)); } var requestContext = RequestContexts.GetCurrentContext(); contextChain.PreWrite(args); outputTransport.ResetOutputBuffer(); WriteArguments(outputProtocol, sequenceId, args); IByteBuffer requestBuffer = outputTransport.OutputBuffer.Copy(); contextChain.PostWrite(args); requestBuffer.Retain(); channel.SendAsynchronousRequest(requestBuffer, false, new RequestListener( onRequestSent: reqs => { reqs.Release(); if (this._oneway) { try { ForceDoneChain(contextChain); future.TrySetResult(null); } catch (Exception e) { ForceDoneChain(contextChain); future.TrySetException(e); } } }, onResponseReceive: message => { IRequestContext oldRequestContext = RequestContexts.GetCurrentContext(); RequestContexts.SetCurrentContext(requestContext); try { contextChain.PreRead(); inputTransport.SetInputBuffer(message); WaitForResponse(inputProtocol, sequenceId); Object results = ReadResponse(inputProtocol); contextChain.PostRead(results); ForceDoneChain(contextChain); future.TrySetResult(results); } catch (Exception e) { var wrapException = ThriftClientManager.WrapTException(e); contextChain.PostReadException(e); ForceDoneChain(contextChain); future.TrySetException(wrapException); } finally { RequestContexts.SetCurrentContext(oldRequestContext); } }, onChannelError: e => { if (requestBuffer.ReferenceCount > 0) { requestBuffer.Release(); } IRequestContext oldRequestContext = RequestContexts.GetCurrentContext(); RequestContexts.SetCurrentContext(requestContext); try { contextChain.PreReadException(e); ForceDoneChain(contextChain); var wrappedException = ThriftClientManager.WrapTException(e); future.TrySetException(wrappedException); } finally { RequestContexts.SetCurrentContext(oldRequestContext); } } )); return(future.Task); }