org.apache.curator.utils.DebugUtils Java Examples

The following examples show how to use org.apache.curator.utils.DebugUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RemoveWatchesBuilderImpl.java    From curator with Apache License 2.0 6 votes vote down vote up
void internalRemoval(Watcher watcher, String path) throws Exception
{
    this.watcher = watcher;
    watcherType = WatcherType.Any;
    quietly = true;
    guaranteed = true;
    if ( Boolean.getBoolean(DebugUtils.PROPERTY_REMOVE_WATCHERS_IN_FOREGROUND) )
    {
        this.backgrounding = new Backgrounding();
        pathInForeground(path);
    }
    else
    {
        this.backgrounding = new Backgrounding(true);
        pathInBackground(path);
    }
}
 
Example #2
Source File: RetryLoop.java    From xian with Apache License 2.0 5 votes vote down vote up
/**
 * Pass any caught exceptions here
 *
 * @param exception the exception
 * @throws Exception if not retry-able or the retry policy returned negative
 */
public void         takeException(Exception exception) throws Exception
{
    boolean     rethrow = true;
    if ( isRetryException(exception) )
    {
        if ( !Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES) )
        {
            log.debug("Retry-able exception received", exception);
        }

        if ( retryPolicy.allowRetry(retryCount++, System.currentTimeMillis() - startTimeMs, sleeper) )
        {
            new EventTrace("retries-allowed", tracer.get()).commit();
            if ( !Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES) )
            {
                log.debug("Retrying operation");
            }
            rethrow = false;
        }
        else
        {
            new EventTrace("retries-disallowed", tracer.get()).commit();
            if ( !Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES) )
            {
                log.debug("Retry policy not allowing retry");
            }
        }
    }

    if ( rethrow )
    {
        throw exception;
    }
}
 
Example #3
Source File: ConnectionState.java    From xian with Apache License 2.0 5 votes vote down vote up
private synchronized void checkTimeouts() throws Exception
{
    int minTimeout = Math.min(sessionTimeoutMs, connectionTimeoutMs);
    long elapsed = System.currentTimeMillis() - connectionStartMs;
    if ( elapsed >= minTimeout )
    {
        if ( zooKeeper.hasNewConnectionString() )
        {
            handleNewConnectionString();
        }
        else
        {
            int maxTimeout = Math.max(sessionTimeoutMs, connectionTimeoutMs);
            if ( elapsed > maxTimeout )
            {
                if ( !Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES) )
                {
                    log.warn(String.format("Connection attempt unsuccessful after %d (greater than max timeout of %d). Resetting connection and trying again with a new connection.", elapsed, maxTimeout));
                }
                reset();
            }
            else
            {
                KeeperException.ConnectionLossException connectionLossException = new CuratorConnectionLossException();
                if ( !Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES) )
                {
                    log.error(String.format("Connection timed out for connection string (%s) and timeout (%d) / elapsed (%d)", zooKeeper.getConnectionString(), connectionTimeoutMs, elapsed), connectionLossException);
                }
                new EventTrace("connections-timed-out", tracer.get(), getSessionId()).commit();
                throw connectionLossException;
            }
        }
    }
}
 
Example #4
Source File: CuratorFrameworkImpl.java    From xian with Apache License 2.0 5 votes vote down vote up
private <DATA_TYPE> void handleBackgroundOperationException(OperationAndData<DATA_TYPE> operationAndData, Throwable e)
{
    do
    {
        if ( (operationAndData != null) && RetryLoop.isRetryException(e) )
        {
            if ( !Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES) )
            {
                log.debug("Retry-able exception received", e);
            }
            if ( client.getRetryPolicy().allowRetry(operationAndData.getThenIncrementRetryCount(), operationAndData.getElapsedTimeMs(), operationAndData) )
            {
                if ( !Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES) )
                {
                    log.debug("Retrying operation");
                }
                backgroundOperations.offer(operationAndData);
                break;
            }
            else
            {
                if ( !Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES) )
                {
                    log.debug("Retry policy did not allow retry");
                }
                if ( operationAndData.getErrorCallback() != null )
                {
                    operationAndData.getErrorCallback().retriesExhausted(operationAndData);
                }
            }
        }

        logError("Background exception was not retry-able or retry gave up", e);
    }
    while ( false );
}
 
