Async Workers and Worker managers for Android

Overview

Android-Zorn

Asynchronous Workers and Worker Managers for Android.

Android Arsenal

How to use

simply fork or download the project, you can also download and create .aar file yourself.

Notable Features

  • use Worker API as a replacement for AsyncTask
  • workers run on background threads and return callbacks on the main(calling) thread.
  • automate a batch of workers with two worker managers:
    • PriorityWorkerManager - workers are processed according to their priority both serially or unbounded.
    • TopologicalWorkerManager - workers are processed according to a binary topological relation and order.

Using a Worker

1. Simply anonymously instantiate AbstractWorker

AbstractWorker worker = new AbstractWorker() {
    @Override
    protected void onProgress() {
        // runs on the calling/main thread
    }

    @Override
    protected void onComplete() {
        // runs on the calling/main thread
    }

    @Override
    public void work() {
        // here you put work to be done in a background thread
    }
};

// run async
worker.process();

2. Simply extend AbstractWorker

MyWorker worker = new MyWorker();

worker.process(new WorkerObserver() {
    @Override
    public void onWorkerComplete(IWorker worker) {
        // runs on the calling/main thread
    }

    @Override
    public void onWorkerProgress(IWorker worker) {
        // runs on the calling/main thread
    }

    @Override
    public void onWorkerError(IWorker worker) {
        // runs on the calling/main thread
    }
});

3. use SimpleWorker with a IWork object (like Runnable)

SimpleWorker sw = new SimpleWorker(new IWork() {
    @Override
    public void work() {
        // here you put work to be done in a background thread
    }
});

sw.process();

notes

  • IWorker.process(..) method also have an overloaded version where one can pass ExecutorService
  • IWorker supports many more methods and ideas. I did not go through all.
  • in the future, I will add support for Java native FutureTask and Callable so worker can have cancelling feature.

Using a Worker Manager

Worker managers support a lot of functionality such as pause, start, stop etc.. You can also implement a Worker manager using BaseAbstractWorkerManager, it is very easy. Contributions of new Worker managers are most welcome.

Priority Worker Manager.

pm = new PriorityWorkerManager("myId");
// serial mode
pm.setExecutionMode(AbstractWorkerManager.EXECUTION_MODE.SERIAL);

IWorker worker = null;
String  id;
int     priority;

for(int ix = 0; ix < 20; ix++) {
    id        = String.valueOf(ix);
    priority  = ix;
    
    worker    = new TestWorker(id, priority);

    pm.enqueue(worker);
}

pm.setListener(new WorkerManagerObserver() {
    @Override
    public void onComplete(IWorkerManager wm) {
        // runs on the calling/main thread
    }

    @Override
    public void onProgress(String id) {
        // runs on the calling/main thread
    }

    @Override
    public void onError(WorkerManagerErrorInfo err) {
        // runs on the calling/main thread
    }
});

pm.start();

Topological Worker Manager.

Use the TopologicalWorkerManager.Builder or Zorn.newTopologicalWorkerManager() to create a worker manager that takes into account a directed binary relation among workers.

TestWorker a1 = new TestWorker("a1");
TestWorker a2 = new TestWorker("a2");
TestWorker a3 = new TestWorker("a3");
TestWorker a4 = new TestWorker("a4");
TestWorker a5 = new TestWorker("a5");

TopologicalWorkerManager tm = new TopologicalWorkerManager.Builder().id("topological_test")
                                                          .listener(this)
                                                          .before(a1, a3)
                                                          .before(a2, a3)
                                                          .after(a4, a3)
                                                          .after(a5, a4)
                                                          .build();
                                                          
tm.setListener(...);

tm.start();                                                          

Dependencies

Terms

Contact Author

You might also like...
[] Easy async loading for Android's ListView/GridView

NOTE: Smoothie's API is not final yet. Although the library is fairly funcional, this is still beta-quality code. Do not rely on it for production cod

[Deprecated] Sexy way to execute async/background tasks on Android

Groundy library for Android @Deprecated Unfortunatenly this library is no longer maintained, we encourage you to use other widely supported solutions

