當前位置: 首頁>>代碼示例>>Java>>正文


Java Metadata類代碼示例

本文整理匯總了Java中com.datastax.driver.core.Metadata的典型用法代碼示例。如果您正苦於以下問題:Java Metadata類的具體用法?Java Metadata怎麽用?Java Metadata使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Metadata類屬於com.datastax.driver.core包,在下文中一共展示了Metadata類的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();
}
 
開發者ID:alokawi,項目名稱:spark-cassandra-poc,代碼行數:26,代碼來源:CassandraConnection.java

示例3: connectToMultipleAddresses

import com.datastax.driver.core.Metadata; //導入依賴的package包/類
private void connectToMultipleAddresses(String address) {
	PoolingOptions poolingOptions =
		new PoolingOptions()
    	.setConnectionsPerHost(HostDistance.LOCAL,  4, 10)
    	.setConnectionsPerHost(HostDistance.REMOTE, 2, 4);
	String[] music_hosts = address.split(",");
	if (cluster == null) {
		logger.debug("Initializing MUSIC Client with endpoints "+address);
		cluster = Cluster.builder()
			.withPort(9042)
			.withPoolingOptions(poolingOptions)
			.withoutMetrics()
			.addContactPoints(music_hosts)
			.build();
		Metadata metadata = cluster.getMetadata();
		logger.debug("Connected to cluster:"+metadata.getClusterName()+" at address:"+address);
	}
	session = cluster.connect();
}
 
開發者ID:att,項目名稱:music,代碼行數:20,代碼來源:MusicConnector.java

示例4: connectToCassaCluster

import com.datastax.driver.core.Metadata; //導入依賴的package包/類
@SuppressWarnings("unused")
private void connectToCassaCluster(String address) {
	PoolingOptions poolingOptions =
		new PoolingOptions()
    	.setConnectionsPerHost(HostDistance.LOCAL,  4, 10)
    	.setConnectionsPerHost(HostDistance.REMOTE, 2, 4);
	Iterator<String> it = getAllPossibleLocalIps().iterator();
	logger.debug("Iterating through possible ips:"+getAllPossibleLocalIps());
	while (it.hasNext()) {
		try {
			cluster = Cluster.builder()
				.withPort(9042)
				.withPoolingOptions(poolingOptions)
				.withoutMetrics()
				.addContactPoint(address)
				.build();
			//cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(Integer.MAX_VALUE);
			Metadata metadata = cluster.getMetadata();
			logger.debug("Connected to cluster:"+metadata.getClusterName()+" at address:"+address);
			session = cluster.connect();
			break;
		} catch (NoHostAvailableException e) {
			address = it.next();
		}
	}
}
 
開發者ID:att,項目名稱:music,代碼行數:27,代碼來源:MusicConnector.java

示例5: connectToCassaCluster

import com.datastax.driver.core.Metadata; //導入依賴的package包/類
private void connectToCassaCluster(){
		Iterator<String> it = getAllPossibleLocalIps().iterator();
		String address= "localhost";
		logger.debug("Connecting to cassa cluster: Iterating through possible ips:"+getAllPossibleLocalIps());
		while(it.hasNext()){
			try {
				cluster = Cluster.builder().withPort(9042).addContactPoint(address).build();
				//cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(Integer.MAX_VALUE);
				Metadata metadata = cluster.getMetadata();
				logger.debug("Connected to cassa cluster "+metadata.getClusterName()+" at "+address);
/*				for ( Host host : metadata.getAllHosts() ) {
						.out.printf("Datacenter: %s; Host broadcast: %s; Rack: %s\n",
							host.getDatacenter(), host.getBroadcastAddress(), host.getRack());
							
				}*/
				session = cluster.connect();
				
				break;
			} catch (NoHostAvailableException e) {
				address= it.next();
			} 
		}
	}
 
開發者ID:att,項目名稱:music,代碼行數:24,代碼來源:MusicDataStore.java

示例6: connectToCassaCluster

import com.datastax.driver.core.Metadata; //導入依賴的package包/類
private void connectToCassaCluster(){
		Iterator<String> it = getAllPossibleLocalIps().iterator();
		String address= "localhost";
//		logger.debug("Connecting to cassa cluster: Iterating through possible ips:"+getAllPossibleLocalIps());
		while(it.hasNext()){
			try {
				cluster = Cluster.builder().withPort(9042).addContactPoint(address).build();
				//cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(Integer.MAX_VALUE);
				Metadata metadata = cluster.getMetadata();
//				logger.debug("Connected to cassa cluster "+metadata.getClusterName()+" at "+address);
/*				for ( Host host : metadata.getAllHosts() ) {
					System.out.printf("Datacenter: %s; Host broadcast: %s; Rack: %s\n",
							host.getDatacenter(), host.getBroadcastAddress(), host.getRack());
							
				}*/
				session = cluster.connect();
				
				break;
			} catch (NoHostAvailableException e) {
				address= it.next();
			} 
		}
	}
 
