java - Subscribe to different event bus in same class -
i using greenrobot event bus 3.0 event bus , have 2 publishers:
private static final eventbus event_bus = new eventbus(); //publish event event bus public static void sendevent(loggingevent event){ logpublisher.event_bus.post(event); } //publish event event bus public static void sendevent(otherloggingevent event){ logpublisher.event_bus.post(event); } i have 2 subscribers:
@subscribe(threadmode = threadmode.async) public void onevent(loggingevent event){ logevent( event); } @subscribe(threadmode = threadmode.async) public void onevent(otherloggingevent event){ logevent( event); } the issue when make call like:
mypublisher.sendevent(new otherloggingevent(vara, varb, varc));
both subscribers called , can't figure out why. think might have fact otherloggingevent subclass of loggingevent, i'm not sure. question becomes how maintain 1-1 relationship publisher , subscriber. want call:
mypublisher.sendevent(new otherloggingevent(vara, varb, varc)); and have subscriber public void onevent(otherloggingevent event) called , when call:
mypublisher.sendevent(new loggingevent(vard, vare, varf)); the subscriber:
public void onevent(loggingevent event) will called? work is, have make sure classes unique, , not subclass of each other? have create new eventbus object?
both subscribers calling because of event class inheritance. can switch off eventinheritance feature in eventbus itself. using method:
eventbus bus = eventbus.builder().eventinheritance(false).installdefaulteventbus();
Comments
Post a Comment