Giter VIP home page Giter VIP logo

Comments (2)

eregon avatar eregon commented on July 29, 2024 1

This works fine:

Dir.glob("pulsar-client/*.jar").each { |f| Java.add_to_classpath File.expand_path f }
pulsar = Java.type('org.apache.pulsar.client.api.PulsarClient')
p pulsar
client = pulsar.builder.serviceUrl("pulsar://localhost:6650/").build
p client

Schema = Java.type('org.apache.pulsar.client.api.Schema')
producer = client.newProducer(Schema.STRING).topic("my-topic").create
p producer

producer[:send].call("My message")
# Or:
Truffle::Interop.invoke_member(producer, :send, "My message")

I followed https://pulsar.apache.org/docs/next/getting-started-standalone/ (including running bin/pulsar standalone)
and https://pulsar.apache.org/docs/next/client-libraries-java-setup/
and downloaded all Maven jars to a folder with https://stackoverflow.com/a/75183691/388803

So it's producer[:send].call("My message") not producer['send'].call(-> {"My message"}) which would pass a Proc and not a String.
The Schema.STRING is also needed otherwise the API seems to expect [B, i.e. byte[].
There is also Truffle::Interop.invoke_member(producer, :send, "My message") which uses interop explicitly.

from truffleruby.

AlexeyMatskevich avatar AlexeyMatskevich commented on July 29, 2024

This seems to be done as follows

producer['send'].call(-> {"My message"})

but I seem to be having trouble typing.

producer['send'].call(-> {"My message"})
#<Polyglot::ForeignException[Java] java.lang.ClassCastException:0x71cdc44c: class com.oracle.truffle.polyglot.PolyglotMapAndFunction cannot be cast to class java.lang.String (com.oracle.truffle.polyglot.PolyglotMapAndFunction is in module org.graalvm.truffle of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')>
backtraces are hidden because TruffleRuby doesn't have a case for the org.truffleruby.language.objects.IsCopyableObjectNodeGen node with values of type com.oracle.truffle.host.HostException
        from org.truffleruby.language.objects.IsCopyableObjectNodeGen.executeAndSpecialize(IsCopyableObjectNodeGen.java:168)
        from org.truffleruby.language.objects.IsCopyableObjectNodeGen.execute(IsCopyableObjectNodeGen.java:113)
        from org.truffleruby.core.kernel.KernelNodesFactory$CloneNodeFactory$CloneNodeGen.executeAndSpecialize(KernelNodesFactory.java:2953)
        from org.truffleruby.core.kernel.KernelNodesFactory$CloneNodeFactory$CloneNodeGen.execute(KernelNodesFactory.java:2935)
        from org.truffleruby.language.control.SequenceNode.execute(SequenceNode.java:38)
        from org.truffleruby.language.RubyMethodRootNode.execute(RubyMethodRootNode.java:65) was raised when processing them

Even if one tries to use Java types (if I'm doing it right)

irb(main):007> ST = Java.type('java.lang.String')
=> #<Polyglot::ForeignClass[Java] type java.lang.String>
irb(main):009> s = ST.new("Hello, world")
=> "Hello, world"
irb(main):012> producer['send'].call(-> {s})
#<Polyglot::ForeignException[Java] java.lang.ClassCastException:0x68d272c7: class com.oracle.truffle.polyglot.PolyglotMapAndFunction cannot be cast to class java.lang.String (com.oracle.truffle.polyglot.PolyglotMapAndFunction is in module org.graalvm.truffle of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')>
backtraces are hidden because TruffleRuby doesn't have a case for the org.truffleruby.language.objects.IsCopyableObjectNodeGen node with values of type com.oracle.truffle.host.HostException
        from org.truffleruby.language.objects.IsCopyableObjectNodeGen.executeAndSpecialize(IsCopyableObjectNodeGen.java:168)
        from org.truffleruby.language.objects.IsCopyableObjectNodeGen.execute(IsCopyableObjectNodeGen.java:113)
        from org.truffleruby.core.kernel.KernelNodesFactory$CloneNodeFactory$CloneNodeGen.executeAndSpecialize(KernelNodesFactory.java:2953)
        from org.truffleruby.core.kernel.KernelNodesFactory$CloneNodeFactory$CloneNodeGen.execute(KernelNodesFactory.java:2935)
        from org.truffleruby.language.control.SequenceNode.execute(SequenceNode.java:38)
        from org.truffleruby.language.RubyMethodRootNode.execute(RubyMethodRootNode.java:65) was raised when processing them

from truffleruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.