-
Notifications
You must be signed in to change notification settings - Fork 16
Broadcasting results
Chronos provides a technology to broadcast a single Operations result to all Chronos clients.
To launch an Operation, which result has to be delivered to all Chronos clients. That means, each ChronosConnector will deliver the result to an attached GUI object, in the same relation to the lifecycle, as if it would be a not broadcast result.
To run an Operation in broadcast mode, use either runOperation(Operation, boolean)
method of ChronosConnector with the second parameter set to true
, or call runOperationBroadcast
in accessors of pre-defined GUI classes.
class MyActivity extends ChronosActivity{
private void loadWithBroadcast(){
runOperationBroadcast(new MyOperation());
}
}
class MyActivity extends Activity{
private final ChronosConnector mConnector = new ChronosConnector();
private void loadWithBroadcast(){
mConnector.runOperation(new MyOperation(), true);
}
}
Mention that you can combine broadcast and [single launch] (https://github.com/RedMadRobot/Chronos/wiki/Sinlge-launch-mode) modes, providing a String tag
parameter to the methods. There is no difference between broadcast and non-broadcast launches in terms of "single instance" quality.
After broadcast launch is finished, the GUI element that started it, gets the result in the same way as if it would be a non-broadcast operation.
class MyActivity extends Activity{
private final ChronosConnector mConnector = new ChronosConnector();
private void loadWithBroadcast(){
mConnector.runOperation(new MyOperation(), true);
}
public void onOperationFinished(final MyOperation.Result result) {
if (result.isSuccessful()) {
showData(result.getOutput());
} else {
showDataLoadError(result.getError());
}
}
}
However, all other Chronos clients have to handle it in onBroadcastOperationFinished
method, which signature matches onOperationFinished
method, with the only exception in names.
class MyFragment extends Fragment{
public void onBroadcastOperationFinished(final MyOperation.Result result) {
if (result.isSuccessful()) {
reloadMyData();
} else {
// do nothing, rely on the operation owner responsibility to handle its errors
// but of course it's not a rule and you can implement any logic here
}
}
}
The broadcast delivery related to objects lifecycle is pretty the same as with non-broadcast results. That means, results will be delivered, and will be delivered only when objects are ready to process it – between onResume()
and onPause()
usually.