開發者ID:att,項目名稱:music,代碼行數:24,代碼來源:CassaHandle.java

示例7: testClusterHintsPollerWhenNodeDown

import com.datastax.driver.core.Metadata; //導入依賴的package包/類
@Test
public void testClusterHintsPollerWhenNodeDown() throws UnknownHostException {
    ClusterHintsPoller clusterHintsPoller = new ClusterHintsPoller();
    Session mockSession = mock(Session.class);
    Cluster mockCluster = mock(Cluster.class);
    Metadata mockMetadata = mock(Metadata.class);
    when(mockCluster.getMetadata()).thenReturn(mockMetadata);
    when(mockCluster.getClusterName()).thenReturn("test-cluster");
    Host node1 = mock(Host.class);
    when(node1.getAddress()).thenReturn(InetAddress.getByName("127.0.0.1"));
    Host node2 = mock(Host.class);
    when(node2.getAddress()).thenReturn(InetAddress.getByName("127.0.0.2"));
    Host node3 = mock(Host.class);
    when(node3.getAddress()).thenReturn(InetAddress.getByName("127.0.0.3"));

    when(mockSession.getCluster()).thenReturn(mockCluster);
    // The first node queried is down
    when(mockSession.execute(any(Statement.class))).thenThrow(new NoHostAvailableException(ImmutableMap.<InetSocketAddress, Throwable>of()));

    when(mockMetadata.getAllHosts()).thenReturn(ImmutableSet.of(node1, node2, node3));
    HintsPollerResult actualResult = clusterHintsPoller.getOldestHintsInfo(mockSession);

    // Make sure HintsPollerResult fails
    assertFalse(actualResult.areAllHostsPolling(), "Result should show hosts failing");
    assertEquals(actualResult.getHostFailure(), ImmutableSet.of(InetAddress.getByName("127.0.0.1")), "Node 1 should return with host failure");
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:27,代碼來源:ClusterHintsPollerTest.java

示例8: ensureMockCassandraRunningAndEstablished

import com.datastax.driver.core.Metadata; //導入依賴的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

示例9: loadTablesFromRemote

import com.datastax.driver.core.Metadata; //導入依賴的package包/類
public static Cluster loadTablesFromRemote(String host, int port, String cfidOverrides) throws IOException {
    Map<String, UUID> cfs = parseOverrides(cfidOverrides);
    Cluster.Builder builder = Cluster.builder().addContactPoints(host).withPort(port);
    Cluster cluster = builder.build();
    Metadata metadata = cluster.getMetadata();
    IPartitioner partitioner = FBUtilities.newPartitioner(metadata.getPartitioner());
    if (DatabaseDescriptor.getPartitioner() == null)
        DatabaseDescriptor.setPartitionerUnsafe(partitioner);
    for (com.datastax.driver.core.KeyspaceMetadata ksm : metadata.getKeyspaces()) {
        if (!ksm.getName().equals("system")) {
            for (TableMetadata tm : ksm.getTables()) {
                String name = ksm.getName()+"."+tm.getName();
                try {
                    CassandraUtils.tableFromCQL(
                            new ByteArrayInputStream(tm.asCQLQuery().getBytes()),
                            cfs.get(name) != null ? cfs.get(name) : tm.getId());
                } catch(SyntaxException e) {
                    // ignore tables that we cant parse (probably dse)
                    logger.debug("Ignoring table " + name + " due to syntax exception " + e.getMessage());
                }
            }
        }
    }
    return cluster;
}
 
開發者ID:tolbertam,項目名稱:sstable-tools,代碼行數:26,代碼來源:CassandraUtils.java

示例10: 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();
}
 
開發者ID:benhumphreys,項目名稱:jgit-cassandra,代碼行數:25,代碼來源:StoreConnection.java

示例11: SmartThriftClient

