1515 */
1616package com .datastax .driver .core .policies ;
1717
18- import java .net .InetAddress ;
18+ import java .net .InetSocketAddress ;
1919import java .util .ArrayList ;
2020import java .util .Collection ;
2121import java .util .Iterator ;
4949 */
5050public class WhiteListPolicy implements LoadBalancingPolicy {
5151 private final LoadBalancingPolicy childPolicy ;
52- private final Set <InetAddress > whiteList ;
52+ private final Set <InetSocketAddress > whiteList ;
5353
5454 /**
5555 * Create a new policy that wraps the provided child policy but only "allow" hosts
@@ -59,7 +59,7 @@ public class WhiteListPolicy implements LoadBalancingPolicy {
5959 * @param whiteList the white listed hosts. Only hosts from this list may get connected
6060 * to (whether they will get connected to or not depends on the child policy).
6161 */
62- public WhiteListPolicy (LoadBalancingPolicy childPolicy , Collection <InetAddress > whiteList ) {
62+ public WhiteListPolicy (LoadBalancingPolicy childPolicy , Collection <InetSocketAddress > whiteList ) {
6363 this .childPolicy = childPolicy ;
6464 this .whiteList = ImmutableSet .copyOf (whiteList );
6565 }
@@ -77,7 +77,7 @@ public WhiteListPolicy(LoadBalancingPolicy childPolicy, Collection<InetAddress>
7777 public void init (Cluster cluster , Collection <Host > hosts ) {
7878 List <Host > whiteHosts = new ArrayList <Host >(hosts .size ());
7979 for (Host host : hosts )
80- if (whiteList .contains (host .getAddress ()))
80+ if (whiteList .contains (host .getSocketAddress ()))
8181 whiteHosts .add (host );
8282
8383 if (whiteHosts .isEmpty ())
@@ -95,7 +95,7 @@ public void init(Cluster cluster, Collection<Host> hosts) {
9595 */
9696 @ Override
9797 public HostDistance distance (Host host ) {
98- return whiteList .contains (host .getAddress ())
98+ return whiteList .contains (host .getSocketAddress ())
9999 ? childPolicy .distance (host )
100100 : HostDistance .IGNORED ;
101101 }
@@ -121,25 +121,25 @@ public Iterator<Host> newQueryPlan(String loggedKeyspace, Statement statement) {
121121
122122 @ Override
123123 public void onUp (Host host ) {
124- if (whiteList .contains (host .getAddress ()))
124+ if (whiteList .contains (host .getSocketAddress ()))
125125 childPolicy .onUp (host );
126126 }
127127
128128 @ Override
129129 public void onDown (Host host ) {
130- if (whiteList .contains (host .getAddress ()))
130+ if (whiteList .contains (host .getSocketAddress ()))
131131 childPolicy .onDown (host );
132132 }
133133
134134 @ Override
135135 public void onAdd (Host host ) {
136- if (whiteList .contains (host .getAddress ()))
136+ if (whiteList .contains (host .getSocketAddress ()))
137137 childPolicy .onAdd (host );
138138 }
139139
140140 @ Override
141141 public void onRemove (Host host ) {
142- if (whiteList .contains (host .getAddress ()))
142+ if (whiteList .contains (host .getSocketAddress ()))
143143 childPolicy .onRemove (host );
144144 }
145145}
0 commit comments