Esempio n. 1
0
        /// <summary>
        /// Perform the given operation, retrying if the connection fails </summary>
        /// <returns> object. it needs to be cast to the callee's expected
        /// return type. </returns>
        protected async Task <bool> retryOperation(ZooKeeperOperation operation)
        {
            KeeperException exception = null;

            for (int i = 0; i < retryCount; i++)
            {
                try
                {
                    return(await operation.execute());
                }
                catch (KeeperException.SessionExpiredException e)
                {
                    LOG.warn("Session expired for: " + zookeeper + " so reconnecting due to: " + e, e);
                    throw;
                }
                catch (KeeperException.ConnectionLossException e)
                {
                    if (exception == null)
                    {
                        exception = e;
                    }
                    LOG.debug("Attempt " + i + " failed with connection loss so " + "attempting to reconnect: " + e, e);
                }
                await retryDelay(i);
            }
            throw exception;
        }
Esempio n. 2
0
		/// <summary>
		/// Perform the given operation, retrying if the connection fails
		/// </summary>
		/// <returns> object. it needs to be cast to the callee's expected
		/// return type. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected Object retryOperation(ZooKeeperOperation operation) throws org.apache.zookeeper.KeeperException, InterruptedException
		protected internal virtual object retryOperation(ZooKeeperOperation operation)
		{
			KeeperException exception = null;
			for (int i = 0; i < retryCount; i++)
			{
				try
				{
					return operation.execute();
				}
				catch (KeeperException.SessionExpiredException e)
				{
					LOG.warn("Session expired for: " + zookeeper + " so reconnecting due to: " + e, e);
					throw e;
				}
				catch (KeeperException.ConnectionLossException e)
				{
					if (exception == null)
					{
						exception = e;
					}
					LOG.debug("Attempt " + i + " failed with connection loss so " + "attempting to reconnect: " + e, e);
					retryDelay(i);
				}
			}
			throw exception;
		}