Async (value of stereotype)

From JRapid

(Redirected from Async)
Jump to: navigation, search

async is a value of stereotype attribute of entity.



The Async stereotype changes the common behavior for the form submission of a JRapid entity. After the form is submitted the method store() is called synchronously and then the method storeAsync() is called asynchronously providing a way to send feedback to the user about the running process.

A new window is opened to show the messages being appended by the storeAsync() method. This provides a way of running long operations keeping the user informed of the progress.

In the storeAsync() method you may use the appendToMessage() method to add new messages that will be printed in the console shown to the user in the front end.

The storeAsync() method receives an id and a value object parameters just as the store() method for every entity, and an extra key parameter that is used by the appendToMessage() method to identify the corresponding console. See example below to learn how to use it in your code.


<entity label = LABEL name = NAME stereotype="Async">


Suppose we have a large number of invoices to process every month for our customers and we need to trigger that task using a form where we may select the month. By using the Async stereotype we may give the user feedback of the running process so that the overall progress can be followed.

A simple implementation of this could define an entity as follows.

<entity label="Massive Generate Invoice" name="MassiveGenerateInvoice" stereotype="Async" transient="transient">
        <property label="Month" name="month"/>

Then we must implement the storeAsync() method in the services class, in this case MassiveGenerateInvoiceServices. We simulate a long running process by calling a private method that waits for one second before returning.

public class MassiveGenerateInvoiceServices extends MassiveGenerateInvoiceServicesAbstract {
	public void storeAsync(String id, MassiveGenerateInvoice vo, Long key) {
		appendToMessage(key, "Starting to process invoices for " + vo.getMonth());
		for(int i=0; i < 20; i++) {
			appendToMessage(key, "Processed Invoice Group " + i);
	private void processInvoiceGroup(int group) {
		/* Do something */ 
		try {
		} catch (InterruptedException e) {

Once the month is entered and the form submitted, the console window opens and the messages are appended there.

Async example

Methods inherited

As explained for stereotype, specifying one will make the target entity's class extend a class that will provide methods to address the specific functionality.

These are the methods provided by the Async stereotype:

  • void storeAsync(String id, T vo, Long key): id and vo (value object) are the same as for the store method generated for every entity. The key parameter is used for linking the current running process with the corresponding front end console and must be used when calling the appendToMessage method.
  • void appendToMessage(Long key, String value): key is the identifier for the process and value is the string message to be appended to the console.

See also

Personal tools