Exemplo n.º 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);
        }
Exemplo n.º 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;
 }
Exemplo n.º 3
0
 private async Task Disconnect(RiakPbcSocket socket)
 {
     if (socket != null)
     {
         await socket.Disconnect().ConfigureAwait(false);
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 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");
        }
Exemplo n.º 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));
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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();
            }
        }
Exemplo n.º 13
0
 public async Task GetSingleResultViaPbc(RiakPbcSocket socket, Func <RiakPbcSocket, Task> useFun)
 {
     await useFun(socket).ConfigureAwait(false);
 }
Exemplo n.º 14
0
 public async Task Release(RiakPbcSocket socket)
 {
     await _connectionManager.Release(socket).ConfigureAwait(false);
 }
Exemplo n.º 15
0
        public async Task <TResult> GetSingleResultViaPbc <TResult>(RiakPbcSocket socket, Func <RiakPbcSocket, Task <TResult> > useFun)
        {
            var result = await useFun(socket).ConfigureAwait(false);

            return(result);
        }