Пример #1
0
  @Override
  public synchronized Channel write(File file) {
    try {
      FileInputStream stream = new FileInputStream(file);
      FileChannel fileChannel = stream.getChannel();
      output.append(fileChannel);
      stream.close();
    } catch (IOException e) {
      throw U.rte(e);
    }

    return this;
  }
Пример #2
0
  protected String get(String url) {
    try {
      CloseableHttpClient client = HttpClientBuilder.create().disableAutomaticRetries().build();

      HttpGet get = new HttpGet(localhost(url));

      CloseableHttpResponse result = client.execute(get);

      eq(result.getStatusLine().getStatusCode(), 200);

      InputStream resp = result.getEntity().getContent();

      return IOUtils.toString(resp, "UTF-8");
    } catch (Throwable e) {
      throw U.rte(e);
    }
  }
Пример #3
0
  protected byte[] getBytes(String url) {
    try {
      CloseableHttpClient client = HttpClientBuilder.create().disableAutomaticRetries().build();

      HttpGet get = new HttpGet(localhost(url));

      CloseableHttpResponse result = client.execute(get);

      Assert.assertEquals(200, result.getStatusLine().getStatusCode());

      InputStream resp = result.getEntity().getContent();

      return IOUtils.toByteArray(resp);
    } catch (Throwable e) {
      throw U.rte(e);
    }
  }
Пример #4
0
  /**
   * ACID transactional semantics:<br>
   * - Atomicity with automatic rollback in case of exception,<br>
   * - Consistency - only with constraints enforced programmatically inside transaction,<br>
   * - Isolation is serializable (with global lock),<br>
   * - Durability through on-commit callbacks.<br>
   */
  public void transaction(Runnable transaction, boolean readOnly, Callback<Void> txCallback) {
    globalLock();

    data.txIdCounter.set(data.ids.get());
    data.txChanges.clear();
    data.txInsertions.clear();
    data.txReadonly.set(readOnly);
    data.insideTx.set(true);

    boolean success = false;
    try {
      transaction.run();
      success = true;

    } catch (Throwable e) {
      if (SuccessException.isSuccess(e)) {
        success = true;
        throw U.rte(e);
      } else {
        Log.error("Error in transaction, rolling back", e);
        txRollback();
        if (txCallback != null) {
          txCallback.onDone(null, e);
          txCallback = null;
        }
      }

    } finally {
      data.txChanges.clear();
      data.txInsertions.clear();
      data.insideTx.set(false);

      if (persistor != null) {
        if (success && txCallback != null) {
          data.txCallbacks.add(txCallback);
        }
      } else {
        if (success && txCallback != null) {
          txCallback.onDone(null, null);
        }
      }

      globalUnlock();
    }
  }