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


Java Cluster.connect方法代码示例

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


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

示例1: testRequestMessageStatement

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
/**
 * Test with incoming message containing a header with RegularStatement.
 */
@Test
public void testRequestMessageStatement() throws Exception {
    Update.Where update = update("camel_user")
            .with(set("first_name", bindMarker()))
            .and(set("last_name", bindMarker()))
            .where(eq("login", bindMarker()));
    Object response = producerTemplate.requestBodyAndHeader(new Object[]{"Claus 2", "Ibsen 2", "c_ibsen"},
            CassandraConstants.CQL_QUERY, update);

    Cluster cluster = CassandraUnitUtils.cassandraCluster();
    Session session = cluster.connect(CassandraUnitUtils.KEYSPACE);
    ResultSet resultSet = session.execute("select login, first_name, last_name from camel_user where login = ?", "c_ibsen");
    Row row = resultSet.one();
    assertNotNull(row);
    assertEquals("Claus 2", row.getString("first_name"));
    assertEquals("Ibsen 2", row.getString("last_name"));
    session.close();
    cluster.close();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:CassandraComponentProducerTest.java

示例2: getClientSession

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
public static Session getClientSession(String hostAddr) {
    if(REGISTRY.containsKey(hostAddr)) {
        return REGISTRY.get(hostAddr);
    } else {
        Cluster.Builder clientClusterBuilder = new Cluster.Builder()
                .addContactPoint(hostAddr)
                .withQueryOptions(new QueryOptions()
                        .setConsistencyLevel(ConsistencyLevel.ONE)
                        .setSerialConsistencyLevel(ConsistencyLevel.LOCAL_SERIAL))
                .withoutJMXReporting()
                .withoutMetrics()
                .withReconnectionPolicy(new ConstantReconnectionPolicy(RECONNECT_DELAY_IN_MS));
        long startTimeInMillis = System.currentTimeMillis();
        Cluster clientCluster = clientClusterBuilder.build();
        Session clientSession = clientCluster.connect();

        LOG.info("Client session established after {} ms.", System.currentTimeMillis() - startTimeInMillis);
        REGISTRY.putIfAbsent(hostAddr, clientSession);
        return clientSession;
    }
}
 
开发者ID:mcfongtw,项目名称:flink-cassandra-connector-examples,代码行数:22,代码来源:ClientSessionProvider.java

示例3: createSession

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
public static Session createSession(String ip, int port) {
    Cluster cluster;

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

    Session session = cluster.connect();

    session.execute("CREATE KEYSPACE IF NOT EXISTS cassandrait WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }");
    session.execute("DROP TABLE IF EXISTS cassandrait.counter");
    session.execute("CREATE TABLE cassandrait.counter (key text, value counter, PRIMARY key(key));");

    return session;
}
 
开发者ID:nielsutrecht,项目名称:cassandra-it,代码行数:17,代码来源:ApplicationConfiguration.java

示例4: selectByDeviceAndSensor

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@Override
	public Status selectByDeviceAndSensor(TsPoint point, Double max, Double min, Date startTime, Date endTime) {
		long costTime = 0L;
		Cluster cluster = null;
		try {
			cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build();
			Session session = cluster.connect(KEY_SPACE_NAME);
			String createIndexCql = "CREATE INDEX IF NOT EXISTS value_index ON " + TABLE_NAME + "(value)";
//			System.out.println(createIndexCql);
			long startTime1 = System.nanoTime();
			session.execute(createIndexCql);
			String selectCql = "SELECT * FROM point WHERE device_code='" + point.getDeviceCode() + "' and sensor_code='"
					+ point.getSensorCode() + "' and value<" + max + " and value>" + min + " and timestamp>="
					+ startTime.getTime() + " and timestamp<=" + endTime.getTime() + " ALLOW FILTERING";
//			System.out.println(selectCql);
			ResultSet rs = session.execute(selectCql);
			long endTime1 = System.nanoTime();
			costTime = endTime1 - startTime1;
		} finally {
			if (cluster != null)
				cluster.close();
		}
//		System.out.println("此次查询消耗时间[" + costTime / 1000 + "]s");
		return Status.OK(costTime);
	}
 
开发者ID:dbiir,项目名称:ts-benchmark,代码行数:26,代码来源:CassandraDB.java

示例5: selectMinByDeviceAndSensor

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@Override
	public Status selectMinByDeviceAndSensor(String deviceCode, String sensorCode, Date startTime, Date endTime) {
		long costTime = 0L;
		Cluster cluster = null;
		try {
			cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build();
			Session session = cluster.connect(KEY_SPACE_NAME);
			String selectCql = "SELECT MIN(value) FROM point WHERE device_code='" + deviceCode + "' and sensor_code='"
					+ sensorCode + "' and timestamp>=" + startTime.getTime() + " and timestamp<=" + endTime.getTime()
					+ " ALLOW FILTERING";
//			System.out.println(selectCql);
			long startTime1 = System.nanoTime();
			ResultSet rs = session.execute(selectCql);
			long endTime1 = System.nanoTime();
			costTime = endTime1 - startTime1;
		} finally {
			if (cluster != null)
				cluster.close();
		}
//		System.out.println("此次查询消耗时间[" + costTime / 1000 + "]s");
		return Status.OK(costTime);
	}
 
开发者ID:dbiir,项目名称:ts-benchmark,代码行数:23,代码来源:CassandraDB.java

示例6: selectAvgByDeviceAndSensor

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@Override
	public Status selectAvgByDeviceAndSensor(String deviceCode, String sensorCode, Date startTime, Date endTime) {
		long costTime = 0L;
		Cluster cluster = null;
		try {
			cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build();
			Session session = cluster.connect(KEY_SPACE_NAME);
			String selectCql = "SELECT AVG(value) FROM point WHERE device_code='" + deviceCode + "' and sensor_code='"
					+ sensorCode + "' and timestamp>=" + startTime.getTime() + " and timestamp<=" + endTime.getTime()
					+ " ALLOW FILTERING";
//			System.out.println(selectCql);
			long startTime1 = System.nanoTime();
			ResultSet rs = session.execute(selectCql);
			long endTime1 = System.nanoTime();
			costTime = endTime1 - startTime1;
		} finally {
			if (cluster != null)
				cluster.close();
		}
//		System.out.println("此次查询消耗时间[" + costTime / 1000 + "]s");
		return Status.OK(costTime);
	}
 
开发者ID:dbiir,项目名称:ts-benchmark,代码行数:23,代码来源:CassandraDB.java

示例7: selectCountByDeviceAndSensor

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@Override
	public Status selectCountByDeviceAndSensor(String deviceCode, String sensorCode, Date startTime, Date endTime) {
		long costTime = 0L;
		Cluster cluster = null;
		try {
			cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build();
			Session session = cluster.connect(KEY_SPACE_NAME);
			String selectCql = "SELECT COUNT(*) FROM point WHERE device_code='" + deviceCode + "' and sensor_code='"
					+ sensorCode + "' and timestamp>=" + startTime.getTime() + " and timestamp<=" + endTime.getTime()
					+ " ALLOW FILTERING";
//			System.out.println(selectCql);
			long startTime1 = System.nanoTime();
			ResultSet rs = session.execute(selectCql);
			long endTime1 = System.nanoTime();
			costTime = endTime1 - startTime1;
		} finally {
			if (cluster != null)
				cluster.close();
		}
//		System.out.println("此次查询消耗时间[" + costTime / 1000 + "]s");
		return Status.OK(costTime);
	}
 
开发者ID:dbiir,项目名称:ts-benchmark,代码行数:23,代码来源:CassandraDB.java

示例8: uploadPackage

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@Override
public long uploadPackage(DataPackage dataPack) {
    long time = System.currentTimeMillis();
    try {
        Session session;
        Cluster cluster;
        cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
        session = cluster.connect();
        ByteBuffer buffer = ByteBuffer.wrap(dataPack.getData());
        Statement statement = QueryBuilder.insertInto(DATABASE, MAIN_TABLE)
                .value(COL_ID, time)
                .value(COL_DATA, buffer)
                .value(COL_DESC, dataPack.getDescription());
        session.execute(statement);
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }
    return time;
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:20,代码来源:CassandraManager.java

示例9: downloadPackage

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@Override
public DataPackage downloadPackage(long packageID) {
    DataPackage dataPack = new DataPackage();
    try {
        Session session;
        Cluster cluster;
        cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
        session = cluster.connect();
        Statement statement = QueryBuilder.select()
                .all()
                .from(DATABASE, MAIN_TABLE)
                .where(eq(COL_ID, packageID));
        ResultSet results = session.execute(statement);
        for(Row row : results) {
            dataPack.setId(row.getLong(COL_ID));
            dataPack.setDescription(row.getString(COL_DESC));
            dataPack.setData(row.getBytes(COL_DATA).array());
        }
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }
    return dataPack;
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:24,代码来源:CassandraManager.java

示例10: listPackages

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@Override
public List<DataPackage> listPackages() {
    List<DataPackage> dataPacks = new ArrayList<>();
    try {
        Session session;
        Cluster cluster;
        cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
        session = cluster.connect();
        Statement statement = QueryBuilder.select()
                .all()
                .from(DATABASE, MAIN_TABLE);
        ResultSet results = session.execute(statement);
        for(Row row : results) {
            DataPackage dataPack = new DataPackage();
            dataPack.setId(row.getLong(COL_ID));
            dataPack.setDescription(row.getString(COL_DESC));
            dataPacks.add(dataPack);
        }
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }
    return dataPacks;
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:24,代码来源:CassandraManager.java

示例11: startServer

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@BeforeClass
public static void startServer() throws InterruptedException, TTransportException, ConfigurationException, IOException, URISyntaxException  {
    if (! started) {
        EmbeddedCassandraServerHelper.startEmbeddedCassandra(CASSANDRA_UNIT_RANDOM_PORT_YAML, CASSANDRA_TIMEOUT);
        Cluster cluster = new Cluster.Builder().addContactPoints("127.0.0.1").withPort(getNativeTransportPort()).build();
        Session session = cluster.connect();
        String createQuery = "CREATE KEYSPACE " + CASSANDRA_UNIT_KEYSPACE + " WITH replication={'class' : 'SimpleStrategy', 'replication_factor':1}";
        session.execute(createQuery);
        String useKeyspaceQuery = "USE " + CASSANDRA_UNIT_KEYSPACE;
        session.execute(useKeyspaceQuery);
        CQLDataLoader dataLoader = new CQLDataLoader(session);
        applyScripts(dataLoader, "config/cql/changelog/", "*.cql");
        started = true;
    }
}
 
开发者ID:xm-online,项目名称:xm-ms-timeline,代码行数:16,代码来源:AbstractCassandraTest.java

示例12: check

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@Override
protected Result check() throws Exception {
	Cluster cassandraClient = null;
	Session cassandraSession = null;

	try {
		cassandraClient = createCassandraClient();
		cassandraSession = cassandraClient.connect(keySpace);
		cassandraSession.execute(query);
	} catch (Exception e) {
		Exception wrappedException = wrapException(e);
		logger.error("Cassandra Healthcheck Failure", wrappedException);
		return Result.unhealthy(wrappedException);
	} finally {
		closeSessionQuietly(cassandraSession);
		closeClusterQuietly(cassandraClient);
	}

	return Result.healthy();
}
 
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:21,代码来源:CassandraHealthCheck.java

示例13: create

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
/**
 * Creates a session and ensures schema if configured. Closes the cluster and session if any
 * exception occurred.
 */
@Override public Session create(Cassandra3Storage cassandra) {
  Closer closer = Closer.create();
  try {
    Cluster cluster = closer.register(buildCluster(cassandra));
    cluster.register(new QueryLogger.Builder().build());
    Session session;
    if (cassandra.ensureSchema) {
      session = closer.register(cluster.connect());
      Schema.ensureExists(cassandra.keyspace, session);
      session.execute("USE " + cassandra.keyspace);
    } else {
      session = cluster.connect(cassandra.keyspace);
    }

    initializeUDTs(session);

    return session;
  } catch (RuntimeException e) {
    try {
      closer.close();
    } catch (IOException ignored) {
    }
    throw e;
  }
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:30,代码来源:DefaultSessionFactory.java

示例14: create

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
/**
 * Creates a session and ensures schema if configured. Closes the cluster and session if any
 * exception occurred.
 */
@Override public Session create(CassandraStorage cassandra) {
  Closer closer = Closer.create();
  try {
    Cluster cluster = closer.register(buildCluster(cassandra));
    cluster.register(new QueryLogger.Builder().build());
    if (cassandra.ensureSchema) {
      Session session = closer.register(cluster.connect());
      Schema.ensureExists(cassandra.keyspace, session);
      session.execute("USE " + cassandra.keyspace);
      return session;
    } else {
      return cluster.connect(cassandra.keyspace);
    }
  } catch (RuntimeException e) {
    try {
      closer.close();
    } catch (IOException ignored) {
    }
    throw e;
  }
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:26,代码来源:SessionFactory.java

示例15: cleanUpDataTable

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
public static void cleanUpDataTable(IOTestPipelineOptions options) {
    Cluster cluster = null;
    Session session = null;
    try {
      cluster = getCluster(options);
      session = cluster.connect();
      session.execute("TRUNCATE TABLE " + KEYSPACE + "." + TABLE_WRITE_NAME);
    } finally {
      if (session != null) {
        session.close();
      }
      if (cluster != null) {
        cluster.close();
      }
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:17,代码来源:CassandraTestDataSet.java


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