English 中文(简体)
在 Google Evention Bus 上拨打电话课
原标题:Getting the caller class in the Google s EventBus
  • 时间:2012-05-24 16:19:45
  •  标签:
  • events
  • guava

我有一套监听方法,等待 FooBarEvent Dummy 类中的 :

@Subscribe
public void testingEvents(FooBarEvent event) {

}

但另一方面,我有一个需要这种方法的班级:

public class TestEvents{
    public TestEvents(event){
        FooBarEvent event = new FooBarEvent (...);
        event.post(event);
    }
}

这被称为主要类别 采取这样的行为 :

EventBus bus = new EventBus();
bus.register(new Dummy());

问题是 : 如何在 < code> secumentEvents (订阅者) 上获得发布事件的类?

(因此,我预期会得到这个方法,即打电话者是TestEvents 类)。

谢谢

问题回答

在大多数我所看到的代码中,它就是有 < code> 源代码 字段的事件本身, 显示事件发源地。 您可以在 < code> FooBarEvent 中添加一个字段, 该字段要么包含源对象( 或者只是源的类别, 如果您需要的话) 吗?





相关问题
Mysql trigger/events vs Cronjob

I have an auction website which let my users place an unlimited amount of autobiddings. To monitor these autobiddings something has to check the database every second. My question is if it is ...

Can an event be used as an event listener?

I m trying to expose some events from a private object which is contained inside the object I am creating and it looks like the compiler is happy with this: private WindowUpdateServer ...

鸡奸

由于将javascript DOM方法放在第html页底部(在<有人>之后)远比利用“j Query”准备活动要快得多,因此我们不得不这样做:

Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

jQuery bind on ajax load() event

I have a page which displays multiple blocks with results details. Inside each block I have some <a> tags with thickbox jQuery plugin attached: class="thickbox" Here is an example of one kind ...

HTML text input event

I have a form, and want to disable/enable its submit button depending on whether the form s input text fields are empty or have had text entered into them. I think this means having an event handler ...

IE doesn t run Javascript when you click back button

I ve built a shop with tons of JS running. One of the pieces of the cart, is a zip code field which is required to calculate shipping cost. This works fine going through the cart. Now clicking ...

热门标签