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

            return(result);
        }