Command-Based Architecture
Process concurrent tasks on data sources
Command Based Architecture for Android
Process concurrent tasks on data sources
Features
This is an Android Command Based Architecture for processing concurrent tasks (commands) on single or multiple data sources. This library supports the execution and synchronization of different tasks on multiple threads.
Key features in flow control:
- Ability to control if a task should be executed or skipped based on current data (screen) state.
- Ability to control if a task should be executed immediately or delayed based on current data (screen) state.
- Ability to block/postpone other tasks during task execution.
Key features in data change: Each task has its own lifecycle:
- After command was added to the queue -
onCommandWasAdded
- Immediately before command execution -
onExecuteStarting
- Immediately after successful execution -
onExecuteSuccess
- Immediately after failed execution -
onExecuteFail
- Final step of execution (called on any success or fail) -
onExecuteFinished
Integration with Gradle
For coroutine implementation:
implementation 'io.scal:commandbasedarchitecture_coroutine:version'
Please replace version
with the latest version:
For RxJava implementation:
implementation 'io.scal:commandbasedarchitecture_rxjava:version'
Please replace version
with the latest version:
How to use
Please find the full description in the post.
Basic Setup:
- Create an instance of CommandManager:
val commandManager: CommandManager<ScreenState> by lazy { CommandManagerImpl(mutableScreenState, viewModelScope) }
- Use an existing or create a custom command (RefreshCommand, LoadNextCommand). a. Implement execution strategy directly in the command (ExecutionStrategy class) b. Implement data side effects during command lifecycle
- Add command to execution queue by calling
commandManager.postCommand(yourCommand)
By default, the CommandManager uses Dispatchers.Main
for execution, so you will need to switch to an appropriate Dispatcher if you require more complex logic.
Customizations
TBD
Example
Contact
Feel free to reach out to me.
Website: https://scal.io LinkedIn: https://www.linkedin.com/company/scalio/ LinkedIn: https://www.linkedin.com/in/mig35/ Email: [email protected] Email: [email protected]
License
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.