tags:

views:

138

answers:

1

I'm trying to use EventBus from Jython. Sending events to the from Jython bus works as expected, they can be listened from my Java code. But subscribing to the bus from Jython is problematic. I'm trying this:

class Listener(EventTopicSubscriber):
    def onEvent(self, topic, object):
        print("got an event")

EventBus.subscribe("Topic", Listener)

It gives the following :

TypeError: subscribe(): 1st arg can't be coerced to java.util.regex.Pattern,
java.lang.reflect.Type, String, java.lang.Class

I'm surprised that there can be something wrong with the 1st argument. My understanding is that it's a String literal, just as it's supposed to be. Any ideas?

+2  A: 

I'm not sure whether the error message is misleading, but something else looks odd about your code. I would expect subscribe's second argument to be an EventTopicSubscriber instance - you've passed a class. Perhaps

EventBus.subscribe("Topic", Listener())

is more appropriate?

Vinay Sajip
It was that, thanks! It's incredible how blind to one's mistakes one can be. Oh well, at least the error message was misleading.
Joonas Pulakka
Actually it might be that the event EventBus.subscribe was attemnpting to pass "Topic" down into some Listener() method. When that failed (since the class has the method but it's an instance method and we have an unbound class reference) then it failed in a way that looked like a "couldn't make that a regex" to the dispatching wrapper?
Jim Dennis
Quite possible. Anyway, it was my mistake and now it works like a dream :-)
Joonas Pulakka