curator-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CURATOR-239) RetryPolicy that retries forever
Date Thu, 23 Jul 2015 23:11:04 GMT

    [ https://issues.apache.org/jira/browse/CURATOR-239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14639653#comment-14639653
] 

ASF GitHub Bot commented on CURATOR-239:
----------------------------------------

Github user Randgalt commented on a diff in the pull request:

    https://github.com/apache/curator/pull/94#discussion_r35382264
  
    --- Diff: curator-client/src/main/java/org/apache/curator/retry/RetryForever.java ---
    @@ -0,0 +1,58 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.curator.retry;
    +
    +import org.apache.curator.RetryPolicy;
    +import org.apache.curator.RetrySleeper;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.util.concurrent.TimeUnit;
    +
    +import static com.google.common.base.Preconditions.checkArgument;
    +
    +/**
    + * {@link RetryPolicy} implementation that always <i>allowsRetry</i>.
    + */
    +public class RetryForever implements RetryPolicy
    +{
    +    private static final Logger log = LoggerFactory.getLogger(RetryForever.class);
    +
    +    private final int retryIntervalMs;
    +
    +    public RetryForever(int retryIntervalMs)
    +    {
    +        checkArgument(retryIntervalMs > 0);
    +        this.retryIntervalMs = retryIntervalMs;
    +    }
    +
    +    @Override
    +    public boolean allowRetry(int retryCount, long elapsedTimeMs, RetrySleeper sleeper)
    +    {
    +        try
    +        {
    +            sleeper.sleepFor(retryIntervalMs, TimeUnit.MILLISECONDS);
    +        }
    +        catch (InterruptedException e)
    +        {
    +            log.warn("Error occurred while sleeping", e);
    --- End diff --
    
    When catching InterrptedException, always reset the state via:
    
    {code}
    Thread.currentThread().interrupt();
    {code}


> RetryPolicy that retries forever
> --------------------------------
>
>                 Key: CURATOR-239
>                 URL: https://issues.apache.org/jira/browse/CURATOR-239
>             Project: Apache Curator
>          Issue Type: Wish
>          Components: Client
>            Reporter: Leandro Nunes
>            Assignee: Jordan Zimmerman
>            Priority: Trivial
>
> I'd like to have a RetryPolicy that never ceases to retry. I find having to come up with
number for maxRetries a pain. I mean, I guess it makes sense to have my clients repeatedly
trying to connect to zookeeper on most cases. I can be missing something though (this seems
so obvious to me that I most definitely am).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message