use of org.apache.cassandra.dht.Token.TokenFactory in project cassandra by apache.
the class NativeSSTableLoaderClient method init.
public void init(String keyspace) {
Cluster.Builder builder = Cluster.builder().addContactPoints(hosts).withPort(port);
if (sslOptions != null)
builder.withSSL(sslOptions);
if (authProvider != null)
builder = builder.withAuthProvider(authProvider);
try (Cluster cluster = builder.build();
Session session = cluster.connect()) {
Metadata metadata = cluster.getMetadata();
Set<TokenRange> tokenRanges = metadata.getTokenRanges();
IPartitioner partitioner = FBUtilities.newPartitioner(metadata.getPartitioner());
TokenFactory tokenFactory = partitioner.getTokenFactory();
for (TokenRange tokenRange : tokenRanges) {
Set<Host> endpoints = metadata.getReplicas(Metadata.quote(keyspace), tokenRange);
Range<Token> range = new Range<>(tokenFactory.fromString(tokenRange.getStart().getValue().toString()), tokenFactory.fromString(tokenRange.getEnd().getValue().toString()));
for (Host endpoint : endpoints) addRangeForEndpoint(range, endpoint.getAddress());
}
Types types = fetchTypes(keyspace, session);
tables.putAll(fetchTables(keyspace, session, partitioner, types));
// We only need the TableMetadata for the views, so we only load that.
tables.putAll(fetchViews(keyspace, session, partitioner, types));
}
}
Aggregations