Wordcount fonctionnel
- Timeout to permit to worker to join cluster - wordcount - sort
This commit is contained in:
50
src/main/scala/cm/gintou/WordCountApp.scala
Normal file
50
src/main/scala/cm/gintou/WordCountApp.scala
Normal file
@@ -0,0 +1,50 @@
|
||||
package cm.gintou
|
||||
|
||||
import akka.actor.typed.ActorSystem
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration.Duration
|
||||
import scala.util.Try
|
||||
|
||||
object WordCountApp {
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
/*
|
||||
Paramètres attendus :
|
||||
1) role : "master" ou "worker"
|
||||
2) port : le port sur lequel ce nœud va écouter
|
||||
3) filePath : si role = "master", chemin vers le fichier
|
||||
|
||||
Exemples de lancement en local :
|
||||
sbt "runMain cm.gintou.WordCountApp master 2551 /chemin/vers/monFichier.txt"
|
||||
sbt "runMain cm.gintou.WordCountApp worker 2552"
|
||||
*/
|
||||
|
||||
if (args.length < 2) {
|
||||
println("Usage:\n WordCountApp master <port> <filePath>\n WordCountApp worker <port>")
|
||||
System.exit(1)
|
||||
}
|
||||
|
||||
val role = args(0)
|
||||
val port = args(1).toInt
|
||||
val filePathOpt = if (role == "master" && args.length >= 3) Some(args(2)) else None
|
||||
|
||||
// On construit une configuration Akka en surchargeant le port et en attribuant un rôle
|
||||
val config = ConfigFactory.parseString(
|
||||
s"""
|
||||
|akka.remote.artery.canonical.port = $port
|
||||
|akka.cluster.roles = [ "$role" ]
|
||||
|""".stripMargin
|
||||
).withFallback(ConfigFactory.load())
|
||||
|
||||
// On crée l'ActorSystem avec l'acteur guardian
|
||||
val system = ActorSystem(
|
||||
GuardianActor(role, filePathOpt),
|
||||
"WordCountCluster",
|
||||
config
|
||||
)
|
||||
|
||||
Await.result(system.whenTerminated, Duration.Inf)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user