private LoadBalancingPolicy getPolicyInstance ( BalancingPolicy policy , Properties conProperties ) { LoadBalancingPolicy loadBalancingPolicy = null ; String isTokenAware = ( String ) conProperties . get ( "isTokenAware" ) ; String isLatencyAware = ( String ) conProperties . get ( "isLatencyAware" ) ; String whiteList = ( String ) conProperties . get ( "whiteList" ) ; String hostFilterPolicy = ( String ) conProperties . get ( "hostFilterPolicy" ) ; // Policy.v switch ( policy ) { case DCAwareRoundRobinPolicy : String usedHostsPerRemoteDc = ( String ) conProperties . get ( "usedHostsPerRemoteDc" ) ; String localdc = ( String ) conProperties . get ( "localdc" ) ; String allowRemoteDCsForLocalConsistencyLevel = ( String ) conProperties . get ( "allowRemoteDCsForLocalConsistencyLevel" ) ; DCAwareRoundRobinPolicy . Builder policyBuilder = DCAwareRoundRobinPolicy . builder ( ) ; policyBuilder . withLocalDc ( localdc == null ? "DC1" : localdc ) ; policyBuilder . withUsedHostsPerRemoteDc ( usedHostsPerRemoteDc != null ? Integer . parseInt ( usedHostsPerRemoteDc ) : 0 ) ; if ( allowRemoteDCsForLocalConsistencyLevel != null && "true" . equalsIgnoreCase ( allowRemoteDCsForLocalConsistencyLevel ) ) { policyBuilder . allowRemoteDCsForLocalConsistencyLevel ( ) ; } loadBalancingPolicy = policyBuilder . build ( ) ; break ; // case RoundRobinPolicy: // loadBalancingPolicy = new RoundRobinPolicy(); // break; default : // default is RoundRobinPolicy loadBalancingPolicy = new RoundRobinPolicy ( ) ; break ; } if ( loadBalancingPolicy != null && Boolean . valueOf ( isTokenAware ) ) { loadBalancingPolicy = new TokenAwarePolicy ( loadBalancingPolicy ) ; } else if ( loadBalancingPolicy != null && Boolean . valueOf ( isLatencyAware ) ) { loadBalancingPolicy = LatencyAwarePolicy . builder ( loadBalancingPolicy ) . build ( ) ; } if ( loadBalancingPolicy != null && whiteList != null ) { Collection < InetSocketAddress > whiteListCollection = buildWhiteListCollection ( whiteList ) ; loadBalancingPolicy = new WhiteListPolicy ( loadBalancingPolicy , whiteListCollection ) ; } if ( loadBalancingPolicy != null && hostFilterPolicy != null ) { Predicate < com . datastax . driver . core . Host > predicate = getHostFilterPredicate ( hostFilterPolicy ) ; loadBalancingPolicy = new HostFilterPolicy ( loadBalancingPolicy , predicate ) ; } return loadBalancingPolicy ; }
Gets the policy instance .