();
23 |
24 | Object event;
25 | Subscription subscription;
26 | PendingPost next;
27 |
28 | private PendingPost(Object event, Subscription subscription) {
29 | this.event = event;
30 | this.subscription = subscription;
31 | }
32 |
33 | static PendingPost obtainPendingPost(Subscription subscription, Object event) {
34 | synchronized (pendingPostPool) {
35 | int size = pendingPostPool.size();
36 | if (size > 0) {
37 | PendingPost pendingPost = pendingPostPool.remove(size - 1);
38 | pendingPost.event = event;
39 | pendingPost.subscription = subscription;
40 | pendingPost.next = null;
41 | return pendingPost;
42 | }
43 | }
44 | return new PendingPost(event, subscription);
45 | }
46 |
47 | static void releasePendingPost(PendingPost pendingPost) {
48 | pendingPost.event = null;
49 | pendingPost.subscription = null;
50 | pendingPost.next = null;
51 | synchronized (pendingPostPool) {
52 | // Don't let the pool grow indefinitely
53 | if (pendingPostPool.size() < 10000) {
54 | pendingPostPool.add(pendingPost);
55 | }
56 | }
57 | }
58 |
59 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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/src/org/greenrobot/eventbus/SubscriberMethod.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 java.lang.reflect.Method;
19 |
20 | /** Used internally by EventBus and generated subscriber indexes. */
21 | public class SubscriberMethod {
22 | final Method method;
23 | final ThreadMode threadMode;
24 | final Class> eventType;
25 | final int priority;
26 | final boolean sticky;
27 | /** Used for efficient comparison */
28 | String methodString;
29 |
30 | public SubscriberMethod(Method method, Class> eventType, ThreadMode threadMode, int priority, boolean sticky) {
31 | this.method = method;
32 | this.threadMode = threadMode;
33 | this.eventType = eventType;
34 | this.priority = priority;
35 | this.sticky = sticky;
36 | }
37 |
38 | @Override
39 | public boolean equals(Object other) {
40 | if (other == this) {
41 | return true;
42 | } else if (other instanceof SubscriberMethod) {
43 | checkMethodString();
44 | SubscriberMethod otherSubscriberMethod = (SubscriberMethod)other;
45 | otherSubscriberMethod.checkMethodString();
46 | // Don't use method.equals because of http://code.google.com/p/android/issues/detail?id=7811#c6
47 | return methodString.equals(otherSubscriberMethod.methodString);
48 | } else {
49 | return false;
50 | }
51 | }
52 |
53 | private synchronized void checkMethodString() {
54 | if (methodString == null) {
55 | // Method.toString has more overhead, just take relevant parts of the method
56 | StringBuilder builder = new StringBuilder(64);
57 | builder.append(method.getDeclaringClass().getName());
58 | builder.append('#').append(method.getName());
59 | builder.append('(').append(eventType.getName());
60 | methodString = builder.toString();
61 | }
62 | }
63 |
64 | @Override
65 | public int hashCode() {
66 | return method.hashCode();
67 | }
68 | }
--------------------------------------------------------------------------------
/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/ThreadMode.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 | * Each subscriber method has a thread mode, which determines in which thread the method is to be called by EventBus.
20 | * EventBus takes care of threading independently of the posting thread.
21 | *
22 | * @see EventBus#register(Object)
23 | */
24 | public enum ThreadMode {
25 | /**
26 | * This is the default. Subscriber will be called directly in the same thread, which is posting the event. Event delivery
27 | * implies the least overhead because it avoids thread switching completely. Thus, this is the recommended mode for
28 | * simple tasks that are known to complete in a very short time without requiring the main thread. Event handlers
29 | * using this mode must return quickly to avoid blocking the posting thread, which may be the main thread.
30 | */
31 | POSTING,
32 |
33 | /**
34 | * On Android, subscriber will be called in Android's main thread (UI thread). If the posting thread is
35 | * the main thread, subscriber methods will be called directly, blocking the posting thread. Otherwise the event
36 | * is queued for delivery (non-blocking). Subscribers using this mode must return quickly to avoid blocking the main thread.
37 | *
38 | * If not on Android, behaves the same as {@link #POSTING}.
39 | */
40 | MAIN,
41 |
42 | /**
43 | * On Android, subscriber will be called in Android's main thread (UI thread). Different from {@link #MAIN},
44 | * the event will always be queued for delivery. This ensures that the post call is non-blocking.
45 | *
46 | * If not on Android, behaves the same as {@link #POSTING}.
47 | */
48 | MAIN_ORDERED,
49 |
50 | /**
51 | * On Android, subscriber will be called in a background thread. If posting thread is not the main thread, subscriber methods
52 | * will be called directly in the posting thread. If the posting thread is the main thread, EventBus uses a single
53 | * background thread, that will deliver all its events sequentially. Subscribers using this mode should try to
54 | * return quickly to avoid blocking the background thread.
55 | *
56 | * If not on Android, always uses a background thread.
57 | */
58 | BACKGROUND,
59 |
60 | /**
61 | * Subscriber will be called in a separate thread. This is always independent of the posting thread and the
62 | * main thread. Posting events never wait for subscriber methods using this mode. Subscriber methods should
63 | * use this mode if their execution might take some time, e.g. for network access. Avoid triggering a large number
64 | * of long-running asynchronous subscriber methods at the same time to limit the number of concurrent threads. EventBus
65 | * uses a thread pool to efficiently reuse threads from completed asynchronous subscriber notifications.
66 | */
67 | ASYNC
68 | }
--------------------------------------------------------------------------------
/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/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/AbstractSubscriberInfo.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.EventBusException;
19 | import org.greenrobot.eventbus.SubscriberMethod;
20 | import org.greenrobot.eventbus.ThreadMode;
21 |
22 | import java.lang.reflect.Method;
23 |
24 | /** Base class for generated subscriber meta info classes created by annotation processing. */
25 | public abstract class AbstractSubscriberInfo implements SubscriberInfo {
26 | private final Class subscriberClass;
27 | private final Class extends SubscriberInfo> superSubscriberInfoClass;
28 | private final boolean shouldCheckSuperclass;
29 |
30 | protected AbstractSubscriberInfo(Class subscriberClass, Class extends SubscriberInfo> superSubscriberInfoClass,
31 | boolean shouldCheckSuperclass) {
32 | this.subscriberClass = subscriberClass;
33 | this.superSubscriberInfoClass = superSubscriberInfoClass;
34 | this.shouldCheckSuperclass = shouldCheckSuperclass;
35 | }
36 |
37 | @Override
38 | public Class getSubscriberClass() {
39 | return subscriberClass;
40 | }
41 |
42 | @Override
43 | public SubscriberInfo getSuperSubscriberInfo() {
44 | if(superSubscriberInfoClass == null) {
45 | return null;
46 | }
47 | try {
48 | return superSubscriberInfoClass.newInstance();
49 | } catch (InstantiationException e) {
50 | throw new RuntimeException(e);
51 | } catch (IllegalAccessException e) {
52 | throw new RuntimeException(e);
53 | }
54 | }
55 |
56 | @Override
57 | public boolean shouldCheckSuperclass() {
58 | return shouldCheckSuperclass;
59 | }
60 |
61 | protected SubscriberMethod createSubscriberMethod(String methodName, Class> eventType) {
62 | return createSubscriberMethod(methodName, eventType, ThreadMode.POSTING, 0, false);
63 | }
64 |
65 | protected SubscriberMethod createSubscriberMethod(String methodName, Class> eventType, ThreadMode threadMode) {
66 | return createSubscriberMethod(methodName, eventType, threadMode, 0, false);
67 | }
68 |
69 | protected SubscriberMethod createSubscriberMethod(String methodName, Class> eventType, ThreadMode threadMode,
70 | int priority, boolean sticky) {
71 | try {
72 | Method method = subscriberClass.getDeclaredMethod(methodName, eventType);
73 | return new SubscriberMethod(method, eventType, threadMode, priority, sticky);
74 | } catch (NoSuchMethodException e) {
75 | throw new EventBusException("Could not find subscriber method in " + subscriberClass +
76 | ". Maybe a missing ProGuard rule?", e);
77 | }
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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/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/util/AsyncExecutor.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 | import org.greenrobot.eventbus.EventBus;
19 |
20 | import java.lang.reflect.Constructor;
21 | import java.util.concurrent.Executor;
22 | import java.util.concurrent.Executors;
23 | import java.util.logging.Level;
24 |
25 | /**
26 | * Executes an {@link RunnableEx} using a thread pool. Thrown exceptions are propagated by posting failure events.
27 | * By default, uses {@link ThrowableFailureEvent}.
28 | *
29 | * Set a custom event type using {@link Builder#failureEventType(Class)}.
30 | * The failure event class must have a constructor with one parameter of type {@link Throwable}.
31 | * If using ProGuard or R8 make sure the constructor of the failure event class is kept, it is accessed via reflection.
32 | * E.g. add a rule like
33 | *
34 | * -keepclassmembers class com.example.CustomThrowableFailureEvent {
35 | * <init>(java.lang.Throwable);
36 | * }
37 | *
38 | */
39 | public class AsyncExecutor {
40 |
41 | public static class Builder {
42 | private Executor threadPool;
43 | private Class> failureEventType;
44 | private EventBus eventBus;
45 |
46 | private Builder() {
47 | }
48 |
49 | public Builder threadPool(Executor threadPool) {
50 | this.threadPool = threadPool;
51 | return this;
52 | }
53 |
54 | public Builder failureEventType(Class> failureEventType) {
55 | this.failureEventType = failureEventType;
56 | return this;
57 | }
58 |
59 | public Builder eventBus(EventBus eventBus) {
60 | this.eventBus = eventBus;
61 | return this;
62 | }
63 |
64 | public AsyncExecutor build() {
65 | return buildForScope(null);
66 | }
67 |
68 | public AsyncExecutor buildForScope(Object executionContext) {
69 | if (eventBus == null) {
70 | eventBus = EventBus.getDefault();
71 | }
72 | if (threadPool == null) {
73 | threadPool = Executors.newCachedThreadPool();
74 | }
75 | if (failureEventType == null) {
76 | failureEventType = ThrowableFailureEvent.class;
77 | }
78 | return new AsyncExecutor(threadPool, eventBus, failureEventType, executionContext);
79 | }
80 | }
81 |
82 | /** Like {@link Runnable}, but the run method may throw an exception. */
83 | public interface RunnableEx {
84 | void run() throws Exception;
85 | }
86 |
87 | public static Builder builder() {
88 | return new Builder();
89 | }
90 |
91 | public static AsyncExecutor create() {
92 | return new Builder().build();
93 | }
94 |
95 | private final Executor threadPool;
96 | private final Constructor> failureEventConstructor;
97 | private final EventBus eventBus;
98 | private final Object scope;
99 |
100 | private AsyncExecutor(Executor threadPool, EventBus eventBus, Class> failureEventType, Object scope) {
101 | this.threadPool = threadPool;
102 | this.eventBus = eventBus;
103 | this.scope = scope;
104 | try {
105 | failureEventConstructor = failureEventType.getConstructor(Throwable.class);
106 | } catch (NoSuchMethodException e) {
107 | throw new RuntimeException(
108 | "Failure event class must have a constructor with one parameter of type Throwable", e);
109 | }
110 | }
111 |
112 | /** Posts an failure event if the given {@link RunnableEx} throws an Exception. */
113 | public void execute(final RunnableEx runnable) {
114 | threadPool.execute(() -> {
115 | try {
116 | runnable.run();
117 | } catch (Exception e) {
118 | Object event;
119 | try {
120 | event = failureEventConstructor.newInstance(e);
121 | } catch (Exception e1) {
122 | eventBus.getLogger().log(Level.SEVERE, "Original exception:", e);
123 | throw new RuntimeException("Could not create failure event", e1);
124 | }
125 | if (event instanceof HasExecutionScope) {
126 | ((HasExecutionScope) event).setExecutionScope(scope);
127 | }
128 | eventBus.post(event);
129 | }
130 | });
131 | }
132 |
133 | }
134 |
--------------------------------------------------------------------------------
/EventBus/src/org/greenrobot/eventbus/util/ExceptionToResourceMapping.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2020 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 | import org.greenrobot.eventbus.Logger;
20 |
21 | import java.util.HashMap;
22 | import java.util.Map;
23 | import java.util.Map.Entry;
24 | import java.util.Set;
25 | import java.util.logging.Level;
26 |
27 |
28 | /**
29 | * Maps throwables to texts for error dialogs. Use Config to configure the mapping.
30 | *
31 | * @author Markus
32 | */
33 | public class ExceptionToResourceMapping {
34 |
35 | public final Map, Integer> throwableToMsgIdMap;
36 |
37 | public ExceptionToResourceMapping() {
38 | throwableToMsgIdMap = new HashMap<>();
39 | }
40 |
41 | /** Looks at the exception and its causes trying to find an ID. */
42 | public Integer mapThrowable(final Throwable throwable) {
43 | Throwable throwableToCheck = throwable;
44 | int depthToGo = 20;
45 |
46 | while (true) {
47 | Integer resId = mapThrowableFlat(throwableToCheck);
48 | if (resId != null) {
49 | return resId;
50 | } else {
51 | throwableToCheck = throwableToCheck.getCause();
52 | depthToGo--;
53 | if (depthToGo <= 0 || throwableToCheck == throwable || throwableToCheck == null) {
54 | Logger logger = Logger.Default.get(); // No EventBus instance here
55 | logger.log(Level.FINE, "No specific message resource ID found for " + throwable);
56 | // return config.defaultErrorMsgId;
57 | return null;
58 | }
59 | }
60 | }
61 |
62 | }
63 |
64 | /** Mapping without checking the cause (done in mapThrowable). */
65 | protected Integer mapThrowableFlat(Throwable throwable) {
66 | Class extends Throwable> throwableClass = throwable.getClass();
67 | Integer resId = throwableToMsgIdMap.get(throwableClass);
68 | if (resId == null) {
69 | Class extends Throwable> closestClass = null;
70 | Set, Integer>> mappings = throwableToMsgIdMap.entrySet();
71 | for (Entry, Integer> mapping : mappings) {
72 | Class extends Throwable> candidate = mapping.getKey();
73 | if (candidate.isAssignableFrom(throwableClass)) {
74 | if (closestClass == null || closestClass.isAssignableFrom(candidate)) {
75 | closestClass = candidate;
76 | resId = mapping.getValue();
77 | }
78 | }
79 | }
80 |
81 | }
82 | return resId;
83 | }
84 |
85 | public ExceptionToResourceMapping addMapping(Class extends Throwable> clazz, int msgId) {
86 | throwableToMsgIdMap.put(clazz, msgId);
87 | return this;
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/EventBusAnnotationProcessor/res/META-INF/services/javax.annotation.processing.Processor:
--------------------------------------------------------------------------------
1 | org.greenrobot.eventbus.annotationprocessor.EventBusAnnotationProcessor
2 |
--------------------------------------------------------------------------------
/EventBusPerformance/.gitignore:
--------------------------------------------------------------------------------
1 | /bin
2 | /gen
3 |
--------------------------------------------------------------------------------
/EventBusPerformance/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/EventBusPerformance/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/greenrobot/EventBus/0194926b3bcf70cc0d7bfd3c5da16708dd5ab876/EventBusPerformance/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/EventBusPerformance/res/drawable-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/greenrobot/EventBus/0194926b3bcf70cc0d7bfd3c5da16708dd5ab876/EventBusPerformance/res/drawable-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/EventBusPerformance/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/greenrobot/EventBus/0194926b3bcf70cc0d7bfd3c5da16708dd5ab876/EventBusPerformance/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/EventBusPerformance/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/greenrobot/EventBus/0194926b3bcf70cc0d7bfd3c5da16708dd5ab876/EventBusPerformance/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/EventBusPerformance/res/layout/activity_runtests.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
19 |
20 |
26 |
27 |
32 |
33 |
34 |
43 |
44 |
53 |
54 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/EventBusPerformance/src/org/greenrobot/eventbusperf/Test.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 | import android.content.Context;
20 |
21 | import java.util.concurrent.atomic.AtomicLong;
22 |
23 | public abstract class Test {
24 | protected final Context context;
25 | protected final TestParams params;
26 | public final AtomicLong eventsReceivedCount = new AtomicLong();
27 | protected long primaryResultMicros;
28 | protected int primaryResultCount;
29 | protected String otherTestResults;
30 |
31 | protected boolean canceled;
32 |
33 | public Test(Context context, TestParams params) {
34 | this.context = context;
35 | this.params = params;
36 | }
37 |
38 | public void cancel() {
39 | canceled = true;
40 | }
41 |
42 | /** prepares the test, all things which are not relevant for test results */
43 | public abstract void prepareTest();
44 |
45 | public abstract void runTest();
46 |
47 | /** returns the display name of the test. e.g. EventBus */
48 | public abstract String getDisplayName();
49 |
50 | protected void waitForReceivedEventCount(int expectedEventCount) {
51 | while (eventsReceivedCount.get() < expectedEventCount) {
52 | try {
53 | Thread.sleep(1);
54 | } catch (InterruptedException e) {
55 | throw new RuntimeException(e);
56 | }
57 | }
58 | }
59 |
60 | public long getPrimaryResultMicros() {
61 | return primaryResultMicros;
62 | }
63 |
64 | public double getPrimaryResultRate() {
65 | return primaryResultCount / (primaryResultMicros / 1000000d);
66 | }
67 |
68 | public String getOtherTestResults() {
69 | return otherTestResults;
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/EventBusPerformance/src/org/greenrobot/eventbusperf/TestParams.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 | import org.greenrobot.eventbus.ThreadMode;
20 |
21 | import java.io.Serializable;
22 | import java.util.ArrayList;
23 |
24 | public class TestParams implements Serializable {
25 | private static final long serialVersionUID = -2739435088947740809L;
26 |
27 | private int eventCount;
28 | private int subscriberCount;
29 | private int publisherCount;
30 | private ThreadMode threadMode;
31 | private boolean eventInheritance;
32 | private boolean ignoreGeneratedIndex;
33 | private int testNumber;
34 | private ArrayList> testClasses;
35 |
36 | public int getEventCount() {
37 | return eventCount;
38 | }
39 |
40 | public void setEventCount(int iterations) {
41 | this.eventCount = iterations;
42 | }
43 |
44 | public int getSubscriberCount() {
45 | return subscriberCount;
46 | }
47 |
48 | public void setSubscriberCount(int subscriberCount) {
49 | this.subscriberCount = subscriberCount;
50 | }
51 |
52 | public int getPublisherCount() {
53 | return publisherCount;
54 | }
55 |
56 | public void setPublisherCount(int publisherCount) {
57 | this.publisherCount = publisherCount;
58 | }
59 |
60 | public ThreadMode getThreadMode() {
61 | return threadMode;
62 | }
63 |
64 | public void setThreadMode(ThreadMode threadMode) {
65 | this.threadMode = threadMode;
66 | }
67 |
68 | public boolean isEventInheritance() {
69 | return eventInheritance;
70 | }
71 |
72 | public void setEventInheritance(boolean eventInheritance) {
73 | this.eventInheritance = eventInheritance;
74 | }
75 |
76 | public boolean isIgnoreGeneratedIndex() {
77 | return ignoreGeneratedIndex;
78 | }
79 |
80 | public void setIgnoreGeneratedIndex(boolean ignoreGeneratedIndex) {
81 | this.ignoreGeneratedIndex = ignoreGeneratedIndex;
82 | }
83 |
84 | public ArrayList> getTestClasses() {
85 | return testClasses;
86 | }
87 |
88 | public void setTestClasses(ArrayList> testClasses) {
89 | this.testClasses = testClasses;
90 | }
91 |
92 | public int getTestNumber() {
93 | return testNumber;
94 | }
95 |
96 | public void setTestNumber(int testNumber) {
97 | this.testNumber = testNumber;
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/EventBusPerformance/src/org/greenrobot/eventbusperf/TestRunner.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 | import android.content.Context;
20 |
21 | import org.greenrobot.eventbus.EventBus;
22 |
23 | import java.lang.reflect.Constructor;
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | /**
28 | * This thread initialize all selected tests and runs them through. Also the thread skips the tests, when it is canceled
29 | */
30 | public class TestRunner extends Thread {
31 | private List tests;
32 | private volatile boolean canceled;
33 | private final EventBus controlBus;
34 |
35 | public TestRunner(Context context, TestParams testParams, EventBus controlBus) {
36 | this.controlBus = controlBus;
37 | tests = new ArrayList();
38 | for (Class extends Test> testClazz : testParams.getTestClasses()) {
39 | try {
40 | Constructor>[] constructors = testClazz.getConstructors();
41 | Constructor extends Test> constructor = testClazz.getConstructor(Context.class, TestParams.class);
42 | Test test = constructor.newInstance(context, testParams);
43 | tests.add(test);
44 | } catch (Exception e) {
45 | throw new RuntimeException(e);
46 | }
47 | }
48 | }
49 |
50 | public void run() {
51 |
52 | int idx = 0;
53 | for (Test test : tests) {
54 | // Clean up and let the main thread calm down
55 | System.gc();
56 | try {
57 | Thread.sleep(300);
58 | System.gc();
59 | Thread.sleep(300);
60 | } catch (InterruptedException e) {
61 | }
62 |
63 | test.prepareTest();
64 | if (!canceled) {
65 | test.runTest();
66 | }
67 | if (!canceled) {
68 | boolean isLastEvent = idx == tests.size() - 1;
69 | controlBus.post(new TestFinishedEvent(test, isLastEvent));
70 | }
71 | idx++;
72 | }
73 |
74 | }
75 |
76 | public List getTests() {
77 | return tests;
78 | }
79 |
80 | public void cancel() {
81 | canceled = true;
82 | for (Test test : tests) {
83 | test.cancel();
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/EventBusPerformance/src/org/greenrobot/eventbusperf/TestRunnerActivity.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 | import android.app.Activity;
20 | import android.os.Bundle;
21 | import android.os.Process;
22 | import android.text.Html;
23 | import android.view.View;
24 | import android.widget.TextView;
25 |
26 | import org.greenrobot.eventbus.EventBus;
27 | import org.greenrobot.eventbus.Subscribe;
28 | import org.greenrobot.eventbus.ThreadMode;
29 |
30 | /**
31 | * This activity gets the information from the activity before, sets up the test and starts the test. After it watchs
32 | * after that, if a test is finished. When a test is finished, the activity appends it on the textview analyse. If all
33 | * test are finished, it cancels the timer.
34 | */
35 | public class TestRunnerActivity extends Activity {
36 |
37 | private TestRunner testRunner;
38 | private EventBus controlBus;
39 | private TextView textViewResult;
40 |
41 | @Override
42 | public void onCreate(Bundle savedInstanceState) {
43 | super.onCreate(savedInstanceState);
44 | setContentView(R.layout.activity_runtests);
45 | textViewResult = findViewById(R.id.textViewResult);
46 | controlBus = new EventBus();
47 | controlBus.register(this);
48 | }
49 |
50 | @Override
51 | protected void onResume() {
52 | super.onResume();
53 | if (testRunner == null) {
54 | TestParams testParams = (TestParams) getIntent().getSerializableExtra("params");
55 | testRunner = new TestRunner(getApplicationContext(), testParams, controlBus);
56 |
57 | if (testParams.getTestNumber() == 1) {
58 | textViewResult.append("Events: " + testParams.getEventCount() + "\n");
59 | }
60 | textViewResult.append("Subscribers: " + testParams.getSubscriberCount() + "\n\n");
61 | testRunner.start();
62 | }
63 | }
64 |
65 | @Subscribe(threadMode = ThreadMode.MAIN)
66 | public void onEventMainThread(TestFinishedEvent event) {
67 | Test test = event.test;
68 | String text = "" + test.getDisplayName() + " " + //
69 | test.getPrimaryResultMicros() + " micro seconds " + //
70 | ((int) test.getPrimaryResultRate()) + "/s ";
71 | if (test.getOtherTestResults() != null) {
72 | text += test.getOtherTestResults();
73 | }
74 | text += " ---------------- ";
75 | textViewResult.append(Html.fromHtml(text));
76 | if (event.isLastEvent) {
77 | findViewById(R.id.buttonCancel).setVisibility(View.GONE);
78 | findViewById(R.id.textViewTestRunning).setVisibility(View.GONE);
79 | findViewById(R.id.buttonKillProcess).setVisibility(View.VISIBLE);
80 | }
81 | }
82 |
83 | public void onClickCancel(View view) {
84 | // Cancel asap
85 | if (testRunner != null) {
86 | testRunner.cancel();
87 | testRunner = null;
88 | }
89 | finish();
90 | }
91 |
92 | public void onClickKillProcess(View view) {
93 | Process.killProcess(Process.myPid());
94 | }
95 |
96 | public void onDestroy() {
97 | if (testRunner != null) {
98 | testRunner.cancel();
99 | }
100 | controlBus.unregister(this);
101 | super.onDestroy();
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/EventBusPerformance/src/org/greenrobot/eventbusperf/TestSetupActivity.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 | import android.app.Activity;
20 | import android.content.Intent;
21 | import android.os.Bundle;
22 | import android.view.View;
23 | import android.widget.AdapterView;
24 | import android.widget.CheckBox;
25 | import android.widget.EditText;
26 | import android.widget.Spinner;
27 |
28 | import org.greenrobot.eventbus.ThreadMode;
29 |
30 | import java.util.ArrayList;
31 |
32 | import org.greenrobot.eventbusperf.testsubject.PerfTestEventBus;
33 | import org.greenrobot.eventbusperf.testsubject.PerfTestOtto;
34 |
35 | public class TestSetupActivity extends Activity {
36 |
37 | @SuppressWarnings("rawtypes")
38 | static final Class[] TEST_CLASSES_EVENTBUS = {PerfTestEventBus.Post.class,//
39 | PerfTestEventBus.RegisterOneByOne.class,//
40 | PerfTestEventBus.RegisterAll.class, //
41 | PerfTestEventBus.RegisterFirstTime.class};
42 |
43 | static final Class[] TEST_CLASSES_OTTO = {PerfTestOtto.Post.class,//
44 | PerfTestOtto.RegisterOneByOne.class,//
45 | PerfTestOtto.RegisterAll.class, //
46 | PerfTestOtto.RegisterFirstTime.class};
47 |
48 | @Override
49 | public void onCreate(Bundle savedInstanceState) {
50 | super.onCreate(savedInstanceState);
51 | setContentView(R.layout.activity_setuptests);
52 |
53 | Spinner spinnerRun = findViewById(R.id.spinnerTestToRun);
54 | spinnerRun.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
55 |
56 | public void onItemSelected(AdapterView> adapter, View v, int pos, long lng) {
57 | int eventsVisibility = pos == 0 ? View.VISIBLE : View.GONE;
58 | findViewById(R.id.relativeLayoutForEvents).setVisibility(eventsVisibility);
59 | findViewById(R.id.spinnerThread).setVisibility(eventsVisibility);
60 | }
61 |
62 | public void onNothingSelected(AdapterView> arg0) {
63 | }
64 | });
65 | }
66 |
67 | public void checkEventBus(View v) {
68 | Spinner spinnerThread = findViewById(R.id.spinnerThread);
69 | CheckBox checkBoxEventBus = findViewById(R.id.checkBoxEventBus);
70 | int visibility = checkBoxEventBus.isChecked() ? View.VISIBLE : View.GONE;
71 | spinnerThread.setVisibility(visibility);
72 | }
73 |
74 | public void startClick(View v) {
75 | TestParams params = new TestParams();
76 | Spinner spinnerThread = findViewById(R.id.spinnerThread);
77 | String threadModeStr = spinnerThread.getSelectedItem().toString();
78 | ThreadMode threadMode = ThreadMode.valueOf(threadModeStr);
79 | params.setThreadMode(threadMode);
80 |
81 | params.setEventInheritance(((CheckBox) findViewById(R.id.checkBoxEventBusEventHierarchy)).isChecked());
82 | params.setIgnoreGeneratedIndex(((CheckBox) findViewById(R.id.checkBoxEventBusIgnoreGeneratedIndex)).isChecked());
83 |
84 | EditText editTextEvent = findViewById(R.id.editTextEvent);
85 | params.setEventCount(Integer.parseInt(editTextEvent.getText().toString()));
86 |
87 | EditText editTextSubscriber = findViewById(R.id.editTextSubscribe);
88 | params.setSubscriberCount(Integer.parseInt(editTextSubscriber.getText().toString()));
89 |
90 | Spinner spinnerTestToRun = findViewById(R.id.spinnerTestToRun);
91 | int testPos = spinnerTestToRun.getSelectedItemPosition();
92 | params.setTestNumber(testPos + 1);
93 | ArrayList> testClasses = initTestClasses(testPos);
94 | params.setTestClasses(testClasses);
95 |
96 | Intent intent = new Intent();
97 | intent.setClass(this, TestRunnerActivity.class);
98 | intent.putExtra("params", params);
99 | startActivity(intent);
100 | }
101 |
102 | @SuppressWarnings("unchecked")
103 | private ArrayList> initTestClasses(int testPos) {
104 | ArrayList> testClasses = new ArrayList>();
105 | // the attributes are putted in the intent (eventbus, otto, broadcast, local broadcast)
106 | final CheckBox checkBoxEventBus = findViewById(R.id.checkBoxEventBus);
107 | final CheckBox checkBoxOtto = findViewById(R.id.checkBoxOtto);
108 | final CheckBox checkBoxBroadcast = findViewById(R.id.checkBoxBroadcast);
109 | final CheckBox checkBoxLocalBroadcast = findViewById(R.id.checkBoxLocalBroadcast);
110 | if (checkBoxEventBus.isChecked()) {
111 | testClasses.add(TEST_CLASSES_EVENTBUS[testPos]);
112 | }
113 | if (checkBoxOtto.isChecked()) {
114 | testClasses.add(TEST_CLASSES_OTTO[testPos]);
115 | }
116 | if (checkBoxBroadcast.isChecked()) {
117 | }
118 | if (checkBoxLocalBroadcast.isChecked()) {
119 | }
120 |
121 | return testClasses;
122 | }
123 | }
--------------------------------------------------------------------------------
/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/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/EventBusTest/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 | androidTestImplementation project(':eventbus-android')
17 | androidTestImplementation project(':EventBusTestJava')
18 | androidTestAnnotationProcessor project(':eventbus-annotation-processor')
19 | // Trying to repro bug:
20 | // androidTestAnnotationProcessor 'org.greenrobot:eventbus-annotation-processor:3.1.0'
21 | implementation fileTree(dir: 'libs', include: '*.jar')
22 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
23 | androidTestImplementation 'com.android.support.test:rules:1.0.2'
24 | }
25 |
26 | android {
27 | compileSdkVersion _compileSdkVersion
28 |
29 | compileOptions {
30 | sourceCompatibility = JavaVersion.VERSION_1_7
31 | targetCompatibility = JavaVersion.VERSION_1_7
32 | }
33 |
34 | sourceSets {
35 | main {
36 | manifest.srcFile 'AndroidManifest.xml'
37 | }
38 |
39 | androidTest {
40 | java.srcDirs = ['src']
41 | }
42 | }
43 |
44 | defaultConfig {
45 | minSdkVersion 9
46 | targetSdkVersion 26
47 | versionCode 1
48 | versionName "1.0"
49 |
50 | testApplicationId "de.greenrobot.event.test"
51 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
52 |
53 | javaCompileOptions {
54 | annotationProcessorOptions {
55 | arguments = [ eventBusIndex : 'org.greenrobot.eventbus.EventBusTestsIndex' ]
56 | }
57 | }
58 | }
59 |
60 | useLibrary 'android.test.base'
61 |
62 | lintOptions {
63 | // To see problems right away, also nice for Travis CI
64 | textOutput 'stdout'
65 |
66 | // TODO FIXME: Travis only error
67 | abortOnError false
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/EventBusTest/libs/EventBusTestSubscriberInJar-3.0.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/greenrobot/EventBus/0194926b3bcf70cc0d7bfd3c5da16708dd5ab876/EventBusTest/libs/EventBusTestSubscriberInJar-3.0.0.jar
--------------------------------------------------------------------------------
/EventBusTest/src/org/greenrobot/eventbus/AbstractAndroidEventBusTest.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.annotation.SuppressLint;
19 | import android.os.Handler;
20 | import android.os.Looper;
21 | import android.os.Message;
22 | import android.support.test.runner.AndroidJUnit4;
23 |
24 | import org.junit.Before;
25 | import org.junit.runner.RunWith;
26 |
27 |
28 | import static org.junit.Assert.assertFalse;
29 |
30 | /**
31 | * @author Markus Junginger, greenrobot
32 | */
33 | @RunWith(AndroidJUnit4.class)
34 | public abstract class AbstractAndroidEventBusTest extends AbstractEventBusTest {
35 | private EventPostHandler mainPoster;
36 |
37 | public AbstractAndroidEventBusTest() {
38 | this(false);
39 | }
40 |
41 | public AbstractAndroidEventBusTest(boolean collectEventsReceived) {
42 | super(collectEventsReceived);
43 | }
44 |
45 | @Before
46 | public void setUpAndroid() throws Exception {
47 | mainPoster = new EventPostHandler(Looper.getMainLooper());
48 | assertFalse(Looper.getMainLooper().getThread().equals(Thread.currentThread()));
49 | }
50 |
51 | protected void postInMainThread(Object event) {
52 | mainPoster.post(event);
53 | }
54 |
55 | @SuppressLint("HandlerLeak")
56 | class EventPostHandler extends Handler {
57 | public EventPostHandler(Looper looper) {
58 | super(looper);
59 | }
60 |
61 | @Override
62 | public void handleMessage(Message msg) {
63 | eventBus.post(msg.obj);
64 | }
65 |
66 | void post(Object event) {
67 | sendMessage(obtainMessage(0, event));
68 | }
69 |
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/EventBusTest/src/org/greenrobot/eventbus/EventBusAndroidActivityTest.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.app.Activity;
19 | import android.support.test.annotation.UiThreadTest;
20 | import android.support.test.rule.UiThreadTestRule;
21 | import android.util.Log;
22 |
23 | import org.junit.Rule;
24 | import org.junit.Test;
25 |
26 |
27 | import static org.junit.Assert.assertEquals;
28 |
29 | /**
30 | * @author Markus Junginger, greenrobot
31 | */
32 | // Do not extend from AbstractAndroidEventBusTest, because it asserts test may not be in main thread
33 | public class EventBusAndroidActivityTest extends AbstractEventBusTest {
34 |
35 | public static class WithIndex extends EventBusBasicTest {
36 | @Test
37 | public void dummy() {
38 | }
39 |
40 | }
41 |
42 | @Rule
43 | public final UiThreadTestRule uiThreadTestRule = new UiThreadTestRule();
44 |
45 | @Test
46 | @UiThreadTest
47 | public void testRegisterAndPost() {
48 | // Use an activity to test real life performance
49 | TestActivity testActivity = new TestActivity();
50 | String event = "Hello";
51 |
52 | long start = System.currentTimeMillis();
53 | eventBus.register(testActivity);
54 | long time = System.currentTimeMillis() - start;
55 | Log.d(EventBus.TAG, "Registered in " + time + "ms");
56 |
57 | eventBus.post(event);
58 |
59 | assertEquals(event, testActivity.lastStringEvent);
60 | }
61 |
62 | public static class TestActivity extends Activity {
63 | public String lastStringEvent;
64 |
65 | @Subscribe
66 | public void onEvent(String event) {
67 | lastStringEvent = event;
68 | }
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/EventBusTest/src/org/greenrobot/eventbus/EventBusAndroidMultithreadedTest.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.os.Looper;
22 | import android.support.test.runner.AndroidJUnit4;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | import static org.junit.Assert.assertNotSame;
28 | import static org.junit.Assert.assertSame;
29 |
30 | @RunWith(AndroidJUnit4.class)
31 | public class EventBusAndroidMultithreadedTest extends EventBusMultithreadedTest {
32 |
33 | @Test
34 | public void testSubscribeUnSubscribeAndPostMixedEventType() throws InterruptedException {
35 | List threads = new ArrayList();
36 |
37 | // Debug.startMethodTracing("testSubscribeUnSubscribeAndPostMixedEventType");
38 | for (int i = 0; i < 5; i++) {
39 | SubscribeUnsubscribeThread thread = new SubscribeUnsubscribeThread();
40 | thread.start();
41 | threads.add(thread);
42 | }
43 | // This test takes a bit longer, so just use fraction the regular count
44 | runThreadsMixedEventType(COUNT / 4, 5);
45 | for (SubscribeUnsubscribeThread thread : threads) {
46 | thread.shutdown();
47 | }
48 | for (SubscribeUnsubscribeThread thread : threads) {
49 | thread.join();
50 | }
51 | // Debug.stopMethodTracing();
52 | }
53 |
54 | public class SubscribeUnsubscribeThread extends Thread {
55 | boolean running = true;
56 |
57 | public void shutdown() {
58 | running = false;
59 | }
60 |
61 | @Override
62 | public void run() {
63 | try {
64 | while (running) {
65 | eventBus.register(this);
66 | double random = Math.random();
67 | if (random > 0.6d) {
68 | Thread.sleep(0, (int) (1000000 * Math.random()));
69 | } else if (random > 0.3d) {
70 | Thread.yield();
71 | }
72 | eventBus.unregister(this);
73 | }
74 | } catch (InterruptedException e) {
75 | throw new RuntimeException(e);
76 | }
77 | }
78 |
79 | @Subscribe(threadMode = ThreadMode.MAIN)
80 | public void onEventMainThread(String event) {
81 | assertSame(Looper.getMainLooper(), Looper.myLooper());
82 | }
83 |
84 | @Subscribe(threadMode = ThreadMode.BACKGROUND)
85 | public void onEventBackgroundThread(Integer event) {
86 | assertNotSame(Looper.getMainLooper(), Looper.myLooper());
87 | }
88 |
89 | @Subscribe
90 | public void onEvent(Object event) {
91 | assertNotSame(Looper.getMainLooper(), Looper.myLooper());
92 | }
93 |
94 | @Subscribe(threadMode = ThreadMode.ASYNC)
95 | public void onEventAsync(Object event) {
96 | assertNotSame(Looper.getMainLooper(), Looper.myLooper());
97 | }
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/EventBusTest/src/org/greenrobot/eventbus/EventBusAndroidOrderTest.java:
--------------------------------------------------------------------------------
1 | package org.greenrobot.eventbus;
2 |
3 | import android.os.Handler;
4 | import android.os.Looper;
5 |
6 | import org.junit.After;
7 | import org.junit.Before;
8 | import org.junit.Test;
9 |
10 |
11 | import static org.junit.Assert.assertEquals;
12 |
13 | public class EventBusAndroidOrderTest extends AbstractAndroidEventBusTest {
14 |
15 | private TestBackgroundPoster backgroundPoster;
16 | private Handler handler;
17 |
18 | @Before
19 | public void setUp() throws Exception {
20 | handler = new Handler(Looper.getMainLooper());
21 | backgroundPoster = new TestBackgroundPoster(eventBus);
22 | backgroundPoster.start();
23 | }
24 |
25 | @After
26 | public void tearDown() throws Exception {
27 | backgroundPoster.shutdown();
28 | backgroundPoster.join();
29 | }
30 |
31 | @Test
32 | public void backgroundAndMainUnordered() {
33 | eventBus.register(this);
34 |
35 | handler.post(new Runnable() {
36 | @Override
37 | public void run() {
38 | // post from non-main thread
39 | backgroundPoster.post("non-main");
40 | // post from main thread
41 | eventBus.post("main");
42 | }
43 | });
44 |
45 | waitForEventCount(2, 1000);
46 |
47 | // observe that event from *main* thread is posted FIRST
48 | // NOT in posting order
49 | assertEquals("non-main", lastEvent);
50 | }
51 |
52 | @Test
53 | public void backgroundAndMainOrdered() {
54 | eventBus.register(this);
55 |
56 | handler.post(new Runnable() {
57 | @Override
58 | public void run() {
59 | // post from non-main thread
60 | backgroundPoster.post(new OrderedEvent("non-main"));
61 | // post from main thread
62 | eventBus.post(new OrderedEvent("main"));
63 | }
64 | });
65 |
66 | waitForEventCount(2, 1000);
67 |
68 | // observe that event from *main* thread is posted LAST
69 | // IN posting order
70 | assertEquals("main", ((OrderedEvent) lastEvent).thread);
71 | }
72 |
73 | @Subscribe(threadMode = ThreadMode.MAIN)
74 | public void onEvent(String event) {
75 | trackEvent(event);
76 | }
77 |
78 | @Subscribe(threadMode = ThreadMode.MAIN_ORDERED)
79 | public void onEvent(OrderedEvent event) {
80 | trackEvent(event);
81 | }
82 |
83 | static class OrderedEvent {
84 | String thread;
85 |
86 | OrderedEvent(String thread) {
87 | this.thread = thread;
88 | }
89 | }
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/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/EventBusMainThreadRacingTest.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.Handler;
19 | import android.os.Looper;
20 |
21 | import org.junit.Test;
22 |
23 | import java.util.Random;
24 | import java.util.concurrent.CountDownLatch;
25 |
26 | /**
27 | * @author Markus Junginger, greenrobot
28 | */
29 | public class EventBusMainThreadRacingTest extends AbstractAndroidEventBusTest {
30 |
31 | private static final int ITERATIONS = LONG_TESTS ? 100000 : 1000;
32 |
33 | protected boolean unregistered;
34 | private CountDownLatch startLatch;
35 | private volatile RuntimeException failed;
36 |
37 | @Test
38 | public void testRacingThreads() throws InterruptedException {
39 | Runnable register = new Runnable() {
40 | @Override
41 | public void run() {
42 | eventBus.register(EventBusMainThreadRacingTest.this);
43 | unregistered = false;
44 | }
45 | };
46 |
47 | Runnable unregister = new Runnable() {
48 | @Override
49 | public void run() {
50 | eventBus.unregister(EventBusMainThreadRacingTest.this);
51 | unregistered = true;
52 | }
53 | };
54 |
55 | startLatch = new CountDownLatch(2);
56 | BackgroundPoster backgroundPoster = new BackgroundPoster();
57 | backgroundPoster.start();
58 | try {
59 | Handler handler = new Handler(Looper.getMainLooper());
60 | Random random = new Random();
61 | countDownAndAwaitLatch(startLatch, 10);
62 | for (int i = 0; i < ITERATIONS; i++) {
63 | handler.post(register);
64 | Thread.sleep(0, random.nextInt(300)); // Sleep just some nanoseconds, timing is crucial here
65 | handler.post(unregister);
66 | if (failed != null) {
67 | throw new RuntimeException("Failed in iteration " + i, failed);
68 | }
69 | // Don't let the queue grow to avoid out-of-memory scenarios
70 | waitForHandler(handler);
71 | }
72 | } finally {
73 | backgroundPoster.running = false;
74 | backgroundPoster.join();
75 | }
76 | }
77 |
78 | protected void waitForHandler(Handler handler) {
79 | final CountDownLatch doneLatch = new CountDownLatch(1);
80 | handler.post(new Runnable() {
81 |
82 | @Override
83 | public void run() {
84 | doneLatch.countDown();
85 | }
86 | });
87 | awaitLatch(doneLatch, 10);
88 | }
89 |
90 | @Subscribe(threadMode = ThreadMode.MAIN)
91 | public void onEventMainThread(String event) {
92 | trackEvent(event);
93 | if (unregistered) {
94 | failed = new RuntimeException("Main thread event delivered while unregistered on received event #"
95 | + eventCount);
96 | }
97 | }
98 |
99 | class BackgroundPoster extends Thread {
100 | volatile boolean running = true;
101 |
102 | public BackgroundPoster() {
103 | super("BackgroundPoster");
104 | }
105 |
106 | @Override
107 | public void run() {
108 | countDownAndAwaitLatch(startLatch, 10);
109 | while (running) {
110 | eventBus.post("Posted in background");
111 | if (Math.random() > 0.9f) {
112 | // Single cores would take very long without yielding
113 | Thread.yield();
114 | }
115 | }
116 | }
117 |
118 | }
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/EventBusTest/src/org/greenrobot/eventbus/EventBusMethodModifiersTest.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.assertNotSame;
23 | import static org.junit.Assert.assertSame;
24 |
25 | /**
26 | * @author Markus Junginger, greenrobot
27 | */
28 | public class EventBusMethodModifiersTest extends AbstractAndroidEventBusTest {
29 |
30 | @Test
31 | public void testRegisterForEventTypeAndPost() throws InterruptedException {
32 | eventBus.register(this);
33 | String event = "Hello";
34 | eventBus.post(event);
35 | waitForEventCount(4, 1000);
36 | }
37 |
38 | @Subscribe
39 | public void onEvent(String event) {
40 | trackEvent(event);
41 | assertNotSame(Looper.getMainLooper(), Looper.myLooper());
42 | }
43 |
44 | @Subscribe(threadMode = ThreadMode.MAIN)
45 | public void onEventMainThread(String event) {
46 | trackEvent(event);
47 | assertSame(Looper.getMainLooper(), Looper.myLooper());
48 | }
49 |
50 | @Subscribe(threadMode = ThreadMode.BACKGROUND)
51 | public void onEventBackgroundThread(String event) {
52 | trackEvent(event);
53 | assertNotSame(Looper.getMainLooper(), Looper.myLooper());
54 | }
55 |
56 | @Subscribe(threadMode = ThreadMode.ASYNC)
57 | public void onEventAsync(String event) {
58 | trackEvent(event);
59 | assertNotSame(Looper.getMainLooper(), Looper.myLooper());
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/EventBusTest/src/org/greenrobot/eventbus/TestBackgroundPoster.java:
--------------------------------------------------------------------------------
1 | package org.greenrobot.eventbus;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class TestBackgroundPoster extends Thread {
7 | private final EventBus eventBus;
8 | volatile boolean running = true;
9 | private final List eventQ = new ArrayList<>();
10 | private final List eventsDone = new ArrayList<>();
11 |
12 | TestBackgroundPoster(EventBus eventBus) {
13 | super("BackgroundPoster");
14 | this.eventBus = eventBus;
15 | }
16 |
17 | @Override
18 | public void run() {
19 | while (running) {
20 | Object event = pollEvent();
21 | if (event != null) {
22 | eventBus.post(event);
23 | synchronized (eventsDone) {
24 | eventsDone.add(event);
25 | eventsDone.notifyAll();
26 | }
27 | }
28 | }
29 | }
30 |
31 | private synchronized Object pollEvent() {
32 | Object event = null;
33 | synchronized (eventQ) {
34 | if (eventQ.isEmpty()) {
35 | try {
36 | eventQ.wait(1000);
37 | } catch (InterruptedException ignored) {
38 | }
39 | }
40 | if(!eventQ.isEmpty()) {
41 | event = eventQ.remove(0);
42 | }
43 | }
44 | return event;
45 | }
46 |
47 | void shutdown() {
48 | running = false;
49 | synchronized (eventQ) {
50 | eventQ.notifyAll();
51 | }
52 | }
53 |
54 | void post(Object event) {
55 | synchronized (eventQ) {
56 | eventQ.add(event);
57 | eventQ.notifyAll();
58 | }
59 | synchronized (eventsDone) {
60 | while (!eventsDone.remove(event)) {
61 | try {
62 | eventsDone.wait();
63 | } catch (InterruptedException e) {
64 | throw new RuntimeException(e);
65 | }
66 | }
67 | }
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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/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 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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/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/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/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/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/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/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/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/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/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 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/EventBusTestJava/libs/EventBusTestSubscriberInJar-3.0.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/greenrobot/EventBus/0194926b3bcf70cc0d7bfd3c5da16708dd5ab876/EventBusTestJava/libs/EventBusTestSubscriberInJar-3.0.0.jar
--------------------------------------------------------------------------------
/EventBusTestJava/src/main/java/org/greenrobot/eventbus/AbstractEventBusTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012-2017 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.Before;
19 |
20 | import java.util.List;
21 | import java.util.concurrent.CopyOnWriteArrayList;
22 | import java.util.concurrent.CountDownLatch;
23 | import java.util.concurrent.TimeUnit;
24 | import java.util.concurrent.atomic.AtomicInteger;
25 | import java.util.logging.Level;
26 |
27 |
28 | import static org.junit.Assert.assertEquals;
29 | import static org.junit.Assert.assertTrue;
30 | import static org.junit.Assert.fail;
31 |
32 | /**
33 | * @author Markus Junginger, greenrobot
34 | */
35 | public abstract class AbstractEventBusTest {
36 | /** Activates long(er) running tests e.g. testing multi-threading more thoroughly. */
37 | protected static final boolean LONG_TESTS = false;
38 |
39 | protected EventBus eventBus;
40 |
41 | protected final AtomicInteger eventCount = new AtomicInteger();
42 | protected final List eventsReceived;
43 |
44 | protected volatile Object lastEvent;
45 | protected volatile Thread lastThread;
46 |
47 | public AbstractEventBusTest() {
48 | this(false);
49 | }
50 |
51 | public AbstractEventBusTest(boolean collectEventsReceived) {
52 | if (collectEventsReceived) {
53 | eventsReceived = new CopyOnWriteArrayList();
54 | } else {
55 | eventsReceived = null;
56 | }
57 | }
58 |
59 | @Before
60 | public void setUpBase() throws Exception {
61 | EventBus.clearCaches();
62 | eventBus = new EventBus();
63 | }
64 |
65 | protected void waitForEventCount(int expectedCount, int maxMillis) {
66 | for (int i = 0; i < maxMillis; i++) {
67 | int currentCount = eventCount.get();
68 | if (currentCount == expectedCount) {
69 | break;
70 | } else if (currentCount > expectedCount) {
71 | fail("Current count (" + currentCount + ") is already higher than expected count (" + expectedCount
72 | + ")");
73 | } else {
74 | try {
75 | Thread.sleep(1);
76 | } catch (InterruptedException e) {
77 | throw new RuntimeException(e);
78 | }
79 | }
80 | }
81 | assertEquals(expectedCount, eventCount.get());
82 | }
83 |
84 | protected void trackEvent(Object event) {
85 | lastEvent = event;
86 | lastThread = Thread.currentThread();
87 | if (eventsReceived != null) {
88 | eventsReceived.add(event);
89 | }
90 | // Must the the last one because we wait for this
91 | eventCount.incrementAndGet();
92 | }
93 |
94 | protected void assertEventCount(int expectedEventCount) {
95 | assertEquals(expectedEventCount, eventCount.intValue());
96 | }
97 |
98 | protected void countDownAndAwaitLatch(CountDownLatch latch, long seconds) {
99 | latch.countDown();
100 | awaitLatch(latch, seconds);
101 | }
102 |
103 | protected void awaitLatch(CountDownLatch latch, long seconds) {
104 | try {
105 | assertTrue(latch.await(seconds, TimeUnit.SECONDS));
106 | } catch (InterruptedException e) {
107 | throw new RuntimeException(e);
108 | }
109 | }
110 |
111 | protected void log(String msg) {
112 | eventBus.getLogger().log(Level.FINE, msg);
113 | }
114 |
115 | protected void log(String msg, Throwable e) {
116 | eventBus.getLogger().log(Level.FINE, msg, e);
117 | }
118 |
119 | }
120 |
--------------------------------------------------------------------------------
/EventBusTestJava/src/main/java/org/greenrobot/eventbus/EventBusBuilderTest.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.Assert;
19 | import org.junit.Test;
20 |
21 | import static org.junit.Assert.fail;
22 |
23 | /**
24 | * @author Markus Junginger, greenrobot
25 | */
26 | public class EventBusBuilderTest extends AbstractEventBusTest {
27 |
28 | @Test
29 | public void testThrowSubscriberException() {
30 | eventBus = EventBus.builder().throwSubscriberException(true).build();
31 | eventBus.register(new SubscriberExceptionEventTracker());
32 | eventBus.register(new ThrowingSubscriber());
33 | try {
34 | eventBus.post("Foo");
35 | fail("Should have thrown");
36 | } catch (EventBusException e) {
37 | // Expected
38 | }
39 | }
40 |
41 | @Test
42 | public void testDoNotSendSubscriberExceptionEvent() {
43 | eventBus = EventBus.builder().logSubscriberExceptions(false).sendSubscriberExceptionEvent(false).build();
44 | eventBus.register(new SubscriberExceptionEventTracker());
45 | eventBus.register(new ThrowingSubscriber());
46 | eventBus.post("Foo");
47 | assertEventCount(0);
48 | }
49 |
50 | @Test
51 | public void testDoNotSendNoSubscriberEvent() {
52 | eventBus = EventBus.builder().logNoSubscriberMessages(false).sendNoSubscriberEvent(false).build();
53 | eventBus.register(new NoSubscriberEventTracker());
54 | eventBus.post("Foo");
55 | assertEventCount(0);
56 | }
57 |
58 | @Test
59 | public void testInstallDefaultEventBus() {
60 | EventBusBuilder builder = EventBus.builder();
61 | try {
62 | // Either this should throw when another unit test got the default event bus...
63 | eventBus = builder.installDefaultEventBus();
64 | Assert.assertEquals(eventBus, EventBus.getDefault());
65 |
66 | // ...or this should throw
67 | eventBus = builder.installDefaultEventBus();
68 | fail("Should have thrown");
69 | } catch (EventBusException e) {
70 | // Expected
71 | }
72 | }
73 |
74 | @Test
75 | public void testEventInheritance() {
76 | eventBus = EventBus.builder().eventInheritance(false).build();
77 | eventBus.register(new ThrowingSubscriber());
78 | eventBus.post("Foo");
79 | }
80 |
81 | public class SubscriberExceptionEventTracker {
82 | @Subscribe
83 | public void onEvent(SubscriberExceptionEvent event) {
84 | trackEvent(event);
85 | }
86 | }
87 |
88 | public class NoSubscriberEventTracker {
89 | @Subscribe
90 | public void onEvent(NoSubscriberEvent event) {
91 | trackEvent(event);
92 | }
93 | }
94 |
95 | public class ThrowingSubscriber {
96 | @Subscribe
97 | public void onEvent(Object event) {
98 | throw new RuntimeException();
99 | }
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/EventBusTestJava/src/main/java/org/greenrobot/eventbus/EventBusCancelEventDeliveryTest.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 |
20 | import java.util.concurrent.CountDownLatch;
21 |
22 | import static org.junit.Assert.assertEquals;
23 | import static org.junit.Assert.assertNotNull;
24 | import static org.junit.Assert.fail;
25 |
26 | public class EventBusCancelEventDeliveryTest extends AbstractEventBusTest {
27 |
28 | Throwable failed;
29 |
30 | @Test
31 | public void testCancel() {
32 | Subscriber canceler = new Subscriber(1, true);
33 | eventBus.register(new Subscriber(0, false));
34 | eventBus.register(canceler);
35 | eventBus.register(new Subscriber(0, false));
36 | eventBus.post("42");
37 | assertEquals(1, eventCount.intValue());
38 |
39 | eventBus.unregister(canceler);
40 | eventBus.post("42");
41 | assertEquals(1 + 2, eventCount.intValue());
42 | }
43 |
44 | @Test
45 | public void testCancelInBetween() {
46 | eventBus.register(new Subscriber(2, true));
47 | eventBus.register(new Subscriber(1, false));
48 | eventBus.register(new Subscriber(3, false));
49 | eventBus.post("42");
50 | assertEquals(2, eventCount.intValue());
51 | }
52 |
53 | @Test
54 | public void testCancelOutsideEventHandler() {
55 | try {
56 | eventBus.cancelEventDelivery(this);
57 | fail("Should have thrown");
58 | } catch (EventBusException e) {
59 | // Expected
60 | }
61 | }
62 |
63 | @Test
64 | public void testCancelWrongEvent() {
65 | eventBus.register(new SubscriberCancelOtherEvent());
66 | eventBus.post("42");
67 | assertEquals(0, eventCount.intValue());
68 | assertNotNull(failed);
69 | }
70 |
71 | public class Subscriber {
72 | private final int prio;
73 | private final boolean cancel;
74 |
75 | public Subscriber(int prio, boolean cancel) {
76 | this.prio = prio;
77 | this.cancel = cancel;
78 | }
79 |
80 | @Subscribe
81 | public void onEvent(String event) {
82 | handleEvent(event, 0);
83 | }
84 |
85 | @Subscribe(priority = 1)
86 | public void onEvent1(String event) {
87 | handleEvent(event, 1);
88 | }
89 |
90 | @Subscribe(priority = 2)
91 | public void onEvent2(String event) {
92 | handleEvent(event, 2);
93 | }
94 |
95 | @Subscribe(priority = 3)
96 | public void onEvent3(String event) {
97 | handleEvent(event, 3);
98 | }
99 |
100 | private void handleEvent(String event, int prio) {
101 | if(this.prio == prio) {
102 | trackEvent(event);
103 | if (cancel) {
104 | eventBus.cancelEventDelivery(event);
105 | }
106 | }
107 | }
108 | }
109 |
110 | public class SubscriberCancelOtherEvent {
111 | @Subscribe
112 | public void onEvent(String event) {
113 | try {
114 | eventBus.cancelEventDelivery(this);
115 | } catch (EventBusException e) {
116 | failed = e;
117 | }
118 | }
119 | }
120 |
121 | public class SubscriberMainThread {
122 | final CountDownLatch done = new CountDownLatch(1);
123 |
124 | @Subscribe(threadMode = ThreadMode.MAIN)
125 | public void onEventMainThread(String event) {
126 | try {
127 | eventBus.cancelEventDelivery(event);
128 | } catch (EventBusException e) {
129 | failed = e;
130 | }
131 | done.countDown();
132 | }
133 | }
134 |
135 | }
136 |
--------------------------------------------------------------------------------
/EventBusTestJava/src/main/java/org/greenrobot/eventbus/EventBusFallbackToReflectionTest.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.Test;
20 |
21 | import static org.junit.Assert.assertEquals;
22 |
23 | public class EventBusFallbackToReflectionTest extends AbstractEventBusTest {
24 | private class PrivateEvent {
25 | }
26 |
27 | public class PublicClass {
28 | @Subscribe
29 | public void onEvent(Object any) {
30 | trackEvent(any);
31 | }
32 | }
33 |
34 | private class PrivateClass {
35 | @Subscribe
36 | public void onEvent(Object any) {
37 | trackEvent(any);
38 | }
39 | }
40 |
41 | public class PublicWithPrivateSuperClass extends PrivateClass {
42 | @Subscribe
43 | public void onEvent(String any) {
44 | trackEvent(any);
45 | }
46 | }
47 |
48 | public class PublicClassWithPrivateEvent {
49 | @Subscribe
50 | public void onEvent(PrivateEvent any) {
51 | trackEvent(any);
52 | }
53 | }
54 |
55 | public class PublicClassWithPublicAndPrivateEvent {
56 | @Subscribe
57 | public void onEvent(String any) {
58 | trackEvent(any);
59 | }
60 |
61 | @Subscribe
62 | public void onEvent(PrivateEvent any) {
63 | trackEvent(any);
64 | }
65 | }
66 |
67 | public class PublicWithPrivateEventInSuperclass extends PublicClassWithPrivateEvent {
68 | @Subscribe
69 | public void onEvent(Object any) {
70 | trackEvent(any);
71 | }
72 | }
73 |
74 | public EventBusFallbackToReflectionTest() {
75 | super(true);
76 | }
77 |
78 | @Test
79 | public void testAnonymousSubscriberClass() {
80 | Object subscriber = new Object() {
81 | @Subscribe
82 | public void onEvent(String event) {
83 | trackEvent(event);
84 | }
85 | };
86 | eventBus.register(subscriber);
87 |
88 | eventBus.post("Hello");
89 | assertEquals("Hello", lastEvent);
90 | assertEquals(1, eventsReceived.size());
91 | }
92 |
93 | @Test
94 | public void testAnonymousSubscriberClassWithPublicSuperclass() {
95 | Object subscriber = new PublicClass() {
96 | @Subscribe
97 | public void onEvent(String event) {
98 | trackEvent(event);
99 | }
100 | };
101 | eventBus.register(subscriber);
102 |
103 | eventBus.post("Hello");
104 | assertEquals("Hello", lastEvent);
105 | assertEquals(2, eventsReceived.size());
106 | }
107 |
108 | @Test
109 | public void testAnonymousSubscriberClassWithPrivateSuperclass() {
110 | eventBus.register(new PublicWithPrivateSuperClass());
111 | eventBus.post("Hello");
112 | assertEquals("Hello", lastEvent);
113 | assertEquals(2, eventsReceived.size());
114 | }
115 |
116 | @Test
117 | public void testSubscriberClassWithPrivateEvent() {
118 | eventBus.register(new PublicClassWithPrivateEvent());
119 | PrivateEvent privateEvent = new PrivateEvent();
120 | eventBus.post(privateEvent);
121 | assertEquals(privateEvent, lastEvent);
122 | assertEquals(1, eventsReceived.size());
123 | }
124 |
125 | @Test
126 | public void testSubscriberClassWithPublicAndPrivateEvent() {
127 | eventBus.register(new PublicClassWithPublicAndPrivateEvent());
128 |
129 | eventBus.post("Hello");
130 | assertEquals("Hello", lastEvent);
131 | assertEquals(1, eventsReceived.size());
132 |
133 | PrivateEvent privateEvent = new PrivateEvent();
134 | eventBus.post(privateEvent);
135 | assertEquals(privateEvent, lastEvent);
136 | assertEquals(2, eventsReceived.size());
137 | }
138 |
139 | @Test
140 | public void testSubscriberExtendingClassWithPrivateEvent() {
141 | eventBus.register(new PublicWithPrivateEventInSuperclass());
142 | PrivateEvent privateEvent = new PrivateEvent();
143 | eventBus.post(privateEvent);
144 | assertEquals(privateEvent, lastEvent);
145 | assertEquals(2, eventsReceived.size());
146 | }
147 |
148 | }
149 |
--------------------------------------------------------------------------------
/EventBusTestJava/src/main/java/org/greenrobot/eventbus/EventBusGenericsTest.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.Test;
20 |
21 | public class EventBusGenericsTest extends AbstractEventBusTest {
22 | public static class GenericEvent {
23 | T value;
24 | }
25 |
26 | public class GenericEventSubscriber {
27 | @Subscribe
28 | public void onGenericEvent(GenericEvent event) {
29 | trackEvent(event);
30 | }
31 | }
32 |
33 | public class FullGenericEventSubscriber {
34 | @Subscribe
35 | public void onGenericEvent(T event) {
36 | trackEvent(event);
37 | }
38 | }
39 |
40 | public class GenericNumberEventSubscriber {
41 | @Subscribe
42 | public void onGenericEvent(T event) {
43 | trackEvent(event);
44 | }
45 | }
46 |
47 | public class GenericFloatEventSubscriber extends GenericNumberEventSubscriber {
48 | }
49 |
50 | @Test
51 | public void testGenericEventAndSubscriber() {
52 | GenericEventSubscriber genericSubscriber = new GenericEventSubscriber();
53 | eventBus.register(genericSubscriber);
54 | eventBus.post(new GenericEvent());
55 | assertEventCount(1);
56 | }
57 |
58 | @Test
59 | public void testGenericEventAndSubscriber_TypeErasure() {
60 | FullGenericEventSubscriber genericSubscriber = new FullGenericEventSubscriber();
61 | eventBus.register(genericSubscriber);
62 | eventBus.post(new IntTestEvent(42));
63 | eventBus.post("Type erasure!");
64 | assertEventCount(2);
65 | }
66 |
67 | @Test
68 | public void testGenericEventAndSubscriber_BaseType() {
69 | GenericNumberEventSubscriber genericSubscriber = new GenericNumberEventSubscriber<>();
70 | eventBus.register(genericSubscriber);
71 | eventBus.post(new Float(42));
72 | eventBus.post(new Double(23));
73 | assertEventCount(2);
74 | eventBus.post("Not the same base type");
75 | assertEventCount(2);
76 | }
77 |
78 | @Test
79 | public void testGenericEventAndSubscriber_Subclass() {
80 | GenericFloatEventSubscriber genericSubscriber = new GenericFloatEventSubscriber();
81 | eventBus.register(genericSubscriber);
82 | eventBus.post(new Float(42));
83 | eventBus.post(new Double(77));
84 | assertEventCount(2);
85 | eventBus.post("Not the same base type");
86 | assertEventCount(2);
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/EventBusTestJava/src/main/java/org/greenrobot/eventbus/EventBusIndexTest.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.greenrobot.eventbus.meta.SimpleSubscriberInfo;
20 | import org.greenrobot.eventbus.meta.SubscriberInfo;
21 | import org.greenrobot.eventbus.meta.SubscriberInfoIndex;
22 | import org.greenrobot.eventbus.meta.SubscriberMethodInfo;
23 | import org.junit.Assert;
24 | import org.junit.Test;
25 |
26 | public class EventBusIndexTest {
27 | private String value;
28 |
29 | /** Ensures the index is actually used and no reflection fall-back kicks in. */
30 | @Test
31 | public void testManualIndexWithoutAnnotation() {
32 | SubscriberInfoIndex index = new SubscriberInfoIndex() {
33 |
34 | @Override
35 | public SubscriberInfo getSubscriberInfo(Class> subscriberClass) {
36 | Assert.assertEquals(EventBusIndexTest.class, subscriberClass);
37 | SubscriberMethodInfo[] methodInfos = {
38 | new SubscriberMethodInfo("someMethodWithoutAnnotation", String.class)
39 | };
40 | return new SimpleSubscriberInfo(EventBusIndexTest.class, false, methodInfos);
41 | }
42 | };
43 |
44 | EventBus eventBus = EventBus.builder().addIndex(index).build();
45 | eventBus.register(this);
46 | eventBus.post("Yepp");
47 | eventBus.unregister(this);
48 | Assert.assertEquals("Yepp", value);
49 | }
50 |
51 | public void someMethodWithoutAnnotation(String value) {
52 | this.value = value;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/EventBusTestJava/src/main/java/org/greenrobot/eventbus/EventBusNoSubscriberEventTest.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 |
20 | import static org.junit.Assert.assertEquals;
21 | import static org.junit.Assert.assertSame;
22 |
23 | /**
24 | * @author Markus Junginger, greenrobot
25 | */
26 | public class EventBusNoSubscriberEventTest extends AbstractEventBusTest {
27 |
28 | @Test
29 | public void testNoSubscriberEvent() {
30 | eventBus.register(this);
31 | eventBus.post("Foo");
32 | assertEventCount(1);
33 | assertEquals(NoSubscriberEvent.class, lastEvent.getClass());
34 | NoSubscriberEvent noSub = (NoSubscriberEvent) lastEvent;
35 | assertEquals("Foo", noSub.originalEvent);
36 | assertSame(eventBus, noSub.eventBus);
37 | }
38 |
39 | @Test
40 | public void testNoSubscriberEventAfterUnregister() {
41 | Object subscriber = new DummySubscriber();
42 | eventBus.register(subscriber);
43 | eventBus.unregister(subscriber);
44 | testNoSubscriberEvent();
45 | }
46 |
47 | @Test
48 | public void testBadNoSubscriberSubscriber() {
49 | eventBus = EventBus.builder().logNoSubscriberMessages(false).build();
50 | eventBus.register(this);
51 | eventBus.register(new BadNoSubscriberSubscriber());
52 | eventBus.post("Foo");
53 | assertEventCount(2);
54 |
55 | assertEquals(SubscriberExceptionEvent.class, lastEvent.getClass());
56 | NoSubscriberEvent noSub = (NoSubscriberEvent) ((SubscriberExceptionEvent) lastEvent).causingEvent;
57 | assertEquals("Foo", noSub.originalEvent);
58 | }
59 |
60 | @Subscribe
61 | public void onEvent(NoSubscriberEvent event) {
62 | trackEvent(event);
63 | }
64 |
65 | @Subscribe
66 | public void onEvent(SubscriberExceptionEvent event) {
67 | trackEvent(event);
68 | }
69 |
70 | public static class DummySubscriber {
71 | @SuppressWarnings("unused")
72 | @Subscribe
73 | public void onEvent(String dummy) {
74 | }
75 | }
76 |
77 | public class BadNoSubscriberSubscriber {
78 | @Subscribe
79 | public void onEvent(NoSubscriberEvent event) {
80 | throw new RuntimeException("I'm bad");
81 | }
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/EventBusTestJava/src/main/java/org/greenrobot/eventbus/EventBusRegistrationRacingTest.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 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 | import java.util.concurrent.CountDownLatch;
23 | import java.util.concurrent.Executor;
24 | import java.util.concurrent.Executors;
25 |
26 | import static org.junit.Assert.fail;
27 |
28 | /**
29 | * @author Markus Junginger, greenrobot
30 | */
31 | public class EventBusRegistrationRacingTest extends AbstractEventBusTest {
32 |
33 | // On a Nexus 5, bad synchronization always failed on the first iteration or went well completely.
34 | // So a high number of iterations do not guarantee a better probability of finding bugs.
35 | private static final int ITERATIONS = LONG_TESTS ? 1000 : 10;
36 | private static final int THREAD_COUNT = 16;
37 |
38 | volatile CountDownLatch startLatch;
39 | volatile CountDownLatch registeredLatch;
40 | volatile CountDownLatch canUnregisterLatch;
41 | volatile CountDownLatch unregisteredLatch;
42 |
43 | final Executor threadPool = Executors.newCachedThreadPool();
44 |
45 | @Test
46 | public void testRacingRegistrations() throws InterruptedException {
47 | for (int i = 0; i < ITERATIONS; i++) {
48 | startLatch = new CountDownLatch(THREAD_COUNT);
49 | registeredLatch = new CountDownLatch(THREAD_COUNT);
50 | canUnregisterLatch = new CountDownLatch(1);
51 | unregisteredLatch = new CountDownLatch(THREAD_COUNT);
52 |
53 | List threads = startThreads();
54 | registeredLatch.await();
55 | eventBus.post("42");
56 | canUnregisterLatch.countDown();
57 | for (int t = 0; t < THREAD_COUNT; t++) {
58 | int eventCount = threads.get(t).eventCount;
59 | if (eventCount != 1) {
60 | fail("Failed in iteration " + i + ": thread #" + t + " has event count of " + eventCount);
61 | }
62 | }
63 | // Wait for threads to be done
64 | unregisteredLatch.await();
65 | }
66 | }
67 |
68 | private List startThreads() {
69 | List threads = new ArrayList(THREAD_COUNT);
70 | for (int i = 0; i < THREAD_COUNT; i++) {
71 | SubscriberThread thread = new SubscriberThread();
72 | threadPool.execute(thread);
73 | threads.add(thread);
74 | }
75 | return threads;
76 | }
77 |
78 | public class SubscriberThread implements Runnable {
79 | volatile int eventCount;
80 |
81 | @Override
82 | public void run() {
83 | countDownAndAwaitLatch(startLatch, 10);
84 | eventBus.register(this);
85 | registeredLatch.countDown();
86 | try {
87 | canUnregisterLatch.await();
88 | } catch (InterruptedException e) {
89 | throw new RuntimeException(e);
90 | }
91 | eventBus.unregister(this);
92 | unregisteredLatch.countDown();
93 | }
94 |
95 | @Subscribe
96 | public void onEvent(String event) {
97 | eventCount++;
98 | }
99 |
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/EventBusTestJava/src/main/java/org/greenrobot/eventbus/EventBusSubscriberExceptionTest.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 |
20 | import static org.junit.Assert.assertEquals;
21 | import static org.junit.Assert.assertSame;
22 |
23 | /**
24 | * @author Markus Junginger, greenrobot
25 | */
26 | public class EventBusSubscriberExceptionTest extends AbstractEventBusTest {
27 |
28 | @Test
29 | public void testSubscriberExceptionEvent() {
30 | eventBus = EventBus.builder().logSubscriberExceptions(false).build();
31 | eventBus.register(this);
32 | eventBus.post("Foo");
33 | assertEventCount(1);
34 | assertEquals(SubscriberExceptionEvent.class, lastEvent.getClass());
35 | SubscriberExceptionEvent exEvent = (SubscriberExceptionEvent) lastEvent;
36 | assertEquals("Foo", exEvent.causingEvent);
37 | assertSame(this, exEvent.causingSubscriber);
38 | assertEquals("Bar", exEvent.throwable.getMessage());
39 | }
40 |
41 | @Test
42 | public void testBadExceptionSubscriber() {
43 | eventBus = EventBus.builder().logSubscriberExceptions(false).build();
44 | eventBus.register(this);
45 | eventBus.register(new BadExceptionSubscriber());
46 | eventBus.post("Foo");
47 | assertEventCount(1);
48 | }
49 |
50 | @Subscribe
51 | public void onEvent(String event) {
52 | throw new RuntimeException("Bar");
53 | }
54 |
55 | @Subscribe
56 | public void onEvent(SubscriberExceptionEvent event) {
57 | trackEvent(event);
58 | }
59 |
60 | public class BadExceptionSubscriber {
61 | @Subscribe
62 | public void onEvent(SubscriberExceptionEvent event) {
63 | throw new RuntimeException("Bad");
64 | }
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/EventBusTestJava/src/main/java/org/greenrobot/eventbus/EventBusSubscriberLegalTest.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 |
20 | import static org.junit.Assert.assertEquals;
21 |
22 | /**
23 | * @author Markus Junginger, greenrobot
24 | */
25 | public class EventBusSubscriberLegalTest extends AbstractEventBusTest {
26 |
27 | @Test
28 | public void testSubscriberLegal() {
29 | eventBus.register(this);
30 | eventBus.post("42");
31 | eventBus.unregister(this);
32 | assertEquals(1, eventCount.intValue());
33 | }
34 |
35 | // With build time verification, some of these tests are obsolete (and cause problems during build)
36 | // public void testSubscriberNotPublic() {
37 | // try {
38 | // eventBus.register(new NotPublic());
39 | // fail("Registration of ilegal subscriber successful");
40 | // } catch (EventBusException e) {
41 | // // Expected
42 | // }
43 | // }
44 |
45 | // public void testSubscriberStatic() {
46 | // try {
47 | // eventBus.register(new Static());
48 | // fail("Registration of ilegal subscriber successful");
49 | // } catch (EventBusException e) {
50 | // // Expected
51 | // }
52 | // }
53 |
54 | public void testSubscriberLegalAbstract() {
55 | eventBus.register(new AbstractImpl());
56 |
57 | eventBus.post("42");
58 | assertEquals(1, eventCount.intValue());
59 | }
60 |
61 | @Subscribe
62 | public void onEvent(String event) {
63 | trackEvent(event);
64 | }
65 |
66 | // public static class NotPublic {
67 | // @Subscribe
68 | // void onEvent(String event) {
69 | // }
70 | // }
71 |
72 | public static abstract class Abstract {
73 | @Subscribe
74 | public abstract void onEvent(String event);
75 | }
76 |
77 | public class AbstractImpl extends Abstract {
78 |
79 | @Override
80 | @Subscribe
81 | public void onEvent(String event) {
82 | trackEvent(event);
83 | }
84 |
85 | }
86 |
87 | // public static class Static {
88 | // @Subscribe
89 | // public static void onEvent(String event) {
90 | // }
91 | // }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | EventBus
2 | ========
3 | [EventBus](https://greenrobot.org/eventbus/) is a publish/subscribe event bus for Android and Java.
4 |
5 |
6 | [](https://github.com/greenrobot/EventBus/actions)
7 | [](https://twitter.com/greenrobot_de)
8 |
9 | EventBus...
10 |
11 | * simplifies the communication between components
12 | * decouples event senders and receivers
13 | * performs well with Activities, Fragments, and background threads
14 | * avoids complex and error-prone dependencies and life cycle issues
15 | * makes your code simpler
16 | * is fast
17 | * is tiny (~60k jar)
18 | * is proven in practice by apps with 1,000,000,000+ installs
19 | * has advanced features like delivery threads, subscriber priorities, etc.
20 |
21 | EventBus in 3 steps
22 | -------------------
23 | 1. Define events:
24 |
25 | ```java
26 | public static class MessageEvent { /* Additional fields if needed */ }
27 | ```
28 |
29 | 2. Prepare subscribers:
30 | Declare and annotate your subscribing method, optionally specify a [thread mode](https://greenrobot.org/eventbus/documentation/delivery-threads-threadmode/):
31 |
32 | ```java
33 | @Subscribe(threadMode = ThreadMode.MAIN)
34 | public void onMessageEvent(MessageEvent event) {
35 | // Do something
36 | }
37 | ```
38 | Register and unregister your subscriber. For example on Android, activities and fragments should usually register according to their life cycle:
39 |
40 | ```java
41 | @Override
42 | public void onStart() {
43 | super.onStart();
44 | EventBus.getDefault().register(this);
45 | }
46 |
47 | @Override
48 | public void onStop() {
49 | super.onStop();
50 | EventBus.getDefault().unregister(this);
51 | }
52 | ```
53 |
54 | 3. Post events:
55 |
56 | ```java
57 | EventBus.getDefault().post(new MessageEvent());
58 | ```
59 |
60 | Read the full [getting started guide](https://greenrobot.org/eventbus/documentation/how-to-get-started/).
61 |
62 | There are also some [examples](https://github.com/greenrobot-team/greenrobot-examples).
63 |
64 | **Note:** we highly recommend the [EventBus annotation processor with its subscriber index](https://greenrobot.org/eventbus/documentation/subscriber-index/).
65 | This will avoid some reflection related problems seen in the wild.
66 |
67 | Add EventBus to your project
68 | ----------------------------
69 |
70 |
71 | Available on Maven Central .
72 |
73 | Android projects:
74 | ```groovy
75 | implementation("org.greenrobot:eventbus:3.3.1")
76 | ```
77 |
78 | Java projects:
79 | ```groovy
80 | implementation("org.greenrobot:eventbus-java:3.3.1")
81 | ```
82 | ```xml
83 |
84 | org.greenrobot
85 | eventbus-java
86 | 3.3.1
87 |
88 | ```
89 |
90 | R8, ProGuard
91 | ------------
92 |
93 | If your project uses R8 or ProGuard this library ships [with embedded rules](/eventbus-android/consumer-rules.pro).
94 |
95 | Homepage, Documentation, Links
96 | ------------------------------
97 | For more details please check the [EventBus website](https://greenrobot.org/eventbus). Here are some direct links you may find useful:
98 |
99 | [Features](https://greenrobot.org/eventbus/features/)
100 |
101 | [Documentation](https://greenrobot.org/eventbus/documentation/)
102 |
103 | [Changelog](https://github.com/greenrobot/EventBus/releases)
104 |
105 | [FAQ](https://greenrobot.org/eventbus/documentation/faq/)
106 |
107 | License
108 | -------
109 | Copyright (C) 2012-2021 Markus Junginger, greenrobot (https://greenrobot.org)
110 |
111 | EventBus binaries and source code can be used according to the [Apache License, Version 2.0](LICENSE).
112 |
113 | Other projects by greenrobot
114 | ============================
115 | [__ObjectBox__](https://objectbox.io/) ([GitHub](https://github.com/objectbox/objectbox-java)) is a new superfast object-oriented database.
116 |
117 | [__Essentials__](https://github.com/greenrobot/essentials) is a set of utility classes and hash functions for Android & Java projects.
118 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext {
3 | _compileSdkVersion = 30 // Android 11 (R)
4 | }
5 | repositories {
6 | mavenCentral()
7 | maven { url "https://plugins.gradle.org/m2/" }
8 | }
9 | dependencies {
10 | classpath "io.github.gradle-nexus:publish-plugin:1.1.0"
11 | }
12 | }
13 |
14 | // Set group and version in root build.gradle so publish-plugin can detect them.
15 | group = "org.greenrobot"
16 | version = "3.3.1"
17 |
18 | allprojects {
19 | repositories {
20 | mavenCentral()
21 | google()
22 | }
23 | }
24 |
25 | if (JavaVersion.current().isJava8Compatible()) {
26 | allprojects {
27 | tasks.withType(Javadoc) {
28 | options.addStringOption('Xdoclint:none', '-quiet')
29 | }
30 | }
31 | }
32 |
33 | wrapper {
34 | distributionType = Wrapper.DistributionType.ALL
35 | }
36 |
37 | // Plugin to publish to Central https://github.com/gradle-nexus/publish-plugin/
38 | // This plugin ensures a separate, named staging repo is created for each build when publishing.
39 | apply plugin: "io.github.gradle-nexus.publish-plugin"
40 | nexusPublishing {
41 | repositories {
42 | sonatype {
43 | if (project.hasProperty("sonatypeUsername") && project.hasProperty("sonatypePassword")) {
44 | println('nexusPublishing credentials supplied.')
45 | username = sonatypeUsername
46 | password = sonatypePassword
47 | } else {
48 | println('nexusPublishing credentials NOT supplied.')
49 | }
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/eventbus-android/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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-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 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/eventbus-android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/eventbus-android/src/main/java/org/greenrobot/eventbus/HandlerPoster.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.Handler;
19 | import android.os.Looper;
20 | import android.os.Message;
21 | import android.os.SystemClock;
22 |
23 | public class HandlerPoster extends Handler implements Poster {
24 |
25 | private final PendingPostQueue queue;
26 | private final int maxMillisInsideHandleMessage;
27 | private final EventBus eventBus;
28 | private boolean handlerActive;
29 |
30 | public HandlerPoster(EventBus eventBus, Looper looper, int maxMillisInsideHandleMessage) {
31 | super(looper);
32 | this.eventBus = eventBus;
33 | this.maxMillisInsideHandleMessage = maxMillisInsideHandleMessage;
34 | queue = new PendingPostQueue();
35 | }
36 |
37 | public void enqueue(Subscription subscription, Object event) {
38 | PendingPost pendingPost = PendingPost.obtainPendingPost(subscription, event);
39 | synchronized (this) {
40 | queue.enqueue(pendingPost);
41 | if (!handlerActive) {
42 | handlerActive = true;
43 | if (!sendMessage(obtainMessage())) {
44 | throw new EventBusException("Could not send handler message");
45 | }
46 | }
47 | }
48 | }
49 |
50 | @Override
51 | public void handleMessage(Message msg) {
52 | boolean rescheduled = false;
53 | try {
54 | long started = SystemClock.uptimeMillis();
55 | while (true) {
56 | PendingPost pendingPost = queue.poll();
57 | if (pendingPost == null) {
58 | synchronized (this) {
59 | // Check again, this time in synchronized
60 | pendingPost = queue.poll();
61 | if (pendingPost == null) {
62 | handlerActive = false;
63 | return;
64 | }
65 | }
66 | }
67 | eventBus.invokeSubscriber(pendingPost);
68 | long timeInMethod = SystemClock.uptimeMillis() - started;
69 | if (timeInMethod >= maxMillisInsideHandleMessage) {
70 | if (!sendMessage(obtainMessage())) {
71 | throw new EventBusException("Could not send handler message");
72 | }
73 | rescheduled = true;
74 | return;
75 | }
76 | }
77 | } finally {
78 | handlerActive = rescheduled;
79 | }
80 | }
81 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/eventbus-android/src/main/java/org/greenrobot/eventbus/android/AndroidLogger.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.android;
17 |
18 | import android.util.Log;
19 | import org.greenrobot.eventbus.Logger;
20 |
21 | import java.util.logging.Level;
22 |
23 | public class AndroidLogger implements Logger {
24 |
25 | private final String tag;
26 |
27 | public AndroidLogger(String tag) {
28 | this.tag = tag;
29 | }
30 |
31 | public void log(Level level, String msg) {
32 | if (level != Level.OFF) {
33 | Log.println(mapLevel(level), tag, msg);
34 | }
35 | }
36 |
37 | public void log(Level level, String msg, Throwable th) {
38 | if (level != Level.OFF) {
39 | // That's how Log does it internally
40 | Log.println(mapLevel(level), tag, msg + "\n" + Log.getStackTraceString(th));
41 | }
42 | }
43 |
44 | private int mapLevel(Level level) {
45 | int value = level.intValue();
46 | if (value < 800) { // below INFO
47 | if (value < 500) { // below FINE
48 | return Log.VERBOSE;
49 | } else {
50 | return Log.DEBUG;
51 | }
52 | } else if (value < 900) { // below WARNING
53 | return Log.INFO;
54 | } else if (value < 1000) { // below ERROR
55 | return Log.WARN;
56 | } else {
57 | return Log.ERROR;
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/gradle/publish.gradle:
--------------------------------------------------------------------------------
1 | // Configures common publishing settings.
2 |
3 | apply plugin: "maven-publish"
4 | apply plugin: "signing"
5 |
6 | publishing {
7 | publications {
8 | // Note: Sonatype repo created by publish-plugin, see root build.gradle.
9 | mavenJava(MavenPublication) {
10 | pom {
11 | url = "https://greenrobot.org/eventbus/"
12 |
13 | scm {
14 | connection = "scm:git@github.com:greenrobot/EventBus.git"
15 | developerConnection = "scm:git@github.com:greenrobot/EventBus.git"
16 | url = "https://github.com/greenrobot/EventBus"
17 | }
18 |
19 | licenses {
20 | license {
21 | name = "The Apache Software License, Version 2.0"
22 | url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
23 | distribution = "repo"
24 | }
25 | }
26 |
27 | developers {
28 | developer {
29 | id = "greenrobot"
30 | name = "greenrobot"
31 | }
32 | }
33 |
34 | issueManagement {
35 | system = "https://github.com/greenrobot/EventBus/issues"
36 | url = "https://github.com/greenrobot/EventBus/issues"
37 | }
38 |
39 | organization {
40 | name = "greenrobot"
41 | url = "https://greenrobot.org"
42 | }
43 | }
44 | }
45 | }
46 | }
47 |
48 | // Note: ext to export to scripts applying this script.
49 | ext {
50 | // Signing: in-memory ascii-armored key (CI) or keyring file (dev machine), see https://docs.gradle.org/current/userguide/signing_plugin.html
51 | hasSigningPropertiesKeyFile = {
52 | return (project.hasProperty('signingKeyId')
53 | && project.hasProperty('signingKeyFile')
54 | && project.hasProperty('signingPassword'))
55 | }
56 | // Typically via ~/.gradle/gradle.properties; default properties for signing plugin.
57 | hasSigningPropertiesKeyRing = {
58 | return (project.hasProperty('signing.keyId')
59 | && project.hasProperty('signing.secretKeyRingFile')
60 | && project.hasProperty('signing.password'))
61 | }
62 | hasSigningProperties = {
63 | return hasSigningPropertiesKeyFile() || hasSigningPropertiesKeyRing()
64 | }
65 | }
66 |
67 | signing {
68 | if (hasSigningProperties()) {
69 | if (hasSigningPropertiesKeyFile()) {
70 | println "Configured signing to use key file."
71 | String signingKey = new File(signingKeyFile).text
72 | useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
73 | } else if (hasSigningPropertiesKeyRing()) {
74 | println "Configured signing to use key ring."
75 | // Note: using expected property names (see above), no need to configure anything.
76 | }
77 | sign publishing.publications.mavenJava
78 | } else {
79 | println "WARNING: signing properties NOT set, will not sign artifacts."
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/greenrobot/EventBus/0194926b3bcf70cc0d7bfd3c5da16708dd5ab876/gradle/wrapper/gradle-wrapper.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 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/javadoc-style/background.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/greenrobot/EventBus/0194926b3bcf70cc0d7bfd3c5da16708dd5ab876/javadoc-style/background.gif
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------