本文整理汇总了Java中com.datastax.driver.core.Cluster.close方法的典型用法代码示例。如果您正苦于以下问题:Java Cluster.close方法的具体用法?Java Cluster.close怎么用?Java Cluster.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.datastax.driver.core.Cluster
的用法示例。
在下文中一共展示了Cluster.close方法的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();
}
示例2: selectByDevice
import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@Override
public Status selectByDevice(TsPoint point, 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);
Session session = SessionManager.getSession();
String selectCql = "SELECT * FROM point WHERE device_code='" + point.getDeviceCode() + "' 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);
}
示例3: selectByDeviceAndSensor
import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@Override
public Status selectByDeviceAndSensor(TsPoint point, 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);
Session session = SessionManager.getSession();
String selectCql = "SELECT * FROM point WHERE device_code='" + point.getDeviceCode() + "' and sensor_code='"
+ point.getSensorCode() + "' 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);
}
示例4: selectMaxByDeviceAndSensor
import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@Override
public Status selectMaxByDeviceAndSensor(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);
Session session = SessionManager.getSession();
String selectCql = "SELECT MAX(value) FROM point WHERE device_code='" + deviceCode + "' and sensor_code='"
+ sensorCode + "' and timestamp>=" + startTime.getTime() + " and timestamp<=" + endTime.getTime()
+ " ALLOW FILTERING";
long startTime1 = System.nanoTime();
// System.out.println("aaa");
ResultSet rs = session.execute(selectCql);
// System.out.println("bbb");
long endTime1 = System.nanoTime();
costTime = endTime1 - startTime1;
} finally {
if (cluster != null)
cluster.close();
}
// System.out.println("此次查询消耗时间[" + costTime / 1000 + "]s");
return Status.OK(costTime);
}
示例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);
}
示例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);
}
示例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);
}
示例8: createTable
import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
private static void createTable(IOTestPipelineOptions options, String tableName) {
Cluster cluster = null;
Session session = null;
try {
cluster = getCluster(options);
session = cluster.connect();
LOG.info("Create {} keyspace if not exists", KEYSPACE);
session.execute("CREATE KEYSPACE IF NOT EXISTS " + KEYSPACE + " WITH REPLICATION = "
+ "{'class':'SimpleStrategy', 'replication_factor':3};");
session.execute("USE " + KEYSPACE);
LOG.info("Create {} table if not exists", tableName);
session.execute("CREATE TABLE IF NOT EXISTS " + tableName + "(id int, name text, PRIMARY "
+ "KEY(id))");
} finally {
if (session != null) {
session.close();
}
if (cluster != null) {
cluster.close();
}
}
}
示例9: 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();
}
}
}
示例10: 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", "Claus 2"))
.and(set("last_name", "Ibsen 2"))
.where(eq("login", "c_ibsen"));
Object response = producerTemplate.requestBodyAndHeader(null,
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();
}
示例11: init
import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@Override
public void init() {
super.init();
Properties properties = getProperties();
CASSADRA_URL = properties.getProperty(CASSADRA_URL_PROPERTY, "127.0.0.1");
SessionManager.url=CASSADRA_URL;
SessionManager.keyspaceName=KEY_SPACE_NAME;
Cluster cluster = null;
try {
// cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build();
// Session connect = cluster.connect();
Session connect = SessionManager.getRootSession();
connect.execute("CREATE KEYSPACE IF NOT EXISTS " + KEY_SPACE_NAME
+ " WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}");//FIXME 副本数
// connect.close();
// Session session = cluster.connect(KEY_SPACE_NAME);
Session session = SessionManager.getSession();
String createTableCql = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME
+ "(timestamp timestamp,device_code text,sensor_code text,value double,primary key(timestamp,device_code,sensor_code)) "
+ "WITH comment='wind test records' AND read_repair_chance = 1.0";
ResultSet rs = session.execute(createTableCql);
String createIndexCql = "CREATE INDEX IF NOT EXISTS value_index ON " + TABLE_NAME + "(value)";
session.execute(createIndexCql);
} finally {
if (cluster != null)
cluster.close();
}
}
示例12: insertMulti
import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@Override
public Status insertMulti(List<TsPoint> points) {
long costTime = 0L;
if (points != null) {
Cluster cluster = null;
try {
// cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build();
// Session session = cluster.connect(KEY_SPACE_NAME);
Session session = SessionManager.getSession();
BatchStatement batch = new BatchStatement();
PreparedStatement ps = session.prepare(
"INSERT INTO " + TABLE_NAME + "(timestamp,device_code,sensor_code,value) VALUES(?,?,?,?)");
for (TsPoint point : points) {
BoundStatement bs = ps.bind(new Date(point.getTimestamp()), point.getDeviceCode(),
point.getSensorCode(), Double.parseDouble(point.getValue().toString()));
batch.add(bs);
}
long startTime = System.nanoTime();
session.execute(batch);
long endTime = System.nanoTime();
costTime = endTime - startTime;
batch.clear();
// session.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cluster != null)
cluster.close();
}
}
// System.out.println("costTime=" + costTime);
return Status.OK(costTime);
}
示例13: updatePoints
import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@Override
public Status updatePoints(List<TsPoint> points) {
long costTime = 0L;
if (points != null) {
Cluster cluster = null;
try {
// cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build();
// Session session = cluster.connect(KEY_SPACE_NAME);
Session session = SessionManager.getSession();
BatchStatement batch = new BatchStatement();
PreparedStatement ps = session.prepare(
"UPDATE " + TABLE_NAME + " SET value=? WHERE timestamp=? and device_code=? and sensor_code=?");
for (TsPoint point : points) {
BoundStatement bs = ps.bind(Double.parseDouble(point.getValue().toString()),new Date(point.getTimestamp()), point.getDeviceCode(),
point.getSensorCode());
batch.add(bs);
}
long startTime = System.nanoTime();
session.execute(batch);
long endTime = System.nanoTime();
costTime = endTime - startTime;
batch.clear();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cluster != null)
cluster.close();
}
}
// System.out.println("此次更新消耗时间[" + costTime / 1000 + "]s");
return Status.OK(costTime);
}
示例14: before
import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@Override
protected void before() throws Throwable {
dependency.before();
Cluster cluster = Cluster.builder().addContactPoint(getHost()).withPort(getPort())
.withNettyOptions(new NettyOptions() {
@Override
public void onClusterClose(EventLoopGroup eventLoopGroup) {
eventLoopGroup.shutdownGracefully(0, 0, TimeUnit.MILLISECONDS).syncUninterruptibly();
}
}).build();
Session session = cluster.newSession();
try {
if (requiredVersion != null) {
Version cassandraReleaseVersion = CassandraVersion.getReleaseVersion(session);
if (cassandraReleaseVersion.isLessThan(requiredVersion)) {
throw new AssumptionViolatedException(
String.format("Cassandra at %s:%s runs in Version %s but we require at least %s", getHost(), getPort(),
cassandraReleaseVersion, requiredVersion));
}
}
session.execute(String.format("CREATE KEYSPACE IF NOT EXISTS %s \n"
+ "WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", keyspaceName));
} finally {
session.close();
cluster.close();
}
}
示例15: main
import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Cluster cluster = Cluster
.builder()
.addContactPoint("localhost")
.build();
session = cluster.connect();
String sql = "insert into demo.stocks (date, open, high, low, close, volume, adjclose, symbol) values (?, ?, ?, ?, ?, ?, ?, ?)";
loadStatement = session.prepare(sql);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
List<String[]> rows = readData("/home/training/Downloads/datasets/stocks.csv");
for(String[] tokens: rows) {
if(!tokens[0].startsWith("date")) {
Date date = simpleDateFormat.parse(tokens[0]);
LocalDate localDate = LocalDate.fromMillisSinceEpoch(date.getTime());
Double open = Double.valueOf(tokens[1]);
Double high= Double.valueOf(tokens[2]);
Double low= Double.valueOf(tokens[3]);
Double close= Double.valueOf(tokens[4]);
Double volume= Double.valueOf(tokens[5]);
Double adjclose = Double.valueOf(tokens[6]);
String symbol = tokens[7];
session.execute(loadStatement.bind(localDate, open, high, low, close, volume, adjclose, symbol));
}
}
session.close();
cluster.close();
}