interface - Is it possible to convert an anonymous class from Java to JRuby? -


i working on implementing jruby wrapper around snmp4j-agent library, found here:

website: http://www.snmp4j.org/
javadocs: http://www.snmp4j.org/agent/doc/


it's been pretty fun far, having trouble deciphering following piece of java code implement in jruby:

server = new defaultmoserver(); vacmmib = new vacmmib(new moserver[] { server }); 

the problem - far can tell - casting new moserver[] (which interface) creates anonymous function passed server object, , can't seem find right way express jruby. i've included information java classes:


defaultmoserver defined as

public class defaultmoserver implements moserver {     public defaultmoserver() {        ...     }     ... } 

javadoc: http://www.snmp4j.org/agent/doc/org/snmp4j/agent/defaultmoserver.html


vacmmib defined as

public class vacmmib implements mogroup, mutablevacm {     public vacmmib(moserver[] server) {        this.server = server;        ...     }     ... } 

javadoc: http://www.snmp4j.org/agent/doc/org/snmp4j/agent/mo/snmp/vacmmib.html


and finally, moserver defined as

public interface moserver {    ... } 

javadoc: http://www.snmp4j.org/agent/doc/org/snmp4j/agent/moserver.html



here doing in jruby:

require 'java' require 'snmp4jruby' require 'lib/snmp4j-agent-1.4.3.jar'  module agent     include_package 'org.snmp4j.agent'      module mo        include_package 'org.snmp4j.agent.mo'         module snmp           include_package 'org.snmp4j.agent.mo.snmp'        end     end end  class snmpagent < agent::baseagent      # setup agent     def init        ... works fine here ...         # server created on without issue        self.server = agent::defaultmoserver.new         # having trouble here        _server = agent::moserver.new { self.server }        self.vacmmib = agent::mo::snmp::vacmmib.new(_server)     end  end 

running above code gives me following error line set self.vacmmib = ...:

typeerror: failed coerce org.jruby.gen.interfaceimpl792882806 [lorg.snmp4j.agent.moserver; 



direction on appreciated!

your issue seems vacmmib constructor takes array of moserver argument , you're passing instance of moserver.

try this:

_server = agent::moserver.new { self.server } # code # self.vacmmib = agent::mo::snmp::vacmmib.new(_server)  # updated code self.vacmmib = agent::mo::snmp::vacmmib.new([_server])  

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -