backtype.storm.grouping.CustomStreamGrouping Java Examples

The following examples show how to use backtype.storm.grouping.CustomStreamGrouping. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TridentTopologyBuilder.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Override
public BoltDeclarer customGrouping(final String component, final CustomStreamGrouping grouping) {
    addDeclaration(new InputDeclaration() {
        @Override
        public void declare(InputDeclarer declarer) {
            declarer.customGrouping(component, grouping);
        }                

        @Override
        public String getComponent() {
            return component;
        }                

        @Override
        public String getStream() {
            return null;
        }
    });
    return this;        
}
 
Example #2
Source File: TridentTopologyBuilder.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Override
public BoltDeclarer customGrouping(final String component, final String streamId, final CustomStreamGrouping grouping) {
    addDeclaration(new InputDeclaration() {
        @Override
        public void declare(InputDeclarer declarer) {
            declarer.customGrouping(component, streamId, grouping);
        }                

        @Override
        public String getComponent() {
            return component;
        }                

        @Override
        public String getStream() {
            return streamId;
        }
    });
    return this;
}
 
Example #3
Source File: TransactionalTopologyBuilder.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public BoltDeclarer customGrouping(final String component, final String streamId, final CustomStreamGrouping grouping) {
    addDeclaration(new InputDeclaration() {
        @Override
        public void declare(InputDeclarer declarer) {
            declarer.customGrouping(component, streamId, grouping);
        }

        @Override
        public String getComponent() {
            return component;
        }
    });
    return this;
}
 
Example #4
Source File: TransactionalTopologyBuilder.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public BoltDeclarer customGrouping(final String component, final CustomStreamGrouping grouping) {
    addDeclaration(new InputDeclaration() {
        @Override
        public void declare(InputDeclarer declarer) {
            declarer.customGrouping(component, grouping);
        }

        @Override
        public String getComponent() {
            return component;
        }
    });
    return this;
}
 
Example #5
Source File: BatchSubtopologyBuilder.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public BoltDeclarer customGrouping(final String component, final String streamId, final CustomStreamGrouping grouping) {
    addDeclaration(new InputDeclaration() {
        @Override
        public void declare(InputDeclarer declarer) {
            declarer.customGrouping(component, streamId, grouping);
        }

        @Override
        public String getComponent() {
            return component;
        }
    });
    return this;
}
 
Example #6
Source File: BatchSubtopologyBuilder.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public BoltDeclarer customGrouping(final String component, final CustomStreamGrouping grouping) {
    addDeclaration(new InputDeclaration() {
        @Override
        public void declare(InputDeclarer declarer) {
            declarer.customGrouping(component, grouping);
        }

        @Override
        public String getComponent() {
            return component;
        }
    });
    return this;
}
 
Example #7
Source File: LinearDRPCTopologyBuilder.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public LinearDRPCInputDeclarer customGrouping(final String streamId, final CustomStreamGrouping grouping) {
    addDeclaration(new InputDeclaration() {
        @Override
        public void declare(String prevComponent, InputDeclarer declarer) {
            declarer.customGrouping(prevComponent, streamId, grouping);
        }
    });
    return this;
}
 
Example #8
Source File: Thrift.java    From jstorm with Apache License 2.0 5 votes vote down vote up
public static CustomStreamGrouping 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 (CustomStreamGrouping) cons.newInstance(paraValues);
    } catch (Exception e) {
        LOG.error("instantiate_java_object fail", e);
    }

    return null;

}
 
Example #9
Source File: MkCustomGrouper.java    From jstorm with Apache License 2.0 5 votes vote down vote up
public MkCustomGrouper(TopologyContext context, CustomStreamGrouping grouping,
                       GlobalStreamId stream, List<Integer> targetTask, int myTaskId) {
    this.myTaskId = myTaskId;
    this.grouping = grouping;
    this.grouping.prepare(context, stream, targetTask);

}
 
Example #10
Source File: LinearDRPCTopologyBuilder.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public LinearDRPCInputDeclarer customGrouping(final CustomStreamGrouping grouping) {
    addDeclaration(new InputDeclaration() {
        @Override
        public void declare(String prevComponent, InputDeclarer declarer) {
            declarer.customGrouping(prevComponent, grouping);
        }
    });
    return this;
}
 
Example #11
Source File: TridentTopology.java    From jstorm with Apache License 2.0 5 votes vote down vote up
private static boolean isIdentityPartition(PartitionNode n) {
    Grouping g = n.thriftGrouping;
    if(g.is_set_custom_serialized()) {
        CustomStreamGrouping csg = (CustomStreamGrouping) Utils.javaDeserialize(g.get_custom_serialized(), Serializable.class);
        return csg instanceof IdentityGrouping;
    }
    return false;
}
 
Example #12
Source File: TopologyBuilder.java    From jstorm with Apache License 2.0 4 votes vote down vote up
@Override
public BoltDeclarer customGrouping(String componentId, String streamId, CustomStreamGrouping grouping) {
    return grouping(componentId, streamId, Grouping.custom_serialized(Utils.javaSerialize(grouping)));
}
 
