GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - HendrixString/Android-Zorn: Async Workers and Worker managers for Android

BranchesTags
Open more actions menu

Latest commit

 

History

21 Commits
21 Commits

Folders and files

NameName
Last commit message
Last commit date
libs
libs
 
 
src
src
 
 
.gitignore
.gitignore
 
 
Android-Zorn.iml
Android-Zorn.iml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
build.gradle
build.gradle
 
 
proguard-rules.pro
proguard-rules.pro
 
 

Repository files navigation

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

  • Erdos

Terms

  • completely free source code. Apache License, Version 2.0.
  • if you like it -> star or share it with others

Contact Author

  • [email protected]
  • Google+ TomershalevMan
  • Facebook - HendrixString

About

Async Workers and Worker managers for Android

Topics

androidandroid-zornworker-manager

Resources

Readme
Apache-2.0 license
Activity

Stars

87 stars

Watchers

7 watching

Forks

11 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.