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

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

                Author: ASF GitHub Bot
            Created on: 03/Aug/19 23:11
            Start Date: 03/Aug/19 23:11
    Worklog Time Spent: 10m 
      Work Description: shayshim commented on pull request #320: [CURATOR-533] 
- improve circuit breaking behavior
URL: https://github.com/apache/curator/pull/320#discussion_r310365228
 
 

 ##########
 File path: 
curator-framework/src/main/java/org/apache/curator/framework/state/CircuitBreakingManager.java
 ##########
 @@ -0,0 +1,91 @@
+/**
+ * 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.framework.state;
+
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.listen.StandardListenerManager;
+import org.apache.curator.framework.listen.UnaryListenerManager;
+import java.util.concurrent.Executor;
+import java.util.function.Consumer;
+
+class CircuitBreakingManager implements 
UnaryListenerManager<ConnectionStateListener>
+{
+    private final StandardListenerManager<ConnectionStateListener> 
mainContainer = StandardListenerManager.standard();
+    private final StandardListenerManager<ConnectionStateListener> 
doNotProxyContainer = StandardListenerManager.standard();
+    private final CircuitBreakingConnectionStateListener masterListener;
+
+    CircuitBreakingManager(CuratorFramework client, CircuitBreaker 
circuitBreaker)
+    {
+        ConnectionStateListener masterStateChanged = (__, newState) -> 
mainContainer.forEach(listener -> listener.stateChanged(client, newState));
+        masterListener = new CircuitBreakingConnectionStateListener(client, 
masterStateChanged, circuitBreaker);
+    }
+
+    @Override
+    public void clear()
+    {
+        doNotProxyContainer.clear();
+        mainContainer.clear();
+    }
+
+    @Override
+    public int size()
+    {
+        return mainContainer.size() + doNotProxyContainer.size();
+    }
+
+    @Override
+    public void forEach(Consumer<ConnectionStateListener> function)
+    {
+        doNotProxyContainer.forEach(function);
+        function.accept(masterListener);
 
 Review comment:
   function.accept(masterListener) is probably the same as 
mainContainer.forEach(function), right? but I think the second is clearer and 
symmetric with doNotProxyContainer.forEach(function)
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

    Worklog Id:     (was: 288487)
    Time Spent: 1h 20m  (was: 1h 10m)

> Improve CURATOR-505 by making the CircuitBreaker instance shared
> ----------------------------------------------------------------
>
>                 Key: CURATOR-533
>                 URL: https://issues.apache.org/jira/browse/CURATOR-533
>             Project: Apache Curator
>          Issue Type: Improvement
>          Components: Framework, Recipes
>    Affects Versions: 4.2.0
>            Reporter: Jordan Zimmerman
>            Assignee: Jordan Zimmerman
>            Priority: Major
>             Fix For: 4.2.1
>
>          Time Spent: 1h 20m
>  Remaining Estimate: 0h
>
> CURATOR-505 introduced circuit breaking behavior via 
> {{CircuitBreakingConnectionStateListener}} and 
> {{ConnectionStateListenerDecorator}}. Elastic has been using it to success 
> but reports that the implementation can be improved. The existing 
> implementation uses a new {{CircuitBreaker}} for each 
> {{ConnectionStateListener}} set in a Curator client. It turns out that this 
> is not ideal. Instead, a shared {{CircuitBreaker}} should be used per Curator 
> client.
> Unfortunately, the best way to do this is to remove the 
> {{ConnectionStateListenerDecorator}} semantics and use a different mechanism. 
> This Issue proposes to do this and remove 
> {{ConnectionStateListenerDecorator}}. This is a breaking change but given the 
> short amount of time it's been in Curator it's unlikely that it's been widely 
> adopted. 
> If the community considers a breaking change too harsh the older classes can 
> be maintained for a while and marked as {{@Deprecated}}.



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to