Asynchronous Operations Support
For defining an asynchronous operation, you should return an instance of com.tibco.tea.agent.api.SettableFuture.
SettableFuture is a custom Future object which the TIBCO Enterprise Administrator agent library uses for tracking asynchronous operations.
For example,
public SettableFuture<Response> startProcess { SettableFuture<Response> future = SettableFutureFactory.create(); // pass future to the code which will handle the operation execution return future; }
Where,
- startProcess is an asynchronous operation which has to return an object of type Response. To use the asynchronous support provided by the TIBCO Enterprise Administrator agent library, startProcess sets the return type as SettableFuture<Response>.
- startProcess will start by creating an instance of SettableFuture using the SettableFutureFactory.
- The SettableFuture instance is passed to the code which handles the operation execution. For example, the SettableFuture instance might be passed on to an instance of a class which implements java.lang.Runnable and that instance is passed to an instance of java.util.concurrent.Executor. Hence the starting of the process is handled by a thread pool.
- Finally, the instance of SettableFuture is returned to the TIBCO Enterprise Administrator agent library. The TIBCO Enterprise Administrator agent library tracks the asynchronous operation by following this instance.
Using SettableFuture instance to set the progress
You can also use the instance of SettableFuture for setting the progress, progress status, and returning the object. For example,
// inside the code handling operation execution future.setProgressStatus("Connecting to host to start the process"); // ... future.setProgress(25); future.setProgressStatus("Spawning the process"); // ... future.setProgress(50); future.setProgressStatus("Waiting for the process to come up"); // ... future.setProgress(100); future.set(response);
Where,
- SettableFuture.setProgressStatus()is used to update the message which is displayed to the user to indicate the status of the asynchronous operation.
- SettableFuture.setProgress() is used to update the percentage of work that is completed so far. This number should be between 0 and 100.
- SettableFuture.set() is used for setting the response object which is returned to the TIBCO Enterprise Administrator server. This indicates the completion of the asynchronous operation.
Using SettableFuture instance for exception
You can also use the instance of SettableFuture in case of an exception.
// inside the code handling operation execution future.setException(ex);
Where, SettableFuture.setException() should be used for setting the exception object that is returned to the TIBCO Enterprise Administrator server. This indicates the completion of the asynchronous operation.
Copyright © Cloud Software Group, Inc. All Rights Reserved.