本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}