In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Communication model architecture diagram
The master side code import akka.actor. {Actor, ActorSystem, Props} import com.typesafe.config.ConfigFactory// needs to import these two packages to encapsulate some properties. Class MasterActor extends Actor {/ / calls override def preStart (): Unit = {} / / to receive the message override def receive: Receive = {case "started" = > {println ("Master has been started!") / / before starting, indicating that the Master thread has started and completed} case "connecting" = > {println ("Master has been get connect from Worker!") Println ("a Worker Node has been register!") / / returns a message to Worker sender ()! "connected" Thread.sleep (1000)} case "stoped" = > {} object Demo01MasterActor {def main (args: Array [String]) {/ / set MasterIP and port val masterHost = "localhost" val masterPort = "1234" / / Port and IP are encapsulated into akka architecture Get an attribute profile val conStr = s "" | akka.actor.provider = "akka.remote.RemoteActorRefProvider" | akka.remote.netty.tcp.hostname = "$masterHost" | akka.remote.netty.tcp.port = "$masterPort" .stripMargin val config = ConfigFactory.parseString (conStr) val masterActorSystem = ActorSystem ("MasterActorSystem", config) val masterActor = masterActorSystem.actorOf (Props [MasterActor], "MasterActor") masterActor! "started" masterActorSystem.awaitTermination () }} worker side code import akka.actor. {Actor, ActorSelection, ActorSystem, Props} import com.typesafe.config.ConfigFactoryclass WorkerActor extends Actor {var masterURL: ActorSelection = null / / execute before starting Actor Do initialization work override def preStart (): Unit = {/ / configure URL / / MasterIP:localhost / / MasterPort:8888 (according to Master configuration) / / ActorSystem object of Master to access Master: MasterActorSystem, MasterActor masterURL = context.actorSelection ("akka.tcp://MasterActorSystem@localhost:8888/user/MasterActor")} override def receive: Receive = {case "started" = > {println ("Worker has been started!") / / enter this branch Indicates that this Worker thread has started and / / can register / / request with Master to establish a connection with Master masterURL! "connecting"} case "connected" = > {println ("Worker received confirmation message from Master!")} case "stoped" = > {} object Demo01WorkerActor {def main (args: Array [String]) {/ / initialize MastereIP and port, WorkerIP and port / / val masterHost = args (0) / / val masterPort = args (1) / / val workerHost = args (2) / / val workePort = args (3) val masterHost = "localhost" val masterPort = "8888" val workerHost = "localhost" val workePort = "8889" / / Port and IP encapsulated into akka architecture Get an attribute profile val conStr = s "" | akka.actor.provider = "akka.remote.RemoteActorRefProvider" | akka.remote.netty.tcp.hostname = "$workerHost" | akka.remote.netty.tcp.port = "$workePort" .stripMargin val config = ConfigFactory.parseString (conStr) val workerActorSystem = ActorSystem ("WorkerActorSystem", config) val workerActor = workerActorSystem.actorOf (Props [WorkerActor], "WorkerActor") workerActor! "started" workerActorSystem.awaitTermination ();}}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 266
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.