All Projects → amitkma → Stitch

amitkma / Stitch

Licence: Apache-2.0 license
Simple threading library using annotations for Android

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Stitch

libquo
Dynamic execution environments for coupled, thread-heterogeneous MPI+X applications
Stars: ✭ 21 (-25%)
Mutual labels:  threading
AnnotationProcessorStarter
Project to set up basics of a Java annotation processor
Stars: ✭ 19 (-32.14%)
Mutual labels:  annotation-processor
android-actors-library
Android Actors Library was inspired by the Actor model. The main purpose of this library is to help developers in creating a worker attached to a thread and make all interactions with this worker natural and simple.
Stars: ✭ 24 (-14.29%)
Mutual labels:  threading
thread-pool
A modern thread pool implementation based on C++20
Stars: ✭ 104 (+271.43%)
Mutual labels:  threading
Perfect-Thread
Core threading library for Perfect Server Side Swift. Includes support for serial and concurrent thread queues, locks, read/write locks and events.
Stars: ✭ 17 (-39.29%)
Mutual labels:  threading
concurrent-resource
A header-only C++ library that allows easily creating thread-safe, concurrency friendly resources.
Stars: ✭ 17 (-39.29%)
Mutual labels:  threading
CodeProject
Common code for unity project develop.
Stars: ✭ 28 (+0%)
Mutual labels:  threading
Xiecheng Comment
🌈Xiecheng_Comment多线程Threading爬取携程的丽江古城景点评论并生成词云
Stars: ✭ 23 (-17.86%)
Mutual labels:  threading
AnnotationProcessing
✔️ㅤ[ARTICLE] Writing your own Annotation Processors in Android
Stars: ✭ 47 (+67.86%)
Mutual labels:  annotation-processor
SwiftConcurrentCollections
Swift Concurrent Collections
Stars: ✭ 40 (+42.86%)
Mutual labels:  threading
MoviesApp
A Movie Application uses TheMovie API, MVVM architecture and all jetpack components.
Stars: ✭ 100 (+257.14%)
Mutual labels:  threading
think-async
🌿 Exploring cooperative concurrency primitives in Python
Stars: ✭ 178 (+535.71%)
Mutual labels:  threading
ColdStorage
Lightweight data loading and caching library for android
Stars: ✭ 39 (+39.29%)
Mutual labels:  annotation-processor
People-Counting-in-Real-Time
People Counting in Real-Time with an IP camera.
Stars: ✭ 233 (+732.14%)
Mutual labels:  threading
jtsgen
Convert Java Types to TypeScript
Stars: ✭ 34 (+21.43%)
Mutual labels:  annotation-processor
mantichora
A simple interface to Python multiprocessing and threading
Stars: ✭ 13 (-53.57%)
Mutual labels:  threading
piri
Piri is a lightweight annotation processing library that generates static factory methods for your Activities and Fragments.
Stars: ✭ 53 (+89.29%)
Mutual labels:  annotation-processor
The-Java-Workshop
A New, Interactive Approach to Learning Java
Stars: ✭ 65 (+132.14%)
Mutual labels:  threading
generate-kotlin-multiple-rounds
Android sample project demonstrating how to generate Kotlin code through annotation processing, and then feeding it into a second round of annotation processing.
Stars: ✭ 25 (-10.71%)
Mutual labels:  annotation-processor
ObviousAwait
🧵 Expressive aliases to ConfigureAwait(true) and ConfigureAwait(false)
Stars: ✭ 55 (+96.43%)
Mutual labels:  threading

Stitch Build Status Download Android Arsenal API License

Simple threading library using annotations for Android

Download

dependencies {
  compile 'com.github.amitkma:stitch-lib:1.0.1'
  annotationProcessor 'com.github.amitkma:compiler:1.0.1'
}

Usage

Using this library is as simple as creating Hello World Android app. Currently, there are three types of annotations which we support.

  • @CallOnAnyThread : This annotation annotates a method to execute on any thread from thread pool. This library create a fixed size thread pool on the basis of availbale processors. If all threads of the thread pool are busy, the task will be added to the task queue wait until a thread is available to process that task.
  • @CallOnNewThread : A method which is annotated with @CallOnNewThread will always execute on a new thread. So the task will never have to wait and always start executing immediately.
  • @CallOnUiThread : Want to do some ui changes like setting text, starting animation or anything else, simply annotate the method with @CallOnUiThread.

Any method which you want to execute on any particular thread, simply annotate that method like below.

class ExampleClass {
    
    public ExampleClass() {
    }

    @CallOnAnyThread
    public Bitmap getBitmapFromURL(String src) {
        try {
            URL url = new URL(src);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            return BitmapFactory.decodeStream(input);
        } catch (IOException e) {
            // Log exception
            return null;
        }
    }
}

Now, build the project using terminal or by Build -> Rebuild Project in android studio. StitchCompiler will generate a new class file for the class in which annotated methods are. The name of generated class will be the name of existing class + "Stitch". For example in above case, name of generated file will be "ExampleClassStitch".

Next is to get the instance of the generated class (for calling the methods). So to get the instance of generated class, you need to stitch generated class and the required class like below :

// If getting instance in other class.
ExampleClassStitch exampleClassStitch = ExampleClassStitch.stitch(new ExampleClass()); 

// Or if getting instance in same class
ExampleClassStitch exampleClassStitch = ExampleClassStitch.stitch(this);.

After that, you can call the method as usual and the method will execute upon the annotated thread.

exampleClassStitch.getBitmapFromURL("https://image.freepik.com/free-vector/android-boot-logo_634639.jpg");

This is it.

Performance Issue

The answer is NO. This is because this library uses compile time processing and generates the code at compile time. So no reflection, No perf issue.

Remember - Don't make any change/update UI using @CallOnAnyThread or @CallOnNewThread otherwise android will throw an exception.

Contribution

For contribution guidelines, read Contribution guidelines for this project

License

Copyright 2017 Amit Kumar

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].