From 416467b5ec09e20d98d1956a3edfe6e72d4f7cbf Mon Sep 17 00:00:00 2001 From: usbharu Date: Mon, 15 Apr 2024 11:49:05 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20wip=20consumer=20SPI=E3=81=A7TaskRunner?= =?UTF-8?q?=E3=82=92=E3=83=AD=E3=83=BC=E3=83=89=E3=81=A7=E3=81=8D=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/dev/usbharu/owl/consumer/Main.kt | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/consumer/src/main/kotlin/dev/usbharu/owl/consumer/Main.kt b/consumer/src/main/kotlin/dev/usbharu/owl/consumer/Main.kt index 785d2808..fd8ce00b 100644 --- a/consumer/src/main/kotlin/dev/usbharu/owl/consumer/Main.kt +++ b/consumer/src/main/kotlin/dev/usbharu/owl/consumer/Main.kt @@ -17,29 +17,46 @@ package dev.usbharu.owl.consumer import dev.usbharu.dev.usbharu.owl.consumer.ConsumerConfig +import dev.usbharu.dev.usbharu.owl.consumer.TaskRunner import dev.usbharu.owl.AssignmentTaskServiceGrpcKt import dev.usbharu.owl.SubscribeTaskServiceGrpcKt import dev.usbharu.owl.TaskResultServiceGrpcKt import dev.usbharu.owl.common.property.CustomPropertySerializerFactory import io.grpc.ManagedChannelBuilder import kotlinx.coroutines.runBlocking +import java.util.* fun main() { val consumerConfig = ConsumerConfig(20, "localhost", 50051) val channel = ManagedChannelBuilder.forAddress(consumerConfig.address, consumerConfig.port).usePlaintext().build() - val subscribeTaskServiceCoroutineStub = SubscribeTaskServiceGrpcKt.SubscribeTaskServiceCoroutineStub(channel) - val assignmentTaskServiceCoroutineStub = AssignmentTaskServiceGrpcKt.AssignmentTaskServiceCoroutineStub(channel) - val taskResultServiceCoroutineStub = TaskResultServiceGrpcKt.TaskResultServiceCoroutineStub(channel) + val subscribeStub = SubscribeTaskServiceGrpcKt.SubscribeTaskServiceCoroutineStub(channel) + val assignmentTaskStub = AssignmentTaskServiceGrpcKt.AssignmentTaskServiceCoroutineStub(channel) + val taskResultStub = TaskResultServiceGrpcKt.TaskResultServiceCoroutineStub(channel) val customPropertySerializerFactory = CustomPropertySerializerFactory(emptySet()) + + val taskRunnerMap = ServiceLoader + .load(TaskRunner::class.java) + .associateBy { it::class.qualifiedName!! } + .filterNot { it.key.isBlank() } + val consumer = Consumer( - subscribeTaskServiceCoroutineStub, assignmentTaskServiceCoroutineStub, taskResultServiceCoroutineStub, - emptyMap(), customPropertySerializerFactory, consumerConfig + subscribeStub, + assignmentTaskStub, + taskResultStub, + taskRunnerMap, + customPropertySerializerFactory, + consumerConfig ) runBlocking { + consumer.init("consumer", "consumer-1") consumer.start() + + Runtime.getRuntime().addShutdownHook(Thread { + consumer.stop() + }) } } \ No newline at end of file