aboutsummaryrefslogtreecommitdiff
path: root/kamon-akka/src/main/scala/kamon/akka/instrumentation/RouterInstrumentation.scala
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2016-03-15 23:31:11 +0100
committerIvan Topolnjak <ivantopo@gmail.com>2016-03-15 23:31:11 +0100
commit60880bb1b6ec15f40ecacf5ab46c849a86ce4b60 (patch)
tree0fe880c75b891b99f3503d876b3f7e98de11a67b /kamon-akka/src/main/scala/kamon/akka/instrumentation/RouterInstrumentation.scala
parentcf45b7bcac148945ff209fd7abefc761d916be9a (diff)
parent9e52aad6b02da72ca28d52d0c94e2e8784e7aa65 (diff)
downloadKamon-60880bb1b6ec15f40ecacf5ab46c849a86ce4b60.tar.gz
Kamon-60880bb1b6ec15f40ecacf5ab46c849a86ce4b60.tar.bz2
Kamon-60880bb1b6ec15f40ecacf5ab46c849a86ce4b60.zip
Merge branch 'issue#271/fix-balancing-pool-metrics'
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.scala53
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