mirror of https://github.com/usbharu/Hideout.git
feat: wip consumer SPIでTaskRunnerをロードできるように
This commit is contained in:
parent
17ae665441
commit
416467b5ec
|
@ -17,29 +17,46 @@
|
||||||
package dev.usbharu.owl.consumer
|
package dev.usbharu.owl.consumer
|
||||||
|
|
||||||
import dev.usbharu.dev.usbharu.owl.consumer.ConsumerConfig
|
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.AssignmentTaskServiceGrpcKt
|
||||||
import dev.usbharu.owl.SubscribeTaskServiceGrpcKt
|
import dev.usbharu.owl.SubscribeTaskServiceGrpcKt
|
||||||
import dev.usbharu.owl.TaskResultServiceGrpcKt
|
import dev.usbharu.owl.TaskResultServiceGrpcKt
|
||||||
import dev.usbharu.owl.common.property.CustomPropertySerializerFactory
|
import dev.usbharu.owl.common.property.CustomPropertySerializerFactory
|
||||||
import io.grpc.ManagedChannelBuilder
|
import io.grpc.ManagedChannelBuilder
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
|
|
||||||
val consumerConfig = ConsumerConfig(20, "localhost", 50051)
|
val consumerConfig = ConsumerConfig(20, "localhost", 50051)
|
||||||
|
|
||||||
val channel = ManagedChannelBuilder.forAddress(consumerConfig.address, consumerConfig.port).usePlaintext().build()
|
val channel = ManagedChannelBuilder.forAddress(consumerConfig.address, consumerConfig.port).usePlaintext().build()
|
||||||
val subscribeTaskServiceCoroutineStub = SubscribeTaskServiceGrpcKt.SubscribeTaskServiceCoroutineStub(channel)
|
val subscribeStub = SubscribeTaskServiceGrpcKt.SubscribeTaskServiceCoroutineStub(channel)
|
||||||
val assignmentTaskServiceCoroutineStub = AssignmentTaskServiceGrpcKt.AssignmentTaskServiceCoroutineStub(channel)
|
val assignmentTaskStub = AssignmentTaskServiceGrpcKt.AssignmentTaskServiceCoroutineStub(channel)
|
||||||
val taskResultServiceCoroutineStub = TaskResultServiceGrpcKt.TaskResultServiceCoroutineStub(channel)
|
val taskResultStub = TaskResultServiceGrpcKt.TaskResultServiceCoroutineStub(channel)
|
||||||
val customPropertySerializerFactory = CustomPropertySerializerFactory(emptySet())
|
val customPropertySerializerFactory = CustomPropertySerializerFactory(emptySet())
|
||||||
|
|
||||||
|
val taskRunnerMap = ServiceLoader
|
||||||
|
.load(TaskRunner::class.java)
|
||||||
|
.associateBy { it::class.qualifiedName!! }
|
||||||
|
.filterNot { it.key.isBlank() }
|
||||||
|
|
||||||
val consumer = Consumer(
|
val consumer = Consumer(
|
||||||
subscribeTaskServiceCoroutineStub, assignmentTaskServiceCoroutineStub, taskResultServiceCoroutineStub,
|
subscribeStub,
|
||||||
emptyMap(), customPropertySerializerFactory, consumerConfig
|
assignmentTaskStub,
|
||||||
|
taskResultStub,
|
||||||
|
taskRunnerMap,
|
||||||
|
customPropertySerializerFactory,
|
||||||
|
consumerConfig
|
||||||
)
|
)
|
||||||
|
|
||||||
runBlocking {
|
runBlocking {
|
||||||
|
consumer.init("consumer", "consumer-1")
|
||||||
consumer.start()
|
consumer.start()
|
||||||
|
|
||||||
|
Runtime.getRuntime().addShutdownHook(Thread {
|
||||||
|
consumer.stop()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue