Process configurable action
A Service Object is a JRebirth Component (part of CSM pattern, Command-Service-Model).
It can be retrieved from the ServiceFacade.
A Service can hold several Tasks defined by a WaveType. Each Task requires:
That's all ! You don't have to bother about threading issues and asynchronous tasks.
You must pay attention to the lifecycle of your service instance. As a JRebirth Component, each service object is eligible to garbage collection if it isn't retained by another object currently used.
So your data stored or processed into your service can be loss if you didn't manage correctly your Service life.
The most easy way is to hold your service with a strong reference into a long-living object like a top-levelModel.
Short UML Diagram:
This is the
used to process a Wave generated anywhere into the application.
This WaveType uses only one WaveItem to store the file that must be loaded. WaveItem wrap the type of the object we want to use, thus it's possible to check that API contract isn't broken.
The return Wave Type is automatically created with by the using the returnAction value with returnItem as WaveItem. The code above will generate a WaveType that uses only one WaveItem to store the list of events loaded from the given file.
Each Task requires to be registered in order to generate the right WaveType that wrap the return
This registration must be done into the JRebirth's Component void initService() method like this:
If you don't declare the return WaveType a exception will be thrown at runtime when trying to send back the Service Task output.
If your Service Task doesn't return anything (void return) you can dismiss this step except if you want to receive an empty notification when the Job is done; just use JRebirthItems.voidItem.
To call this Service Feature, you can use the returnData from any JRebirth's Component. It takes at least 2 mandatory arguments:
Hereafter you will fin an example of service call with only one arguments passed:
The Service Feature Result is sent as a Wave that wrap returned value. So to be informed when the result is available, there is two things to do :
Each JRebirth's Component are able to listen some WaveType's waves by calling the
method with one or several Wave Types.
This call must be done into one of the following method according to component used:
Each initXXX method is called into JRebirth Internal Thread by ready method.
Add a method that suit the WaveType convention.
The name must used the predefined prefix (in our case DO_ converted to do), then the WaveType's name converted in a camel cased format.
Method parameters must be compliant with Wave Items defined into the Wave Type.
A final parameter must be added, the Wave itself taht could be useful to get extra data, for example when chained waves are used.
All communications with Service Component is done into JIT and all Service Tasks are performed into one slot of JTP or HPTP according to priority defined with annotation.
Each Service feature call will be processed by the
(JRebirth Thread Pool) or by the
(High Priority Thread Pool) according to their predefined priority.
By default the Priority is set to RunnablePriority.Low (a level below Normal) to let other task to be performed into JTP before Service feature calls (like Command).
Its possible to increase or decrease this value by adding an annotation on the Service Feature method like this:
Each Service Task are able to update a progress bar with integer value and message.
In both cases you must provide the wave provided as a method argument, it will be used to link the
and find the right
widgets to update.
You can update the message test by calling this method:
You can update progress bar indicator by calling this method: