My environment is:
Akka: 2.3.6
Scala 2.11.2
sbt: 0.13.5
My actor signature is like:
class MyActor extends Actor with ReceiveTimerActor with Instrumented {
When applying metrics to my actor following the instructions on https://github.com/ erikvanoosten/metrics-scala/ blob/master/src/main/akka/nl/ grons/metrics/scala/ ActorMetrics.scala, I got compilation errors below
overriding method receive in trait ReceiveTimerActor of type => PartialFunction[Any,Unit];
[error] method receive needs `override' modifier
[error] def receive = {
And when I add override, then I got compilation errors like:
overriding method receive in trait ReceiveTimerActor of type => PartialFunction[Any,Unit];
[error] method receive needs `abstract override' modifiers
[error] override def receive = {
Any advice?
So the akka metric helpers in metrics-scala use a stackable traits pattern using the "abstract override" keywords. The scaladocs are incorrect in this case. The metric trait must be mixed in after the trait that provides the concrete functionality. See below for an example (MyActor need not be a trait):
trait MyActor extends Actor {
def receive = {
case "ping" => sender() ! "pong"
}
}
class MyInstrumentedActor extends MyActor with ReceiveCounterActor withInstrumented
val actor = ActorSystem("sample").actorOf( Props[MyInstrumentedActor])
I'll work on a PR to correct the API docs.
Thanks for the instruction. It works. It is better to put a link about "stackable traits pattern" in your documentation as well.
댓글 없음:
댓글 쓰기