Пример #1
0
        /// <summary>
        /// Writes data to Bob asynchronously
        /// </summary>
        /// <param name="key">Key</param>
        /// <param name="data">Binary data</param>
        /// <param name="token">Cancellation token</param>
        /// <returns>Operation result</returns>
        /// <exception cref="ArgumentNullException">Data is null</exception>
        /// <exception cref="ObjectDisposedException">Client was closed</exception>
        /// <exception cref="TimeoutException">Timeout reached</exception>
        /// <exception cref="OperationCanceledException">Operation was cancelled</exception>
        /// <exception cref="BobOperationException">Other operation errors</exception>
        public async Task PutAsync(BobKey key, byte[] data, CancellationToken token)
        {
            int clientIndex = SelectClientIndex(BobOperationKind.Put, key);

            int retryCount = 0;

            while (true)
            {
                retryCount++;

                try
                {
                    await _clients[clientIndex].PutAsync(key, data, token).ConfigureAwait(false);
                    return;
                }
                catch (BobOperationException) when(retryCount <= _operationRetryCount)
                {
                    if (!TrySelectClientIndexOnRetry(ref clientIndex, BobOperationKind.Put, key))
                    {
                        throw;
                    }
                }
                catch (TimeoutException) when(retryCount <= _operationRetryCount)
                {
                    if (!TrySelectClientIndexOnRetry(ref clientIndex, BobOperationKind.Put, key))
                    {
                        throw;
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Checks data presented in Bob
        /// </summary>
        /// <param name="keys">Keys array</param>
        /// <param name="fullGet">Try read data from sup nodes</param>
        /// <param name="token">Cancellation token</param>
        /// <returns>Operation result</returns>
        /// <exception cref="ObjectDisposedException">Client was closed</exception>
        /// <exception cref="TimeoutException">Timeout reached</exception>
        /// <exception cref="OperationCanceledException">Operation was cancelled</exception>
        /// <exception cref="BobOperationException">Other operation errors</exception>
        /// <exception cref="ArgumentNullException">keys is null</exception>
        protected internal bool[] Exists(BobKey[] keys, bool fullGet, CancellationToken token)
        {
            BobKey firstOrDefaultKey = keys.Length > 0 ? keys[0] : default(BobKey);
            int    clientIndex       = SelectClientIndex(BobOperationKind.Exist, firstOrDefaultKey);

            int retryCount = 0;

            while (true)
            {
                retryCount++;

                try
                {
                    return(_clients[clientIndex].Exists(keys, fullGet, token));
                }
                catch (BobOperationException) when(retryCount <= _operationRetryCount)
                {
                    if (!TrySelectClientIndexOnRetry(ref clientIndex, BobOperationKind.Exist, firstOrDefaultKey))
                    {
                        throw;
                    }
                }
                catch (TimeoutException) when(retryCount <= _operationRetryCount)
                {
                    if (!TrySelectClientIndexOnRetry(ref clientIndex, BobOperationKind.Exist, firstOrDefaultKey))
                    {
                        throw;
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Asynchronously checks data presented in Bob
        /// </summary>
        /// <param name="keys">Keys array</param>
        /// <param name="fullGet">Try read data from sup nodes</param>
        /// <param name="token">Cancellation token</param>
        /// <returns>Operation result</returns>
        /// <exception cref="ObjectDisposedException">Client was closed</exception>
        /// <exception cref="TimeoutException">Timeout reached</exception>
        /// <exception cref="OperationCanceledException">Operation was cancelled</exception>
        /// <exception cref="BobOperationException">Other operation errors</exception>
        /// <exception cref="ArgumentNullException">keys is null</exception>
        protected internal async Task <bool[]> ExistsAsync(IReadOnlyList <BobKey> keys, bool fullGet, CancellationToken token)
        {
            BobKey firstOrDefaultKey = keys.Count > 0 ? keys[0] : default(BobKey);
            int    clientIndex       = SelectClientIndex(BobOperationKind.Exist, firstOrDefaultKey);

            int retryCount = 0;

            while (true)
            {
                retryCount++;

                try
                {
                    return(await _clients[clientIndex].ExistsAsync(keys, fullGet, token).ConfigureAwait(false));
                }
                catch (BobOperationException) when(retryCount <= _operationRetryCount)
                {
                    if (!TrySelectClientIndexOnRetry(ref clientIndex, BobOperationKind.Exist, firstOrDefaultKey))
                    {
                        throw;
                    }
                }
                catch (TimeoutException) when(retryCount <= _operationRetryCount)
                {
                    if (!TrySelectClientIndexOnRetry(ref clientIndex, BobOperationKind.Exist, firstOrDefaultKey))
                    {
                        throw;
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Writes data to Bob
        /// </summary>
        /// <param name="key">Key</param>
        /// <param name="data">Binary data</param>
        /// <param name="token">Cancellation token</param>
        /// <exception cref="ArgumentNullException">Data is null</exception>
        /// <exception cref="ObjectDisposedException">Client was closed</exception>
        /// <exception cref="TimeoutException">Timeout reached</exception>
        /// <exception cref="OperationCanceledException">Operation was cancelled</exception>
        /// <exception cref="BobOperationException">Other operation errors</exception>
        public void Put(BobKey key, byte[] data, CancellationToken token)
        {
            int clientIndex = SelectClientIndex(BobOperationKind.Put, key);

            int retryCount = 0;

            while (true)
            {
                retryCount++;

                try
                {
                    _clients[clientIndex].Put(key, data, token);
                    return;
                }
                catch (BobOperationException) when(retryCount <= _operationRetryCount)
                {
                    if (!TrySelectClientIndexOnRetry(ref clientIndex, BobOperationKind.Put, key))
                    {
                        throw;
                    }
                }
                catch (TimeoutException) when(retryCount <= _operationRetryCount)
                {
                    if (!TrySelectClientIndexOnRetry(ref clientIndex, BobOperationKind.Put, key))
                    {
                        throw;
                    }
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Checks data presented in Bob
        /// </summary>
        /// <param name="keys">Keys array</param>
        /// <param name="fullGet">Try read data from sup nodes</param>
        /// <param name="token">Cancellation token</param>
        /// /// <returns>Operation result</returns>
        /// <exception cref="ObjectDisposedException">Client was closed</exception>
        /// <exception cref="TimeoutException">Timeout reached</exception>
        /// <exception cref="OperationCanceledException">Operation was cancelled</exception>
        /// <exception cref="BobOperationException">Other operation errors</exception>
        /// <exception cref="ArgumentNullException">keys is null</exception>
        /// <exception cref="ArgumentException">At least one key in <paramref name="keys"/> array is not specified</exception>
        protected internal bool[] Exists(TKey[] keys, bool fullGet, CancellationToken token)
        {
            if (keys == null)
            {
                throw new ArgumentNullException(nameof(keys));
            }

            BobKey[] bobKeyArray = new BobKey[keys.Length];
            try
            {
                for (int i = 0; i < keys.Length; i++)
                {
                    bobKeyArray[i] = SerializeToBobKeyFromPool(keys[i], skipLocalInPool: i >= 1);
                }

                return(_innerClient.Exists(bobKeyArray, fullGet, token));
            }
            finally
            {
                for (int i = 0; i < bobKeyArray.Length; i++)
                {
                    ReleaseBobKeyToPool(bobKeyArray[i], skipLocalInPool: i >= 1);
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Reads data from Bob asynchronously
        /// </summary>
        /// <param name="key">Key</param>
        /// <param name="token">Cancellation token</param>
        /// <param name="fullGet">Try read data from sup nodes</param>
        /// <returns>Operation result with data</returns>
        /// <exception cref="ObjectDisposedException">Client was closed</exception>
        /// <exception cref="TimeoutException">Timeout reached</exception>
        /// <exception cref="OperationCanceledException">Operation was cancelled</exception>
        /// <exception cref="BobKeyNotFoundException">Specified key was not found</exception>
        /// <exception cref="BobOperationException">Other operation errors</exception>
        protected internal async Task <byte[]> GetAsync(BobKey key, bool fullGet, CancellationToken token)
        {
            int clientIndex = SelectClientIndex(BobOperationKind.Get, key);

            int retryCount = 0;

            while (true)
            {
                retryCount++;

                try
                {
                    return(await _clients[clientIndex].GetAsync(key, fullGet, token).ConfigureAwait(false));
                }
                catch (BobOperationException ex) when(!(ex is BobKeyNotFoundException) && retryCount <= _operationRetryCount)
                {
                    if (!TrySelectClientIndexOnRetry(ref clientIndex, BobOperationKind.Get, key))
                    {
                        throw;
                    }
                }
                catch (TimeoutException) when(retryCount <= _operationRetryCount)
                {
                    if (!TrySelectClientIndexOnRetry(ref clientIndex, BobOperationKind.Get, key))
                    {
                        throw;
                    }
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Asynchronously checks data presented in Bob
        /// </summary>
        /// <param name="keys">Keys array</param>
        /// <param name="fullGet">Try read data from sup nodes</param>
        /// <param name="token">Cancellation token</param>
        /// <returns>Operation result</returns>
        /// <exception cref="ObjectDisposedException">Client was closed</exception>
        /// <exception cref="TimeoutException">Timeout reached</exception>
        /// <exception cref="OperationCanceledException">Operation was cancelled</exception>
        /// <exception cref="BobOperationException">Other operation errors</exception>
        /// <exception cref="ArgumentNullException">keys is null</exception>
        /// <exception cref="ArgumentException">At least one key in <paramref name="keys"/> array is not specified</exception>
        protected internal async Task <bool[]> ExistsAsync(IReadOnlyList <TKey> keys, bool fullGet, CancellationToken token)
        {
            if (keys == null)
            {
                throw new ArgumentNullException(nameof(keys));
            }

            BobKey[] bobKeyArray = new BobKey[keys.Count];
            try
            {
                for (int i = 0; i < keys.Count; i++)
                {
                    bobKeyArray[i] = SerializeToBobKeyFromPool(keys[i], skipLocalInPool: true);
                }

                return(await _innerClient.ExistsAsync(bobKeyArray, fullGet, token).ConfigureAwait(false));
            }
            finally
            {
                for (int i = 0; i < bobKeyArray.Length; i++)
                {
                    ReleaseBobKeyToPool(bobKeyArray[i], skipLocalInPool: true);
                }
            }
        }
Пример #8
0
        private int SelectClientIndex(BobOperationKind operation, BobKey key)
        {
            int clientIndex = _selectionPolicy.SelectNodeIndex(operation, key);

            if (clientIndex < 0 || clientIndex > _clients.Length)
            {
                ThrowSelectedIndexOutOfRange(clientIndex, _clients.Length);
            }
            return(clientIndex);
        }
Пример #9
0
        /// <summary>
        /// Writes data to Bob asynchronously
        /// </summary>
        /// <param name="key">Key</param>
        /// <param name="data">Binary data</param>
        /// <param name="token">Cancellation token</param>
        /// <returns>Operation result</returns>
        /// <exception cref="ArgumentNullException">Data is null</exception>
        /// <exception cref="ObjectDisposedException">Client was closed</exception>
        /// <exception cref="TimeoutException">Timeout reached</exception>
        /// <exception cref="OperationCanceledException">Operation was cancelled</exception>
        /// <exception cref="BobOperationException">Other operation errors</exception>
        public async Task PutAsync(TKey key, byte[] data, CancellationToken token)
        {
            BobKey bobKey = SerializeToBobKeyFromPool(key, skipLocalInPool: true);

            try
            {
                await _innerCluster.PutAsync(bobKey, data, token).ConfigureAwait(false);
            }
            finally
            {
                ReleaseBobKeyToPool(bobKey, skipLocalInPool: true);
            }
        }
Пример #10
0
        /// <summary>
        /// Reads data from Bob
        /// </summary>
        /// <param name="key">Key</param>
        /// <param name="token">Cancellation token</param>
        /// /// <param name="fullGet">Try read data from sup nodes</param>
        /// <returns>Operation result</returns>
        /// <exception cref="ArgumentException">key is not specified</exception>
        /// <exception cref="ObjectDisposedException">Client was closed</exception>
        /// <exception cref="TimeoutException">Timeout reached</exception>
        /// <exception cref="OperationCanceledException">Operation was cancelled</exception>
        /// <exception cref="BobKeyNotFoundException">Specified key was not found</exception>
        /// <exception cref="BobOperationException">Other operation errors</exception>
        protected internal byte[] Get(TKey key, bool fullGet, CancellationToken token)
        {
            BobKey bobKey = SerializeToBobKeyFromPool(key, skipLocalInPool: false);

            try
            {
                return(_innerClient.Get(bobKey, fullGet, token));
            }
            finally
            {
                ReleaseBobKeyToPool(bobKey, skipLocalInPool: false);
            }
        }
Пример #11
0
        /// <summary>
        /// Reads data from Bob asynchronously
        /// </summary>
        /// <param name="key">Key</param>
        /// <param name="token">Cancellation token</param>
        /// <param name="fullGet">Try read data from sup nodes</param>
        /// <returns>Operation result with data</returns>
        /// <exception cref="ArgumentException">key is not specified</exception>
        /// <exception cref="ObjectDisposedException">Client was closed</exception>
        /// <exception cref="TimeoutException">Timeout reached</exception>
        /// <exception cref="OperationCanceledException">Operation was cancelled</exception>
        /// <exception cref="BobKeyNotFoundException">Specified key was not found</exception>
        /// <exception cref="BobOperationException">Other operation errors</exception>
        protected internal async Task <byte[]> GetAsync(TKey key, bool fullGet, CancellationToken token)
        {
            BobKey bobKey = SerializeToBobKeyFromPool(key, skipLocalInPool: true);

            try
            {
                return(await _innerClient.GetAsync(bobKey, fullGet, token).ConfigureAwait(false));
            }
            finally
            {
                ReleaseBobKeyToPool(bobKey, skipLocalInPool: true);
            }
        }
Пример #12
0
        /// <summary>
        /// Writes data to Bob
        /// </summary>
        /// <param name="key">Key</param>
        /// <param name="data">Binary data</param>
        /// <param name="token">Cancellation token</param>
        /// <exception cref="ArgumentException">key is not specified</exception>
        /// <exception cref="ArgumentNullException">Data is null</exception>
        /// <exception cref="ObjectDisposedException">Client was closed</exception>
        /// <exception cref="TimeoutException">Timeout reached</exception>
        /// <exception cref="OperationCanceledException">Operation was cancelled</exception>
        /// <exception cref="BobOperationException">Other operation errors</exception>
        public void Put(TKey key, byte[] data, CancellationToken token)
        {
            BobKey bobKey = SerializeToBobKeyFromPool(key, skipLocalInPool: false);

            try
            {
                _innerClient.Put(bobKey, data, token);
            }
            finally
            {
                ReleaseBobKeyToPool(bobKey, skipLocalInPool: false);
            }
        }
Пример #13
0
 /// <summary>
 /// Reads data from Bob asynchronously
 /// </summary>
 /// <param name="key">Key</param>
 /// <param name="token">Cancellation token</param>
 /// <returns>Operation result with data</returns>
 /// <exception cref="ObjectDisposedException">Client was closed</exception>
 /// <exception cref="TimeoutException">Timeout reached</exception>
 /// <exception cref="OperationCanceledException">Operation was cancelled</exception>
 /// <exception cref="BobKeyNotFoundException">Specified key was not found</exception>
 /// <exception cref="BobOperationException">Other operation errors</exception>
 public Task <byte[]> GetAsync(BobKey key, CancellationToken token)
 {
     return(GetAsync(key, false, token));
 }
Пример #14
0
 private bool TrySelectClientIndexOnRetry(ref int clientIndex, BobOperationKind operation, BobKey key)
 {
     clientIndex = _selectionPolicy.SelectNodeIndexOnRetry(clientIndex, operation, key);
     if (clientIndex > _clients.Length)
     {
         ThrowSelectedIndexOutOfRange(clientIndex, _clients.Length);
     }
     return(clientIndex >= 0);
 }
Пример #15
0
 private void ReleaseBobKeyToPool(BobKey key, bool skipLocalInPool)
 {
     _keySerializationPool?.Release(key.GetKeyBytes(), skipLocalInPool);
 }
Пример #16
0
 /// <summary>
 /// Writes data to Bob
 /// </summary>
 /// <param name="key">Key</param>
 /// <param name="data">Binary data</param>
 /// <exception cref="ArgumentNullException">Data is null</exception>
 /// <exception cref="ObjectDisposedException">Client was closed</exception>
 /// <exception cref="TimeoutException">Timeout reached</exception>
 /// <exception cref="BobOperationException">Other operation errors</exception>
 public void Put(BobKey key, byte[] data)
 {
     Put(key, data, default(CancellationToken));
 }
Пример #17
0
 /// <summary>
 /// Writes data to Bob asynchronously
 /// </summary>
 /// <param name="key">Key</param>
 /// <param name="data">Binary data</param>
 /// <returns>Operation result</returns>
 /// <exception cref="ArgumentNullException">Data is null</exception>
 /// <exception cref="ObjectDisposedException">Client was closed</exception>
 /// <exception cref="TimeoutException">Timeout reached</exception>
 /// <exception cref="BobOperationException">Other operation errors</exception>
 public Task PutAsync(BobKey key, byte[] data)
 {
     return(PutAsync(key, data, default(CancellationToken)));
 }
Пример #18
0
 /// <summary>
 /// Reads data from Bob asynchronously
 /// </summary>
 /// <param name="key">Key</param>
 /// <returns>Operation result with data</returns>
 /// <exception cref="ObjectDisposedException">Client was closed</exception>
 /// <exception cref="TimeoutException">Timeout reached</exception>
 /// <exception cref="BobKeyNotFoundException">Specified key was not found</exception>
 /// <exception cref="BobOperationException">Other operation errors</exception>
 public Task <byte[]> GetAsync(BobKey key)
 {
     return(GetAsync(key, false, default(CancellationToken)));
 }
Пример #19
0
 /// <summary>
 /// Reads data from Bob
 /// </summary>
 /// <param name="key">Key</param>
 /// <param name="token">Cancellation token</param>
 /// <returns>Operation result</returns>
 /// <exception cref="ObjectDisposedException">Client was closed</exception>
 /// <exception cref="TimeoutException">Timeout reached</exception>
 /// <exception cref="OperationCanceledException">Operation was cancelled</exception>
 /// <exception cref="BobKeyNotFoundException">Specified key was not found</exception>
 /// <exception cref="BobOperationException">Other operation errors</exception>
 public byte[] Get(BobKey key, CancellationToken token)
 {
     return(Get(key, false, token));
 }
Пример #20
0
 /// <summary>
 /// Reads data from Bob
 /// </summary>
 /// <param name="key">Key</param>
 /// <returns>Operation result</returns>
 /// <exception cref="ObjectDisposedException">Client was closed</exception>
 /// <exception cref="TimeoutException">Timeout reached</exception>
 /// <exception cref="BobKeyNotFoundException">Specified key was not found</exception>
 /// <exception cref="BobOperationException">Other operation errors</exception>
 public byte[] Get(BobKey key)
 {
     return(Get(key, false, default(CancellationToken)));
 }