【发布时间】:2014-05-09 07:46:03
【问题描述】:
我正在查看 Akka 代码库中的一些 Scala 代码,下面这段代码 sn-p 负责处理异常。
override val supervisorStrategy =
OneForOneStrategy(loggingEnabled = false) {
case e @ InvalidAssociation(localAddress, remoteAddress, reason) ⇒
log.warning("Tried to associate with unreachable remote address [{}]. " +
"Address is now gated for {} ms, all messages to this address will be delivered to dead letters. Reason: {}",
remoteAddress, settings.RetryGateClosedFor.toMillis, reason.getMessage)
endpoints.markAsFailed(sender(), Deadline.now + settings.RetryGateClosedFor)
AddressTerminatedTopic(context.system).publish(AddressTerminated(remoteAddress))
Stop
case ShutDownAssociation(localAddress, remoteAddress, _) ⇒
log.debug("Remote system with address [{}] has shut down. " +
"Address is now gated for {} ms, all messages to this address will be delivered to dead letters.",
remoteAddress, settings.RetryGateClosedFor.toMillis)
endpoints.markAsFailed(sender(), Deadline.now + settings.RetryGateClosedFor)
AddressTerminatedTopic(context.system).publish(AddressTerminated(remoteAddress))
Stop
第 3 行的代码,case e @ InvalidAssociation - InvalidAssociation 确实是一个异常类型,但为什么e @ 是必要的,它有什么作用?
【问题讨论】:
-
@DonRoby 在我查看时没有出现在任何搜索结果中,无论如何。
-
搜索“@”之类的内容有些困难。完全可以理解!
-
@DonRoby 完全同意!
-
如果您使用引号,则可以正确搜索符号 - 例如搜索
scala "@"有效,但搜索scala @无效。我只是偶然发现了这一点,但事后看来,search help