From d7769cc1f17afb13b90be664b518913c0a6ea8ae Mon Sep 17 00:00:00 2001 From: Mathieu Ancelin Date: Wed, 22 Nov 2023 14:55:35 +0100 Subject: [PATCH] Add more type --- .../wasm4s/scaladsl/integration.scala | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/main/scala/io/otoroshi/wasm4s/scaladsl/integration.scala b/src/main/scala/io/otoroshi/wasm4s/scaladsl/integration.scala index d5e2d17..4d36443 100644 --- a/src/main/scala/io/otoroshi/wasm4s/scaladsl/integration.scala +++ b/src/main/scala/io/otoroshi/wasm4s/scaladsl/integration.scala @@ -61,7 +61,7 @@ class BasicWasmIntegrationContextWithNoHttpClient[A <: WasmConfiguration](name: Executors.newWorkStealingPool(Math.max(32, (Runtime.getRuntime.availableProcessors * 4) + 1)) ) - override def url(path: String, tlsConfigOpt: Option[TlsConfig] = None): WSRequest = ??? + override def url(path: String, tlsConfigOpt: Option[TlsConfig] = None): WSRequest = throw new RuntimeException("BasicWasmIntegrationContextWithNoHttpClient does not provide an httpclient implementation") override def wasmConfigSync(path: String): Option[WasmConfiguration] = store.wasmConfiguration(path) override def wasmConfigs(): Future[Seq[WasmConfiguration]] = store.wasmConfigurations().vfuture @@ -198,3 +198,42 @@ class WasmIntegration(ic: WasmIntegrationContext) { ().vfuture } } + +abstract class DefaultWasmIntegrationContext[A <: WasmConfiguration]( + val name: String, + val wasmCacheTtl: Long = 30000, + val wasmQueueBufferSize: Int = 100, + val maxWorkers: Int = Math.max(32, (Runtime.getRuntime.availableProcessors * 4) + 1), + val selfRefreshingPools: Boolean = false, + val wasmoSettings: Option[WasmManagerSettings] = None, +) extends WasmIntegrationContext { + val system = ActorSystem(name) + val materializer: Materializer = Materializer(system) + val executionContext: ExecutionContext = system.dispatcher + val logger: Logger = Logger(name) + val wasmManagerSettings: Future[Option[WasmManagerSettings]] = Future.successful(wasmoSettings) + val wasmScriptCache: TrieMap[String, CacheableWasmScript] = new TrieMap[String, CacheableWasmScript]() + val wasmExecutor: ExecutionContext = ExecutionContext.fromExecutorService( + Executors.newWorkStealingPool(maxWorkers) + ) +} + +abstract class DefaultWasmIntegrationContextWithNoHttpClient[A <: WasmConfiguration]( + val name: String, + val wasmCacheTtl: Long = 30000, + val wasmQueueBufferSize: Int = 100, + val maxWorkers: Int = Math.max(32, (Runtime.getRuntime.availableProcessors * 4) + 1), + val selfRefreshingPools: Boolean = false, + val wasmoSettings: Option[WasmManagerSettings] = None, +) extends WasmIntegrationContext { + val system = ActorSystem(name) + val materializer: Materializer = Materializer(system) + val executionContext: ExecutionContext = system.dispatcher + val logger: Logger = Logger(name) + val wasmManagerSettings: Future[Option[WasmManagerSettings]] = Future.successful(wasmoSettings) + val wasmScriptCache: TrieMap[String, CacheableWasmScript] = new TrieMap[String, CacheableWasmScript]() + val wasmExecutor: ExecutionContext = ExecutionContext.fromExecutorService( + Executors.newWorkStealingPool(maxWorkers) + ) + override def url(path: String, tlsConfigOpt: Option[TlsConfig] = None): WSRequest = throw new RuntimeException("DefaultWasmIntegrationContextWithNoHttpClient does not provide an httpclient implementation") +} \ No newline at end of file