Created
December 3, 2014 04:27
-
-
Save bsbodden/27309f7b698deb898e3e to your computer and use it in GitHub Desktop.
HelloCassandra.java: Main Method
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
public static void main(String[] args) { | |
Cluster cluster = null; | |
Session session = null; | |
try { | |
cluster = Cluster.builder().addContactPoints("localhost").build(); | |
Metadata metadata = cluster.getMetadata(); | |
System.out.printf("Connected to cluster: %s\n", metadata.getClusterName()); | |
for ( Host host : metadata.getAllHosts() ) { | |
System.out.printf("Datacenter: %s; Host: %s; Rack: %s\n", host.getDatacenter(), host.getAddress(), host.getRack()); | |
} | |
} catch (NoHostAvailableException nhae) { | |
System.err.println("No alive hosts to use:" + nhae.getMessage()); | |
System.exit(1); | |
} catch (Exception e) { | |
System.err.println("Unexpected error: " + e.getMessage()); | |
e.printStackTrace(); | |
System.exit(1); | |
} finally { | |
//session.close(); | |
cluster.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment