Skip to content

Annotation Support #126

Closed
Closed
@rjbrock

Description

@rjbrock
Contributor

Hey, this looks like a great library, and I have been exploring using it. I know you guys have quite done quite a bit of research regarding Anotations vs Method Naming, but overall I really feel like Annotations are a much cleaner and more flexible solution.

I added annotations to my local branch. You can create a new EventBus that uses annotations like this new EventBus(DeclarationType.ANNOTATIONS). Then you can subscribe to receive events on any method like this:

@Subscribe
public void onMyEvent(CustomEvent e)

This uses the caller chooses thread method. We can also change this by adding an argument.

@Subscribe(threadMode = ThreadMode.Background)
public void onMyEvent(CustomEvent e)

This uses the background thread and is definitely a more explicit syntax.

Here is a link to my repo where I implemented the changes.
https://github.com/rjbrock/EventBus

I would still need to add unit tests before submitting a pull request so I just wanted to see what your thoughts were first.

Rick

Activity

greenrobot

greenrobot commented on Nov 12, 2014

@greenrobot
Owner

Awesome! Annotations were planned for EventBus version 3. It makes sense today, because Android 4 is adopted widely these days. With Android 4, the performance difference should not really matter anymore. You can verify with the performance app project. Looking forward to check your changes, however it might get December - so no hurry. We just did a release anyway. Thanks!

rjbrock

rjbrock commented on Nov 12, 2014

@rjbrock
ContributorAuthor

Sounds good! Here is a link to the actual changeset.

rjbrock@e42992a

If things look ok (so far) I can flesh this out with more comments and unit test coverage as well as docs.

greenrobot

greenrobot commented on Nov 12, 2014

@greenrobot
Owner

I see it's possible to do either method names searching and Annotations? That's nice for transition. I'd suggest to move that switch to the builder. The forthcoming release (e.g. 3.1) can prune the method name option afterwards.

Let's think a bit about consequences of adopting annotations:

  • Options should move from registration to annotation (sticky, priority)
  • Lots of unit tests have to be adjusted
  • New unit tests are required, e.g. there may be multiple subscriber methods wired to the same subscriber, but with different options (sticky, priority)

What do you think?

PS.: Please ensure you are working on the latest version, there were some changes in this area...

changed the title [-]Question about Annotations[/-] [+]Annotation Support[/+] on Nov 12, 2014
greenrobot

greenrobot commented on Nov 12, 2014

@greenrobot
Owner

Giving it some more thought, maybe we should just drop method name searching completely? It will get messy supporting both. Forcing people to add an annotation to their onEvent method should not be a big problem, I think.

rjbrock

rjbrock commented on Nov 12, 2014

@rjbrock
ContributorAuthor

I am totally on board with dropping method name searching completely. My goal with the original changeset that I linked you to was to be as minimally intrusive as possible.

I will update my changes to remove method name searching altogether then.

Do you want me working off of my repo for now? I will create an annotations branch.

greenrobot

greenrobot commented on Nov 12, 2014

@greenrobot
Owner

Sounds good. Next weeks will be busy for me, but I'm really looking forward to have a look.

MariusVolkhart

MariusVolkhart commented on Dec 29, 2014

@MariusVolkhart

How is this going to work with inheritance? When using Otto for example, you can't put an annotation on a superclass and have the subclass get the message because Otto doesn't traverse the class hierarchy for performance reasons.

rjbrock

rjbrock commented on Dec 29, 2014

@rjbrock
ContributorAuthor

@MariusVolkhart This doesn't change any behavior. This only changes the way that reflection is used to find the methods that are subscribing.

19 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @greenrobot@smorloc@rjbrock@WonderCsabo@minhoryang

        Issue actions

          Annotation Support · Issue #126 · greenrobot/EventBus