diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2016-03-14 21:59:02 +0100 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2016-03-14 21:59:02 +0100 |
commit | 3566482d061248ff01882fa9647ae2d65677d5ed (patch) | |
tree | 60746d0545a5c72fbf7ded521b9f463244e96417 /kamon-akka/src/main/scala/kamon/akka/instrumentation/RouterInstrumentation.scala | |
parent | 8b20cf6440e032750e574d8a6da13084541c1500 (diff) | |
download | Kamon-3566482d061248ff01882fa9647ae2d65677d5ed.tar.gz Kamon-3566482d061248ff01882fa9647ae2d65677d5ed.tar.bz2 Kamon-3566482d061248ff01882fa9647ae2d65677d5ed.zip |
introduce selective instrumentation for akka actors.
Diffstat (limited to 'kamon-akka/src/main/scala/kamon/akka/instrumentation/RouterInstrumentation.scala')
-rw-r--r-- | kamon-akka/src/main/scala/kamon/akka/instrumentation/RouterInstrumentation.scala | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/kamon-akka/src/main/scala/kamon/akka/instrumentation/RouterInstrumentation.scala b/kamon-akka/src/main/scala/kamon/akka/instrumentation/RouterInstrumentation.scala new file mode 100644 index 00000000..c11abc34 --- /dev/null +++ b/kamon-akka/src/main/scala/kamon/akka/instrumentation/RouterInstrumentation.scala @@ -0,0 +1,53 @@ +package akka.kamon.instrumentation + +import akka.actor.{ Props, ActorRef, ActorSystem, Cell } +import akka.dispatch.{ Envelope, MessageDispatcher } +import akka.routing.RoutedActorCell +import org.aspectj.lang.ProceedingJoinPoint +import org.aspectj.lang.annotation._ + +@Aspect +class RoutedActorCellInstrumentation { + + def routerInstrumentation(cell: Cell): RouterMonitor = + cell.asInstanceOf[RouterInstrumentationAware].routerInstrumentation + + @Pointcut("execution(akka.routing.RoutedActorCell.new(..)) && this(cell) && args(system, ref, props, dispatcher, routeeProps, supervisor)") + def routedActorCellCreation(cell: RoutedActorCell, system: ActorSystem, ref: ActorRef, props: Props, dispatcher: MessageDispatcher, routeeProps: Props, supervisor: ActorRef): Unit = {} + + @After("routedActorCellCreation(cell, system, ref, props, dispatcher, routeeProps, supervisor)") + def afterRoutedActorCellCreation(cell: RoutedActorCell, system: ActorSystem, ref: ActorRef, props: Props, dispatcher: MessageDispatcher, routeeProps: Props, supervisor: ActorRef): Unit = { + cell.asInstanceOf[RouterInstrumentationAware].setRouterInstrumentation( + RouterMonitor.createRouterInstrumentation(cell)) + } + + @Pointcut("execution(* akka.routing.RoutedActorCell.sendMessage(*)) && this(cell) && args(envelope)") + def sendMessageInRouterActorCell(cell: RoutedActorCell, envelope: Envelope) = {} + + @Around("sendMessageInRouterActorCell(cell, envelope)") + def aroundSendMessageInRouterActorCell(pjp: ProceedingJoinPoint, cell: RoutedActorCell, envelope: Envelope): Any = { + routerInstrumentation(cell).processMessage(pjp) + } +} + +trait RouterInstrumentationAware { + def routerInstrumentation: RouterMonitor + def setRouterInstrumentation(ai: RouterMonitor): Unit +} + +object RouterInstrumentationAware { + def apply(): RouterInstrumentationAware = new RouterInstrumentationAware { + private var _ri: RouterMonitor = _ + + def setRouterInstrumentation(ai: RouterMonitor): Unit = _ri = ai + def routerInstrumentation: RouterMonitor = _ri + } +} + +@Aspect +class MetricsIntoRouterCellsMixin { + + @DeclareMixin("akka.routing.RoutedActorCell") + def mixinActorCellMetricsToRoutedActorCell: RouterInstrumentationAware = RouterInstrumentationAware() + +}
\ No newline at end of file |