public <T> T newPlugin(Class<T> iface, PluginType type) throws PluginSourceNotMatchException { String name = type.getName(); String category; if (InputPlugin.class.isAssignableFrom(iface)) { category = "input"; } else if (OutputPlugin.class.isAssignableFrom(iface)) { category = "output"; } else if (ParserPlugin.class.isAssignableFrom(iface)) { category = "parser"; } else if (FormatterPlugin.class.isAssignableFrom(iface)) { category = "formatter"; } else if (DecoderPlugin.class.isAssignableFrom(iface)) { category = "decoder"; } else if (EncoderPlugin.class.isAssignableFrom(iface)) { category = "encoder"; } else if (FilterPlugin.class.isAssignableFrom(iface)) { category = "filter"; } else if (GuessPlugin.class.isAssignableFrom(iface)) { category = "guess"; } else if (ExecutorPlugin.class.isAssignableFrom(iface)) { category = "executor"; } else { // unsupported plugin category throw new PluginSourceNotMatchException( "Plugin interface " + iface + " is not supported in JRuby"); } String methodName = "new_java_" + category; try { return jruby.callMethod(rubyPluginManager, methodName, name, iface); } catch (InvokeFailedException ex) { throw new PluginSourceNotMatchException(ex.getCause()); } }
private void setupJRuby(Activity startActivity) { System.setProperty("jruby.bytecode.version", "1.5"); // enable proxy classes System.setProperty( "jruby.ji.proxyClassFactory", "com.rickbutton.rubydroid.DalvikProxyClassFactory"); System.setProperty("jruby.ji.upper.case.package.name.allowed", "true"); System.setProperty("jruby.class.cache.path", appContext.getDir("dex", 0).getAbsolutePath()); // setup jruby home String apkName = getApkName(); String jrubyHome = "file:" + apkName + "!/jruby.home"; System.setProperty("jruby.home", jrubyHome); // configure jruby System.setProperty("jruby.compile.mode", "OFF"); // OFF OFFIR JITIR? FORCE FORCEIR // System.setProperty("jruby.compile.backend", "DALVIK"); System.setProperty("jruby.bytecode.version", "1.6"); System.setProperty("jruby.interfaces.useProxy", "true"); System.setProperty("jruby.management.enabled", "false"); System.setProperty("jruby.objectspace.enabled", "false"); System.setProperty("jruby.thread.pooling", "true"); System.setProperty("jruby.native.enabled", "false"); System.setProperty("jruby.ir.passes", "LocalOptimizationPass,DeadCodeElimination"); System.setProperty("jruby.backtrace.style", "normal"); // normal raw full mri ClassLoader loader = new PathClassLoader(apkName, RubySystem.class.getClassLoader()); // disable gems RubyInstanceConfig config = new RubyInstanceConfig(); config.setDisableGems(true); config.setLoader(loader); Ruby.newInstance(config); container = new ScriptingContainer(LocalContextScope.SINGLETON, LocalVariableBehavior.PERSISTENT); container.setClassLoader(loader); Thread.currentThread().setContextClassLoader(loader); if (appContext.getFilesDir() != null) { container.setCurrentDirectory(appContext.getFilesDir().getPath()); } container.put("$package_name", appContext.getPackageName()); container.put("app_context", appContext); container.put("system", this); rubyContext = container.runScriptlet(PathType.CLASSPATH, "ruby/droid/init.rb"); Object mainActivity = container.get("MainActivity"); container.callMethod(rubyContext, "start_ruby_activity", mainActivity, startActivity); }
public void stop() throws Exception { try { // We call the script with receiver = null - this causes the method to be called on the top // level // script container.callMethod(null, "vertx_stop"); } catch (InvokeFailedException e) { Throwable cause = e.getCause(); if (cause instanceof RaiseException) { // Gosh, this is a bit long winded! RaiseException re = (RaiseException) cause; String msg = "(NoMethodError) undefined method `vertx_stop'"; if (re.getMessage().startsWith(msg)) { // OK - method is not mandatory return; } } throw e; } }
public double rms() { return (Double) rubyContainer.callMethod(waveform, "rms"); }
public WaveformWrapper(double[] points) { Object waveformClass = rubyContainer.runScriptlet("Waveform"); waveform = rubyContainer.callMethod(waveformClass, "new", points); }