/autobus

An enhanced event bus for Android projects

Primary LanguageJava

Autobus
An event bus by BQ

alt text

What?

An enhanced event bus intended to allow communication between decoupled parts of an application.

It is based on concepts from Otto, EventBus and RxJava.

For usage instructions please see Autobus website.

Why?

We developed our own Event Bus to cover two main needs that aren't covered by existing libraries:

  • Decouple channels and emitted data

Both Otto and EventBus use Events (defined classes) to carry data and also to represent the channel the subscribers are listening to. This approach is valid but it is quite inflexible.

Autobus allows representing channels as Strings and data as a separate class; this way a subscriber can listen to a channel expecting a concrete class of data (or even Any class of data) and emitters can send data of a concrete class (or no data at all) to a concrete channel. When an emitter sends data of class D to a channel C, every subscriber listening to channel C and expecting data of class D is notified. Also subscribers listening to channel C and expecting data of any class are notified.

  • Explicit contract between subscribers and emitters

As one of the common use case of Event Buses is the communication between interactors (asynchronous core operations of an app) and presenters (adapters between views and interactors) it is desirable to maintain an explicit definition or contract between the emitters and the subscribers. Autobus accomplishes this task with BusObservable API. A interactor can return a BusObservable instance and subscribers can directly be subscribed to this observable; the observable is the contract itself as it defines the Bus, the Channel and also the data that will be emitted.

Ok, what else?

  • Full annotated with @Nullable and @NotNull.
  • Clean code enforcement by strong typing. No need for upcasting/downcasting any object.
  • Autocomplete heaven (related to this string typing).

Comparison

Functionality EventBus Otto Autobus
Declare event handling methods Name Convention Annotations Explicity
Event inheritance Yes Yes No
Cache most recent events Yes (sticky) No Yes (persistent emmit)
Event producers No Yes No
Event delivery in posting thread Yes Yes Yes
Event delivery in main thread Yes No Yes (using preprocessor)
Event delivery in bg thread Yes No Yes
Aynchronous event delivery Yes No Yes

Download

Autobus is available on Maven Central. Please ensure that you are using the latest version by checking here.

Maven:

<dependency>
  <groupId>com.bq</groupId>
  <artifactId>autobus</artifactId>
  <version>0.1.0</version>
</dependency>

or Gradle:

compile 'com.bq:autobus:0.1.0'

Snapshots of the development version are available in Sonatype's snapshots repository.

License

This project is licensed under the Apache Software License, Version 2.0.

Copyright (c) 2015 BQ

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.