Created
October 22, 2020 13:50
-
-
Save mpenick/d1baf06957d0df0870935e70a8470571 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.datastax; | |
import com.datastax.oss.driver.api.core.CqlSession; | |
import com.datastax.oss.driver.api.core.config.DefaultDriverOption; | |
import com.datastax.oss.driver.api.core.config.DriverConfigLoader; | |
import com.datastax.oss.driver.api.core.config.ProgrammaticDriverConfigLoaderBuilder; | |
import com.datastax.oss.driver.api.core.metadata.Node; | |
import com.datastax.oss.driver.api.core.metadata.NodeStateListener; | |
import com.datastax.oss.driver.internal.core.loadbalancing.DcInferringLoadBalancingPolicy; | |
import java.net.InetSocketAddress; | |
import java.time.Duration; | |
public class Main | |
{ | |
private static ProgrammaticDriverConfigLoaderBuilder getDriverConfigLoaderBuilder() { | |
return DriverConfigLoader.programmaticBuilder() | |
.withBoolean(DefaultDriverOption.METADATA_TOKEN_MAP_ENABLED, false) | |
.withString( | |
DefaultDriverOption.LOAD_BALANCING_POLICY_CLASS, | |
DcInferringLoadBalancingPolicy.class.getName()) | |
.withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(5)) | |
.withDuration(DefaultDriverOption.CONTROL_CONNECTION_TIMEOUT, Duration.ofSeconds(5)); | |
} | |
public static void main(String[] args) throws Throwable | |
{ | |
try (CqlSession session = CqlSession.builder() | |
.withNodeStateListener(new NodeStateListener() { | |
@Override | |
public void onAdd(Node node) { | |
System.out.println("Added " + node.getEndPoint().toString()); | |
} | |
@Override | |
public void onUp(Node node) { | |
System.out.println("Up " + node.getEndPoint().toString()); | |
} | |
@Override | |
public void onDown(Node node) { | |
System.out.println("Down " + node.getEndPoint().toString()); | |
} | |
@Override | |
public void onRemove(Node node) { | |
System.out.println("Removed " + node.getEndPoint().toString()); | |
} | |
@Override | |
public void close() throws Exception { | |
} | |
}) | |
.withConfigLoader(getDriverConfigLoaderBuilder().build()) | |
.addContactPoint(new InetSocketAddress("127.0.0.10", 9042)).build()) { | |
while (true) { | |
Thread.sleep(1000); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment