scala目前的书籍有两《快学scala》和《scala编程》。资料确实不多,对这个语法使用只能结合使用进行理解。

先看源码:

private[spark] trait ActorLogReceive {
self: Actor => override def receive: Actor.Receive = new Actor.Receive { private val _receiveWithLogging = receiveWithLogging override def isDefinedAt(o: Any): Boolean = {
val handled = _receiveWithLogging.isDefinedAt(o)
if (!handled) {
log.debug(s"Received unexpected actor system event: $o")
}
handled
} override def apply(o: Any): Unit = {
if (log.isDebugEnabled) {
log.debug(s"[actor] received message $o from ${self.sender}")
}
val start = System.nanoTime
_receiveWithLogging.apply(o)
val timeTaken = (System.nanoTime - start).toDouble / 1000000
if (log.isDebugEnabled) {
log.debug(s"[actor] handled message ($timeTaken ms) $o from ${self.sender}")
}
}
} def receiveWithLogging: Actor.Receive protected def log: Logger
}

这块代码是spark的akka日志记录代码,很具有代表性,self:Actor =>这里有两个作用

1: ActorLogReceive的实现类必须继承Actor

2: 重写Actor里面的方法,该trait里面使用Actor里面的属性不要添加self.

本理实现一种代理,或是模板模式....

来看看他的使用

    lazy val actorRef = actorSystem.actorOf(Props(new Actor with ActorLogReceive with Logging{
override def receiveWithLogging: Receive = ???
}))

最新文章

  1. 利用select实现IO多路复用TCP服务端
  2. Scrapy的中Css 选择器
  3. go语言包与包引用
  4. MYSQL学习笔记2--mysql 静态和动态plugin
  5. js操作iframe框架时应该屡清楚的一些概念
  6. 【原创】JPEG图像密写研究(二) 哈夫曼树的建立
  7. UML之部署图(Deployment Diagram)
  8. angular 实现自定义样式下拉菜单
  9. 【Sublime Text】sublime text 安装插件方法总结
  10. leetcode7:反转整数
  11. SpringCache学习实践
  12. nginx的http_sub_module模块使用之替换字符串
  13. 20165236 实验二 《Java面向对象程序设计》实验报告
  14. 关于final static修饰的常量部署后没有更新的问题
  15. 添加删除mysql用户
  16. SQL高效查询两个表不同的数据
  17. 解决appcompat中各种奇葩的错误
  18. 【jquery】图片前后对比效果——beforeAfter
  19. css 初始包含块
  20. CentOS普通用户没有sudo权限

热门文章

  1. Springboot演示小Demo
  2. C#异步编程(二)用户模式线程同步
  3. LeetCode 4 Keys Keyboard
  4. 自编jQuery插件实现模拟alert和confirm
  5. JavaEE中的Cookie的基本使用方法
  6. 50 states of America
  7. mysql 回顾小练习
  8. Python类(三)-多继承的区别
  9. Firefox切换页面默认显示语言
  10. SpringMVC + AJAX 实现多文件异步上传