CyberReveal/storm-test — pull request #1 by practice2014 (2014-04-25 00:03:44+00:00)
Title: Patch 1

the Main class instantiates an object a thread class called BookTopology. BookTopology is a thread which implements Runnable interface. the Main class has directly called method run(); which is not creating another thread but is executing in the same thread. I would say that thread should start by calling a start(); method. The call to this thread should have been made from Main class by calling a start() method. An instance of BookTopology (one that implements runnable) can be passed as an argument to the thread constructor. and an object of Thread can then call method start();
BookTopology topology = new BookTopology (string, input file, File output file);
Thread th = new Thread (topology);
th.start();
by doing this, a seperate thread will start. the thread will go into runnable state and will be executed when CPU/schedular puts it in a running state. this way it improves the utilisation of resources.

Adding more Bolts:
More Bolts can be created by using setBolt() methods of class TopologyBuilder. The class BookTopology instantiates TopologyBuilder. so we can override method setBolt () in the definition of class BookTopology.
public final class BookTopology implements Runnable
{
public void run()
{
TopologyBuilder builder = new TopologyBuilder();
builder.setBolt("Splitter", new SplitBolt(), 2).shuffleGrouping("line");
// can add more Bolts here by using the setBolt method which takes string and another class object argument
}
}

setBolt(String id, IBasicBolt bolt,Number parallelism_hint)
IBasicBolt - interface
Class BaseBasicBolt

Class BaseBasicBolt
java.lang.Object
backtype.storm.topology.base.BaseComponent
backtype.storm.topology.base.BaseBasicBolt
All Implemented Interfaces:
IBasicBolt, IComponent, Serializable

another bolt will be defined in another class that will be created by extending class BaseBasicBolt.
e.g.
public class LetterSplitBolt extends BaseBasicBolt
public class LetterCountBolt extends BaseBasicBolt
in this class we can define how to fragment a word or a line etc inside an execute() method.
two methods need to be overridden as they are inherited from interface IBasicBolt and IComponent
method execute() and declareOutputFields() are supposed to be overriden.

two more bolts are added to split a word into letters and then to count the number of times that letter has previously been seen. two new classes have been added i.e. LetterSplitBolt.java and LetterCountBolt.java
then the same FilePrinterBolt.java is used to write it to a new file.

some improvements and new features:
1-some more interesting Bolts can be added e.g to check the longest line in the file or to check the longest word in the whole file. we can take the file input dynamically instead of passing a set file path.
2-It will be interesting to take the file from a socket and reading that. e.g. create a client socket and connect it to an application running on some open port on a machine. then we can read from that application and assess the contents.

implementing the suggested improvements and features:
public class LongestLineBolt extends BaseBasicBolt
public class LongestWordBolt extends BaseBasicBolt

then in class Main's main() method a file
Socket ClientSocket = new Socket(192.168.0.0, 8080);
InputStream indata = ClientSocket.getInputStream();
BookTopology topology = new BookTopology(topologyName, indata, new File( "file.out"));