entrée akka

 

dépendance:

<xml version = " 1.0 " encoding = " UTF-8 " ?> 
<project xmlns = " http://maven.apache.org/POM/4.0.0 " 
         xmlns: xsi = " http: //www.w3 .org / 2001 / XMLSchema instance " 
         xsi: schemaLocation = " http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd " > 
    <parent> 
        <artifactId> Seascala </ artifactId> 
        <groupId> com.sea </ groupId> 
        <version> 1.0 -snapshot </ version>
    </ parent> 
    <modelVersion> 4.0. 0 </ modelVersion> 

    <artifactId> AkkaDemo </ artifactId> 


    <dépendances> 
        <- scala -> 
        <- https: // mvnrepository.com/artifact/org.scala-lang/scala-library -> 
        <dependency> 
            <groupId> org.scala-lang </ groupId> 
            <artifactId> scala-bibliothèque </ artifactId> 
            <version> 2.13 . 1 </ version> 
        </ dependency> 
        <! -配置akka acteur依赖-> 
        <dependency> 
            <groupId> com.typesafe.akka </ groupId> 
            <artifactId> Akka-actor_2.2.6 . 3 </ version> 
        </ dependency> 
        <! -多进程之间的通信akka acteur依赖-> 
        <dependency> 
            <groupId> com.typesafe.akka </ groupId> 
            <artifactId> Akka-remote_2. 13 </ artifactId> 
            <version> 2.6 . 3 </ version> 
        </ dependency> 
    </ dépendances> 
    <build> 
        <! -指定源码位置-> 
        <sourceDirectory> src / main / scala </ sourceDirectory> 
        <répertoire testSourceDirectory> src / test / scala </ répertoire testSourceDirectory> 
    </ build> 


</ project>

 

démo:

package com.sea.f01 

. akka.actor import {Acteur, ActorRef, ActorSystem, Props} 

classe SayHelloActor étend {Acteur
   override def recevoir: réception = { 

    cas  " bonjour " => println ( " 您好! " )
     cas  " xf " => println ( " xf hahhahah! " )
     cas _ => println ( " 您是? " ) 

  } 
} 


objet SayHelloActorDemo {
   // 创建一个ActorSystem,Créé spécialement pour l'acteur 
  privé Val actoryFactory = ActorSystem (« ActoryFactory » )
  // créer un acteur en même temps, renvoie une référence à l' acteur actorref
   // Description:
 // Props [SayHelloActor] réflexion utiliser pour créer une instance de SayHelloActor
 //   « sayHelloActor » à l' acteur nommé
 //   sayHelloActorActorRef est Props [ SayHelloActor] le ActorRef 
  privé Val sayHelloActorRef: ActorRef = actoryFactory.actorOf (Props [SayHelloActor], " sayHelloActor " ) 



  // test de 
  principaux DEF (args: Array [String]): Unité = {
     // Dites SayHelloActor un message 
    ! sayHelloActorRef " XF « 
    Imprimer ( » plus" ) 
  } 


}

 

Je suppose que tu aimes

Origine www.cnblogs.com/lshan/p/12587104.html
conseillé
Classement