com.datastax.driver.core.Metadata.getClusterName()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中com.datastax.driver.core.Metadata.getClusterName()方法的一些代码示例,展示了Metadata.getClusterName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metadata.getClusterName()方法的具体详情如下:
包路径:com.datastax.driver.core.Metadata
类名称:Metadata
方法名:getClusterName

Metadata.getClusterName介绍

[英]The Cassandra name for the cluster connect to.
[中]连接到的群集的Cassandra名称。

代码示例

代码示例来源:origin: Netflix/conductor

@Override
  public Cluster get() {
    String host = configuration.getHostAddress();
    int port = configuration.getPort();

    LOGGER.info("Connecting to cassandra cluster with host:{}, port:{}", host, port);

    Cluster cluster = Cluster.builder()
        .addContactPoint(host)
        .withPort(port)
        .build();

    Metadata metadata = cluster.getMetadata();
    LOGGER.info("Connected to cluster: {}", metadata.getClusterName());
    metadata.getAllHosts().forEach(h -> {
      LOGGER.info("Datacenter:{}, host:{}, rack: {}", h.getDatacenter(), h.getAddress(), h.getRack());
    });
    return cluster;
  }
}

代码示例来源:origin: brianfrankcooper/YCSB

metadata.getClusterName());

代码示例来源:origin: apache/nifi

String transitUri = "cassandra://" + connectionSession.getCluster().getMetadata().getClusterName();
session.getProvenanceReporter().send(flowFile, transitUri, transmissionMillis, true);
session.transfer(flowFile, REL_SUCCESS);

代码示例来源:origin: apache/nifi

Metadata metadata = newCluster.getMetadata();
log.info("Connected to Cassandra cluster: {}", new Object[]{metadata.getClusterName()});

代码示例来源:origin: apache/nifi

stopWatch.stop();
long duration = stopWatch.getDuration(TimeUnit.MILLISECONDS);
String transitUri = "cassandra://" + connectionSession.getCluster().getMetadata().getClusterName() + "." + cassandraTable;

代码示例来源:origin: apache/nifi

log.info("Connected to Cassandra cluster: {}", new Object[]{metadata.getClusterName()});

代码示例来源:origin: adejanovski/cassandra-jdbc-wrapper

public String getCatalog() throws SQLException
{
  checkNotClosed();
  return metadata.getClusterName();
}

代码示例来源:origin: com.netflix.astyanax/astyanax-cql

@Override
public String describeClusterName() throws ConnectionException {
  return cluster.getMetadata().getClusterName();
}

代码示例来源:origin: Contrast-Security-OSS/cassandra-migration

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();
}

代码示例来源:origin: org.mobicents.smsc/smsc-common-library

public void stop() throws Exception {
  if (!this.started)
    return;
  if (cluster != null && !cluster.isClosed()) {
    Metadata metadata = cluster.getMetadata();
    cluster.close();
    logger.info(String.format("Disconnected from cluster: %s\n", metadata.getClusterName()));
  }
  this.started = false;
}

代码示例来源:origin: intuit/wasabi

