当前位置: 首页>>代码示例>>Java>>正文


Java Cluster.getMetadata方法代码示例

本文整理汇总了Java中com.datastax.driver.core.Cluster.getMetadata方法的典型用法代码示例。如果您正苦于以下问题:Java Cluster.getMetadata方法的具体用法?Java Cluster.getMetadata怎么用?Java Cluster.getMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.datastax.driver.core.Cluster的用法示例。


在下文中一共展示了Cluster.getMetadata方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ensureMockCassandraRunningAndEstablished

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
/**
 * Ensures that the Mock Cassandra instance is up and running. Will reinit
 * the database every time it is called.
 *
 * @param cassandraKeyspace Cassandra keyspace to setup.
 * @return A cluster object.
 * @throws ConfigurationException
 * @throws IOException
 * @throws InterruptedException
 * @throws TTransportException
 */
public static Cluster ensureMockCassandraRunningAndEstablished(String cassandraKeyspace) throws ConfigurationException, IOException, InterruptedException, TTransportException
{
    Cluster cluster;
    long timeout = 60000;
    EmbeddedCassandraServerHelper.startEmbeddedCassandra(timeout);
    cluster = Cluster.builder().addContactPoints("127.0.0.1").withPort(9142).build();
    //Thread.sleep(20000);//time to let cassandra startup
    final Metadata metadata = cluster.getMetadata();

    Session session = cluster.connect();
    Utils.initDatabase(DB_CQL, session);
    session = cluster.connect(cassandraKeyspace);

    logger.info("Connected to cluster: " + metadata.getClusterName() + '\n');
    return cluster;
}
 
开发者ID:PearsonEducation,项目名称:Docussandra,代码行数:28,代码来源:Fixtures.java

示例2: Fixtures

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
/**
 * Private constructor as this is a singleton object
 */
private Fixtures(String seedsList, boolean mockCassandra) throws Exception
{
    cassandraKeyspace = "docussandra";
    cassandraSeeds = seedsList.split(",");

    Cluster cluster;
    if (mockCassandra)//using cassandra-unit for testing
    {
        cluster = Fixtures.ensureMockCassandraRunningAndEstablished(cassandraKeyspace);
    } else if (seedsList.startsWith("172.17."))
    {
        cluster = Fixtures.ensureDockerCassandraRunningAndEstablished(cassandraKeyspace, cassandraSeeds[0]);
    } else //using a remote or local server for testing
    {
        cluster = Cluster.builder().addContactPoints(cassandraSeeds).build();
    }
    final Metadata metadata = cluster.getMetadata();
    session = cluster.connect(this.getCassandraKeyspace());
    logger.info("Connected to cluster: " + metadata.getClusterName() + '\n');
    indexRepo = new IndexRepositoryImpl(session);
    cleanUpInstance = new ITableRepositoryImpl(getSession());
    databaseRepo = new DatabaseRepositoryImpl(getSession());
    docRepo = new DocumentRepositoryImpl(getSession());
    tableRepo = new TableRepositoryImpl(getSession());
    indexStatusRepo = new IndexStatusRepositoryImpl(getSession());

    //set up bus just like rest express would
    EventBus bus = new LocalEventBusBuilder()
            .subscribe(new IndexCreatedHandler(indexRepo, indexStatusRepo, docRepo))
            .build();
    DomainEvents.addBus("local", bus);
}
 
开发者ID:PearsonEducation,项目名称:Docussandra,代码行数:36,代码来源:Fixtures.java

示例3: ensureDockerCassandraRunningAndEstablished

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
/**
 * Ensures that the Docker Cassandra instance is up and running. Will reinit
 * the database every time it is called.
 *
 * @param cassandraKeyspace Cassandra keyspace to setup.
 * @return A cluster object.
 * @throws ConfigurationException
 * @throws IOException
 * @throws InterruptedException
 * @throws TTransportException
 */
public static Cluster ensureDockerCassandraRunningAndEstablished(String cassandraKeyspace, String seed) throws ConfigurationException, IOException, InterruptedException, TTransportException
{
    Cluster cluster = Cluster.builder().addContactPoints(seed).withPort(9042).build();
    //Thread.sleep(20000);//time to let cassandra startup
    final Metadata metadata = cluster.getMetadata();

    Session session = cluster.connect();
    Utils.initDatabase(DB_CQL, session);
    session = cluster.connect(cassandraKeyspace);

    logger.info("Connected to cluster: " + metadata.getClusterName() + '\n');
    return cluster;
}
 
