WordCountPerformanceSplitter.java 1.9 KB
Newer Older
J
jfeher 已提交
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.
 *
 **********************************************************************************************************************/

16
package eu.stratosphere.streaming.performance;
J
jfeher 已提交
17

G
gyfora 已提交
18 19 20
import java.io.IOException;
import java.io.ObjectInputStream;

J
jfeher 已提交
21 22 23 24 25 26
import eu.stratosphere.api.java.functions.FlatMapFunction;
import eu.stratosphere.api.java.tuple.Tuple1;
import eu.stratosphere.streaming.util.PerformanceCounter;
import eu.stratosphere.util.Collector;

public class WordCountPerformanceSplitter extends FlatMapFunction<Tuple1<String>, Tuple1<String>> {
J
jfeher 已提交
27

E
Eszes Dávid 已提交
28
	private static final long serialVersionUID = 1L;
M
Márton Balassi 已提交
29

J
jfeher 已提交
30 31
	private Tuple1<String> outTuple = new Tuple1<String>();

G
gyfora 已提交
32
	PerformanceCounter pCounter;
J
jfeher 已提交
33

E
Eszes Dávid 已提交
34
	@Override
J
jfeher 已提交
35 36 37 38 39 40 41
	public void flatMap(Tuple1<String> inTuple, Collector<Tuple1<String>> out) throws Exception {

		for (String word : inTuple.f0.split(" ")) {
			outTuple.f0 = word;
			out.collect(outTuple);
			pCounter.count();
		}
J
jfeher 已提交
42
	}
J
jfeher 已提交
43

G
gyfora 已提交
44 45 46 47 48
	private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
		ois.defaultReadObject();
		pCounter = new PerformanceCounter("SplitterEmitCounter", 1000, 1000, 30000,
				"/home/strato/stratosphere-distrib/resources/splitter.csv");
	}
J
jfeher 已提交
49

J
jfeher 已提交
50
}