JoinSourceTwo.java 1.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/***********************************************************************************************************************
 *
 * Copyright (C) 2010-2014 by the Stratosphere project (http://stratosphere.eu)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 *
 **********************************************************************************************************************/

Y
Yingjun Wu 已提交
16
package eu.stratosphere.streaming.examples.join;
17

Y
Yingjun Wu 已提交
18 19 20
import java.util.Random;

import eu.stratosphere.api.java.tuple.Tuple3;
21 22
import eu.stratosphere.streaming.api.SourceFunction;
import eu.stratosphere.util.Collector;
23

24
public class JoinSourceTwo extends SourceFunction<Tuple3<String, String, Integer>> {
25

Y
Yingjun Wu 已提交
26
	private static final long serialVersionUID = -5897483980082089771L;
27

28 29
	private String[] names = { "tom", "jerry", "alice", "bob", "john", "grace", "sasa", "lawrance",
			"andrew", "jean", "richard", "smith", "gorge", "black", "peter" };
Y
Yingjun Wu 已提交
30
	private Random rand = new Random();
M
Márton Balassi 已提交
31
	private Tuple3<String, String, Integer> outTuple = new Tuple3<String, String, Integer>();
32

Y
Yingjun Wu 已提交
33
	@Override
M
Márton Balassi 已提交
34
	public void invoke(Collector<Tuple3<String, String, Integer>> out) throws Exception {
J
jfeher 已提交
35
		// Continuously emit tuples with random names and integers (grades).
Y
Yingjun Wu 已提交
36
		while (true) {
M
Márton Balassi 已提交
37 38 39
			outTuple.f0 = "grade";
			outTuple.f1 = names[rand.nextInt(names.length)];
			outTuple.f2 = rand.nextInt(5) + 1;
40

M
Márton Balassi 已提交
41
			out.collect(outTuple);
Y
Yingjun Wu 已提交
42 43
		}
	}
44
}