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] [Work logged] (CURATOR-505) A circuit breaking ConnectionStateListener would be very helpful
Date Tue, 12 Feb 2019 23:03:00 GMT

     [ https://issues.apache.org/jira/browse/CURATOR-505?focusedWorklogId=197845&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-197845
]

ASF GitHub Bot logged work on CURATOR-505:
------------------------------------------

                Author: ASF GitHub Bot
            Created on: 12/Feb/19 23:02
            Start Date: 12/Feb/19 23:02
    Worklog Time Spent: 10m 
      Work Description: yuri-tceretian commented on pull request #304: [CURATOR-505] WIP -
Circuit breaking connection state listener decorator
URL: https://github.com/apache/curator/pull/304#discussion_r256184202
 
 

 ##########
 File path: curator-framework/src/main/java/org/apache/curator/framework/state/CircuitBreaker.java
 ##########
 @@ -0,0 +1,79 @@
+package org.apache.curator.framework.state;
+
+import org.apache.curator.RetryPolicy;
+import org.apache.curator.RetrySleeper;
+import java.util.Objects;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+// must be guarded by sync
+class CircuitBreaker
+{
+    private final RetryPolicy retryPolicy;
+    private final ScheduledExecutorService service;
+
+    private boolean isOpen = false;
+    private int retryCount = 0;
+    private long startNanos = 0;
+
+    CircuitBreaker(RetryPolicy retryPolicy, ScheduledExecutorService service)
+    {
+        this.retryPolicy = Objects.requireNonNull(retryPolicy, "retryPolicy cannot be null");
+        this.service = Objects.requireNonNull(service, "service cannot be null");
+    }
+
+    boolean isOpen()
+    {
+        return isOpen;
+    }
+
+    int getRetryCount()
+    {
+        return retryCount;
+    }
+
+    boolean tryToOpen(Runnable completion)
+    {
+        if ( isOpen )
+        {
+            return false;
+        }
+
+        isOpen = true;
+        retryCount = 0;
+        startNanos = System.nanoTime();
+        if ( tryToRetry(completion) )
+        {
+            return true;
+        }
+        close();
+        return false;
+    }
+
+    boolean tryToRetry(Runnable completion)
+    {
+        if ( !isOpen )
+        {
+            return false;
+        }
+
+        long[] sleepTimeNanos = new long[]{0L};
+        RetrySleeper retrySleeper = (time, unit) -> sleepTimeNanos[0] = unit.toNanos(time);
+        if ( retryPolicy.allowRetry(retryCount, System.nanoTime() - startNanos, retrySleeper)
)
 
 Review comment:
   According to the documentation of `RetryPolicy.allowRetry`, the second argument is supposed
to be in milliseconds. You provide nanos instead.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 197845)
    Time Spent: 20m  (was: 10m)

> A circuit breaking ConnectionStateListener would be very helpful
> ----------------------------------------------------------------
>
>                 Key: CURATOR-505
>                 URL: https://issues.apache.org/jira/browse/CURATOR-505
>             Project: Apache Curator
>          Issue Type: New Feature
>          Components: Client, Framework, Recipes
>    Affects Versions: 4.1.0
>            Reporter: Jordan Zimmerman
>            Assignee: Jordan Zimmerman
>            Priority: Major
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> Create a circuit breaker style {{ConnectionStateListener}}. It would proxy any ConnectionStateListeners
used by Curator recipe/classes such that when the connection is lost the circuit would open
for a period of time and, while open, ignore any changes in state. After the time period expires
the circuit would close and send whatever the current connection state is. This way, if the
connection is going up/down/up/down/up/down, the application would only see the first down
and then N ms later hopefully the connection is repaired and the application would only see
the reconnection.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message