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


Java Session.executeAsync方法代码示例

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


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

示例1: executeAdaptiveQueryAsync

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
private static ListenableFuture<ResultSet> executeAdaptiveQueryAsync(Session session, Statement statement, int fetchSize,
                                                                     int remainingAdaptations) {

    statement.setFetchSize(fetchSize);

    ResultSetFuture rawFuture = session.executeAsync(statement);

    // Lazily wrap the result set from the async result with an AdaptiveResultSet
    ListenableFuture<ResultSet> adaptiveFuture = Futures.transform(rawFuture, new Function<ResultSet, ResultSet>() {
        @Override
        public ResultSet apply(ResultSet resultSet) {
            return new AdaptiveResultSet(session, resultSet, remainingAdaptations);
        }
    });

    return Futures.withFallback(adaptiveFuture, t -> {
        if (isAdaptiveException(t) && remainingAdaptations > 0 && fetchSize > MIN_FETCH_SIZE) {
            // Try again with half the fetch size
            int reducedFetchSize = Math.max(fetchSize / 2, MIN_FETCH_SIZE);
            _log.debug("Repeating previous query with fetch size {} due to {}", reducedFetchSize, t.getMessage());
            return executeAdaptiveQueryAsync(session, statement, reducedFetchSize, remainingAdaptations - 1);
        }
        throw Throwables.propagate(t);
    });
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:26,代码来源:AdaptiveResultSet.java

示例2: execute

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
@Override
public CompletableFuture<ResponseInfo<String>> execute(RequestInfo<Void> request, Executor longRunningTaskExecutor,
                                                       ChannelHandlerContext ctx) {

    Session session = EmbeddedCassandraUtils.cassandraSession(disableCassandra);
    if (session == null) {
        throw ApiException.newBuilder()
                          .withApiErrors(SampleCoreApiError.GENERIC_SERVICE_ERROR)
                          .withExceptionMessage("Unable to get cassandra session.")
                          .build();
    }

    ResultSetFuture cassandraResultFuture = session.executeAsync(basicCassandraQuery);

    // Convert the cassandra result future to a CompletableFuture, then add a listener that turns the result of the
    //      Cassandra call into the ResponseInfo<String> we need to return. Note that we're not doing
    //      thenApplyAsync() because the work done to translate the Cassandra result to our ResponseInfo object is
    //      trivial and doesn't need it's own thread. If you had more complex logic that was time consuming (or more
    //      blocking calls) you would want to do the extra work with CompletableFuture.*Async() calls.
    return FutureConverter
        .toCompletableFuture(cassandraResultFuture)
        .thenApply(functionWithTracingAndMdc(this::buildResponseFromCassandraQueryResult, ctx));
}
 
开发者ID:Nike-Inc,项目名称:riposte-microservice-template,代码行数:24,代码来源:ExampleCassandraAsyncEndpoint.java

示例3: migrate

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
/**
 * fix nulls in the repair_run table
 */
public static void migrate(Session session) {
  LOG.warn("Removing NULLs in the repair_run table. This may take some minutes…");

  Statement getRepairSegmentsPrepStmt =
      new SimpleStatement(
              "SELECT id,segment_id,segment_state,segment_start_time,segment_end_time FROM repair_run")
          .setConsistencyLevel(ConsistencyLevel.QUORUM);

  PreparedStatement updateRepairSegmentPrepStmt = session
      .prepare("INSERT INTO repair_run (id,segment_id,segment_start_time,segment_end_time)  VALUES(?, ?, ?, ?)")
      .setConsistencyLevel(ConsistencyLevel.EACH_QUORUM);

  ResultSet resultSet = session.execute(getRepairSegmentsPrepStmt);
  int rowsRead = 0;
  for (Row row : resultSet) {
    resultSet.fetchMoreResults();
    boolean update = false;
    RepairSegment.State state = RepairSegment.State.values()[row.getInt("segment_state")];
    Date startTime = row.getTimestamp("segment_start_time");
    Date endTime = row.getTimestamp("segment_end_time");

    // startTime can only be unset if segment is NOT_STARTED
    if (RepairSegment.State.NOT_STARTED != state && null == startTime) {
      update = true;
      startTime = new Date(0);
    }

    // endTime can only be set if segment is DONE
    if (RepairSegment.State.DONE != state && null != endTime) {
      update = true;
      endTime = null;
    }

    // endTime must be set if segment is DONE
    if (RepairSegment.State.DONE == state && null == endTime) {
      update = true;
      endTime = startTime;
    }

    if (update) {
      session.executeAsync(
          updateRepairSegmentPrepStmt.bind(row.getUUID("id"), row.getUUID("segment_id"), startTime, endTime));
    }
    ++rowsRead;
    if (0 == rowsRead % 1000) {
      LOG.warn("rows read: " + rowsRead);
    }
  }

  LOG.warn("Removal of NULLs in the repair_run table completed.");
}
 
开发者ID:thelastpickle,项目名称:cassandra-reaper,代码行数:55,代码来源:Migration009.java

示例4: main

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
public static void main(String[] args) {

		Session session = Connection.connect();		
		PreparedStatement preparedStatement = session.prepare("select id, name, age from user");
		
		BoundStatement boundStatement = preparedStatement.bind();
		
		ResultSetFuture future = session.executeAsync(boundStatement);
		
		Futures.addCallback(future, new FutureCallback<ResultSet>() {
			
			@Override public void onSuccess(ResultSet result) {
				for(Row row: result) {
					System.out.printf("id: %s, name: %s, age: %d\n", row.get(0, UUID.class), row.getString(1), row.getInt(2));
				}
	        }
	 
	        @Override public void onFailure(Throwable t) {
	            System.err.println("Error while reading Cassandra version: " + t.getMessage());
	        }
			
		});
		
		
		
		Connection.close();
		
	}
 
开发者ID:abulbasar,项目名称:cassandra-java-driver-examples,代码行数:29,代码来源:AsynExecutionExample.java


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