當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。