protected void handle(CQLStatement statement) {
    final Timer asyncExecTimer =
        Metrics.defaultRegistry().newTimer(StatementIteratorConsumer.class, "asyncExec");
    final TimerContext asyncExecTimerContext = asyncExecTimer.time();
    final long startTime = System.nanoTime();
    ResultSetFuture future = this.cqlExecutor.executeAsync(statement);
    futures.add(future);
    Futures.addCallback(
        future,
        new FutureCallback<ResultSet>() {
          @Override
          public void onSuccess(final ResultSet result) {
            Host queriedHost = result.getExecutionInfo().getQueriedHost();
            Metrics.defaultRegistry()
                .newMeter(
                    StatementIteratorConsumer.class,
                    "queriedhost." + queriedHost.getDatacenter(),
                    queriedHost.getDatacenter(),
                    TimeUnit.SECONDS)
                .mark();
            asyncExecTimerContext.stop();
            logger.debug("Async exec time {}us", (System.nanoTime() - startTime) / 1000);
            shutdownLatch.countDown();
          }

          @Override
          public void onFailure(final Throwable t) {
            asyncExecTimerContext.stop();
            logger.debug("Async failure time {}us", (System.nanoTime() - startTime) / 1000);
            executionExceptions.add(t);
            shutdownLatch.countDown();
          }
        },
        executorService);
  }
Exemplo n.º 2
0
  /** Generates the sample collections that will be used in testing */
  private static HashMap<DataType, Object> getSampleCollections() {
    HashMap<DataType, Object> sampleCollections = new HashMap<DataType, Object>();
    HashMap<DataType, Object> setAndListCollection;
    HashMap<DataType, HashMap<DataType, Object>> mapCollection;

    for (DataType.Name dataTypeName : DATA_TYPE_NON_PRIMITIVE_NAMES) {
      switch (dataTypeName) {
        case LIST:
          for (DataType typeArgument : DATA_TYPE_PRIMITIVES) {
            if (exclude(typeArgument)) continue;

            List<Object> list = new ArrayList<Object>();
            for (int i = 0; i < 5; i++) {
              list.add(SAMPLE_DATA.get(typeArgument));
            }

            setAndListCollection = new HashMap<DataType, Object>();
            setAndListCollection.put(typeArgument, list);
            sampleCollections.put(DataType.list(typeArgument), setAndListCollection);
          }
          break;
        case SET:
          for (DataType typeArgument : DATA_TYPE_PRIMITIVES) {
            if (exclude(typeArgument)) continue;

            Set<Object> set = new HashSet<Object>();
            for (int i = 0; i < 5; i++) {
              set.add(SAMPLE_DATA.get(typeArgument));
            }

            setAndListCollection = new HashMap<DataType, Object>();
            setAndListCollection.put(typeArgument, set);
            sampleCollections.put(DataType.set(typeArgument), setAndListCollection);
          }
          break;
        case MAP:
          for (DataType typeArgument1 : DATA_TYPE_PRIMITIVES) {
            if (exclude(typeArgument1)) continue;

            for (DataType typeArgument2 : DATA_TYPE_PRIMITIVES) {
              if (exclude(typeArgument2)) continue;

              HashMap<DataType, Object> map = new HashMap<DataType, Object>();
              map.put(typeArgument1, SAMPLE_DATA.get(typeArgument2));

              mapCollection = new HashMap<DataType, HashMap<DataType, Object>>();
              mapCollection.put(typeArgument1, map);
              sampleCollections.put(DataType.map(typeArgument1, typeArgument2), mapCollection);
            }
          }
          break;
        default:
          throw new RuntimeException("Missing handling of " + dataTypeName);
      }
    }

    return sampleCollections;
  }