Elffuss BraidHub

kikocis/java-driver public

Expose child policy in chainable load balancing policies (JAVA-439).
Changeset650b8bbe497a395b9b54fd67631866fdded2cebc8098ac9623afa3dc67d39c05
Authorolim7t <omichallat+github@gmail.com> · 2014-09-03 22:50 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2014-09-12 11:46 -07:00
Parentscd12beaa38c0

Browse the files at this changeset

5 files changed

modified driver-core/CHANGELOG.rst +1 −0
@@ -13,6 +13,7 @@
1313 - [bug] Fix negative HostConnectionPool open count (JAVA-349)
1414 - [improvement] Log more connection details at trace and debug levels (JAVA-436)
1515 - [bug] Fix cluster shutdown (JAVA-445)
16+- [improvement] Expose child policy in chainable load balancing policies (JAVA-439)
1617
1718 2.0.5:
1819 ------
added driver-core/src/main/java/com/datastax/driver/core/policies/ChainableLoadBalancingPolicy.java +28 −0
@@ -0,0 +1,28 @@
1+/*
2+ * Copyright (C) 2012-2014 DataStax Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+package com.datastax.driver.core.policies;
17+
18+/**
19+ * A load balancing policy that wraps another policy.
20+ */
21+public interface ChainableLoadBalancingPolicy extends LoadBalancingPolicy {
22+ /**
23+ * Returns the child policy.
24+ *
25+ * @return the child policy.
26+ */
27+ LoadBalancingPolicy getChildPolicy();
28+}
modified driver-core/src/main/java/com/datastax/driver/core/policies/LatencyAwarePolicy.java +6 −1
@@ -57,7 +57,7 @@
5757 *
5858 * @since 1.0.4
5959 */
60-public class LatencyAwarePolicy implements LoadBalancingPolicy {
60+public class LatencyAwarePolicy implements ChainableLoadBalancingPolicy {
6161
6262 private static final Logger logger = LoggerFactory.getLogger(LatencyAwarePolicy.class);
6363
@@ -87,6 +87,11 @@
8787 updaterService.scheduleAtFixedRate(new Updater(), updateRate, updateRate, TimeUnit.NANOSECONDS);
8888 }
8989
90+ @Override
91+ public LoadBalancingPolicy getChildPolicy() {
92+ return childPolicy;
93+ }
94+
9095 /**
9196 * Creates a new latency aware policy builder given the child policy
9297 * that the resulting policy should wrap.
modified driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java +6 −1
@@ -46,7 +46,7 @@
4646 * token aware policy, replicas from remote data centers may only be
4747 * returned after all the host of the local data center.
4848 */
49-public class TokenAwarePolicy implements LoadBalancingPolicy {
49+public class TokenAwarePolicy implements ChainableLoadBalancingPolicy {
5050
5151 private final LoadBalancingPolicy childPolicy;
5252 private Metadata clusterMetadata;
@@ -62,6 +62,11 @@
6262 this.childPolicy = childPolicy;
6363 }
6464
65+ @Override
66+ public LoadBalancingPolicy getChildPolicy() {
67+ return childPolicy;
68+ }
69+
6570 @Override
6671 public void init(Cluster cluster, Collection<Host> hosts) {
6772 clusterMetadata = cluster.getMetadata();
modified driver-core/src/main/java/com/datastax/driver/core/policies/WhiteListPolicy.java +6 −1
@@ -47,7 +47,7 @@
4747 * data-center then you should use DCAwareRoundRobinPolicy and *not* this policy
4848 * in particular.
4949 */
50-public class WhiteListPolicy implements LoadBalancingPolicy {
50+public class WhiteListPolicy implements ChainableLoadBalancingPolicy {
5151 private final LoadBalancingPolicy childPolicy;
5252 private final Set<InetSocketAddress> whiteList;
5353
@@ -64,6 +64,11 @@
6464 this.whiteList = ImmutableSet.copyOf(whiteList);
6565 }
6666
67+ @Override
68+ public LoadBalancingPolicy getChildPolicy() {
69+ return childPolicy;
70+ }
71+
6772 /**
6873 * Initialize this load balancing policy.
6974 *