如何解决在 Scala 中没有编织的方面
我试图在源代码中编织一条消息,通过使用:
@Before(value = "call (* *.tell(..))") def printSample(): Unit = {
logger.info("Message ")
}
这(我希望它)意味着对于函数 tell(..) 的任何调用,都会在屏幕控制台上输出记录器信息消息。
这是使用 tell 函数的类:
import akka.actor._
case object PingMessage
case object PongMessage
case object StartMessage
case object StopMessage
/**
* An Akka Actor example written by Alvin Alexander of
* http://alvinalexander.com
*
* Shared here under the terms of the Creative Commons
* Attribution Share-Alike License: http://creativecommons.org/licenses/by-sa/2.5/
*
* more akka info: http://doc.akka.io/docs/akka/snapshot/scala/actors.html
*/
class Ping(pong: ActorRef) extends Actor {
var count = 0
def incrementAndPrint {
count += 1; println("ping")
}
def receive: Receive = {
case StartMessage =>
incrementAndPrint
pong ! PingMessage
case PongMessage =>
incrementAndPrint
if (count > 99) {
sender ! StopMessage
println("ping stopped")
context.stop(self)
} else {
sender ! PingMessage
}
}
}
class Pong extends Actor {
def receive = {
case PingMessage =>
println(" pong")
sender ! PongMessage
case StopMessage =>
println("pong stopped")
context.stop(self)
}
}
object PingPongTest extends App{
val system = ActorSystem("PingPongSystem")
val pong = system.actorOf(Props[Pong],name = "pong")
val ping = system.actorOf(Props(new Ping(pong)),name = "ping")
// start them going
ping.tell(StartMessage,ping)
}
有人可以帮我理解可能出了什么问题吗?
EDIT : 上面的代码片段在一个调用类中,即项目的主类,调用创建一个新的Process,其主要目的是执行上面的代码片段。这是在 Process("java PingPong").!
的帮助下完成的。
主类涉及:
object SCHMLLauncher {
val actorSystem: ActorSystem[Any] = ActorSystem(Behaviors.empty,"system")
var TracerRef: ActorRef[Any] = _
var first: Boolean = true
val schml = new SCHML
def main(args: Array[String]): Unit = {
logger.info("Starting System to be monitored.")
sleep(5000)
Process("java PingPong").!
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。