Learned the use of SBT development Akka The first case of source code parsing mapactor, Reduceactor, Aggregateactor, the application of Mapactor to the word count, send information to Reduceactor, the information to the local level of the summary, Then hand it over to Aggregateactor.
The cases are as follows:
Class Mapactor (reduceactor:actorref) Extend actor{
Val stop_words_list=list ("A", "is")
Deg receive:receive={
Case Message:string=>
Reduceactor! Evaluateexprssion (Message)
Case _=>
}
def evaluateexpression (line:string): mapdata={
var datalist=new Arraylist[word]
var parser:stringtokenizer=new stringtokenizer (line)
var defaultcount:tnteger=1
while (Parser.hasmoretokens ()) {
var word:string=parser.nexttoken (). toLowerCase ()
if (! Stop_words_list.contains (word)) {
Datalist.add (new Word (word, defaultcount))
}
}
return new MapData (dataList)
}
}
Class Reduceactor (aggregateactor:actorref) Extend actor{
def receive:receive = {
Case Message:mapdata =
Aggregateactor! Reduce (message.datalist)
Case _ =
}
def reduce (Datalist:arraylist[word]); reducedata={
var reducedmap = new Hashmap[sting,integer]
for (Wc:word <-datalist) {
var word:string =wc.word
if (Reducemap.containskey (word) {
Reducemap.put (Word,reducemap.get (word) +1)
} else{Reducemap.put (word,1)}
}
return new Reducedata (REDUCEMAP)}
}
Class Aggregateactor extend Actor {
var finalreducemap = new hashmap[string, Integer]
def receive:receive ={
Case Message:reducedata =
Aggregateinmemoryreduce (Message.reducedatamap)
Case Message:result =
System.out.println (Finalreducemap.tostring ())}
def aggregateinmemoryreduce (Reducedlist:hashmap[string,integer]) {
var Count:integer =0
For (key <-Reducelist.keyset) {
if (Finalreducemap.containskey (key)) {
Count = Reducedlist.get (key)
Count+=finalreducemao.get (Key)
Finalreducedmap.put (Key,count)
}else{Finalreducedmap.put (Key,reducedlist.get (key))}
}
}
}
}
DT Big Data Dream Factory Scala video in today's update Breakthrough 100 episodes! Through thick and thin, thank you for the continuous learning and support of big data enthusiasts! (DT Big Data DreamWorks 1 to 100 episode Scala all videos, PPT and code in Baidu Cloud Disk Link: Http://url.cn/fSFPjS)
Using SBT to develop Akka first case source parsing mapactor, Reduceactor, Aggregateactor