package com.kitmenke.storm.spout;

import java.util.Map;
import java.util.Random;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import backtype.storm.spout.SpoutOutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.topology.base.BaseRichSpout;
import backtype.storm.tuple.Fields;
import backtype.storm.tuple.Values;
import backtype.storm.utils.Utils;

/**
 * Spout which generates random sentences.
 * @author Kit Menke
 *
 */
public class RandomSentenceSpout extends BaseRichSpout {
	private static final long serialVersionUID = 1L;

	private static final Logger LOG = LoggerFactory.getLogger(RandomSentenceSpout.class);

	SpoutOutputCollector _collector;
	Random _rand;

	@SuppressWarnings("rawtypes")
	@Override
	public void open(Map conf, TopologyContext context,
			SpoutOutputCollector collector) {
		_collector = collector;
		_rand = new Random();
	}

	@Override
	public void nextTuple() {
		String[] sentences = new String[] { 
				"Don't act like you're not impressed.",
				"Boy, that escalated quickly... I mean, that really got out of hand fast.",
				"I immediately regret this decision.",
				"I'm in a glass case of emotion!",
				"I love lamp.", 
				"They've done studies, you know. 60% of the time, it works every time.",
				"You know I don’t speak Spanish.",
				"And you ate the whole wheel of cheese?"};
		String sentence = sentences[_rand.nextInt(sentences.length)];
		LOG.debug("RandomSentenceSpout generated this sentence: {}", sentence);
		_collector.emit(new Values(sentence));
		Utils.sleep(10000);
	}
	
	@Override
	public void declareOutputFields(OutputFieldsDeclarer declarer) {
		declarer.declare(new Fields("word"));
	}

	@Override
	public void ack(Object id) {
	}

	@Override
	public void fail(Object id) {
	}
}
@@ -1415,11 +1415,333 @@
 se?%22
+, %0A%09%09%09%09%22Open the pod bay doors, HAL.%22,%0A%09%09%09%09%22Space... The final frontier.%22,%0A%09%09%09%09%22These are the voyages of the starship Enterprise.%22,%0A%09%09%09%09%22It's continuing mission, to explore strange new worlds.%22,%0A%09%09%09%09%22To seek out new life and new civilizations.%22,%0A%09%09%09%09%22To boldly go where no one has gone before.%22,%0A%09%09%09%09%22Tea, Earl Grey, hot.%22
 %7D;%0A
-
 %09%09St
@@ -1915,16 +1915,16 @@
 ence));%0A
+
 %09%09Utils.
@@ -1933,17 +1933,16 @@
 eep(1000
-0
 );%0A%09%7D%0A%09%0A

Add some more sentences to the random sentence spout.