public async Task <TResult> GetSingleResultViaPbc <TResult>(Func <RiakPbcSocket, Task <TResult> > useFun) { var result = default(TResult); RiakPbcSocket socket = null; ExceptionDispatchInfo capturedException = null; try { socket = await _connectionManager.CreateSocket().ConfigureAwait(false); result = await useFun(socket).ConfigureAwait(false); } catch (Exception ex) { capturedException = ExceptionDispatchInfo.Capture(ex); } await _connectionManager.Release(socket).ConfigureAwait(false); if (capturedException != null) { capturedException.Throw(); } return(result); }
public RiakConnection(IRiakNodeConfiguration nodeConfiguration) { _restRootUrl = @"{0}://{1}:{2}".Fmt(nodeConfiguration.RestScheme, nodeConfiguration.HostAddress, nodeConfiguration.RestPort); _socket = new RiakPbcSocket(nodeConfiguration.HostAddress, nodeConfiguration.PbcPort, nodeConfiguration.NetworkReadTimeout, nodeConfiguration.NetworkWriteTimeout); _vnodeVclocks = nodeConfiguration.VnodeVclocks; }
private async Task Disconnect(RiakPbcSocket socket) { if (socket != null) { await socket.Disconnect().ConfigureAwait(false); } }
public async Task Release(RiakPbcSocket socket) { if (_disposing) { return; } _resources.Add(socket); }
public async Task Release(RiakPbcSocket socket) { _resources.Dequeue(socket); if (_disposing) { return; } if (socket != null) { socket.Dispose(); } }
public async Task <RiakPbcSocket> CreateSocket() { var socket = new RiakPbcSocket( _nodeConfig.HostAddress, _nodeConfig.PbcPort, _nodeConfig.NetworkReadTimeout, _nodeConfig.NetworkWriteTimeout, _nodeConfig.IdleTimeout, _pool, _bufferManager); _resources.Enqueue(socket); return(socket); }
public async Task <RiakPbcSocket> CreateSocket() { if (_disposing) { throw new ObjectDisposedException(this.GetType().Name); } RiakPbcSocket socket = null; if (_resources.TryTake(out socket, -1)) { return(socket); } throw new TimeoutException("Unable to create socket"); }
private void Init() { _allResources = new List <RiakPbcSocket>(); for (var i = 0; i < _poolSize; ++i) { var socket = new RiakPbcSocket( _hostAddress, _pbcPort, _networkReadTimeout, _networkWriteTimeout, _idleTimeout, _pool, _blockingBufferManager); _allResources.Add(socket); } _resources = new BlockingCollection <RiakPbcSocket>(new ConcurrentQueue <RiakPbcSocket>(_allResources)); }
private async Task PbcRead(RiakPbcSocket socket, MessageCode expectedMessageCode) { try { await socket.Read(expectedMessageCode).ConfigureAwait(false); } catch (RiakException ex) { if (ex.NodeOffline) { Disconnect(socket).ConfigureAwait(false).GetAwaiter().GetResult(); } throw new RiakException((uint)ResultCode.CommunicationError, ex.Message, ex.NodeOffline); } catch (Exception ex) { Disconnect(socket).ConfigureAwait(false).GetAwaiter().GetResult(); throw new RiakException((uint)ResultCode.CommunicationError, ex.Message, true); } }
private Task <TResult> PbcRead <TResult>(RiakPbcSocket socket) where TResult : class, new() { try { return(socket.Read <TResult>()); } catch (RiakException ex) { if (ex.NodeOffline) { Disconnect(socket).ConfigureAwait(false).GetAwaiter().GetResult(); } throw new RiakException((uint)ResultCode.CommunicationError, ex.Message, ex.NodeOffline); } catch (Exception ex) { Disconnect(socket).ConfigureAwait(false).GetAwaiter().GetResult(); throw new RiakException((uint)ResultCode.CommunicationError, ex.Message, true); } }
private async Task PbcWrite <TRequest>(RiakPbcSocket socket, TRequest request) where TRequest : class { try { await socket.Write(request).ConfigureAwait(false); } catch (RiakException ex) { if (ex.NodeOffline) { Disconnect(socket).ConfigureAwait(false).GetAwaiter().GetResult(); } throw new RiakException((uint)ResultCode.CommunicationError, ex.Message, ex.NodeOffline); } catch (Exception ex) { Disconnect(socket).ConfigureAwait(false).GetAwaiter().GetResult(); throw new RiakException((uint)ResultCode.CommunicationError, ex.Message, true); } }
public async Task GetMultipleResultViaPbc(Func <RiakPbcSocket, Task> useFun) { RiakPbcSocket socket = null; ExceptionDispatchInfo capturedException = null; try { socket = await _connectionManager.CreateSocket().ConfigureAwait(false); await useFun(socket).ConfigureAwait(false); } catch (Exception ex) { capturedException = ExceptionDispatchInfo.Capture(ex); } await _connectionManager.Release(socket).ConfigureAwait(false); if (capturedException != null) { capturedException.Throw(); } }
public async Task GetSingleResultViaPbc(RiakPbcSocket socket, Func <RiakPbcSocket, Task> useFun) { await useFun(socket).ConfigureAwait(false); }
public async Task Release(RiakPbcSocket socket) { await _connectionManager.Release(socket).ConfigureAwait(false); }
public async Task <TResult> GetSingleResultViaPbc <TResult>(RiakPbcSocket socket, Func <RiakPbcSocket, Task <TResult> > useFun) { var result = await useFun(socket).ConfigureAwait(false); return(result); }