Example #1
0
  @Override
  public CompletionStage<com.zeroc.Ice.Object.Ice_invokeResult> ice_invokeAsync(
      byte[] inEncaps, Current current) {
    boolean twoway = current.requestId > 0;
    ObjectPrx obj = current.con.createProxy(current.id);
    if (!twoway) {
      if (_startBatch) {
        _startBatch = false;
        _batchProxy = obj.ice_batchOneway();
      }
      if (_batchProxy != null) {
        obj = _batchProxy;
      }

      if (!current.facet.isEmpty()) {
        obj = obj.ice_facet(current.facet);
      }

      final com.zeroc.Ice.Object.Ice_invokeResult success =
          new com.zeroc.Ice.Object.Ice_invokeResult(true, new byte[0]);

      if (_batchProxy != null) {
        obj.ice_invoke(current.operation, current.mode, inEncaps, current.ctx);
        return CompletableFuture.completedFuture(success);
      } else {
        final CompletableFuture<com.zeroc.Ice.Object.Ice_invokeResult> future =
            new CompletableFuture<com.zeroc.Ice.Object.Ice_invokeResult>();
        CompletableFuture<com.zeroc.Ice.Object.Ice_invokeResult> r =
            obj.ice_oneway()
                .ice_invokeAsync(current.operation, current.mode, inEncaps, current.ctx);
        com.zeroc.Ice.Util.getInvocationFuture(r)
            .whenSent(
                (sentSynchronously, ex) -> {
                  if (ex != null) {
                    future.completeExceptionally(ex);
                  } else {
                    future.complete(success);
                  }
                });
        return future;
      }
    } else {
      if (!current.facet.isEmpty()) {
        obj = obj.ice_facet(current.facet);
      }

      final CompletableFuture<com.zeroc.Ice.Object.Ice_invokeResult> future =
          new CompletableFuture<com.zeroc.Ice.Object.Ice_invokeResult>();
      obj.ice_invokeAsync(current.operation, current.mode, inEncaps, current.ctx)
          .whenComplete(
              (result, ex) -> {
                if (ex != null) {
                  future.completeExceptionally(ex);
                } else {
                  future.complete(result);
                }
              });
      return future;
    }
  }
Example #2
0
  private void sayHello() {
    if (_helloPrx == null) {
      return;
    }

    int delay = _delaySlider.getValue();
    try {
      if (!_deliveryMode.isBatch()) {
        _status.setText("Sending request");
        final DeliveryMode mode = _deliveryMode;
        java.util.concurrent.CompletableFuture<Void> f = _helloPrx.sayHelloAsync(delay);
        final Holder<Boolean> response = new Holder<Boolean>(false);
        f.whenComplete(
            (result, ex) -> {
              if (ex == null) {
                assert (!response.value);
                response.value = true;
                _status.setText("Ready");
              } else {
                assert (!response.value);
                response.value = true;
                handleException(ex);
              }
            });
        com.zeroc.Ice.Util.getInvocationFuture(f)
            .whenSent(
                (ss, ex) -> {
                  if (ex == null) {
                    if (mode.isOneway()) {
                      _status.setText("Ready");
                    } else if (!response.value) {
                      _status.setText("Waiting for response");
                    }
                  }
                });
      } else {
        _flush.setEnabled(true);
        _helloPrx.sayHello(delay);
        _status.setText("Queued sayHello request");
      }
    } catch (com.zeroc.Ice.LocalException ex) {
      handleException(ex);
    }
  }