All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hmsonline.virgil.mapreduce.RubyInvoker Maven / Gradle / Ivy

The newest version!
package com.hmsonline.virgil.mapreduce;

import java.util.List;
import java.util.Map;

import javax.script.ScriptException;

import org.apache.hadoop.io.ObjectWritable;
import org.jruby.RubyArray;
import org.jruby.embed.ScriptingContainer;

public class RubyInvoker {    
    public static synchronized RubyArray invokeMap(ScriptingContainer container, Object rubyReceiver, String rowKey,
            Map columns, Emitter emitter, Map params) throws ScriptException {
        // TODO- see if we can possibly deprecate the one without params
        if (params == null) { 
            return (RubyArray) container.callMethod(rubyReceiver, "map", rowKey, columns, emitter);
        } else {
            return (RubyArray) container.callMethod(rubyReceiver, "map", rowKey, columns, emitter, params);
        }
    }
    
    public static synchronized RubyArray invokeMap(ScriptingContainer container, Object rubyReceiver, String rowKey,
                                                   Map columns, Map params) throws ScriptException {
                                               // TODO- see if we can possibly deprecate the one without params
                                               if (params == null) { 
                                                   return (RubyArray) container.callMethod(rubyReceiver, "map", rowKey, columns);
                                               } else {
                                                   return (RubyArray) container.callMethod(rubyReceiver, "map", rowKey, columns, params);
                                               }
                                           }

    @SuppressWarnings("unchecked")
    public static synchronized Map> invokeReduce(ScriptingContainer container,
            Object rubyReceiver, String key, Iterable values, Map params) throws ScriptException {
        // TODO- see if we can possibly deprecate the one without params
        if (params == null) {
            return (Map>) container.callMethod(rubyReceiver, "reduce", key, values);
        } else {
            return (Map>) container.callMethod(rubyReceiver, "reduce", key, values, params);
        }
    }
    
    @SuppressWarnings("unchecked")
    public static synchronized Map> invokeReduce(ScriptingContainer container,
            Object rubyReceiver, String key, List values, Map params) throws ScriptException {
        // TODO- see if we can possibly deprecate the one without params
        if (params == null) {
            return (Map>) container.callMethod(rubyReceiver, "reduce", key, values);
        } else {
            return (Map>) container.callMethod(rubyReceiver, "reduce", key, values, params);
        }
    }
}