├── eventbus-android ├── .gitignore ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── org │ │ └── greenrobot │ │ └── eventbus │ │ ├── android │ │ ├── AndroidComponentsImpl.java │ │ ├── DefaultAndroidMainThreadSupport.java │ │ └── AndroidLogger.java │ │ └── HandlerPoster.java ├── README.md ├── consumer-rules.pro ├── proguard-rules.pro └── build.gradle ├── EventBusPerformance ├── .gitignore ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-ldpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── values │ │ └── strings.xml │ └── layout │ │ ├── activity_runtests.xml │ │ └── activity_setuptests.xml ├── project.properties ├── proguard-project.txt ├── src │ └── org │ │ └── greenrobot │ │ └── eventbusperf │ │ ├── TestEvent.java │ │ ├── TestFinishedEvent.java │ │ ├── testsubject │ │ └── SubscribeClassEventBusDefault.java │ │ ├── Test.java │ │ ├── TestRunner.java │ │ ├── TestParams.java │ │ ├── TestRunnerActivity.java │ │ └── TestSetupActivity.java ├── AndroidManifest.xml └── build.gradle ├── javadoc-style └── background.gif ├── EventBus-Publish-Subscribe.png ├── gradle ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties └── publish.gradle ├── EventBusAnnotationProcessor ├── res │ └── META-INF │ │ └── services │ │ └── javax.annotation.processing.Processor └── build.gradle ├── EventBusTest ├── libs │ └── EventBusTestSubscriberInJar-3.0.0.jar ├── src │ └── org │ │ └── greenrobot │ │ └── eventbus │ │ ├── indexed │ │ ├── EventBusAndroidOrderTestWithIndex.java │ │ ├── EventBusGenericsTestWithIndex.java │ │ ├── EventBusInheritanceTestWithIndex.java │ │ ├── EventBusMainThreadTestWithIndex.java │ │ ├── EventBusStickyEventTestWithIndex.java │ │ ├── EventBusMultithreadedTestWithIndex.java │ │ ├── EventBusMethodModifiersTestWithIndex.java │ │ ├── EventBusNoSubscriberEventTestWithIndex.java │ │ ├── EventBusMainThreadRacingTestWithIndex.java │ │ ├── EventBusCancelEventDeliveryTestWithIndex.java │ │ ├── EventBusRegistrationRacingTestWithIndex.java │ │ ├── EventBusOrderedSubscriptionsTestWithIndex.java │ │ ├── EventBusSubscriberExceptionTestWithIndex.java │ │ ├── EventBusFallbackToReflectionTestWithIndex.java │ │ ├── Indexed.java │ │ ├── EventBusSubscriberInJarTestWithIndex.java │ │ ├── EventBusBasicTestWithIndex.java │ │ ├── EventBusInheritanceDisabledTestWithIndex.java │ │ └── EventBusBackgroundThreadTestWithIndex.java │ │ ├── AndroidComponentsAvailabilityTest.java │ │ ├── EventBusAndroidCancelEventDeliveryTest.java │ │ ├── EventBusBackgroundThreadTest.java │ │ ├── ClassMapPerfTest.java │ │ ├── EventBusMainThreadTest.java │ │ ├── TestBackgroundPoster.java │ │ ├── EventBusMethodModifiersTest.java │ │ ├── AbstractAndroidEventBusTest.java │ │ ├── EventBusAndroidActivityTest.java │ │ ├── EventBusAndroidOrderTest.java │ │ ├── EventBusAndroidMultithreadedTest.java │ │ └── EventBusMainThreadRacingTest.java ├── AndroidManifest.xml └── build.gradle ├── EventBusTestJava ├── libs │ └── EventBusTestSubscriberInJar-3.0.0.jar ├── src │ └── main │ │ └── java │ │ └── org │ │ └── greenrobot │ │ └── eventbus │ │ ├── EventBusInheritanceSubclassNoMethodTest.java │ │ ├── EventBusInheritanceDisabledSubclassNoMethod.java │ │ ├── EventBusInheritanceSubclassTest.java │ │ ├── EventBusInheritanceDisabledSubclassTest.java │ │ ├── IntTestEvent.java │ │ ├── EventBusSubscriberInJarTest.java │ │ ├── EventBusIndexTest.java │ │ ├── EventBusSubscriberExceptionTest.java │ │ ├── EventBusSubscriberLegalTest.java │ │ ├── EventBusNoSubscriberEventTest.java │ │ ├── EventBusGenericsTest.java │ │ ├── EventBusBuilderTest.java │ │ ├── EventBusRegistrationRacingTest.java │ │ ├── AbstractEventBusTest.java │ │ ├── EventBusCancelEventDeliveryTest.java │ │ └── EventBusFallbackToReflectionTest.java └── build.gradle ├── settings.gradle ├── .gitignore ├── EventBusTestSubscriberInJar ├── src │ └── org │ │ └── greenrobot │ │ └── eventbus │ │ └── SubscriberInJar.java └── build.gradle ├── .github └── workflows │ └── gradle.yml ├── EventBus ├── src │ └── org │ │ └── greenrobot │ │ └── eventbus │ │ ├── util │ │ ├── HasExecutionScope.java │ │ ├── ThrowableFailureEvent.java │ │ ├── ExceptionToResourceMapping.java │ │ └── AsyncExecutor.java │ │ ├── meta │ │ ├── SubscriberInfoIndex.java │ │ ├── SubscriberInfo.java │ │ ├── SubscriberMethodInfo.java │ │ ├── SimpleSubscriberInfo.java │ │ └── AbstractSubscriberInfo.java │ │ ├── android │ │ ├── AndroidComponents.java │ │ └── AndroidDependenciesDetector.java │ │ ├── MainThreadSupport.java │ │ ├── Poster.java │ │ ├── NoSubscriberEvent.java │ │ ├── EventBusException.java │ │ ├── AsyncPoster.java │ │ ├── SubscriberExceptionEvent.java │ │ ├── Subscribe.java │ │ ├── Subscription.java │ │ ├── PendingPostQueue.java │ │ ├── PendingPost.java │ │ ├── Logger.java │ │ ├── BackgroundPoster.java │ │ ├── SubscriberMethod.java │ │ └── ThreadMode.java └── build.gradle ├── CONTRIBUTING.md ├── gradlew.bat ├── COMPARISON.md └── README.md /eventbus-android/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /EventBusPerformance/.gitignore: -------------------------------------------------------------------------------- 1 | /bin 2 | /gen 3 | -------------------------------------------------------------------------------- /javadoc-style/background.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greenrobot/EventBus/HEAD/javadoc-style/background.gif -------------------------------------------------------------------------------- /EventBus-Publish-Subscribe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greenrobot/EventBus/HEAD/EventBus-Publish-Subscribe.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greenrobot/EventBus/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /EventBusAnnotationProcessor/res/META-INF/services/javax.annotation.processing.Processor: -------------------------------------------------------------------------------- 1 | org.greenrobot.eventbus.annotationprocessor.EventBusAnnotationProcessor 2 | -------------------------------------------------------------------------------- /EventBusPerformance/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greenrobot/EventBus/HEAD/EventBusPerformance/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /EventBusPerformance/res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greenrobot/EventBus/HEAD/EventBusPerformance/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /EventBusPerformance/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greenrobot/EventBus/HEAD/EventBusPerformance/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /EventBusPerformance/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greenrobot/EventBus/HEAD/EventBusPerformance/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /eventbus-android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /EventBusTest/libs/EventBusTestSubscriberInJar-3.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greenrobot/EventBus/HEAD/EventBusTest/libs/EventBusTestSubscriberInJar-3.0.0.jar -------------------------------------------------------------------------------- /EventBusTestJava/libs/EventBusTestSubscriberInJar-3.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greenrobot/EventBus/HEAD/EventBusTestJava/libs/EventBusTestSubscriberInJar-3.0.0.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /EventBusTestJava/src/main/java/org/greenrobot/eventbus/EventBusInheritanceSubclassNoMethodTest.java: -------------------------------------------------------------------------------- 1 | package org.greenrobot.eventbus; 2 | 3 | // Need to use upper class or Android test runner does not pick it up 4 | public class EventBusInheritanceSubclassNoMethodTest extends EventBusInheritanceTest { 5 | } 6 | -------------------------------------------------------------------------------- /EventBusTestJava/src/main/java/org/greenrobot/eventbus/EventBusInheritanceDisabledSubclassNoMethod.java: -------------------------------------------------------------------------------- 1 | package org.greenrobot.eventbus; 2 | 3 | // Need to use upper class or Android test runner does not pick it up 4 | public class EventBusInheritanceDisabledSubclassNoMethod extends EventBusInheritanceDisabledTest { 5 | } 6 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':EventBus' 2 | include ':EventBusAnnotationProcessor' 3 | include ':EventBusTestJava' 4 | include ':EventBusTest' 5 | include ':EventBusTestSubscriberInJar' 6 | include ':EventBusPerformance' 7 | include ':eventbus-android' 8 | 9 | project(":EventBus").name = "eventbus-java" 10 | project(":EventBusAnnotationProcessor").name = "eventbus-annotation-processor" 11 | -------------------------------------------------------------------------------- /eventbus-android/README.md: -------------------------------------------------------------------------------- 1 | # EventBus for Android 2 | 3 | Despite its name this module is actually published as `org.greenrobot:eventbus` as an Android library (AAR). 4 | 5 | It has a dependency on the Java-only artifact `org.greenrobot:eventbus-java` (JAR) previously available under the `eventbus` name. 6 | 7 | Provides an `AndroidComponents` implementation to the Java library if it detects `AndroidComponentsImpl` on the classpath via reflection. 8 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/indexed/EventBusAndroidOrderTestWithIndex.java: -------------------------------------------------------------------------------- 1 | package org.greenrobot.eventbus.indexed; 2 | 3 | import org.greenrobot.eventbus.EventBusAndroidOrderTest; 4 | 5 | public class EventBusAndroidOrderTestWithIndex extends EventBusAndroidOrderTest { 6 | 7 | @Override 8 | public void setUp() throws Exception { 9 | eventBus = Indexed.build(); 10 | super.setUp(); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /eventbus-android/src/main/java/org/greenrobot/eventbus/android/AndroidComponentsImpl.java: -------------------------------------------------------------------------------- 1 | package org.greenrobot.eventbus.android; 2 | 3 | /** 4 | * Used via reflection in the Java library by {@link AndroidDependenciesDetector}. 5 | */ 6 | public class AndroidComponentsImpl extends AndroidComponents { 7 | 8 | public AndroidComponentsImpl() { 9 | super(new AndroidLogger("EventBus"), new DefaultAndroidMainThreadSupport()); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | release/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | gradle.properties 20 | 21 | # Local configuration file (sdk path, etc) 22 | local.properties 23 | 24 | # IntelliJ project files 25 | *.iml 26 | .idea/ 27 | 28 | # Eclipse project files 29 | .settings/ 30 | 31 | # Misc 32 | .DS_Store 33 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/AndroidComponentsAvailabilityTest.java: -------------------------------------------------------------------------------- 1 | package org.greenrobot.eventbus; 2 | 3 | import org.greenrobot.eventbus.android.AndroidComponents; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertNotNull; 7 | import static org.junit.Assert.assertTrue; 8 | 9 | public class AndroidComponentsAvailabilityTest { 10 | 11 | @Test 12 | public void shouldBeAvailable() { 13 | assertTrue(AndroidComponents.areAvailable()); 14 | assertNotNull(AndroidComponents.get()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /EventBusTest/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /EventBusTestSubscriberInJar/src/org/greenrobot/eventbus/SubscriberInJar.java: -------------------------------------------------------------------------------- 1 | package org.greenrobot.eventbus; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** Helper class used by test inside a jar. */ 7 | public class SubscriberInJar { 8 | List collectedStrings = new ArrayList(); 9 | 10 | @Subscribe 11 | public void collectString(String string) { 12 | collectedStrings.add(string); 13 | } 14 | 15 | public List getCollectedStrings() { 16 | return collectedStrings; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /eventbus-android/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -keepattributes *Annotation* 2 | -keepclassmembers class * { 3 | @org.greenrobot.eventbus.Subscribe ; 4 | } 5 | -keep enum org.greenrobot.eventbus.ThreadMode { *; } 6 | 7 | # If using AsyncExecutord, keep required constructor of default event used. 8 | # Adjust the class name if a custom failure event type is used. 9 | -keepclassmembers class org.greenrobot.eventbus.util.ThrowableFailureEvent { 10 | (java.lang.Throwable); 11 | } 12 | 13 | # Accessed via reflection, avoid renaming or removal 14 | -keep class org.greenrobot.eventbus.android.AndroidComponentsImpl 15 | -------------------------------------------------------------------------------- /EventBusTestJava/src/main/java/org/greenrobot/eventbus/EventBusInheritanceSubclassTest.java: -------------------------------------------------------------------------------- 1 | package org.greenrobot.eventbus; 2 | 3 | import org.junit.Ignore; 4 | 5 | // Need to use upper class or Android test runner does not pick it up 6 | public class EventBusInheritanceSubclassTest extends EventBusInheritanceTest { 7 | int countMyEventOverwritten; 8 | 9 | @Subscribe 10 | public void onEvent(MyEvent event) { 11 | countMyEventOverwritten++; 12 | } 13 | 14 | @Override 15 | @Ignore 16 | public void testEventClassHierarchy() { 17 | // TODO fix test in super, then remove this 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /EventBusPerformance/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}\tools\proguard\proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-17 15 | -------------------------------------------------------------------------------- /EventBusTestJava/src/main/java/org/greenrobot/eventbus/EventBusInheritanceDisabledSubclassTest.java: -------------------------------------------------------------------------------- 1 | package org.greenrobot.eventbus; 2 | 3 | import org.junit.Ignore; 4 | 5 | // Need to use upper class or Android test runner does not pick it up 6 | public class EventBusInheritanceDisabledSubclassTest extends EventBusInheritanceDisabledTest { 7 | 8 | int countMyEventOverwritten; 9 | 10 | @Subscribe 11 | public void onEvent(MyEvent event) { 12 | countMyEventOverwritten++; 13 | } 14 | 15 | @Override 16 | @Ignore 17 | public void testEventClassHierarchy() { 18 | // TODO fix test in super, then remove this 19 | } 20 | } -------------------------------------------------------------------------------- /EventBusTestSubscriberInJar/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "java-library" 2 | 3 | group = "de.greenrobot" 4 | version = "3.0.0" 5 | java.sourceCompatibility = JavaVersion.VERSION_1_8 6 | java.targetCompatibility = JavaVersion.VERSION_1_8 7 | 8 | configurations { 9 | provided 10 | } 11 | 12 | dependencies { 13 | implementation project(":eventbus-java") 14 | annotationProcessor project(":eventbus-annotation-processor") 15 | } 16 | 17 | sourceSets { 18 | main { 19 | compileClasspath += configurations.provided 20 | java { 21 | srcDir "src" 22 | } 23 | } 24 | } 25 | 26 | compileJava { 27 | options.compilerArgs << "-AeventBusIndex=org.greenrobot.eventbus.InJarIndex" 28 | options.fork = true 29 | } 30 | -------------------------------------------------------------------------------- /eventbus-android/src/main/java/org/greenrobot/eventbus/android/DefaultAndroidMainThreadSupport.java: -------------------------------------------------------------------------------- 1 | package org.greenrobot.eventbus.android; 2 | 3 | import android.os.Looper; 4 | import org.greenrobot.eventbus.EventBus; 5 | import org.greenrobot.eventbus.HandlerPoster; 6 | import org.greenrobot.eventbus.MainThreadSupport; 7 | import org.greenrobot.eventbus.Poster; 8 | 9 | public class DefaultAndroidMainThreadSupport implements MainThreadSupport { 10 | 11 | @Override 12 | public boolean isMainThread() { 13 | return Looper.getMainLooper() == Looper.myLooper(); 14 | } 15 | 16 | @Override 17 | public Poster createPoster(EventBus eventBus) { 18 | return new HandlerPoster(eventBus, Looper.getMainLooper(), 10); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /.github/workflows/gradle.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Gradle 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle 3 | 4 | name: Java CI with Gradle 5 | 6 | on: 7 | push: 8 | pull_request: 9 | 10 | jobs: 11 | build: 12 | 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@v3 17 | - name: Set up JDK 11 18 | uses: actions/setup-java@v3 19 | with: 20 | java-version: '11' 21 | distribution: 'temurin' 22 | cache: gradle 23 | - name: Grant execute permission for gradlew 24 | run: chmod +x gradlew 25 | - name: Gradle Info 26 | run: ./gradlew -version 27 | - name: Build with Gradle 28 | run: ./gradlew build 29 | -------------------------------------------------------------------------------- /eventbus-android/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /EventBusTestJava/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "java-library" 2 | 3 | java.sourceCompatibility = JavaVersion.VERSION_1_8 4 | java.targetCompatibility = JavaVersion.VERSION_1_8 5 | 6 | // we have tests in the main source set so they can be shared with the Android test module 7 | // to make Gradle pick them up, add the dir to the test source set 8 | sourceSets { 9 | test { 10 | java { 11 | srcDirs += ["src/main/java"] 12 | } 13 | } 14 | } 15 | 16 | dependencies { 17 | implementation fileTree(dir: "libs", include: "*.jar") 18 | implementation(project(":eventbus-java")) 19 | annotationProcessor project(":eventbus-annotation-processor") 20 | implementation "junit:junit:4.13.2" 21 | } 22 | 23 | tasks.withType(JavaCompile) { 24 | options.compilerArgs += [ "-AeventBusIndex=org.greenrobot.eventbus.EventBusJavaTestsIndex" ] 25 | } 26 | -------------------------------------------------------------------------------- /EventBusPerformance/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /EventBusPerformance/src/org/greenrobot/eventbusperf/TestEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbusperf; 18 | 19 | /** Used by otto and EventBus */ 20 | public class TestEvent { 21 | 22 | } 23 | -------------------------------------------------------------------------------- /EventBus/src/org/greenrobot/eventbus/util/HasExecutionScope.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus.util; 18 | 19 | public interface HasExecutionScope { 20 | Object getExecutionScope(); 21 | 22 | void setExecutionScope(Object executionScope); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /EventBus/src/org/greenrobot/eventbus/meta/SubscriberInfoIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.greenrobot.eventbus.meta; 17 | 18 | /** 19 | * Interface for generated indexes. 20 | */ 21 | public interface SubscriberInfoIndex { 22 | SubscriberInfo getSubscriberInfo(Class subscriberClass); 23 | } 24 | -------------------------------------------------------------------------------- /EventBus/src/org/greenrobot/eventbus/android/AndroidComponents.java: -------------------------------------------------------------------------------- 1 | package org.greenrobot.eventbus.android; 2 | 3 | import org.greenrobot.eventbus.Logger; 4 | import org.greenrobot.eventbus.MainThreadSupport; 5 | 6 | public abstract class AndroidComponents { 7 | 8 | private static final AndroidComponents implementation; 9 | 10 | static { 11 | implementation = AndroidDependenciesDetector.isAndroidSDKAvailable() 12 | ? AndroidDependenciesDetector.instantiateAndroidComponents() 13 | : null; 14 | } 15 | 16 | public static boolean areAvailable() { 17 | return implementation != null; 18 | } 19 | 20 | public static AndroidComponents get() { 21 | return implementation; 22 | } 23 | 24 | public final Logger logger; 25 | public final MainThreadSupport defaultMainThreadSupport; 26 | 27 | public AndroidComponents(Logger logger, MainThreadSupport defaultMainThreadSupport) { 28 | this.logger = logger; 29 | this.defaultMainThreadSupport = defaultMainThreadSupport; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /EventBus/src/org/greenrobot/eventbus/MainThreadSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.greenrobot.eventbus; 17 | 18 | /** 19 | * Interface to the "main" thread, which can be whatever you like. Typically on Android, Android's main thread is used. 20 | */ 21 | public interface MainThreadSupport { 22 | 23 | boolean isMainThread(); 24 | 25 | Poster createPoster(EventBus eventBus); 26 | } 27 | -------------------------------------------------------------------------------- /EventBusPerformance/src/org/greenrobot/eventbusperf/TestFinishedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbusperf; 18 | 19 | public class TestFinishedEvent { 20 | 21 | public final Test test; 22 | public final boolean isLastEvent; 23 | 24 | public TestFinishedEvent(Test test, boolean isLastEvent) { 25 | this.test = test; 26 | this.isLastEvent = isLastEvent; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /EventBusTestJava/src/main/java/org/greenrobot/eventbus/IntTestEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Simple event storing an int value. More efficient than Integer because of the its flat hierarchy. 19 | */ 20 | package org.greenrobot.eventbus; 21 | 22 | public class IntTestEvent { 23 | public final int value; 24 | 25 | public IntTestEvent(int value) { 26 | this.value = value; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /EventBusPerformance/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/indexed/EventBusGenericsTestWithIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus.indexed; 18 | 19 | import org.junit.Before; 20 | 21 | import org.greenrobot.eventbus.EventBusGenericsTest; 22 | 23 | public class EventBusGenericsTestWithIndex extends EventBusGenericsTest { 24 | @Before 25 | public void overwriteEventBus() throws Exception { 26 | eventBus = Indexed.build(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/indexed/EventBusInheritanceTestWithIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus.indexed; 18 | 19 | import org.greenrobot.eventbus.EventBusInheritanceTest; 20 | import org.junit.Before; 21 | 22 | public class EventBusInheritanceTestWithIndex extends EventBusInheritanceTest { 23 | @Before 24 | public void overwriteEventBus() throws Exception { 25 | eventBus = Indexed.build(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/indexed/EventBusMainThreadTestWithIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus.indexed; 18 | 19 | import org.junit.Before; 20 | 21 | import org.greenrobot.eventbus.EventBusMainThreadTest; 22 | 23 | public class EventBusMainThreadTestWithIndex extends EventBusMainThreadTest { 24 | @Before 25 | public void overwriteEventBus() throws Exception { 26 | eventBus = Indexed.build(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/indexed/EventBusStickyEventTestWithIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus.indexed; 18 | 19 | import org.greenrobot.eventbus.EventBusStickyEventTest; 20 | import org.junit.Before; 21 | 22 | public class EventBusStickyEventTestWithIndex extends EventBusStickyEventTest { 23 | @Before 24 | public void overwriteEventBus() throws Exception { 25 | eventBus = Indexed.build(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/indexed/EventBusMultithreadedTestWithIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus.indexed; 18 | 19 | import org.greenrobot.eventbus.EventBusMultithreadedTest; 20 | import org.junit.Before; 21 | 22 | public class EventBusMultithreadedTestWithIndex extends EventBusMultithreadedTest { 23 | @Before 24 | public void overwriteEventBus() throws Exception { 25 | eventBus = Indexed.build(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/indexed/EventBusMethodModifiersTestWithIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus.indexed; 18 | 19 | import org.greenrobot.eventbus.EventBusMethodModifiersTest; 20 | import org.junit.Before; 21 | 22 | public class EventBusMethodModifiersTestWithIndex extends EventBusMethodModifiersTest { 23 | @Before 24 | public void overwriteEventBus() throws Exception { 25 | eventBus = Indexed.build(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/indexed/EventBusNoSubscriberEventTestWithIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus.indexed; 18 | 19 | import org.greenrobot.eventbus.EventBusNoSubscriberEventTest; 20 | import org.junit.Before; 21 | 22 | public class EventBusNoSubscriberEventTestWithIndex extends EventBusNoSubscriberEventTest { 23 | @Before 24 | public void overwriteEventBus() throws Exception { 25 | eventBus = Indexed.build(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/indexed/EventBusMainThreadRacingTestWithIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus.indexed; 18 | 19 | import org.junit.Before; 20 | 21 | import org.greenrobot.eventbus.EventBusMainThreadRacingTest; 22 | 23 | public class EventBusMainThreadRacingTestWithIndex extends EventBusMainThreadRacingTest { 24 | @Before 25 | public void overwriteEventBus() throws Exception { 26 | eventBus = Indexed.build(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/indexed/EventBusCancelEventDeliveryTestWithIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus.indexed; 18 | 19 | import org.greenrobot.eventbus.EventBusCancelEventDeliveryTest; 20 | import org.junit.Before; 21 | 22 | public class EventBusCancelEventDeliveryTestWithIndex extends EventBusCancelEventDeliveryTest { 23 | @Before 24 | public void overwriteEventBus() throws Exception { 25 | eventBus = Indexed.build(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/indexed/EventBusRegistrationRacingTestWithIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus.indexed; 18 | 19 | import org.junit.Before; 20 | 21 | import org.greenrobot.eventbus.EventBusRegistrationRacingTest; 22 | 23 | public class EventBusRegistrationRacingTestWithIndex extends EventBusRegistrationRacingTest { 24 | @Before 25 | public void overwriteEventBus() throws Exception { 26 | eventBus = Indexed.build(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/indexed/EventBusOrderedSubscriptionsTestWithIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus.indexed; 18 | 19 | import org.greenrobot.eventbus.EventBusOrderedSubscriptionsTest; 20 | import org.junit.Before; 21 | 22 | public class EventBusOrderedSubscriptionsTestWithIndex extends EventBusOrderedSubscriptionsTest { 23 | @Before 24 | public void overwriteEventBus() throws Exception { 25 | eventBus = Indexed.build(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/indexed/EventBusSubscriberExceptionTestWithIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus.indexed; 18 | 19 | import org.junit.Before; 20 | 21 | import org.greenrobot.eventbus.EventBusSubscriberExceptionTest; 22 | 23 | public class EventBusSubscriberExceptionTestWithIndex extends EventBusSubscriberExceptionTest { 24 | @Before 25 | public void overwriteEventBus() throws Exception { 26 | eventBus = Indexed.build(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /EventBus/src/org/greenrobot/eventbus/meta/SubscriberInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.greenrobot.eventbus.meta; 17 | 18 | import org.greenrobot.eventbus.SubscriberMethod; 19 | 20 | /** Base class for generated index classes created by annotation processing. */ 21 | public interface SubscriberInfo { 22 | Class getSubscriberClass(); 23 | 24 | SubscriberMethod[] getSubscriberMethods(); 25 | 26 | SubscriberInfo getSuperSubscriberInfo(); 27 | 28 | boolean shouldCheckSuperclass(); 29 | } 30 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/indexed/EventBusFallbackToReflectionTestWithIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus.indexed; 18 | 19 | import org.junit.Before; 20 | 21 | import org.greenrobot.eventbus.EventBusFallbackToReflectionTest; 22 | 23 | public class EventBusFallbackToReflectionTestWithIndex extends EventBusFallbackToReflectionTest { 24 | @Before 25 | public void overwriteEventBus() throws Exception { 26 | eventBus = Indexed.build(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /EventBus/src/org/greenrobot/eventbus/Poster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.greenrobot.eventbus; 17 | 18 | /** 19 | * Posts events. 20 | * 21 | * @author William Ferguson 22 | */ 23 | public interface Poster { 24 | 25 | /** 26 | * Enqueue an event to be posted for a particular subscription. 27 | * 28 | * @param subscription Subscription which will receive the event. 29 | * @param event Event that will be posted to subscribers. 30 | */ 31 | void enqueue(Subscription subscription, Object event); 32 | } 33 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/indexed/Indexed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus.indexed; 18 | 19 | import org.greenrobot.eventbus.EventBus; 20 | import org.greenrobot.eventbus.EventBusJavaTestsIndex; 21 | import org.greenrobot.eventbus.EventBusTestsIndex; 22 | 23 | public class Indexed { 24 | static EventBus build() { 25 | return EventBus.builder() 26 | .addIndex(new EventBusTestsIndex()) 27 | .addIndex(new EventBusJavaTestsIndex()) 28 | .build(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/indexed/EventBusSubscriberInJarTestWithIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus.indexed; 18 | 19 | import org.greenrobot.eventbus.EventBus; 20 | import org.greenrobot.eventbus.EventBusSubscriberInJarTest; 21 | import org.greenrobot.eventbus.InJarIndex; 22 | import org.junit.Before; 23 | 24 | public class EventBusSubscriberInJarTestWithIndex extends EventBusSubscriberInJarTest { 25 | @Before 26 | public void overwriteEventBus() throws Exception { 27 | eventBus = EventBus.builder().addIndex(new InJarIndex()).build(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/indexed/EventBusBasicTestWithIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus.indexed; 18 | 19 | import org.greenrobot.eventbus.EventBusBasicTest; 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | 23 | import static org.junit.Assert.assertTrue; 24 | 25 | public class EventBusBasicTestWithIndex extends EventBusBasicTest { 26 | @Before 27 | public void overwriteEventBus() throws Exception { 28 | eventBus = Indexed.build(); 29 | } 30 | 31 | @Test 32 | public void testIndex() { 33 | assertTrue(eventBus.toString().contains("indexCount=2")); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/indexed/EventBusInheritanceDisabledTestWithIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus.indexed; 18 | 19 | import org.greenrobot.eventbus.EventBus; 20 | import org.greenrobot.eventbus.EventBusTestsIndex; 21 | import org.junit.Before; 22 | 23 | import org.greenrobot.eventbus.EventBusInheritanceDisabledTest; 24 | 25 | public class EventBusInheritanceDisabledTestWithIndex extends EventBusInheritanceDisabledTest { 26 | @Before 27 | public void setUp() throws Exception { 28 | eventBus = EventBus.builder().eventInheritance(false).addIndex(new EventBusTestsIndex()).build(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /EventBusPerformance/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | google() 4 | mavenCentral() 5 | } 6 | 7 | dependencies { 8 | // Note: IntelliJ IDEA 2021.1 only supports up to version 4.1 9 | classpath 'com.android.tools.build:gradle:4.1.3' 10 | } 11 | } 12 | 13 | apply plugin: 'com.android.application' 14 | 15 | dependencies { 16 | implementation project(':eventbus-android') 17 | annotationProcessor project(':eventbus-annotation-processor') 18 | implementation 'com.squareup:otto:1.3.8' 19 | } 20 | 21 | android { 22 | compileSdkVersion _compileSdkVersion 23 | 24 | sourceSets { 25 | main { 26 | manifest.srcFile 'AndroidManifest.xml' 27 | java.srcDirs = ['src'] 28 | res.srcDirs = ['res'] 29 | } 30 | } 31 | 32 | defaultConfig { 33 | minSdkVersion 7 34 | targetSdkVersion 26 35 | versionCode 1 36 | versionName "2.0.0" 37 | javaCompileOptions { 38 | annotationProcessorOptions { 39 | arguments = [eventBusIndex: 'org.greenrobot.eventbusperf.MyEventBusIndex'] 40 | } 41 | } 42 | } 43 | 44 | compileOptions { 45 | sourceCompatibility JavaVersion.VERSION_1_8 46 | targetCompatibility JavaVersion.VERSION_1_8 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/indexed/EventBusBackgroundThreadTestWithIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus.indexed; 18 | 19 | import org.greenrobot.eventbus.EventBusBackgroundThreadTest; 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | 23 | import static org.junit.Assert.assertTrue; 24 | 25 | public class EventBusBackgroundThreadTestWithIndex extends EventBusBackgroundThreadTest { 26 | @Before 27 | public void overwriteEventBus() throws Exception { 28 | eventBus = Indexed.build(); 29 | } 30 | 31 | @Test 32 | public void testIndex() { 33 | assertTrue(eventBus.toString().contains("indexCount=2")); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /EventBus/src/org/greenrobot/eventbus/NoSubscriberEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.greenrobot.eventbus; 17 | 18 | /** 19 | * This Event is posted by EventBus when no subscriber is found for a posted event. 20 | * 21 | * @author Markus 22 | */ 23 | public final class NoSubscriberEvent { 24 | /** The {@link EventBus} instance to with the original event was posted to. */ 25 | public final EventBus eventBus; 26 | 27 | /** The original event that could not be delivered to any subscriber. */ 28 | public final Object originalEvent; 29 | 30 | public NoSubscriberEvent(EventBus eventBus, Object originalEvent) { 31 | this.eventBus = eventBus; 32 | this.originalEvent = originalEvent; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /EventBusTestJava/src/main/java/org/greenrobot/eventbus/EventBusSubscriberInJarTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus; 18 | 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | 22 | public class EventBusSubscriberInJarTest { 23 | protected EventBus eventBus = EventBus.builder().build(); 24 | 25 | @Test 26 | public void testSubscriberInJar() { 27 | SubscriberInJar subscriber = new SubscriberInJar(); 28 | eventBus.register(subscriber); 29 | eventBus.post("Hi Jar"); 30 | eventBus.post(42); 31 | Assert.assertEquals(1, subscriber.getCollectedStrings().size()); 32 | Assert.assertEquals("Hi Jar", subscriber.getCollectedStrings().get(0)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /EventBus/src/org/greenrobot/eventbus/EventBusException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.greenrobot.eventbus; 17 | 18 | /** 19 | * An {@link RuntimeException} thrown in cases something went wrong inside EventBus. 20 | * 21 | * @author Markus 22 | * 23 | */ 24 | public class EventBusException extends RuntimeException { 25 | 26 | private static final long serialVersionUID = -2912559384646531479L; 27 | 28 | public EventBusException(String detailMessage) { 29 | super(detailMessage); 30 | } 31 | 32 | public EventBusException(Throwable throwable) { 33 | super(throwable); 34 | } 35 | 36 | public EventBusException(String detailMessage, Throwable throwable) { 37 | super(detailMessage, throwable); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /EventBusPerformance/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | EventBus Performance 5 | EventBus 6 | Event Inheritance 7 | Ignore generated index 8 | OttoBus 9 | Broadcast 10 | Local Broadcast 11 | Events: 12 | Subscribers: 13 | Start 14 | 15 | 16 | Post Events 17 | Register Subscribers 18 | Register Subscribers, no unregister 19 | Register Subscribers, 1. time 20 | 21 | 22 | POSTING 23 | MAIN 24 | MAIN_ORDERED 25 | BACKGROUND 26 | ASYNC 27 | 28 | 29 | Test Is \nRunning! 30 | Cancel 31 | Kill Process 32 | 33 | -------------------------------------------------------------------------------- /EventBus/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | 3 | group = rootProject.group 4 | version = rootProject.version 5 | 6 | java.sourceCompatibility = JavaVersion.VERSION_1_8 7 | java.targetCompatibility = JavaVersion.VERSION_1_8 8 | 9 | sourceSets { 10 | main { 11 | java { 12 | srcDir 'src' 13 | // exclude 'de/greenrobot/event/util/**' 14 | } 15 | } 16 | } 17 | 18 | javadoc { 19 | failOnError = false 20 | title = "EventBus ${version} API" 21 | options.bottom = 'Available under the Apache License, Version 2.0 - Copyright © 2012-2020 greenrobot.org. All Rights Reserved.' 22 | } 23 | 24 | task javadocJar(type: Jar, dependsOn: javadoc) { 25 | archiveClassifier.set("javadoc") 26 | from 'build/docs/javadoc' 27 | } 28 | 29 | task sourcesJar(type: Jar) { 30 | archiveClassifier.set("sources") 31 | from sourceSets.main.allSource 32 | } 33 | 34 | apply from: rootProject.file("gradle/publish.gradle") 35 | // Set project-specific properties 36 | afterEvaluate { 37 | publishing.publications { 38 | mavenJava(MavenPublication) { 39 | artifactId = "eventbus-java" 40 | 41 | from components.java 42 | artifact javadocJar 43 | artifact sourcesJar 44 | pom { 45 | name = "EventBus" 46 | description = "EventBus is a publish/subscribe event bus." 47 | packaging = "jar" 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /EventBusPerformance/src/org/greenrobot/eventbusperf/testsubject/SubscribeClassEventBusDefault.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbusperf.testsubject; 18 | 19 | import org.greenrobot.eventbus.Subscribe; 20 | 21 | import org.greenrobot.eventbusperf.TestEvent; 22 | 23 | public class SubscribeClassEventBusDefault { 24 | private PerfTestEventBus perfTestEventBus; 25 | 26 | public SubscribeClassEventBusDefault(PerfTestEventBus perfTestEventBus) { 27 | this.perfTestEventBus = perfTestEventBus; 28 | } 29 | 30 | @Subscribe 31 | public void onEvent(TestEvent event) { 32 | perfTestEventBus.eventsReceivedCount.incrementAndGet(); 33 | } 34 | 35 | public void dummy() { 36 | } 37 | 38 | public void dummy2() { 39 | } 40 | 41 | public void dummy3() { 42 | } 43 | 44 | public void dummy4() { 45 | } 46 | 47 | public void dummy5() { 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/EventBusAndroidCancelEventDeliveryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.greenrobot.eventbus; 17 | 18 | import org.junit.Test; 19 | import org.junit.runner.RunWith; 20 | 21 | import android.support.test.runner.AndroidJUnit4; 22 | import android.test.UiThreadTest; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.junit.Assert.assertNotNull; 26 | 27 | @RunWith(AndroidJUnit4.class) 28 | public class EventBusAndroidCancelEventDeliveryTest extends EventBusCancelEventDeliveryTest { 29 | 30 | @UiThreadTest 31 | @Test 32 | public void testCancelInMainThread() { 33 | SubscriberMainThread subscriber = new SubscriberMainThread(); 34 | eventBus.register(subscriber); 35 | eventBus.post("42"); 36 | awaitLatch(subscriber.done, 10); 37 | assertEquals(0, eventCount.intValue()); 38 | assertNotNull(failed); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /EventBus/src/org/greenrobot/eventbus/AsyncPoster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.greenrobot.eventbus; 17 | 18 | 19 | /** 20 | * Posts events in background. 21 | * 22 | * @author Markus 23 | */ 24 | class AsyncPoster implements Runnable, Poster { 25 | 26 | private final PendingPostQueue queue; 27 | private final EventBus eventBus; 28 | 29 | AsyncPoster(EventBus eventBus) { 30 | this.eventBus = eventBus; 31 | queue = new PendingPostQueue(); 32 | } 33 | 34 | public void enqueue(Subscription subscription, Object event) { 35 | PendingPost pendingPost = PendingPost.obtainPendingPost(subscription, event); 36 | queue.enqueue(pendingPost); 37 | eventBus.getExecutorService().execute(this); 38 | } 39 | 40 | @Override 41 | public void run() { 42 | PendingPost pendingPost = queue.poll(); 43 | if(pendingPost == null) { 44 | throw new IllegalStateException("No pending post available"); 45 | } 46 | eventBus.invokeSubscriber(pendingPost); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /EventBus/src/org/greenrobot/eventbus/android/AndroidDependenciesDetector.java: -------------------------------------------------------------------------------- 1 | package org.greenrobot.eventbus.android; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | import java.lang.reflect.Method; 5 | 6 | @SuppressWarnings("TryWithIdenticalCatches") 7 | public class AndroidDependenciesDetector { 8 | 9 | public static boolean isAndroidSDKAvailable() { 10 | 11 | try { 12 | Class looperClass = Class.forName("android.os.Looper"); 13 | Method getMainLooper = looperClass.getDeclaredMethod("getMainLooper"); 14 | Object mainLooper = getMainLooper.invoke(null); 15 | return mainLooper != null; 16 | } 17 | catch (ClassNotFoundException ignored) {} 18 | catch (NoSuchMethodException ignored) {} 19 | catch (IllegalAccessException ignored) {} 20 | catch (InvocationTargetException ignored) {} 21 | 22 | return false; 23 | } 24 | 25 | private static final String ANDROID_COMPONENTS_IMPLEMENTATION_CLASS_NAME = "org.greenrobot.eventbus.android.AndroidComponentsImpl"; 26 | 27 | public static boolean areAndroidComponentsAvailable() { 28 | 29 | try { 30 | Class.forName(ANDROID_COMPONENTS_IMPLEMENTATION_CLASS_NAME); 31 | return true; 32 | } 33 | catch (ClassNotFoundException ex) { 34 | return false; 35 | } 36 | } 37 | 38 | public static AndroidComponents instantiateAndroidComponents() { 39 | 40 | try { 41 | Class impl = Class.forName(ANDROID_COMPONENTS_IMPLEMENTATION_CLASS_NAME); 42 | return (AndroidComponents) impl.getConstructor().newInstance(); 43 | } 44 | catch (Throwable ex) { 45 | return null; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /EventBus/src/org/greenrobot/eventbus/meta/SubscriberMethodInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.greenrobot.eventbus.meta; 17 | 18 | import org.greenrobot.eventbus.ThreadMode; 19 | 20 | public class SubscriberMethodInfo { 21 | final String methodName; 22 | final ThreadMode threadMode; 23 | final Class eventType; 24 | final int priority; 25 | final boolean sticky; 26 | 27 | public SubscriberMethodInfo(String methodName, Class eventType, ThreadMode threadMode, 28 | int priority, boolean sticky) { 29 | this.methodName = methodName; 30 | this.threadMode = threadMode; 31 | this.eventType = eventType; 32 | this.priority = priority; 33 | this.sticky = sticky; 34 | } 35 | 36 | public SubscriberMethodInfo(String methodName, Class eventType) { 37 | this(methodName, eventType, ThreadMode.POSTING, 0, false); 38 | } 39 | 40 | public SubscriberMethodInfo(String methodName, Class eventType, ThreadMode threadMode) { 41 | this(methodName, eventType, threadMode, 0, false); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /EventBus/src/org/greenrobot/eventbus/SubscriberExceptionEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.greenrobot.eventbus; 17 | 18 | /** 19 | * This Event is posted by EventBus when an exception occurs inside a subscriber's event handling method. 20 | * 21 | * @author Markus 22 | */ 23 | public final class SubscriberExceptionEvent { 24 | /** The {@link EventBus} instance to with the original event was posted to. */ 25 | public final EventBus eventBus; 26 | 27 | /** The Throwable thrown by a subscriber. */ 28 | public final Throwable throwable; 29 | 30 | /** The original event that could not be delivered to any subscriber. */ 31 | public final Object causingEvent; 32 | 33 | /** The subscriber that threw the Throwable. */ 34 | public final Object causingSubscriber; 35 | 36 | public SubscriberExceptionEvent(EventBus eventBus, Throwable throwable, Object causingEvent, 37 | Object causingSubscriber) { 38 | this.eventBus = eventBus; 39 | this.throwable = throwable; 40 | this.causingEvent = causingEvent; 41 | this.causingSubscriber = causingSubscriber; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /eventbus-android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | google() 4 | mavenCentral() 5 | } 6 | 7 | dependencies { 8 | // Note: IntelliJ IDEA 2021.1 only supports up to version 4.1 9 | classpath 'com.android.tools.build:gradle:4.1.3' 10 | } 11 | } 12 | 13 | apply plugin: 'com.android.library' 14 | 15 | group = rootProject.group 16 | version = rootProject.version 17 | 18 | android { 19 | compileSdkVersion _compileSdkVersion 20 | 21 | defaultConfig { 22 | minSdkVersion 7 23 | targetSdkVersion 30 // Android 11 (R) 24 | 25 | consumerProguardFiles "consumer-rules.pro" 26 | } 27 | compileOptions { 28 | sourceCompatibility JavaVersion.VERSION_1_8 29 | targetCompatibility JavaVersion.VERSION_1_8 30 | } 31 | } 32 | 33 | dependencies { 34 | api project(":eventbus-java") 35 | } 36 | 37 | task sourcesJar(type: Jar) { 38 | from android.sourceSets.main.java.srcDirs 39 | archiveClassifier.set("sources") 40 | } 41 | 42 | apply from: rootProject.file("gradle/publish.gradle") 43 | // Set project-specific properties 44 | // https://developer.android.com/studio/build/maven-publish-plugin 45 | // Because the Android components are created only during the afterEvaluate phase, you must 46 | // configure your publications using the afterEvaluate() lifecycle method. 47 | afterEvaluate { 48 | publishing.publications { 49 | mavenJava(MavenPublication) { 50 | artifactId = "eventbus" 51 | 52 | from components.release 53 | artifact sourcesJar 54 | 55 | pom { 56 | name = "EventBus" 57 | description = "EventBus is a publish/subscribe event bus optimized for Android." 58 | packaging = "aar" 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /EventBus/src/org/greenrobot/eventbus/Subscribe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus; 18 | 19 | 20 | import java.lang.annotation.Documented; 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | @Documented 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target({ElementType.METHOD}) 29 | public @interface Subscribe { 30 | ThreadMode threadMode() default ThreadMode.POSTING; 31 | 32 | /** 33 | * If true, delivers the most recent sticky event (posted with 34 | * {@link EventBus#postSticky(Object)}) to this subscriber (if event available). 35 | */ 36 | boolean sticky() default false; 37 | 38 | /** Subscriber priority to influence the order of event delivery. 39 | * Within the same delivery thread ({@link ThreadMode}), higher priority subscribers will receive events before 40 | * others with a lower priority. The default priority is 0. Note: the priority does *NOT* affect the order of 41 | * delivery among subscribers with different {@link ThreadMode}s! */ 42 | int priority() default 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /EventBus/src/org/greenrobot/eventbus/meta/SimpleSubscriberInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.greenrobot.eventbus.meta; 17 | 18 | import org.greenrobot.eventbus.SubscriberMethod; 19 | 20 | /** 21 | * Uses {@link SubscriberMethodInfo} objects to create {@link org.greenrobot.eventbus.SubscriberMethod} objects on demand. 22 | */ 23 | public class SimpleSubscriberInfo extends AbstractSubscriberInfo { 24 | 25 | private final SubscriberMethodInfo[] methodInfos; 26 | 27 | public SimpleSubscriberInfo(Class subscriberClass, boolean shouldCheckSuperclass, SubscriberMethodInfo[] methodInfos) { 28 | super(subscriberClass, null, shouldCheckSuperclass); 29 | this.methodInfos = methodInfos; 30 | } 31 | 32 | @Override 33 | public synchronized SubscriberMethod[] getSubscriberMethods() { 34 | int length = methodInfos.length; 35 | SubscriberMethod[] methods = new SubscriberMethod[length]; 36 | for (int i = 0; i < length; i++) { 37 | SubscriberMethodInfo info = methodInfos[i]; 38 | methods[i] = createSubscriberMethod(info.methodName, info.eventType, info.threadMode, 39 | info.priority, info.sticky); 40 | } 41 | return methods; 42 | } 43 | } -------------------------------------------------------------------------------- /EventBus/src/org/greenrobot/eventbus/Subscription.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.greenrobot.eventbus; 17 | 18 | final class Subscription { 19 | final Object subscriber; 20 | final SubscriberMethod subscriberMethod; 21 | /** 22 | * Becomes false as soon as {@link EventBus#unregister(Object)} is called, which is checked by queued event delivery 23 | * {@link EventBus#invokeSubscriber(PendingPost)} to prevent race conditions. 24 | */ 25 | volatile boolean active; 26 | 27 | Subscription(Object subscriber, SubscriberMethod subscriberMethod) { 28 | this.subscriber = subscriber; 29 | this.subscriberMethod = subscriberMethod; 30 | active = true; 31 | } 32 | 33 | @Override 34 | public boolean equals(Object other) { 35 | if (other instanceof Subscription) { 36 | Subscription otherSubscription = (Subscription) other; 37 | return subscriber == otherSubscription.subscriber 38 | && subscriberMethod.equals(otherSubscription.subscriberMethod); 39 | } else { 40 | return false; 41 | } 42 | } 43 | 44 | @Override 45 | public int hashCode() { 46 | return subscriber.hashCode() + subscriberMethod.methodString.hashCode(); 47 | } 48 | } -------------------------------------------------------------------------------- /EventBus/src/org/greenrobot/eventbus/PendingPostQueue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus; 18 | 19 | final class PendingPostQueue { 20 | private PendingPost head; 21 | private PendingPost tail; 22 | 23 | synchronized void enqueue(PendingPost pendingPost) { 24 | if (pendingPost == null) { 25 | throw new NullPointerException("null cannot be enqueued"); 26 | } 27 | if (tail != null) { 28 | tail.next = pendingPost; 29 | tail = pendingPost; 30 | } else if (head == null) { 31 | head = tail = pendingPost; 32 | } else { 33 | throw new IllegalStateException("Head present, but no tail"); 34 | } 35 | notifyAll(); 36 | } 37 | 38 | synchronized PendingPost poll() { 39 | PendingPost pendingPost = head; 40 | if (head != null) { 41 | head = head.next; 42 | if (head == null) { 43 | tail = null; 44 | } 45 | } 46 | return pendingPost; 47 | } 48 | 49 | synchronized PendingPost poll(int maxMillisToWait) throws InterruptedException { 50 | if (head == null) { 51 | wait(maxMillisToWait); 52 | } 53 | return poll(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /EventBusAnnotationProcessor/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | 3 | group = rootProject.group 4 | version = rootProject.version 5 | 6 | java.sourceCompatibility = JavaVersion.VERSION_1_8 7 | java.targetCompatibility = JavaVersion.VERSION_1_8 8 | 9 | dependencies { 10 | implementation project(':eventbus-java') 11 | implementation 'de.greenrobot:java-common:2.3.1' 12 | 13 | // Generates the required META-INF descriptor to make the processor incremental. 14 | def incap = '0.2' 15 | compileOnly "net.ltgt.gradle.incap:incap:$incap" 16 | annotationProcessor "net.ltgt.gradle.incap:incap-processor:$incap" 17 | } 18 | 19 | sourceSets { 20 | main { 21 | java { 22 | srcDir 'src' 23 | } 24 | resources { 25 | srcDir 'res' 26 | } 27 | } 28 | } 29 | 30 | javadoc { 31 | title = "EventBus Annotation Processor ${version} API" 32 | options.bottom = 'Available under the Apache License, Version 2.0 - Copyright © 2015-2020 greenrobot.org. All Rights Reserved.' 33 | } 34 | 35 | task javadocJar(type: Jar, dependsOn: javadoc) { 36 | archiveClassifier.set("javadoc") 37 | from 'build/docs/javadoc' 38 | } 39 | 40 | task sourcesJar(type: Jar) { 41 | archiveClassifier.set("sources") 42 | from sourceSets.main.allSource 43 | } 44 | 45 | apply from: rootProject.file("gradle/publish.gradle") 46 | // Set project-specific properties 47 | afterEvaluate { 48 | publishing.publications { 49 | mavenJava(MavenPublication) { 50 | artifactId = "eventbus-annotation-processor" 51 | 52 | from components.java 53 | artifact javadocJar 54 | artifact sourcesJar 55 | pom { 56 | name = "EventBus Annotation Processor" 57 | description = "Precompiler for EventBus Annotations." 58 | packaging = "jar" 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/EventBusBackgroundThreadTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.greenrobot.eventbus; 17 | 18 | import android.os.Looper; 19 | 20 | import org.junit.Test; 21 | 22 | import static org.junit.Assert.assertEquals; 23 | import static org.junit.Assert.assertFalse; 24 | 25 | /** 26 | * @author Markus Junginger, greenrobot 27 | */ 28 | public class EventBusBackgroundThreadTest extends AbstractAndroidEventBusTest { 29 | 30 | @Test 31 | public void testPostInCurrentThread() throws InterruptedException { 32 | eventBus.register(this); 33 | eventBus.post("Hello"); 34 | waitForEventCount(1, 1000); 35 | 36 | assertEquals("Hello", lastEvent); 37 | assertEquals(Thread.currentThread(), lastThread); 38 | } 39 | 40 | @Test 41 | public void testPostFromMain() throws InterruptedException { 42 | eventBus.register(this); 43 | postInMainThread("Hello"); 44 | waitForEventCount(1, 1000); 45 | assertEquals("Hello", lastEvent); 46 | assertFalse(lastThread.equals(Thread.currentThread())); 47 | assertFalse(lastThread.equals(Looper.getMainLooper().getThread())); 48 | } 49 | 50 | @Subscribe(threadMode = ThreadMode.BACKGROUND) 51 | public void onEventBackgroundThread(String event) { 52 | trackEvent(event); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/ClassMapPerfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.greenrobot.eventbus; 18 | 19 | import java.util.HashMap; 20 | import java.util.IdentityHashMap; 21 | import java.util.Map; 22 | 23 | /** 24 | * Just to verify testHashMapClassObject is fastest. Ignore this test. 25 | */ 26 | public class ClassMapPerfTest /* extends TestCase */ { 27 | 28 | static final int COUNT = 10000000; 29 | static final Class CLAZZ = ClassMapPerfTest.class; 30 | 31 | public void testHashMapClassObject() { 32 | Map map = new HashMap(); 33 | for (int i = 0; i < COUNT; i++) { 34 | Class oldValue = map.put(CLAZZ, CLAZZ); 35 | Class value = map.get(CLAZZ); 36 | } 37 | } 38 | 39 | public void testIdentityHashMapClassObject() { 40 | Map map = new IdentityHashMap(); 41 | for (int i = 0; i < COUNT; i++) { 42 | Class oldValue = map.put(CLAZZ, CLAZZ); 43 | Class value = map.get(CLAZZ); 44 | } 45 | } 46 | 47 | public void testHashMapClassName() { 48 | Map map = new HashMap(); 49 | for (int i = 0; i < COUNT; i++) { 50 | Class oldValue = map.put(CLAZZ.getName(), CLAZZ); 51 | Class value = map.get(CLAZZ.getName()); 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /EventBus/src/org/greenrobot/eventbus/util/ThrowableFailureEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.greenrobot.eventbus.util; 17 | 18 | /** 19 | * A generic failure event, which can be used by apps to propagate thrown exceptions. 20 | * Used as default failure event by {@link AsyncExecutor}. 21 | */ 22 | public class ThrowableFailureEvent implements HasExecutionScope { 23 | protected final Throwable throwable; 24 | protected final boolean suppressErrorUi; 25 | private Object executionContext; 26 | 27 | public ThrowableFailureEvent(Throwable throwable) { 28 | this.throwable = throwable; 29 | suppressErrorUi = false; 30 | } 31 | 32 | /** 33 | * @param suppressErrorUi 34 | * true indicates to the receiver that no error UI (e.g. dialog) should now displayed. 35 | */ 36 | public ThrowableFailureEvent(Throwable throwable, boolean suppressErrorUi) { 37 | this.throwable = throwable; 38 | this.suppressErrorUi = suppressErrorUi; 39 | } 40 | 41 | public Throwable getThrowable() { 42 | return throwable; 43 | } 44 | 45 | public boolean isSuppressErrorUi() { 46 | return suppressErrorUi; 47 | } 48 | 49 | public Object getExecutionScope() { 50 | return executionContext; 51 | } 52 | 53 | public void setExecutionScope(Object executionContext) { 54 | this.executionContext = executionContext; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /EventBusTest/src/org/greenrobot/eventbus/EventBusMainThreadTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.greenrobot.eventbus; 17 | 18 | import android.os.Looper; 19 | 20 | import org.junit.Test; 21 | 22 | 23 | import static org.junit.Assert.assertEquals; 24 | 25 | /** 26 | * @author Markus Junginger, greenrobot 27 | */ 28 | public class EventBusMainThreadTest extends AbstractAndroidEventBusTest { 29 | 30 | @Test 31 | public void testPost() throws InterruptedException { 32 | eventBus.register(this); 33 | eventBus.post("Hello"); 34 | waitForEventCount(1, 1000); 35 | 36 | assertEquals("Hello", lastEvent); 37 | assertEquals(Looper.getMainLooper().getThread(), lastThread); 38 | } 39 | 40 | @Test 41 | public void testPostInBackgroundThread() throws InterruptedException { 42 | TestBackgroundPoster backgroundPoster = new TestBackgroundPoster(eventBus); 43 | backgroundPoster.start(); 44 | 45 | eventBus.register(this); 46 | backgroundPoster.post("Hello"); 47 | waitForEventCount(1, 1000); 48 | assertEquals("Hello", lastEvent); 49 | assertEquals(Looper.getMainLooper().getThread(), lastThread); 50 | 51 | backgroundPoster.shutdown(); 52 | backgroundPoster.join(); 53 | } 54 | 55 | @Subscribe(threadMode = ThreadMode.MAIN) 56 | public void onEventMainThread(String event) { 57 | trackEvent(event); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /EventBusPerformance/res/layout/activity_runtests.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 19 | 20 | 26 | 27 | 32 | 33 | 34 |