Search in sources :

Example 1 with JavaObject

use of org.apache.storm.generated.JavaObject in project storm by apache.

the class Thrift method instantiateJavaObject.

public static Object instantiateJavaObject(JavaObject obj) {
    List<JavaObjectArg> args = obj.get_args_list();
    Class[] paraTypes = new Class[args.size()];
    Object[] paraValues = new Object[args.size()];
    for (int i = 0; i < args.size(); i++) {
        JavaObjectArg arg = args.get(i);
        paraValues[i] = arg.getFieldValue();
        if (arg.getSetField().equals(JavaObjectArg._Fields.INT_ARG)) {
            paraTypes[i] = Integer.class;
        } else if (arg.getSetField().equals(JavaObjectArg._Fields.LONG_ARG)) {
            paraTypes[i] = Long.class;
        } else if (arg.getSetField().equals(JavaObjectArg._Fields.STRING_ARG)) {
            paraTypes[i] = String.class;
        } else if (arg.getSetField().equals(JavaObjectArg._Fields.BOOL_ARG)) {
            paraTypes[i] = Boolean.class;
        } else if (arg.getSetField().equals(JavaObjectArg._Fields.BINARY_ARG)) {
            paraTypes[i] = ByteBuffer.class;
        } else if (arg.getSetField().equals(JavaObjectArg._Fields.DOUBLE_ARG)) {
            paraTypes[i] = Double.class;
        } else {
            paraTypes[i] = Object.class;
        }
    }
    try {
        Class clazz = Class.forName(obj.get_full_class_name());
        Constructor cons = clazz.getConstructor(paraTypes);
        return cons.newInstance(paraValues);
    } catch (Exception e) {
        LOG.error("java object instantiation failed", e);
    }
    return null;
}
Also used : JavaObjectArg(org.apache.storm.generated.JavaObjectArg) Constructor(java.lang.reflect.Constructor) JavaObject(org.apache.storm.generated.JavaObject) ComponentObject(org.apache.storm.generated.ComponentObject)

Example 2 with JavaObject

use of org.apache.storm.generated.JavaObject in project storm by apache.

the class Task method mkTaskObject.

private Object mkTaskObject() {
    StormTopology topology = systemTopologyContext.getRawTopology();
    Map<String, SpoutSpec> spouts = topology.get_spouts();
    Map<String, Bolt> bolts = topology.get_bolts();
    Map<String, StateSpoutSpec> stateSpouts = topology.get_state_spouts();
    Object result;
    ComponentObject componentObject;
    if (spouts.containsKey(componentId)) {
        componentObject = spouts.get(componentId).get_spout_object();
    } else if (bolts.containsKey(componentId)) {
        componentObject = bolts.get(componentId).get_bolt_object();
    } else if (stateSpouts.containsKey(componentId)) {
        componentObject = stateSpouts.get(componentId).get_state_spout_object();
    } else {
        throw new RuntimeException("Could not find " + componentId + " in " + topology);
    }
    result = Utils.getSetComponentObject(componentObject);
    if (result instanceof ShellComponent) {
        if (spouts.containsKey(componentId)) {
            result = new ShellSpout((ShellComponent) result);
        } else {
            result = new ShellBolt((ShellComponent) result);
        }
    }
    if (result instanceof JavaObject) {
        result = Thrift.instantiateJavaObject((JavaObject) result);
    }
    return result;
}
Also used : StormTopology(org.apache.storm.generated.StormTopology) ShellSpout(org.apache.storm.spout.ShellSpout) Bolt(org.apache.storm.generated.Bolt) ShellBolt(org.apache.storm.task.ShellBolt) StateSpoutSpec(org.apache.storm.generated.StateSpoutSpec) StateSpoutSpec(org.apache.storm.generated.StateSpoutSpec) SpoutSpec(org.apache.storm.generated.SpoutSpec) JavaObject(org.apache.storm.generated.JavaObject) ComponentObject(org.apache.storm.generated.ComponentObject) ShellBolt(org.apache.storm.task.ShellBolt) JavaObject(org.apache.storm.generated.JavaObject) ComponentObject(org.apache.storm.generated.ComponentObject) ShellComponent(org.apache.storm.generated.ShellComponent)

Aggregations

ComponentObject (org.apache.storm.generated.ComponentObject)2 JavaObject (org.apache.storm.generated.JavaObject)2 Constructor (java.lang.reflect.Constructor)1 Bolt (org.apache.storm.generated.Bolt)1 JavaObjectArg (org.apache.storm.generated.JavaObjectArg)1 ShellComponent (org.apache.storm.generated.ShellComponent)1 SpoutSpec (org.apache.storm.generated.SpoutSpec)1 StateSpoutSpec (org.apache.storm.generated.StateSpoutSpec)1 StormTopology (org.apache.storm.generated.StormTopology)1 ShellSpout (org.apache.storm.spout.ShellSpout)1 ShellBolt (org.apache.storm.task.ShellBolt)1