Class Task<T>

java.lang.Object
java.util.concurrent.CompletableFuture<T>
nl.bimbase.bimworks.client.Task<T>
All Implemented Interfaces:
CompletionStage<T>, Future<T>
Direct Known Subclasses:
AddModelCheckDefinition, AddModelCheckDefinitionSet, DownloadCheckResultsAsBcfDirect, DownloadCheckResultsAsBcfInput, GetModelCheckDefinitionByName, GetModelCheckDefinitionSetByNameInput, GetModelCheckResultsTask, GetModelReportByModelCheckSetUuidTask, GetModelReportTask, ListModelCheckDefinitionsInput, ListModelCheckResultsTask, ModelChecksAvailabilityTask, RunChecksTask, RunCheckTask, RunIdsCheckTask, UpdateModelCheckDefinition

public abstract class Task<T> extends CompletableFuture<T>
A server task exposed as a CompletableFuture. Call executeAsync() to send the request; the future is completed from the transport callbacks when the response (or an error) arrives, so the full CompletableFuture API works: get(), get(long, TimeUnit), join(), CompletableFuture.isDone(), thenApply, whenComplete, etc.

Failure is reported through the future: a server error or transport failure completes the future exceptionally (typically with an ExecuteException carrying the server's error code), which get() surfaces as an ExecutionException and join() as a CompletionException. A send failure in executeAsync() completes the future immediately — it is never silently swallowed.

The blocking get() and join() do not wait forever: they are bounded by the request's own timeout (settable via setTimeOut(long, TimeUnit), with a per-task default from createRequest()), after which they fail with a TaskTimeoutException cause.

CompletableFuture.cancel(boolean) only completes this future; it does not abort the task on the server.

  • Constructor Details

  • Method Details

    • createRequest

      public nl.sascom.backplane.common.Request createRequest()
    • createRequest

      public nl.sascom.backplane.common.Request createRequest(int defaultTimeOut, TimeUnit defaultTimeUnit)
    • setTimeOut

      public void setTimeOut(long timeOutValue, TimeUnit timeOutUnit)
    • createAsyncTask

      public nl.sascom.backplane.common.ClientTask createAsyncTask(BimWorksClient bimWorksClient)
    • getRequest

      public nl.sascom.backplane.common.Request getRequest()
    • setProgressListener

      public void setProgressListener(nl.sascom.backplane.common.ProgressListener progressListener)
    • convert

      protected T convert(nl.sascom.backplane.common.Response response) throws Exception
      Converts the raw Response into this task's result type. Called once, on the thread that delivers the response. The default implementation returns the response's object output; tasks with a differently shaped result override this. Throwing here completes the future exceptionally.
      Throws:
      Exception
    • executeAsync

      public Task<T> executeAsync()
      Sends the request. Idempotent: the request is sent once, no matter how often (or from how many threads) this is called. The returned future completes when the response arrives; if sending fails, it completes exceptionally right away instead of leaving callers to run into the request timeout.
    • get

      Waits for the result, bounded by the request's own timeout. On timeout the future is failed with a TaskTimeoutException (surfaced as this method's ExecutionException cause), unless the response arrived in the meantime.
      Specified by:
      get in interface Future<T>
      Overrides:
      get in class CompletableFuture<T>
      Throws:
      InterruptedException
      ExecutionException
    • get

      public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
      Specified by:
      get in interface Future<T>
      Overrides:
      get in class CompletableFuture<T>
      Throws:
      InterruptedException
      ExecutionException
      TimeoutException
    • join

      public T join()
      Like CompletableFuture.join(), but bounded by the request's own timeout (see get()) and responsive to interrupts, which are rethrown wrapped in a CompletionException after restoring the interrupt flag.
      Overrides:
      join in class CompletableFuture<T>
    • getClientTask

      public nl.sascom.backplane.client.AsyncTask getClientTask() throws BimWorksException
      Throws:
      BimWorksException
    • getBimWorksClient

      public BimWorksClient getBimWorksClient()