I need to write a storm spout for reading data from a port. Wanted to know if that was logically possible.
With that in mind, I had designed a simple topology design
In constructor just assign the variables. Try to instantiate ServerSocket in prepare method, do not write any new ... in constructor. And rename variables, you have two sc variables.
public class ProxySpout extends BaseRichSpout{
int port;
public ProxySpout(int port){
this.port=port;
}
@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
//new ServerSocket
}
@Override
public void nextTuple() {
}
@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
}
}
If you put it in prepare method then it will only be called once the spout is already deployed, so it doesn't need to be serialized, and it will only be called once per lifetime of the spout, so it's not inefficient.