Example #1
0
        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);
        }
Example #2
0
 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;
 }
Example #3
0
 private async Task Disconnect(RiakPbcSocket socket)
 {
     if (socket != null)
     {
         await socket.Disconnect().ConfigureAwait(false);
     }
 }
Example #4
0
        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);
        }
Example #7
0
        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");
        }
Example #8
0
        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));
        }
Example #9
0
 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);
     }
 }
Example #10
0
 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);
     }
 }
Example #11
0
 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);
     }
 }
Example #12
0
        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();
            }
        }
Example #13
0
 public async Task GetSingleResultViaPbc(RiakPbcSocket socket, Func <RiakPbcSocket, Task> useFun)
 {
     await useFun(socket).ConfigureAwait(false);
 }
Example #14
0
 public async Task Release(RiakPbcSocket socket)
 {
     await _connectionManager.Release(socket).ConfigureAwait(false);
 }
Example #15
0
        public async Task <TResult> GetSingleResultViaPbc <TResult>(RiakPbcSocket socket, Func <RiakPbcSocket, Task <TResult> > useFun)
        {
            var result = await useFun(socket).ConfigureAwait(false);

            return(result);
        }