开发者ID:PearsonEducation,项目名称:Docussandra,代码行数:25,代码来源:Fixtures.java

示例4: createStandaloneConnection

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
/**
 * Method to create the standalone cassandra connection .
 * 
 * @param ip
 * @param port
 * @param userName
 * @param password
 * @param keyspace
 * @return
 */
private boolean createStandaloneConnection(String ip, String port, String userName,
    String password, String keyspace) {

  Session cassandraSession = null;
  boolean connection = false;
  Cluster cluster = null;
  try {
    if (null == cassandraSessionMap.get(keyspace)) {
      PropertiesCache cache = PropertiesCache.getInstance();
      PoolingOptions poolingOptions = new PoolingOptions();
      poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL,
          Integer.parseInt(cache.getProperty(Constants.CORE_CONNECTIONS_PER_HOST_FOR_LOCAL)));
      poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL,
          Integer.parseInt(cache.getProperty(Constants.MAX_CONNECTIONS_PER_HOST_FOR_LOCAl)));
      poolingOptions.setCoreConnectionsPerHost(HostDistance.REMOTE,
          Integer.parseInt(cache.getProperty(Constants.CORE_CONNECTIONS_PER_HOST_FOR_REMOTE)));
      poolingOptions.setMaxConnectionsPerHost(HostDistance.REMOTE,
          Integer.parseInt(cache.getProperty(Constants.MAX_CONNECTIONS_PER_HOST_FOR_REMOTE)));
      poolingOptions.setMaxRequestsPerConnection(HostDistance.LOCAL,
          Integer.parseInt(cache.getProperty(Constants.MAX_REQUEST_PER_CONNECTION)));
      poolingOptions.setHeartbeatIntervalSeconds(
          Integer.parseInt(cache.getProperty(Constants.HEARTBEAT_INTERVAL)));
      poolingOptions
          .setPoolTimeoutMillis(Integer.parseInt(cache.getProperty(Constants.POOL_TIMEOUT)));
      if (!ProjectUtil.isStringNullOREmpty(userName)
          && !ProjectUtil.isStringNullOREmpty(password)) {
        cluster = createCluster(ip, port, userName, password, poolingOptions);
      } else {
        cluster = createCluster(ip, port, poolingOptions);
      }
      QueryLogger queryLogger = QueryLogger.builder().withConstantThreshold(
          Integer.parseInt(cache.getProperty(Constants.QUERY_LOGGER_THRESHOLD))).build();
      cluster.register(queryLogger);
      cassandraSession = cluster.connect(keyspace);

      if (null != cassandraSession) {
        connection = true;
        cassandraSessionMap.put(keyspace, cassandraSession);
        cassandraclusterMap.put(keyspace, cluster);
      }
      final Metadata metadata = cluster.getMetadata();
      String msg = String.format("Connected to cluster: %s", metadata.getClusterName());
      ProjectLogger.log(msg);

      for (final Host host : metadata.getAllHosts()) {
        msg = String.format("Datacenter: %s; Host: %s; Rack: %s", host.getDatacenter(),
            host.getAddress(), host.getRack());
        ProjectLogger.log(msg);
      }
    }
  } catch (Exception e) {
    ProjectLogger.log("Error occured while creating connection :", e);
    throw new ProjectCommonException(ResponseCode.internalError.getErrorCode(), e.getMessage(),
        ResponseCode.SERVER_ERROR.getResponseCode());
  }

  if (null != cassandraSessionMap.get(keyspace)) {
    connection = true;
  }
  return connection;


}
 
开发者ID:project-sunbird,项目名称:sunbird-utils,代码行数:74,代码来源:CassandraConnectionManagerImpl.java

