I am a scala newbie and really need help with an issue I've been experiencing with some code. I have set up the following code to create cassandra connections:
package some.package
import java.net.InetAddress
import java.util
import com.datastax.driver.core._
import com.datastax.driver.core.policies.{DCAwareRoundRobinPolicy, TokenAwarePolicy}
import scala.collection.JavaConversions._
object CassandraConnector {
def getCluster(contactPointIpString: String, preferred_dc: String): Cluster = {
val contactPointIpStrings = contactPointIpString.split(",").toList
val contactPointIpList = contactPointIpStrings.flatMap { ipAddress: String => InetAddress.getAllByName(ipAddress) }
println(s"Building Cluster w/ Contact Points: $contactPointIpList")
Cluster.builder()
.addContactPoints(contactPointIpList)
.withClusterName("multi_dc_user_data")
.withLoadBalancingPolicy(new TokenAwarePolicy(new DCAwareRoundRobinPolicy(preferred_dc)))
.withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.LOCAL_ONE))
.build()
}
}
While building the project in IntelliJ, the following error happens:
constructor DCAwareRoundRobinPolicy in class DCAwareRoundRobinPolicy cannot be accessed in object CassandraConnector
.withLoadBalancingPolicy(new TokenAwarePolicy(new DCAwareRoundRobinPolicy(preferred_dc)))
Found something similar to my problem here, and tried to change my code to the following:
val dcAwareRoundRobinPolicyBuilder = new DCAwareRoundRobinPolicy.Builder
val dcAwareRoundRobinPolicy = dcAwareRoundRobinPolicyBuilder.withLocalDc(preferred_dc)
Cluster.builder()
.addContactPoints(contactPointIpList)
.withClusterName("multi_dc_user_data")
.withLoadBalancingPolicy(new TokenAwarePolicy(dcAwareRoundRobinPolicy.build()))
.withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.LOCAL_ONE))
.build()
This resolved the issue and now the build finishes successfully but I am not so sure if what I've done is necessarily correct, so I'd really appreciate any help in this regard.