From 723b1c79114c2962f16ddd534461e4786456d305 Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Sat, 10 Mar 2018 22:20:16 -0600 Subject: [PATCH] server: Add ExternalServiceExecutionContext --- .../ExternalServiceExecutionContext.scala | 15 +++++++++++++++ server/conf/application.conf | 8 ++++++++ .../com/xsn/explorer/helpers/Executors.scala | 16 ++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 server/app/com/xsn/explorer/executors/ExternalServiceExecutionContext.scala create mode 100644 server/test/com/xsn/explorer/helpers/Executors.scala diff --git a/server/app/com/xsn/explorer/executors/ExternalServiceExecutionContext.scala b/server/app/com/xsn/explorer/executors/ExternalServiceExecutionContext.scala new file mode 100644 index 0000000..4856850 --- /dev/null +++ b/server/app/com/xsn/explorer/executors/ExternalServiceExecutionContext.scala @@ -0,0 +1,15 @@ +package com.xsn.explorer.executors + +import javax.inject.{Inject, Singleton} + +import akka.actor.ActorSystem +import play.api.libs.concurrent.CustomExecutionContext + +import scala.concurrent.ExecutionContext + +trait ExternalServiceExecutionContext extends ExecutionContext + +@Singleton +class ExternalServiceAkkaExecutionContext @Inject()(system: ActorSystem) + extends CustomExecutionContext(system, "externalService.dispatcher") + with ExternalServiceExecutionContext diff --git a/server/conf/application.conf b/server/conf/application.conf index 6cb362c..f0bf526 100644 --- a/server/conf/application.conf +++ b/server/conf/application.conf @@ -24,3 +24,11 @@ rpc { } play.modules.enabled += "com.xsn.explorer.modules.ConfigModule" + +externalService.dispatcher { + executor = "thread-pool-executor" + throughput = 1 + thread-pool-executor { + fixed-pool-size = 50 + } +} diff --git a/server/test/com/xsn/explorer/helpers/Executors.scala b/server/test/com/xsn/explorer/helpers/Executors.scala new file mode 100644 index 0000000..cad3034 --- /dev/null +++ b/server/test/com/xsn/explorer/helpers/Executors.scala @@ -0,0 +1,16 @@ +package com.xsn.explorer.helpers + +import com.xsn.explorer.executors.ExternalServiceExecutionContext + +import scala.concurrent.ExecutionContext + +object Executors { + + implicit val globalEC: ExecutionContext = scala.concurrent.ExecutionContext.global + + implicit val externalServiceEC: ExternalServiceExecutionContext = new ExternalServiceExecutionContext { + override def execute(runnable: Runnable): Unit = globalEC.execute(runnable) + + override def reportFailure(cause: Throwable): Unit = globalEC.reportFailure(cause) + } +}