示例5: setTableFieldCombo

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
private void setTableFieldCombo() {

        Runnable fieldLoader = new Runnable() {
        	@Override
    		public void run() {
        		if (!shell.isDisposed()) {
        			String nodes = transMeta.environmentSubstitute(hostText.getText());
        			String port_s = transMeta.environmentSubstitute(portText.getText());
        			String username = transMeta.environmentSubstitute(userText.getText());
        			String password = transMeta.environmentSubstitute(passText.getText());
        			String keyspace = transMeta.environmentSubstitute(keyspaceText.getText());
        			Boolean withSSL = sslenabledBut.getSelection();
        			String truststorefile = transMeta.environmentSubstitute(truststorefileText.getText());
        			String truststorepass = transMeta.environmentSubstitute(truststorepassText.getText());
        			ConnectionCompression compression = ConnectionCompression.fromString(wCompression.getText());
        			String columnFamily = columnFamilyCombo.getText();

        			ciFields[0].setComboValues(new String[0]);
        			if (!Const.isEmpty(columnFamily)) {
        				String[] fieldNames = null;
        				try {
        					connection = Utils.connect(nodes, port_s, username, password, keyspace, withSSL,
        							truststorefile, truststorepass, compression);
        					Cluster cluster = connection.getSession().getCluster();
        					Metadata clusterMeta = cluster != null ? cluster.getMetadata() : null;
        					KeyspaceMetadata keyspaceMeta = clusterMeta != null ? clusterMeta.getKeyspace(keyspace) : null;
        					TableMetadata tableMeta = keyspaceMeta != null ? keyspaceMeta.getTable(columnFamily) : null;

        					if (tableMeta != null) {
        						List<ColumnMetadata> column = tableMeta.getColumns();
        						Iterator<ColumnMetadata> iter = column.iterator();
        						fieldNames = new String[column.size()];
        						int i = 0;
        						while (iter.hasNext()) {
        							fieldNames[(i++)] = iter.next().getName();
        						}
        					}
        				} catch (Exception localException) {
        					localException.printStackTrace();
        				}

        				if (!fieldsList.isDisposed()) {
        					ciFields[0].setComboValues(fieldNames);
        				}
        			}
        			if (connection != null)
        				connection.release();
        		}
        	}
        };
        this.shell.getDisplay().asyncExec(fieldLoader);
    }
 
开发者ID:bcolas,项目名称:pentaho-cassandra-plugin,代码行数:53,代码来源:CassandraOutputDialog.java

示例6: queryIsExecutedOnAllClusterNodesAndAlsoTheOldestHintIsPicked

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@Ignore
@Test
public void queryIsExecutedOnAllClusterNodesAndAlsoTheOldestHintIsPicked() {

    // ***** TODO: Get a cluster with 2 nodes. (RUN WITH PERFTEST LATER.....) ******
    // Ignoring this test for now

    // Insert hints on all the cluster nodes.
    Cluster cluster = Cluster.builder()
            .addContactPoint("127.0.0.1")
            .withPort(9164)
            .withLoadBalancingPolicy(new SelectedHostLoadBalancingPolicyForTest())
            .build();
    Metadata metadata = cluster.getMetadata();
    Session clusterSession = cluster.connect();

    long hintTimestamp = System.currentTimeMillis();
    for (Host host : metadata.getAllHosts()) {
        SelectedHostStatement selectedHostStatement = new SelectedHostStatement(new SimpleStatement(getInsertHintsQuery(hintTimestamp)), host);
        clusterSession.execute(selectedHostStatement);
        hintTimestamp = hintTimestamp + 10000;
    }

    // Now check if the query ran on EVERY node of the cluster.
    Assert.assertEquals(ALL_SELECTED_HOSTS.size(), 2);

    // Get the oldest hint Timestamp of the cluster
    ClusterHintsPoller clusterHintsPoller = new ClusterHintsPoller();
    HintsPollerResult oldestHintsInfo = clusterHintsPoller.getOldestHintsInfo(clusterSession);

    // Note: ?? - This will make the test fail even if one node is down or a connection problem with just one node.
    Assert.assertNotNull(oldestHintsInfo);
    Assert.assertEquals(oldestHintsInfo.getAllPolledHosts().size(), 2);

    long retrievedHintTimeStamp = oldestHintsInfo.getOldestHintTimestamp().or(Long.MAX_VALUE);

    Assert.assertEquals(retrievedHintTimeStamp, hintTimestamp);

    cluster.close();
    clusterSession.close();
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:42,代码来源:HintsPollerTest.java


注:本文中的com.datastax.driver.core.Cluster.getMetadata方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。