Example #13
Source File: TopologyBuilder.java    From jstorm with Apache License 2.0 4 votes vote down vote up
@Override
public BoltDeclarer customGrouping(String componentId, CustomStreamGrouping grouping) {
    return customGrouping(componentId, Utils.DEFAULT_STREAM_ID, grouping);
}
 
Example #14
Source File: FluxBuilder.java    From jstorm with Apache License 2.0 4 votes vote down vote up
private static CustomStreamGrouping buildCustomStreamGrouping(ObjectDef def, ExecutionContext context)
        throws ClassNotFoundException,
        IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
    Object grouping = buildObject(def, context);
    return (CustomStreamGrouping)grouping;
}
 
Example #15
Source File: FluxBuilder.java    From flux with Apache License 2.0 4 votes vote down vote up
private static CustomStreamGrouping buildCustomStreamGrouping(ObjectDef def, ExecutionContext context)
        throws ClassNotFoundException,
        IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
    Object grouping = buildObject(def, context);
    return (CustomStreamGrouping)grouping;
}
 
Example #16
Source File: TestStormCustomGroupingRouting.java    From eagle with Apache License 2.0 4 votes vote down vote up
@Ignore
@Test
public void testRoutingByCustomGrouping() throws Exception {
    Config conf = new Config();
    conf.setNumWorkers(2); // use two worker processes
    TopologyBuilder topologyBuilder = new TopologyBuilder();
    topologyBuilder.setSpout("blue-spout", new BlueSpout()); // parallelism hint

    topologyBuilder.setBolt("green-bolt-1", new GreenBolt(0)).setNumTasks(2)
        .customGrouping("blue-spout", new CustomStreamGrouping() {
            int count = 0;
            List<Integer> targetTask;

            @Override
            public void prepare(WorkerTopologyContext context, GlobalStreamId stream, List<Integer> targetTasks) {
                this.targetTask = targetTasks;
            }

            @Override
            public List<Integer> chooseTasks(int taskId, List<Object> values) {
                if (count % 2 == 0) {
                    count++;
                    return Arrays.asList(targetTask.get(0));
                } else {
                    count++;
                    return Arrays.asList(targetTask.get(1));
                }
            }
        });

    LocalCluster cluster = new LocalCluster();
    cluster.submitTopology("mytopology", new HashMap(), topologyBuilder.createTopology());

    while (true) {
        try {
            Thread.sleep(1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example #17
Source File: BoltDeclarerImpl.java    From incubator-heron with Apache License 2.0 4 votes vote down vote up
@Override
public BoltDeclarer customGrouping(
    String componentId, String streamId, CustomStreamGrouping grouping) {
  delegate.customGrouping(componentId, streamId, new CustomStreamGroupingDelegate(grouping));
  return this;
}
 
Example #18
Source File: BoltDeclarerImpl.java    From incubator-heron with Apache License 2.0 4 votes vote down vote up
@Override
public BoltDeclarer customGrouping(String componentId, CustomStreamGrouping grouping) {
  return customGrouping(componentId, Utils.DEFAULT_STREAM_ID, grouping);
}
 
Example #19
Source File: Stream.java    From jstorm with Apache License 2.0 2 votes vote down vote up
/**
 * ## Repartitioning Operation
 *
 * @param partitioner
 * @return
 */
public Stream partition(CustomStreamGrouping partitioner) {
    return partition(Grouping.custom_serialized(Utils.javaSerialize(partitioner)));
}
 
Example #20
Source File: InputDeclarer.java    From jstorm with Apache License 2.0 2 votes vote down vote up
/**
 * A custom stream grouping by implementing the CustomStreamGrouping interface.
 */
T customGrouping(String componentId, CustomStreamGrouping grouping);
 
Example #21
Source File: InputDeclarer.java    From jstorm with Apache License 2.0 2 votes vote down vote up
/**
 * A custom stream grouping by implementing the CustomStreamGrouping interface.
 */
T customGrouping(String componentId, String streamId, CustomStreamGrouping grouping);
 
Example #22
Source File: LinearDRPCInputDeclarer.java    From jstorm with Apache License 2.0 votes vote down vote up
LinearDRPCInputDeclarer customGrouping(CustomStreamGrouping grouping); 
Example #23
Source File: LinearDRPCInputDeclarer.java    From jstorm with Apache License 2.0 votes vote down vote up
LinearDRPCInputDeclarer customGrouping(String streamId, CustomStreamGrouping grouping); 
Example #24
Source File: InputDeclarer.java    From incubator-heron with Apache License 2.0 votes vote down vote up
T customGrouping(String componentId, String streamId, CustomStreamGrouping grouping); 
Example #25
Source File: InputDeclarer.java    From incubator-heron with Apache License 2.0 votes vote down vote up
T customGrouping(String componentId, CustomStreamGrouping grouping);