async/await for Android built upon coroutines introduced in Kotlin 1.1

Async/Await A Kotlin library for Android to write asynchronous code in a simpler and more reliable way using async/await approach, like: async { pr

Async file downloader for Android
Async file downloader for Android

What is FileBox FileBox is an async file downloader library for Android. Before we develop filebox, we though that URL content changes very rarely. So

AsyncSport - AsyncSports Async sports is very simple application that shows athletes video feeds
AsyncSport - AsyncSports Async sports is very simple application that shows athletes video feeds

AsyncLabs Interview Solution 👀 Writing AsyncLabs Interview Solution App using A

A Kotlin Multiplayform I/O library (buffers, async streams).

kio A Kotlin Multiplatform IO library that supports the JS (node only), JVM, and Native targets. Dependency Kio releases are published to Maven Centra

RX-based async paradigm, Room, DI (Hilt), Retrofit, MVVM, Jetpack, Lottie, Transitions
RX-based async paradigm, Room, DI (Hilt), Retrofit, MVVM, Jetpack, Lottie, Transitions

CatBreedsApp RxJava, Room, DI (Hilt), Jetpack, Shared element transition. clean MVVM architecture, Retrofit Cats need your help, we want to build an a

FixedHeaderTableLayout is a powerful Android library for displaying complex data structures and rendering tabular data composed of rows, columns and cells with scrolling and zooming features. FixedHeaderTableLayout is similar in construction and use as to Android's TableLayout
FixedHeaderTableLayout is a powerful Android library for displaying complex data structures and rendering tabular data composed of rows, columns and cells with scrolling and zooming features. FixedHeaderTableLayout is similar in construction and use as to Android's TableLayout

FixedHeaderTableLayout is a powerful Android library for displaying complex data structures and rendering tabular data composed of rows, columns and cells with scrolling and zooming features. FixedHeaderTableLayout is similar in construction and use as to Android's TableLayout

The idea of ResideMenu is from Dribbble 1 and 2. It has come true and run in iOS devices. iOS ResideMenu This project is the RefsideMenu Android version. The visual effect is partly referred to iOS version of ResideMenu. And thanks to the authors for the above idea and contribution. Healthify - An app to track your daily water intake and sleep and boost your work efficiency. Healthify is built using Kotlin and follows all modern android Development practices and hence is a good learning resource for beginners
Healthify - An app to track your daily water intake and sleep and boost your work efficiency. Healthify is built using Kotlin and follows all modern android Development practices and hence is a good learning resource for beginners

Healthify Healthify is an app to track your daily water intake and sleep and boost your work efficiency. Video Introduction 📹 This is a small introdu

Big image viewer supporting pan and zoom, with very little memory usage and full featured image loading choices. Powered by Subsampling Scale Image View, Fresco, Glide, and Picasso. Even with gif and webp support! 🍻
Big image viewer supporting pan and zoom, with very little memory usage and full featured image loading choices. Powered by Subsampling Scale Image View, Fresco, Glide, and Picasso. Even with gif and webp support! 🍻

BigImageViewer Big image viewer supporting pan and zoom, with very little memory usage and full featured image loading choices. Powered by Subsampling

****. Use the native and support library variants instead - https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml.html. An android library that makes it easy to add custom fonts to edittexts and textviews

Add to your project Add this line to your dependencies in build.gradle compile 'in.workarounds.typography:typography:0.0.8' Using the views There are

A cli tool that helps signing and zip aligning single or multiple Android application packages (APKs) with either debug or provided release certificates. It supports v1, v2 and v3 Android signing scheme has an embedded debug keystore and auto verifies after signing.
AndroidQuery is an Android ORM for SQLite and ContentProvider which focuses on easy of use and performances thanks to annotation processing and code generation

WARNING: now that Room is out, I no longer maintain that library. If you need a library to easy access to default android ContentProvider, I would may

A multi platform image density converting tool converting single or batches of images to Android, iOS, Windows or CSS specific formats and density versions given the source scale factor or width/height in dp. It has a graphical and command line interface and supports many image types (svg, psd, 9-patch, etc.) aswell as some lossless compressors like pngcrush. A layout engine for Android that decouples layouts from the View containers that manage scrolling and view recycling. FreeFlow makes it really easy to create custom layouts and beautiful transition animations as data and layouts change Taskify - An app to manage your daily tasks and boost your productivity. Taskify is built using kotlin and follows all modern android Development practices and hence is a good learning resource for beginners
Taskify - An app to manage your daily tasks and boost your productivity. Taskify is built using kotlin and follows all modern android Development practices and hence is a good learning resource for beginners

Taskify Taskify is an app to manage your daily tasks and boost your productivity Video Introduction 📹 This is a small introduction video about Taskif

Monitoring water tanker level using NodeMCU ESP8266 and HC-SR04P Ultrasonic Sensor and broadcasting it using a simple HTTP server inside NodeMCU ESP8266 and show data in an Android App
Monitoring water tanker level using NodeMCU ESP8266 and HC-SR04P Ultrasonic Sensor and broadcasting it using a simple HTTP server inside NodeMCU ESP8266 and show data in an Android App

WaterLevel Preface This project aims to finding a tanker water level using NodeMCU with ESP8266 core and HC-SR04P Ultrasonic sensor and broadcasting i

A counter down timer for android which supports both dark and light mode and Persian text and digit.
A counter down timer for android which supports both dark and light mode and Persian text and digit.

FlipTimerView A counter down timer for android which supports both dark and light mode and Persian text and digit. English Perisan Getting started Ste

Releases(v1.0.0)
Owner
Tomer Shalev
@Shutterfly
Tomer Shalev
A lightning fast, transactional, file-based FIFO for Android and Java.

Tape by Square, Inc. Tape is a collection of queue-related classes for Android and Java. QueueFile is a lightning-fast, transactional, file-based FIFO

Square 2.4k Dec 20, 2022
A Job Queue specifically written for Android to easily schedule jobs (tasks) that run in the background, improving UX and application stability.

A Job Queue specifically written for Android to easily schedule jobs (tasks) that run in the background, improving UX and application stability.

Yigit Boyar 3.4k Dec 31, 2022
Demo app demonstrating how to create and manage notifications locally using a combination of Jetpacks Worker Manager and Broadcast Receiver.

Worker Notification Demo app demonstrating how to create and manage notifications locally using a combination of Jetpacks Worker Manager and Broadcast

Ayia 1 Sep 19, 2022
Android Study Jams Worker Application

Android_Study_Jams-Worker_Application Worker Application Problem Statement: The digital age is staring us in the face from the near future. We already

Deep Shahane 4 Mar 26, 2022
Kotlin hello world for Cloudflare Workers

Kotlin hello world for Cloudflare Workers Your Kotlin code in main.kt, running on Cloudflare Workers In addition to Wrangler you will need to install

ProtoByter 0 Dec 9, 2021
This repo provides a sample application that demonstrates how you can speed up the authentication experience for frontline workers on shared devices using QR codes.

Project This repo has been populated by an initial template to help get you started. Please make sure to update the content to build a great experienc

Microsoft 5 Dec 7, 2022
Powerful event-bus optimized for high throughput in multi-threaded applications. Features: Sync and Async event publication, weak/strong references, event filtering, annotation driven

MBassador MBassador is a light-weight, high-performance event bus implementing the publish subscribe pattern. It is designed for ease of use and aims

Benjamin Diedrichsen 931 Dec 23, 2022
Kotlin async server template with coroutines and zero deps

kotlin-server At attempt to very light-weight non-blocking http app template with support for Kotlin coroutines. Zero dependencies - Java built-in jdk

Anton Keks 62 Dec 31, 2022
:satellite: [Android Library] Simplified async networking in android

Android library that simplifies networking in android via an async http client. Also featured in [Awesome Android Newsletter #Issue 15 ] Built with ❤︎

Nishant Srivastava 36 May 14, 2022
A swipe button for Android with a circular progress bar for async operations

ProSwipeButton A swipe button for Android with a circular progress bar for async operations Gradle dependencies { ... compile 'in.shadowfax:pr

Shadowfax Technologies 340 Nov 13, 2022