Package org.jruby.embed

Examples of org.jruby.embed.ScriptingContainer


    _scriptPath = scriptPath;
  }

  public Object makeObject()
  {
    ScriptingContainer container = new ScriptingContainer(LocalContextScope.SINGLETHREAD);
    // TODO: handle RUBY LOAD PATH to allow non JRuby dev
    List<String> loadPaths = new ArrayList<String>();
    loadPaths.add(_appPath);
    container.getProvider().setLoadPaths(loadPaths);
    container.runScriptlet("ENV['SIPATRA_PATH'] = '" + _appPath.replaceAll("'", "\'") + "'");
    container.runScriptlet(PathType.CLASSPATH, "sipatra.rb");

    if(_scriptPath != null)
    {
      File file = new File(_scriptPath);
      if(file.isFile())
        container.runScriptlet(PathType.ABSOLUTE, file.getAbsolutePath());
      else if(file.isDirectory())
      {
        for(File f : file.listFiles())
        {
          if(f.getName().endsWith(".rb"))
            container.runScriptlet(PathType.ABSOLUTE, f.getAbsolutePath());
        }
      }
    }
    return container;
  }
View Full Code Here


    invokeMethod(response, "do_response");
 

  private void invokeMethod(SipServletMessage message, String methodName)
  {
    ScriptingContainer container = null;
    try
    {
      GenericObjectPool pool = (GenericObjectPool) message.getSession().getServletContext().getAttribute(Attributes.POOL);
      container = (ScriptingContainer) pool.borrowObject();
            long beginTime = System.currentTimeMillis();
      try
      {
        Object app = container.runScriptlet("Sipatra::Application::new");

        container.callMethod(app, "set_bindings", new Object[] {
            message.getSession().getServletContext()
            message.getSession().getServletContext().getAttribute(SipServlet.SIP_FACTORY),
            message.getSession(),
            message, _log});
        container.callMethod(app, methodName);
      }
      catch(Exception e)
      {
        pool.invalidateObject(container);
        container = null;
View Full Code Here

public class TestFactory extends TestCase{

  public void testFactory(){
   
    ScriptingContainer c = RubyStepFactory.createScriptingContainer(false, RubyVersion.RUBY_1_8);
    c.runScriptlet("puts \"Ruby version: #{RUBY_VERSION}\"");
   
  }
View Full Code Here

        "conn.close";

    // if the script can be executed repeatedly, all is fine. It raises an exception
    // if the driver got unregistered at some point.
    for (int i=1;i<=5;i++){
      ScriptingContainer c = RubyStepFactory.createScriptingContainer(false, RubyVersion.RUBY_1_8);
      c.runScriptlet(testScript);
      c.terminate();
      System.out.println("Testing JDBC Driver persistence: iteration "+i);
    }
   
  }
View Full Code Here

public class RubyStepFactory {

  synchronized public static ScriptingContainer createScriptingContainer(boolean withPersistentLocalVars, RubyVersion rubyVersion){
   
    ScriptingContainer c = new ScriptingContainer(LocalContextScope.SINGLETHREAD, (withPersistentLocalVars)?LocalVariableBehavior.PERSISTENT:LocalVariableBehavior.TRANSIENT);
   
    switch(rubyVersion){
    case RUBY_1_8:
      c.setCompatVersion(CompatVersion.RUBY1_8);
      break;
    case RUBY_1_9:
      c.setCompatVersion(CompatVersion.RUBY1_9);
      break;
    }
   
    c.setCompileMode(CompileMode.JIT);

    c.setRunRubyInProcess(false);
    ClassLoader loader = ScriptingContainer.class.getClassLoader();
    c.setClassLoader(loader);
   
    // does it make sense to include more in the class path?
   
//    List<String> paths = new ArrayList<String>();
//    paths.add(c.getHomeDirectory());
View Full Code Here

  public Vagrant() {
    this(false);
  }
 
  public Vagrant(boolean debug) {
    scriptingContainer = new ScriptingContainer(
        LocalContextScope.SINGLETHREAD);
    if(debug) {
      debug();
    }
  }
View Full Code Here

   {}

   @Override
   public final String transform(HttpServletRewrite event, String input)
   {
      ScriptingContainer container = getContainer(event.getServletContext());
      try {

         Object result = null;
         // 'input' will be the string to transform
         container.put("input", input);

         // execute the script returned by the implementation
         result = runScript(container);

         // the result must be a string
         return result != null ? result.toString() : null;
      }
      finally {
         if (container != null)
            container.clear();
      }

   }
View Full Code Here

      {
         storage = new ConcurrentHashMap<Class<T>, ScriptingContainer>();
         context.setAttribute(CONTAINER_STORE_KEY, storage);
      }

      ScriptingContainer cachedContainer = storage.get(getTransformerType());
      if (cachedContainer == null)
      {
         cachedContainer = new ScriptingContainer(LocalContextScope.CONCURRENT, LocalVariableBehavior.TRANSIENT);
         cachedContainer.setRunRubyInProcess(false);

         storage.put(getTransformerType(), cachedContainer);

         // the user may have set a custom CompileMode
         if (compileMode != null) {
            cachedContainer.setCompileMode(compileMode);
         }

         // the user may have set a customn CompatVersion
         if (compatVersion != null) {
            cachedContainer.setCompatVersion(compatVersion);
         }

         // scripts typically need to set the load path for 3rd party gems
         List<String> loadPaths = getLoadPaths();
         if (loadPaths != null && !loadPaths.isEmpty()) {
            cachedContainer.getLoadPaths().addAll(loadPaths);
         }

         // perform custom initialization of the container
         prepareContainer(cachedContainer);
      }
View Full Code Here

      setupEngine();
    }
  }

  private void setupEngine() {
    rubyEngine = new ScriptingContainer(LocalContextScope.SINGLETHREAD);
    if (rubyEngine == null)
      throw new RuntimeException("cannot find jruby engine");
    try {
      // evaluate ruby library upfront
      rubyEngine.runScriptlet(readRubyWrapperFile(), WRAPPER_FILE_NAME);
View Full Code Here

        //http://wiki.trialox.org/confluence/display/DEV/Using+JRuby+in+OSGi
        //http://kenai.com/projects/jruby-embed/pages/Home
        try {
            ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
            Thread.currentThread().setContextClassLoader(null);
            container = new ScriptingContainer(SINGLETON, TRANSIENT);
            container.put("$console", console);
            container.put("$jruby_home", jrubyHome());
            Thread.currentThread().setContextClassLoader(oldClassLoader);

        } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.jruby.embed.ScriptingContainer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.