What Design-Pattern would be intelligent in which following Components(simplified) exists:
3 Components
- GUI
- Data fetcher
- Database
I have no Access to the Server in the Internet, its just a Data-Source. The Data which lays in the Internet is always the newer one, the local-Database is just a copy(cache) of the one in the Internet. The GUI can request and update of the local cache, the Service-like-component fetches then asynchronously the newest data, which could take awhile. The GUI shows only Data from the local Database, which he can fetch synchronously.
So my Question is, what classes would you use for the maybe longterm running Service with Progressbar capabilities ? Are there better Designs for this kind of "problem"? Are there better practices?
Microservices, aka microservice architecture, is an architectural style that structures an application as a collection of small autonomous services, modeled around a business domain. In a Microservice Architecture, each service is self-contained and implements a single business capability.
Strangler The strangler design pattern is a popular design pattern to incrementally transform your monolithic application to microservices by replacing old functionality with a new service.
The most vital design pattern in Microservice Architecture is the Database per Microservice. Implementing this design pattern is challenging and needs several other closely related design patterns (Event Sourcing, CQRS, Saga).
When it comes to microservices, there are two main types of service discovery patterns: client-side discovery and server-side discovery.
On the Service Like Component:
jobId
to indicate a job that is being processed in the backgroundjobId
. The implementation of this service could return a status, percentCompleted or any other relevant info that will tell the caller the current status of the update process. The implementation of this method needs to be able to report an incremental progress (such as reporting the incremental store in the local storage) in order to make an accurate progress bar, otherwise the best the UI could do is show the spinning progress bar.
AsyncTask
usage which execute update in the background and report to the user when it is finished. If this operation might take a while, you could implement the completion of the update via Android notification bar or push notification. Assuming you have the interface to get the progress of the update, you could utilize the AsyncTask onProgressUpdate to report the progress of the update. The method is specifically designed for that.
Your steps are roughly as follow:
onProgressUpdate
. The AsyncTask roughly looks like
public class GetUpdateStatusAsyncTask extends AsyncTask {
protected Integer doInBackground(Integer... param) {
// this is the jobId that you get from the previous AsyncTask that you use to kick off the
// the update process
int jobId = param[0];
double percentCompleted = fetchStatus(jobId);
while(percentCompleted != 100.00) {
publishProgress(percentCompleted);
}
// return status code
return 1;
}
protected void onProgressUpdate(Double... progress) {
// set the progressBar here
}
protected void onPostExecute(Long result) {
// done, handle status code
}
private double fetchStatus(int jobId) {
double percentCompleted = 0.0;
// call interface to get the update based on the jobId
// return percentCompleted status or make a more complex object if you need
// more detail info
return percentCompleted;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With