Using SBT to develop Akka first case source parsing mapactor, Reduceactor, Aggregateactor

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.