Exemplo n.º 1
0
  /**
   * Sends the planner metrics to the metrics server
   *
   * @param metrics the metrics to log
   * @param url the url to send the metrics to
   */
  private void sendMetricsSynchronously(PlannerMetrics metrics, String url) throws IOException {

    SendMetrics sm = new SendMetrics(metrics, url);

    SendMetricsResult result = sm.call();

    if (result.getCode() == 202) {
      mLogger.log("Metrics succesfully sent to the server", LogManager.DEBUG_MESSAGE_LEVEL);
    } else {
      mLogger.log("Unable to send metrics to the server " + result, LogManager.DEBUG_MESSAGE_LEVEL);
    }
  }
Exemplo n.º 2
0
  /**
   * Sends the planner metrics to the metrics server asynchrnously with a timeout of 5 seconds
   *
   * @param metrics the metrics to log
   * @param url the url to send the metrics to
   */
  private void sendMetricsAsynchronously(PlannerMetrics metrics, String url) {

    ExecutorService executor = Executors.newSingleThreadExecutor();
    //      Future<SendMetricsResult> future =   (Future<SendMetricsResult>) executor.submit(
    //                                                           new FutureTask<SendMetricsResult>(
    // new SendMetrics( metrics, url ) ));

    Future<SendMetricsResult> future =
        (Future<SendMetricsResult>) executor.submit(new SendMetrics(metrics, url));

    SendMetricsResult result = null;
    try {
      result = future.get(METRICS_SEND_TIMEOUT, TimeUnit.SECONDS);

    } catch (InterruptedException ex) {
      mLogger.log("Interrupted while sending metrics " + url, ex, LogManager.DEBUG_MESSAGE_LEVEL);
    } catch (ExecutionException ex) {
      mLogger.log(
          "Exception caught while sending metrics to server " + url,
          ex,
          LogManager.DEBUG_MESSAGE_LEVEL);
    } catch (TimeoutException e) {
      mLogger.log(
          "Sending of metrics to server timed out " + url, e, LogManager.DEBUG_MESSAGE_LEVEL);
    } finally {
      executor.shutdownNow();
    }

    if (result != null) {
      if (result.getCode() == 202) {
        mLogger.log("Metrics succesfully sent to the server", LogManager.DEBUG_MESSAGE_LEVEL);
      } else {
        mLogger.log(
            "Unable to send metrics to the server " + result, LogManager.DEBUG_MESSAGE_LEVEL);
      }
    }
  }