import com.datastax.driver.core.Metadata; //導入依賴的package包/類
public SmartThriftClient(StressSettings settings, String keyspace, Metadata metadata)
{
    this.metadata = metadata;
    this.keyspace = keyspace;
    this.settings = settings;
    if (!settings.node.isWhiteList)
    {
        whiteset = null;
        whitelist = null;
    }
    else
    {
        whiteset = settings.node.resolveAllSpecified();
        whitelist = Arrays.asList(whiteset.toArray(new InetAddress[0]));
    }
}
 
開發者ID:vcostet,項目名稱:cassandra-kmean,代碼行數:17,代碼來源:SmartThriftClient.java

示例12: connectsToTheCassandraCluster

import com.datastax.driver.core.Metadata; //導入依賴的package包/類
@Test
@ConditionalIgnoreRule.IgnoreIf(condition = NoRunningCassandraDbForTests.class)
public void connectsToTheCassandraCluster() throws Exception {
    Cluster cluster = Cluster.builder()
            .addContactPoint(new NoRunningCassandraDbForTests().getHost())
            .withPort(9042)
            .withClusterName("BluePrint")
            .build();
    Metadata metadata = cluster.getMetadata();
    LOG.info("Clustername:" + metadata.getClusterName());
    LOG.info("Partitioner:" + metadata.getPartitioner());
    LOG.info("Hosts:" + metadata.getAllHosts());
    LOG.info("KeySpaces:" + metadata.getKeyspaces());

    Session session = cluster.connect("system");//system keyspace should always be present
    assertNotNull(session);
    session.close();
}
 
開發者ID:Excelian,項目名稱:Mache,代碼行數:19,代碼來源:CassandraConnectorTest.java

示例13: getSchema

import com.datastax.driver.core.Metadata; //導入依賴的package包/類
public List<Column> getSchema(String keySpace, String tableName) {
	Metadata m = session.getCluster().getMetadata();
	KeyspaceMetadata km = m.getKeyspace(keySpace);
	if (km == null)
		return null;
	TableMetadata tm = km.getTable(tableName);
	if (tm == null)
		return null;
	// build schema
	List<Column> columns = new LinkedList<Column>();
	for (ColumnMetadata cm : tm.getColumns()) {
		if (!meta.contains(cm.getName()))
			columns.add(Column.newBuilder().setName(cm.getName())
					.setType(toSimbaType(cm.getType().toString())).build());
	}

	return columns;

}
 
開發者ID:SimbaService,項目名稱:Simba,代碼行數:20,代碼來源:CassandraHandler.java

示例14: fetchKeys

import com.datastax.driver.core.Metadata; //導入依賴的package包/類
private void fetchKeys()
{
    // get CF meta data
    TableMetadata tableMetadata = session.getCluster()
                                         .getMetadata()
                                         .getKeyspace(Metadata.quote(keyspace))
                                         .getTable(Metadata.quote(cfName));
    if (tableMetadata == null)
    {
        throw new RuntimeException("No table metadata found for " + keyspace + "." + cfName);
    }
    //Here we assume that tableMetadata.getPartitionKey() always
    //returns the list of columns in order of component_index
    for (ColumnMetadata partitionKey : tableMetadata.getPartitionKey())
    {
        partitionKeys.add(partitionKey.getName());
    }
}
 
開發者ID:scylladb,項目名稱:scylla-tools-java,代碼行數:19,代碼來源:CqlRecordReader.java

示例15: provideCluster

import com.datastax.driver.core.Metadata; //導入依賴的package包/類
@Provides @Singleton Cluster provideCluster() {
        try {
            Cluster cluster = Cluster.builder()
                    .addContactPointsWithPorts(Arrays.asList(
//                            new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 9042) // mvn cassandra:run + nodetool enablebinary
                            new InetSocketAddress(InetAddress.getByName("localhost"), 9142)  // cassandraunit
                    ))
                    .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE)
                    .withReconnectionPolicy(new ExponentialReconnectionPolicy(100L, 5000L))
                    .build();
            Metadata metadata = cluster.getMetadata();
            LOGGER.info("Connected to cluster: '{}'", metadata.getClusterName());
            metadata.getAllHosts()
                    .forEach(host -> LOGGER.info("Datacenter: '{}'; Host: '{}'; Rack: '{}'",
                            new Object[] { host.getDatacenter(), host.getAddress(), host.getRack() })
                    );
            return cluster;
        } catch (UnknownHostException e) {
            LOGGER.error("Can't connect to Cassandra", e);
            return null;
        }
    }
 
開發者ID:kalixia,項目名稱:kha,代碼行數:23,代碼來源:TestModule.java


注:本文中的com.datastax.driver.core.Metadata類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。