LOGGER.info("Connected to cluster: {}\n", metadata.getClusterName());
for (Host host : metadata.getAllHosts()) {
  LOGGER.info("Datatacenter: {}; Host: {}; Rack: {}\n",

代码示例来源:origin: opendedup/sdfs

private void createTableSpace() {
  if (cluster == null) {
    cluster = Cluster.builder().addContactPointsWithPorts(contactPoints).build();
    log.info("Connected Cassandra to cluster: " + cluster.getMetadata().getClusterName());
    session = cluster.connect();
  }
  session.execute("CREATE KEYSPACE IF NOT EXISTS " + serviceName + " WITH replication "
      + "= {'class':'NetworkTopologyStrategy', '"+this.dataCenter+"': "+this.replicationFactor+"};");
  session.execute("CREATE TABLE IF NOT EXISTS " + serviceName + ".igep (" + "id text PRIMARY KEY," + "host text,"
      + "port int);");
}

代码示例来源:origin: opendedup/sdfs

public void init() {
  if (cluster == null) {
    cluster = Cluster.builder().addContactPointsWithPorts(contactPoints).build();
    SDFSLogger.getLog().info("Connected Cassandra to cluster: " + cluster.getMetadata().getClusterName());
    session = cluster.connect();
  }
  session.execute("CREATE KEYSPACE IF NOT EXISTS " + serviceName + " WITH replication "
      + "= {'class':'NetworkTopologyStrategy', '"+this.dataCenter+"': "+this.replicationFactor+"};");
}

代码示例来源:origin: jgoodyear/ApacheKarafCookbook

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("karaf_demo");
}

代码示例来源:origin: apifest/apifest-oauth20

public static Cluster connect(String cassandraContactPoints) {
  if(cluster == null) {
    cluster = Cluster.builder()
        .addContactPoint(cassandraContactPoints)
        .withReconnectionPolicy(new ConstantReconnectionPolicy(1000))
        .build();
    Metadata metadata = cluster.getMetadata();
    log.info("Connected to cluster: %s\n",
        metadata.getClusterName());
    for (Host host : metadata.getAllHosts()) {
      log.info(String.format("Datacenter: %s; Host: %s; Rack: %s\n",
          host.getDatacenter(), host.getAddress(), host.getRack()));
    }
  }
  return cluster;
}

代码示例来源:origin: ff4j/ff4j

/**
 * Init Cassandra session from Cluster.s
 */
public void initSession() {
  if (null == cluster) {
    Builder builder = Cluster.builder().addContactPoint(hostName).withPort(port);
    if (Util.hasLength(userName)) {
      builder.withCredentials(userName, userPassword);
    }
    this.cluster = builder.build();
  }
  Metadata metadata = cluster.getMetadata();
  LOGGER.info("Connecting to cluster... '{}'",  metadata.getClusterName());
  for ( Host host : metadata.getAllHosts() ) {
    LOGGER.info("Datatacenter: '{}' Host: '{}' Rack '{}'", host.getDatacenter(), host.getAddress(), host.getRack());
  }
  this.session = cluster.connect();  
  LOGGER.info("Connection Successful.");
}

代码示例来源:origin: org.wicketstuff/wicketstuff-datastore-cassandra

/**
 * Constructor.
 *
 * Initializes the connection to the Cassandra cluster and creates
 * the keyspace and/or table if necessary.
 *
 * @param cluster  The Cassandra cluster
 * @param settings The various settings
 */
public CassandraDataStore(Cluster cluster, ICassandraSettings settings)
{
  this.cluster = Args.notNull(cluster, "cluster");
  this.settings = Args.notNull(settings, "settings");
  Metadata metadata = cluster.getMetadata();
  if (LOGGER.isInfoEnabled())
  {
    LOGGER.info("Connected to cluster: {}", metadata.getClusterName());
    for (Host host : metadata.getAllHosts())
    {
      LOGGER.info("Datatacenter: {}; Host: {}; Rack: {}",
          new Object[]{host.getDatacenter(), host.getAddress(), host.getRack()});
    }
  }
  session = cluster.connect();
  String keyspaceName = settings.getKeyspaceName();
  KeyspaceMetadata keyspaceMetadata = createKeyspaceIfNecessary(keyspaceName, metadata);
  createTableIfNecessary(keyspaceName, keyspaceMetadata);
  LOGGER.info("Data will be stored in table '{}' in keyspace '{}'.", settings.getTableName(), keyspaceName);
}

代码示例来源:origin: Stratio/stratio-cassandra-test

this.cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(600000);
metadata = cluster.getMetadata();
logger.debug("Connected to cluster (" + this.host + "): " + metadata.getClusterName() + "\n");
session = cluster.connect();

代码示例来源:origin: srecon/elasticsearch-cassandra-river

private CassandraFactory(String hostName, String port, String dcName, String username, String password, Integer connectTimeoutMillis, Integer readTimeoutMillis){
  LoadBalancingPolicy loadBalancingPolicy = new DCAwareRoundRobinPolicy(dcName,2);
  PoolingOptions poolingOptions = new PoolingOptions();
  poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL,10);
  poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, 50);
  SocketOptions socketOptions = new SocketOptions().setReadTimeoutMillis(readTimeoutMillis)
   .setConnectTimeoutMillis(connectTimeoutMillis);
  Cluster.Builder builder = Cluster.builder().addContactPoints(hostName)
      .withPoolingOptions(poolingOptions)
      .withReconnectionPolicy(new ConstantReconnectionPolicy(100L))
      .withLoadBalancingPolicy(loadBalancingPolicy)
      .withSocketOptions(socketOptions);
  if(!username.isEmpty() && !password.isEmpty()) {
    builder.withCredentials(username, password);
  }
  cluster = builder.build();
  Metadata metadata = cluster.getMetadata();
  LOGGER.info("Connected to cluster: {}", metadata.getClusterName());
  for ( Host host : metadata.getAllHosts() ) {
    LOGGER.info("Datacenter: {}; Host: {}; Rack: {}", new String[]{ host.getDatacenter(), host.getAddress().getHostAddress(), host.getRack() });
  }
}

代码示例来源:origin: org.copper-engine/cassandra-storage

@Override
public synchronized void startup() {
  if (cassandraCluster != null)
    return;
  Builder b = Cluster.builder();
  b.withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().build()));
  for (String host : hosts) {
    b.addContactPoint(host);
  }
  if (port != null) {
    b.withPort(port);
  }
  cassandraCluster = b.build();
  cassandraCluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(60000);
  logger.info("Connected to cluster: {}", cassandraCluster.getMetadata().getClusterName());
  for (Host host : cassandraCluster.getMetadata().getAllHosts()) {
    logger.info("Datatacenter: {} Host: {} Rack: {}", host.getDatacenter(), host.getAddress(), host.getRack());
  }
  session = cassandraCluster.connect(keyspace);
}

相关文章