EventBus Adapter for Java

The EventBus Adapter wraps various EventBus implementations for Java and Android.

License

License

Categories

Categories

Java Languages EventBus Application Layer Libs Messaging
GroupId

GroupId

com.cookingfox
ArtifactId

ArtifactId

eventbus-adapter-java
Last Version

Last Version

3.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

EventBus Adapter for Java
The EventBus Adapter wraps various EventBus implementations for Java and Android.
Project URL

Project URL

https://github.com/cookingfox/eventbus-adapter-java
Project Organization

Project Organization

Cooking Fox
Source Code Management

Source Code Management

http://github.com/cookingfox/eventbus-adapter-java

Download eventbus-adapter-java

How to add to project

<!-- https://jarcasting.com/artifacts/com.cookingfox/eventbus-adapter-java/ -->
<dependency>
    <groupId>com.cookingfox</groupId>
    <artifactId>eventbus-adapter-java</artifactId>
    <version>3.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.cookingfox/eventbus-adapter-java/
implementation 'com.cookingfox:eventbus-adapter-java:3.0.0'
// https://jarcasting.com/artifacts/com.cookingfox/eventbus-adapter-java/
implementation ("com.cookingfox:eventbus-adapter-java:3.0.0")
'com.cookingfox:eventbus-adapter-java:jar:3.0.0'
<dependency org="com.cookingfox" name="eventbus-adapter-java" rev="3.0.0">
  <artifact name="eventbus-adapter-java" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.cookingfox', module='eventbus-adapter-java', version='3.0.0')
)
libraryDependencies += "com.cookingfox" % "eventbus-adapter-java" % "3.0.0"
[com.cookingfox/eventbus-adapter-java "3.0.0"]

Dependencies

provided (3)

Group / Artifact Type Version
de.greenrobot : eventbus jar 2.4.1
org.greenrobot : eventbus jar 3.0.0
com.google.guava : guava jar 19.0

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

EventBus Adapter for Java

The EventBus Adapter wraps various EventBus implementations for Java and Android. It uses a uniform interface (com.cookingfox.eventbus.EventBus) to type your classes to, so that it's possible to change the implementation when required.

Build Status

Download

Download Maven Central

The distribution is hosted on Bintray. To include the package in your projects, you can add the jCenter repository.

Gradle

Add jCenter to your repositories block:

repositories {
    jcenter()
}

and add the project to the dependencies block in your build.gradle:

dependencies {
    compile 'com.cookingfox:eventbus-adapter-java:3.0.0'
}

Maven

Add jCenter to your repositories in pom.xml or settings.xml:

<repositories>
    <repository>
        <id>jcenter</id>
        <url>http://jcenter.bintray.com</url>
    </repository>
</repositories>

and add the project declaration to your pom.xml:

<dependency>
    <groupId>com.cookingfox</groupId>
    <artifactId>eventbus-adapter-java</artifactId>
    <version>3.0.0</version>
</dependency>

Features

Currently the library has adapters for:

The main EventBus interface actually inherits from the EventBusPublisher and EventBusSubscriber interfaces. This allows the user to restrict the available functionality of the consuming class.

Usage

Include in your project's dependencies:

  1. This wrapper library. (see "Download")
  2. The library you want to wrap. (see "Features")

Example for the GreenRobot EventBus version 3:

class ExampleEvent {}

class ExampleSubscriber {
    com.cookingfox.eventbus.EventBus eventBus;

    ExampleSubscriber(com.cookingfox.eventbus.EventBus eventBus) {
        this.eventBus = eventBus;
    }

    void onCreate() {
        eventBus.register(this);
    }

    void onEvent(ExampleEvent event) {
        // handle event
    }

    void onDestroy() {
        eventBus.unregister(this);
    }
}

// create real EventBus and adapter
org.greenrobot.eventbus.EventBus realEventBus = new org.greenrobot.eventbus.EventBus();
com.cookingfox.eventbus.EventBus eventBusAdapter = new GreenRobot3Adapter(realEventBus);

// create and register subscriber
ExampleSubscriber subscriber = new ExampleSubscriber(eventBusAdapter);
subscriber.onCreate();

// post an event
eventBusAdapter.post(new ExampleEvent());

// unregister subscriber
subscriber.onDestroy();

Restricting publish / subscribe capabilities

If you want to restrict your consumer classes' EventBus capabilities, use the following interfaces:

  • EventBusPublisher: the class will only be able to use the post method.
  • EventBusSubscriber: the class will only be able to use the register and unregister methods.

F.A.Q.

Is it possible to support EventBus library X?

If you make an issue for it, we'll take a look at it! :)

Copyright and license

Code and documentation copyright 2017 Cooking Fox. Code released under the Apache 2.0 license.

Versions

Version
3.0.0
2.0.0
1.0.0