本文整理匯總了Java中com.datastax.driver.core.Metadata.getAllHosts方法的典型用法代碼示例。如果您正苦於以下問題:Java Metadata.getAllHosts方法的具體用法?Java Metadata.getAllHosts怎麽用?Java Metadata.getAllHosts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.datastax.driver.core.Metadata
的用法示例。
在下文中一共展示了Metadata.getAllHosts方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: connect
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
private void connect(String seeds) {
if (getWithSSL()) {
LOGGER.info("SSL mode enabled");
try {
SSLOptions sslOptions = new SSLOptions(SSLContext.getDefault(), CIPHERS);
builder = Cluster.builder().withSSL(sslOptions);
} catch (NoSuchAlgorithmException e) {
LOGGER.error("Unable to setup SSL Options for Cassandra");
}
}
String[] contactPoints = seeds.split(",");
for (String contactPoint : contactPoints) {
LOGGER.info("Adding Cassandra contact point " + contactPoint);
builder.addContactPoints(contactPoint);
}
cluster = builder.build();
Metadata metadata = cluster.getMetadata();
for (Host host : metadata.getAllHosts()) {
LOGGER.info("Datacenter "+ host.getDatacenter() + "Host " + host.getAddress() + "Rack " + host.getRack());
session = cluster.connect();
}
}
開發者ID:emc-cloudfoundry,項目名稱:cassandra-cf-service-boshrelease,代碼行數:27,代碼來源:CassandraAdminService.java
示例2: execute
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
@Override
public ResultSet<CassandraDBContext> execute(Query<CassandraDBContext> query) throws QueryExecutionException {
try (Cluster cassandraConnection = buildConnection()) {
final Metadata metadata = cassandraConnection.getMetadata();
System.out.printf("Connected to cluster: %s", metadata.getClusterName());
for (final Host host : metadata.getAllHosts()) {
System.out.printf("Datacenter: %s; Host: %s; Rack: %s", host.getDatacenter(), host.getAddress(),
host.getRack());
}
try (Session session = cassandraConnection.connect()) {
String queryToExecute = query.getQuery();
System.out.println(queryToExecute);
com.datastax.driver.core.ResultSet resultSet = session.execute(queryToExecute);
printResultSet(resultSet);
ExecutionInfo executionInfo = resultSet.getExecutionInfo();
System.out.println(executionInfo);
}
}
// There isn't any resultset for these use-case
return new CassandraResultSet();
}
示例3: StoreConnection
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
/**
* Constructor
*
* @param nodes a list of one or more Cassandra nodes to connect to. Note
* that not all Cassandra nodes in the cluster need be
* supplied; one will suffice however if that node is
* unavailable the connection attempt will fail, even if the
* others are available.
*/
public StoreConnection(List<String> nodes) {
Cluster.Builder builder = Cluster.builder();
for (String node : nodes) {
builder.addContactPoint(node);
}
cluster = builder.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());
}
session = cluster.connect();
}
示例4: logCluster
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
public void logCluster(Cluster cluster) {
try {
if (cluster != null && !cluster.isClosed()) {
String clusterName = cluster.getClusterName();
Metadata metadata = cluster.getMetadata();
Set<Host> allHosts = metadata.getAllHosts();
StringBuilder b = new StringBuilder("\nCassandra Cluster '" + clusterName + "' details (via native client driver) are :");
for (Host host : allHosts) {
b.append(ClusterProbe.prettyHost(host));
}
LOG.info(b.toString());
} else {
LOG.warn("Null or closed cluster");
}
} catch (Throwable t) {
}
}
示例5: testMetadata
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
@Test(groups = {"system"})
public void testMetadata() throws Exception {
Metadata metadata = cluster.getMetadata();
assertTrue(metadata.getClusterName().length() > 0);
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Connected to cluster: %s\n", metadata.getClusterName()));
}
assertTrue(metadata.getAllHosts().size() > 0);
for (Host host : metadata.getAllHosts()) {
assertTrue(host.getDatacenter().length() > 0);
assertNotNull(host.getAddress());
assertTrue(host.getRack().length() > 0);
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Datacenter: %s; Host: %s; Rack: %s\n",
host.getDatacenter(),
host.getAddress(),
host.getRack()));
}
}
}
示例6: setUp
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
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());
}
session = cluster.connect();
repository.createKeyspace();
repository.createAoisTable();
repository.createAclsTable();
repository.createChilrenTable();
SecurityContextHolder.getContext().setAuthentication(
new UsernamePasswordAuthenticationToken(sid1, "password", Arrays.asList(new SimpleGrantedAuthority[] { new SimpleGrantedAuthority(
ROLE_ADMIN) })));
}
開發者ID:RigasGrigoropoulos,項目名稱:spring-security-acl-cassandra,代碼行數:19,代碼來源:CassandraAclServiceTest.java
示例7: setUp
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
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());
}
session = cluster.connect();
service.createKeyspace();
service.createAoisTable();
service.createAclsTable();
service.createChilrenTable();
SecurityContextHolder.getContext().setAuthentication(
new UsernamePasswordAuthenticationToken(sid1, "password", Arrays.asList(new SimpleGrantedAuthority[] { new SimpleGrantedAuthority(
ROLE_ADMIN) })));
}
開發者ID:RigasGrigoropoulos,項目名稱:spring-security-acl-cassandra,代碼行數:19,代碼來源:CassandraAclRepositoryTest.java
示例8: setUp
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
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());
}
session = cluster.connect();
service.createKeyspace();
service.createAoisTable();
service.createAclsTable();
service.createChilrenTable();
SecurityContextHolder.getContext().setAuthentication(
new UsernamePasswordAuthenticationToken(sid1, "password", Arrays.asList(new SimpleGrantedAuthority[] { new SimpleGrantedAuthority(
"ROLE_USER") })));
}
示例9: getCluster
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
private static Cluster getCluster(){
if(cluster==null){
synchronized (SessionManager.class) {
if(cluster==null){
PoolingOptions poolingOptions = new PoolingOptions();
poolingOptions
.setMaxRequestsPerConnection(HostDistance.REMOTE, max)
.setMaxRequestsPerConnection(HostDistance.LOCAL,max)
.setMaxQueueSize(max*10)
.setCoreConnectionsPerHost(HostDistance.LOCAL, 1)
.setMaxConnectionsPerHost( HostDistance.LOCAL, 2)
.setCoreConnectionsPerHost(HostDistance.REMOTE, 1)
.setMaxConnectionsPerHost( HostDistance.REMOTE, 2);
SocketOptions socketOptions = new SocketOptions();
socketOptions.setConnectTimeoutMillis(60000);
socketOptions.setReadTimeoutMillis(60000);
cluster = Cluster.builder().addContactPoint(url).withPoolingOptions(poolingOptions).withSocketOptions(socketOptions).build();
Metadata metadata = cluster.getMetadata();
Set<Host> allHosts = metadata.getAllHosts();
for(Host host:allHosts){
System.out.println("host:"+host.getAddress());
}
}
}
}
return cluster;
}
示例10: getAllNodePublicIps
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
public ArrayList<String> getAllNodePublicIps(){
Metadata metadata = cluster.getMetadata();
ArrayList<String> nodePublicIps = new ArrayList<String>();
for ( Host host : metadata.getAllHosts() ) {
nodePublicIps.add(host.getBroadcastAddress().getHostAddress());
}
return nodePublicIps;
}
示例11: connect
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
public void connect(String node) {
cassandraCluster = Cluster.builder().addContactPoint(node).build();
Metadata metadata = cassandraCluster.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());
}
}
示例12: CassandraConn
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
public CassandraConn(String node, String keyspace, String username, String password) {
PoolingOptions pools = new PoolingOptions();
pools.setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, maxRequestPerConnection);
pools.setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, minRequestPerConnection);
pools.setCoreConnectionsPerHost(HostDistance.LOCAL, coreConnectionLocalPerHost);
pools.setMaxConnectionsPerHost(HostDistance.LOCAL, maxConnectionLocalPerHost);
pools.setCoreConnectionsPerHost(HostDistance.REMOTE, coreConnectionRemotePerHost);
pools.setMaxConnectionsPerHost(HostDistance.REMOTE, maxConnectionRemotePerHost);
cluster = Cluster.builder()
.addContactPoint(node)
.withPoolingOptions(pools)
.withCredentials(username, password)
.withSocketOptions(new SocketOptions().setTcpNoDelay(true))
.build();
Metadata metadata = cluster.getMetadata();
System.out.printf("Connected to cluster: %s\n",
metadata.getClusterName());
for ( Host host : metadata.getAllHosts() ) {
System.out.printf("Datatacenter: %s; Host: %s; Rack: %s\n",
host.getDatacenter(), host.getAddress(), host.getRack());
}
session = cluster.connect(keyspace);
}
示例13: getConnectionInfo
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
private String getConnectionInfo(Metadata metadata) {
StringBuilder sb = new StringBuilder();
sb.append("Connected to cluster: ");
sb.append(metadata.getClusterName());
sb.append("\n");
for (Host host : metadata.getAllHosts()) {
sb.append("Data center: ");
sb.append(host.getDatacenter());
sb.append("; Host: ");
sb.append(host.getAddress());
}
return sb.toString();
}
示例14: connect
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
public void connect() {
cluster = new Cluster.Builder().addContactPoint(seed).build();
// final int core_threads = 1;
// final int max_threads = 4;
//
// PoolingOptions p = cluster.getConfiguration().getPoolingOptions();
// p.setMaxConnectionsPerHost(HostDistance.LOCAL, max_threads);
// p.setCoreConnectionsPerHost(HostDistance.LOCAL, core_threads);
// SocketOptions so = cluster.getConfiguration().getSocketOptions();
// so.setTcpNoDelay(true).setReuseAddress(true).setKeepAlive(true);
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());
}
session = cluster.connect();
// restoreTables(cluster);
}
示例15: connect
import com.datastax.driver.core.Metadata; //導入方法依賴的package包/類
public void connect(String node) {
cluster = Cluster.builder()
.addContactPoint(node).build();
Metadata metadata = cluster.getMetadata();
System.out.printf("Connected to cluster: %s\n",
metadata.getClusterName());
for ( Host host : metadata.getAllHosts() ) {
System.out.printf("Datatacenter: %s; Host: %s; Rack: %s\n",
host.getDatacenter(), host.getAddress(), host.getRack());
}
session=cluster.connect();
}