/**
   * Perform asynchronous remote call via future.
   *
   * <p>With ECF >=3.3 remote services, when a proxy is created, if an interface class with the name
   * [fq service interface name]Async can be loaded and it extends IAsyncRemoteServiceProxy then the
   * proxy will implement that interface.
   *
   * @param svcproxy
   */
  private void asyncInvokeSvcFuture(IHello svcproxy) {
    // Provided that the IHelloAsync interface was available during proxy
    // creation, the created service proxy shall implement it.
    if (svcproxy instanceof IHelloAsync) {
      System.out.println("ENTERED ASYNCHRONOUS REMOTE CALL VIA FUTURE");

      IHelloAsync helloAsync = (IHelloAsync) svcproxy;

      // Call asynchronously with future
      System.out.println("Initiating invocation of remote call via future...");
      IFuture helloAsyncFuture =
          helloAsync.helloAsync(CLASSNAME + " using an asynchronous remote call via future.");
      System.out.println("Completed invocation of remote call via future." + "\n");
      try {
        while (!helloAsyncFuture.isDone()) {
          // Dummy blocking to demonstrate client executing background
          // logic while waiting for service response
          System.out.println("Waiting for remote service response via future...");
          sleep();
        }
        // Once the remote service has replied the future is filled and
        // the
        // response shall be processed
        Object response = helloAsyncFuture.get();
        System.out.println(
            "Successfully received remote service response via future: " + response + "\n");
      } catch (OperationCanceledException e) {
        System.out.println(
            "Received operation cancel in remote service response via future: " + e + "\n");
        e.printStackTrace();
      } catch (InterruptedException e) {
        System.out.println(
            "Interrupted operation in remote service response via future: " + e + "\n");
        e.printStackTrace();
      }
      System.out.println("EXITING ASYNCHRONOUS REMOTE CALL VIA FUTURE" + "\n");
    } else {
      System.err.println("ASYNCHRONOUS REMOTE CALL VIA FUTURE NOT EXECUTED" + "\n");
    }
  }
  /**
   * Perform asynchronous remote call via Future derived from proxy.
   *
   * <p>Non-blocking remote service invocation storing the result inside a Future placeholder.
   *
   * @param remotesvc
   */
  private void asyncInvokeRemoteSvc(IHello svcproxy) {
    System.out.println("ENTERED REMOTE CALL VIA FUTURE");
    IRemoteService remotesvc;
    try {
      // Retrieve the remote service instance from the proxy
      remotesvc = ((IRemoteServiceProxy) svcproxy).getRemoteService();
    } catch (Exception e) {
      e.printStackTrace();
      System.err.println(
          "EXITING REMOTE CALL VIA FUTURE DUE TO EXCEPTION UPON CREATION OF IRemoteService" + "\n");
      return;
    }

    System.out.println("Initiating invocation of remote call via future...");
    IFuture remotesvcFuture =
        RemoteServiceHelper.futureExec(
            remotesvc,
            "hello",
            new Object[] {CLASSNAME + " using an asynchronous remote call via future."});
    System.out.println(
        "Completed invocation of remote call via future. Check service host for details." + "\n");
    try {
      while (!remotesvcFuture.isDone()) {
        // Dummy blocking to demonstrate client executing background
        // logic while waiting for service response
        System.out.println("Waiting for remote service response via future...");
        sleep();
      }
      // Once the remote service has replied the future is filled and the
      // response shall be processed
      Object response = remotesvcFuture.get();
      System.out.println(
          "Successfully received remote service response via future: " + response + "\n");
    } catch (Exception e) {
      e.printStackTrace();
      System.err.println("EXITING REMOTE CALL VIA FUTURE DUE TO EXCEPTION" + "\n");
    }
    System.out.println("EXITING REMOTE CALL VIA FUTURE" + "\n");
  }
  private void refreshInput() {
    if (service != null) {
      try {
        if (service instanceof IKundenServiceAsync) {
          final IKundenServiceAsync serviceAsync = (IKundenServiceAsync) service;
          final IFuture kunden = serviceAsync.listKundenAsync();
          try {
            // do something else here before kunden gets used
            // doSomeHeavyComputation();

            if (kunden.isDone()) {
              setInput((Kunde[]) kunden.get());
            }

            // do again something else first
            // doAnotherHeavyComputation();

            if (kunden.isDone()) {
              setInput((Kunde[]) kunden.get());
            }

            // finally wait for 1000ms to set the input and fail otherwise
            setInput((Kunde[]) kunden.get(1000));
          } catch (OperationCanceledException e) {
            // TODO handle e somehow, but how?
            e.printStackTrace();
          } catch (InterruptedException e) {
            // TODO handle e somehow, but how?
            e.printStackTrace();
          } catch (TimeoutException e) {
            // TODO handle e somehow, but how?
            e.printStackTrace();
          }
        } else {
          setInput(service.listKunden());
        }
      } catch (ServiceException e) {
        e.printStackTrace();
      }
    } else {
      setInput(new Kunde[0]);
    }
  }