Skip to content

Instantly share code, notes, and snippets.

@yelcat
Created January 26, 2013 06:15
Show Gist options
  • Save yelcat/4640514 to your computer and use it in GitHub Desktop.
Save yelcat/4640514 to your computer and use it in GitHub Desktop.
public class OrderEnabledMockSpout implements IRichSpout {
private final static String[] ipAddress = new String[]
{"10.13.43.154", "10.112.43.12", "10.13.45.123", "10.113.43.4"};
private SpoutOutputCollector collector;
@Override
public boolean isDistributed() {
return true;
}
@Override
public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
outputFieldsDeclarer.declare(new Fields("IP", "BizOrderId"));
}
@Override
public void open(Map map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) {
this.collector = spoutOutputCollector;
}
@Override
public void close() {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void nextTuple() {
Utils.sleep(4000);
final Random rand = new Random();
collector.emit(new Values(ipAddress[rand.nextInt(ipAddress.length)], Math.abs(rand.nextLong())));
}
@Override
public void ack(Object o) {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void fail(Object o) {
//To change body of implemented methods use File | Settings | File Templates.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment