Registers the given subscriber to receive events. Subscribers must call #unregister(Object) once they are no longer interested in receiving events. Subscribers have event handling methods that must be annotated by Subscribe. The Subscribe annotation also allows configura
(Object subscriber)
| 140 | * ThreadMode} and priority. |
| 141 | */ |
| 142 | public void register(Object subscriber) { |
| 143 | if (AndroidDependenciesDetector.isAndroidSDKAvailable() && !AndroidDependenciesDetector.areAndroidComponentsAvailable()) { |
| 144 | // Crash if the user (developer) has not imported the Android compatibility library. |
| 145 | throw new RuntimeException("It looks like you are using EventBus on Android, " + |
| 146 | "make sure to add the \"eventbus\" Android library to your dependencies."); |
| 147 | } |
| 148 | |
| 149 | Class<?> subscriberClass = subscriber.getClass(); |
| 150 | List<SubscriberMethod> subscriberMethods = subscriberMethodFinder.findSubscriberMethods(subscriberClass); |
| 151 | synchronized (this) { |
| 152 | for (SubscriberMethod subscriberMethod : subscriberMethods) { |
| 153 | subscribe(subscriber, subscriberMethod); |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // Must be called in synchronized block |
| 159 | private void subscribe(Object subscriber, SubscriberMethod subscriberMethod) { |