Example #5
Source File: ZKClientImpl.java    From codes-scratch-zookeeper-netty with Apache License 2.0 5 votes vote down vote up
public ZKClientImpl(String adds) {
    System.setProperty(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES, "false");
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(BASE_SLEEP_TIMEMS, MAX_RETRIES);
    this.client = CuratorFrameworkFactory.builder().connectString(adds).retryPolicy(retryPolicy)
                                         .connectionTimeoutMs(5000).build();
    waitUntilZkStart();

}
 
Example #6
Source File: CuratorFrameworkImpl.java    From curator with Apache License 2.0 5 votes vote down vote up
void logError(String reason, final Throwable e)
{
    if ( (reason == null) || (reason.length() == 0) )
    {
        reason = "n/a";
    }

    if ( !Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES) || !(e instanceof KeeperException) )
    {
        if ( e instanceof KeeperException.ConnectionLossException )
        {
            if ( LOG_ALL_CONNECTION_ISSUES_AS_ERROR_LEVEL || logAsErrorConnectionErrors.compareAndSet(true, false) )
            {
                log.error(reason, e);
            }
            else
            {
                log.debug(reason, e);
            }
        }
        else
        {
            log.error(reason, e);
        }
    }

    final String localReason = reason;
    unhandledErrorListeners.forEach(l -> l.unhandledError(localReason, e));

    if ( debugUnhandledErrorListener != null )
    {
        debugUnhandledErrorListener.unhandledError(reason, e);
    }
}
 
Example #7
Source File: CuratorFrameworkImpl.java    From curator with Apache License 2.0 5 votes vote down vote up
private <DATA_TYPE> void handleBackgroundOperationException(OperationAndData<DATA_TYPE> operationAndData, Throwable e)
{
    do
    {
        if ( (operationAndData != null) && getZookeeperClient().getRetryPolicy().allowRetry(e) )
        {
            if ( !Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES) )
            {
                log.debug("Retry-able exception received", e);
            }
            if ( client.getRetryPolicy().allowRetry(operationAndData.getThenIncrementRetryCount(), operationAndData.getElapsedTimeMs(), operationAndData) )
            {
                if ( !Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES) )
                {
                    log.debug("Retrying operation");
                }
                backgroundOperations.offer(operationAndData);
                break;
            }
            else
            {
                if ( !Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES) )
                {
                    log.debug("Retry policy did not allow retry");
                }
                if ( operationAndData.getErrorCallback() != null )
                {
                    operationAndData.getErrorCallback().retriesExhausted(operationAndData);
                }
            }
        }

        logError("Background exception was not retry-able or retry gave up", e);
    }
    while ( false );
}
 
Example #8
Source File: RetryLoopImpl.java    From curator with Apache License 2.0 5 votes vote down vote up
@Override
public void takeException(Exception exception) throws Exception
{
    boolean rethrow = true;
    if ( retryPolicy.allowRetry(exception) )
    {
        if ( !Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES) )
        {
            log.debug("Retry-able exception received", exception);
        }

        if ( retryPolicy.allowRetry(retryCount++, System.currentTimeMillis() - startTimeMs, sleeper) )
        {
            new EventTrace("retries-allowed", tracer.get()).commit();
            if ( !Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES) )
            {
                log.debug("Retrying operation");
            }
            rethrow = false;
        }
        else
        {
            new EventTrace("retries-disallowed", tracer.get()).commit();
            if ( !Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES) )
            {
                log.debug("Retry policy not allowing retry");
            }
        }
    }

    if ( rethrow )
    {
        throw exception;
    }
}
 
Example #9
Source File: CuratorFrameworkImpl.java    From xian with Apache License 2.0 4 votes vote down vote up
void logError(String reason, final Throwable e)
{
    if ( (reason == null) || (reason.length() == 0) )
    {
        reason = "n/a";
    }

    if ( !Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES) || !(e instanceof KeeperException) )
    {
        if ( e instanceof KeeperException.ConnectionLossException )
        {
            if ( LOG_ALL_CONNECTION_ISSUES_AS_ERROR_LEVEL || logAsErrorConnectionErrors.compareAndSet(true, false) )
            {
                log.error(reason, e);
            }
            else
            {
                log.debug(reason, e);
            }
        }
        else
        {
            log.error(reason, e);
        }
    }

    final String localReason = reason;
    unhandledErrorListeners.forEach(new Function<UnhandledErrorListener, Void>()
    {
        @Override
        public Void apply(UnhandledErrorListener listener)
        {
            listener.unhandledError(localReason, e);
            return null;
        }
    });

    if ( debugUnhandledErrorListener != null )
    {
        debugUnhandledErrorListener.unhandledError(reason, e);
    }
}