views:

55

answers:

1

I am trying to register a User Defined Function with Esper API. It take a class or string type arguement

http://esper.codehaus.org/esper-4.0.0/doc/api/com/espertech/esper/client/ConfigurationOperations.html#addImport(java.lang.String)

class MyUdf():
    @staticmethod
    def udf():
        return 50

conf.addImport(myudf.getClass().getName())

The error message

AttributeError: class MyUdf has no attribute 'getClass'

I can import java class by

from java.lang import Math
conf.addImport(Math)

@larsmans: class seems only exists in Java Class class

class MyUdf(): 
    @staticmethod 
    def udf(): 
        return 50 

def main(): 
    a = 'abc' 
    print a.__class__ 
    u = MyUdf 
    print u.__class__ 


Traceback (most recent call last): 

line 79, in main print u.__class__ AttributeError: class MyUdf has no attribute '__class__' 
A: 

I don't think this is possible. Jython classes are not Java classes, and as far as I can tell there's no pure-jython mechanism to corce it.

Generally, I would say that you should take the object factory method mentioned in the Jython book, and combine with a proxy class, which is what you'd pass as the parameter.

However, that method involves writing lots of Java, and it seems that in your case it would simpler to just write the MyUdf class in Java and be done with it.

Alternatively, you might be able to do something with dynamic bytecode generation, but that's a whole new rabbit hole...

itsadok