feat: OWLを使用してキューにいれることができるように

This commit is contained in:
usbharu 2024-05-11 15:35:42 +09:00
parent de4ad8ecfd
commit 918de02c86
20 changed files with 284 additions and 173 deletions

View File

@ -202,6 +202,7 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-log4j2") implementation("org.springframework.boot:spring-boot-starter-log4j2")
implementation("org.springframework.boot:spring-boot-starter-validation") implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("dev.usbharu:owl-common-serialize-jackson:0.0.1")
implementation("io.trbl:blurhash:1.0.0") implementation("io.trbl:blurhash:1.0.0")
implementation("software.amazon.awssdk:s3:2.25.23") implementation("software.amazon.awssdk:s3:2.25.23")
implementation("org.jsoup:jsoup:1.17.2") implementation("org.jsoup:jsoup:1.17.2")

View File

@ -17,7 +17,7 @@
package dev.usbharu.hideout.core.external.job package dev.usbharu.hideout.core.external.job
import dev.usbharu.hideout.activitypub.domain.model.Accept import dev.usbharu.hideout.activitypub.domain.model.Accept
import dev.usbharu.owl.common.property.PropertyValue import dev.usbharu.owl.common.property.*
import dev.usbharu.owl.common.task.PropertyDefinition import dev.usbharu.owl.common.task.PropertyDefinition
import dev.usbharu.owl.common.task.Task import dev.usbharu.owl.common.task.Task
import dev.usbharu.owl.common.task.TaskDefinition import dev.usbharu.owl.common.task.TaskDefinition
@ -32,25 +32,39 @@ data class DeliverAcceptTask(
@Component @Component
data object DeliverAcceptTaskDef : TaskDefinition<DeliverAcceptTask> { data object DeliverAcceptTaskDef : TaskDefinition<DeliverAcceptTask> {
override val name: String override val name: String
get() = TODO("Not yet implemented") get() = "DeliverAccept"
override val priority: Int override val priority: Int
get() = TODO("Not yet implemented") get() = 10
override val maxRetry: Int override val maxRetry: Int
get() = TODO("Not yet implemented") get() = 5
override val retryPolicy: String override val retryPolicy: String
get() = TODO("Not yet implemented") get() = ""
override val timeoutMilli: Long override val timeoutMilli: Long
get() = TODO("Not yet implemented") get() = 1000
override val propertyDefinition: PropertyDefinition override val propertyDefinition: PropertyDefinition
get() = TODO("Not yet implemented") get() = PropertyDefinition(
mapOf(
"accept" to PropertyType.binary,
"inbox" to PropertyType.string,
"signer" to PropertyType.number,
)
)
override val type: Class<DeliverAcceptTask> override val type: Class<DeliverAcceptTask>
get() = TODO("Not yet implemented") get() = DeliverAcceptTask::class.java
override fun serialize(task: DeliverAcceptTask): Map<String, PropertyValue<*>> { override fun serialize(task: DeliverAcceptTask): Map<String, PropertyValue<*>> {
TODO("Not yet implemented") return mapOf(
"accept" to ObjectPropertyValue(task.accept),
"inbox" to StringPropertyValue(task.inbox),
"signer" to LongPropertyValue(task.signer)
)
} }
override fun deserialize(value: Map<String, PropertyValue<*>>): DeliverAcceptTask { override fun deserialize(value: Map<String, PropertyValue<*>>): DeliverAcceptTask {
TODO("Not yet implemented") return DeliverAcceptTask(
value.getValue("accept").value as Accept,
value.getValue("inbox").value as String,
value.getValue("signer").value as Long,
)
} }
} }

View File

@ -17,8 +17,6 @@
package dev.usbharu.hideout.core.external.job package dev.usbharu.hideout.core.external.job
import dev.usbharu.hideout.activitypub.domain.model.Create import dev.usbharu.hideout.activitypub.domain.model.Create
import dev.usbharu.owl.common.property.PropertyValue
import dev.usbharu.owl.common.task.PropertyDefinition
import dev.usbharu.owl.common.task.Task import dev.usbharu.owl.common.task.Task
import dev.usbharu.owl.common.task.TaskDefinition import dev.usbharu.owl.common.task.TaskDefinition
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
@ -31,26 +29,7 @@ data class DeliverCreateTask(
@Component @Component
data object DeliverCreateTaskDef : TaskDefinition<DeliverCreateTask> { data object DeliverCreateTaskDef : TaskDefinition<DeliverCreateTask> {
override val name: String
get() = TODO("Not yet implemented")
override val priority: Int
get() = TODO("Not yet implemented")
override val maxRetry: Int
get() = TODO("Not yet implemented")
override val retryPolicy: String
get() = TODO("Not yet implemented")
override val timeoutMilli: Long
get() = TODO("Not yet implemented")
override val propertyDefinition: PropertyDefinition
get() = TODO("Not yet implemented")
override val type: Class<DeliverCreateTask> override val type: Class<DeliverCreateTask>
get() = TODO("Not yet implemented") get() = DeliverCreateTask::class.java
override fun serialize(task: DeliverCreateTask): Map<String, PropertyValue<*>> {
TODO("Not yet implemented")
}
override fun deserialize(value: Map<String, PropertyValue<*>>): DeliverCreateTask {
TODO("Not yet implemented")
}
} }

View File

@ -17,8 +17,6 @@
package dev.usbharu.hideout.core.external.job package dev.usbharu.hideout.core.external.job
import dev.usbharu.hideout.activitypub.domain.model.Delete import dev.usbharu.hideout.activitypub.domain.model.Delete
import dev.usbharu.owl.common.property.PropertyValue
import dev.usbharu.owl.common.task.PropertyDefinition
import dev.usbharu.owl.common.task.Task import dev.usbharu.owl.common.task.Task
import dev.usbharu.owl.common.task.TaskDefinition import dev.usbharu.owl.common.task.TaskDefinition
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
@ -31,26 +29,7 @@ data class DeliverDeleteTask(
@Component @Component
data object DeliverDeleteTaskDef : TaskDefinition<DeliverDeleteTask> { data object DeliverDeleteTaskDef : TaskDefinition<DeliverDeleteTask> {
override val name: String
get() = TODO("Not yet implemented")
override val priority: Int
get() = TODO("Not yet implemented")
override val maxRetry: Int
get() = TODO("Not yet implemented")
override val retryPolicy: String
get() = TODO("Not yet implemented")
override val timeoutMilli: Long
get() = TODO("Not yet implemented")
override val propertyDefinition: PropertyDefinition
get() = TODO("Not yet implemented")
override val type: Class<DeliverDeleteTask> override val type: Class<DeliverDeleteTask>
get() = TODO("Not yet implemented") get() = DeliverDeleteTask::class.java
override fun serialize(task: DeliverDeleteTask): Map<String, PropertyValue<*>> {
TODO("Not yet implemented")
}
override fun deserialize(value: Map<String, PropertyValue<*>>): DeliverDeleteTask {
TODO("Not yet implemented")
}
} }

View File

@ -17,8 +17,6 @@
package dev.usbharu.hideout.core.external.job package dev.usbharu.hideout.core.external.job
import dev.usbharu.hideout.activitypub.domain.model.Like import dev.usbharu.hideout.activitypub.domain.model.Like
import dev.usbharu.owl.common.property.PropertyValue
import dev.usbharu.owl.common.task.PropertyDefinition
import dev.usbharu.owl.common.task.Task import dev.usbharu.owl.common.task.Task
import dev.usbharu.owl.common.task.TaskDefinition import dev.usbharu.owl.common.task.TaskDefinition
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
@ -31,26 +29,6 @@ data class DeliverReactionTask(
@Component @Component
data object DeliverReactionTaskDef : TaskDefinition<DeliverReactionTask> { data object DeliverReactionTaskDef : TaskDefinition<DeliverReactionTask> {
override val name: String
get() = TODO("Not yet implemented")
override val priority: Int
get() = TODO("Not yet implemented")
override val maxRetry: Int
get() = TODO("Not yet implemented")
override val retryPolicy: String
get() = TODO("Not yet implemented")
override val timeoutMilli: Long
get() = TODO("Not yet implemented")
override val propertyDefinition: PropertyDefinition
get() = TODO("Not yet implemented")
override val type: Class<DeliverReactionTask> override val type: Class<DeliverReactionTask>
get() = TODO("Not yet implemented") get() = DeliverReactionTask::class.java
override fun deserialize(value: Map<String, PropertyValue<*>>): DeliverReactionTask {
TODO("Not yet implemented")
}
override fun serialize(task: DeliverReactionTask): Map<String, PropertyValue<*>> {
TODO("Not yet implemented")
}
} }

View File

@ -17,8 +17,6 @@
package dev.usbharu.hideout.core.external.job package dev.usbharu.hideout.core.external.job
import dev.usbharu.hideout.activitypub.domain.model.Reject import dev.usbharu.hideout.activitypub.domain.model.Reject
import dev.usbharu.owl.common.property.PropertyValue
import dev.usbharu.owl.common.task.PropertyDefinition
import dev.usbharu.owl.common.task.Task import dev.usbharu.owl.common.task.Task
import dev.usbharu.owl.common.task.TaskDefinition import dev.usbharu.owl.common.task.TaskDefinition
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
@ -31,26 +29,6 @@ data class DeliverRejectTask(
@Component @Component
data object DeliverRejectTaskDef : TaskDefinition<DeliverRejectTask> { data object DeliverRejectTaskDef : TaskDefinition<DeliverRejectTask> {
override val name: String
get() = TODO("Not yet implemented")
override val priority: Int
get() = TODO("Not yet implemented")
override val maxRetry: Int
get() = TODO("Not yet implemented")
override val retryPolicy: String
get() = TODO("Not yet implemented")
override val timeoutMilli: Long
get() = TODO("Not yet implemented")
override val propertyDefinition: PropertyDefinition
get() = TODO("Not yet implemented")
override val type: Class<DeliverRejectTask> override val type: Class<DeliverRejectTask>
get() = TODO("Not yet implemented") get() = DeliverRejectTask::class.java
override fun serialize(task: DeliverRejectTask): Map<String, PropertyValue<*>> {
TODO("Not yet implemented")
}
override fun deserialize(value: Map<String, PropertyValue<*>>): DeliverRejectTask {
TODO("Not yet implemented")
}
} }

View File

@ -17,8 +17,6 @@
package dev.usbharu.hideout.core.external.job package dev.usbharu.hideout.core.external.job
import dev.usbharu.hideout.activitypub.domain.model.Undo import dev.usbharu.hideout.activitypub.domain.model.Undo
import dev.usbharu.owl.common.property.PropertyValue
import dev.usbharu.owl.common.task.PropertyDefinition
import dev.usbharu.owl.common.task.Task import dev.usbharu.owl.common.task.Task
import dev.usbharu.owl.common.task.TaskDefinition import dev.usbharu.owl.common.task.TaskDefinition
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
@ -31,26 +29,7 @@ data class DeliverUndoTask(
@Component @Component
data object DeliverUndoTaskDef : TaskDefinition<DeliverUndoTask> { data object DeliverUndoTaskDef : TaskDefinition<DeliverUndoTask> {
override val name: String
get() = TODO("Not yet implemented")
override val priority: Int
get() = TODO("Not yet implemented")
override val maxRetry: Int
get() = TODO("Not yet implemented")
override val retryPolicy: String
get() = TODO("Not yet implemented")
override val timeoutMilli: Long
get() = TODO("Not yet implemented")
override val propertyDefinition: PropertyDefinition
get() = TODO("Not yet implemented")
override val type: Class<DeliverUndoTask> override val type: Class<DeliverUndoTask>
get() = TODO("Not yet implemented") get() = DeliverUndoTask::class.java
override fun deserialize(value: Map<String, PropertyValue<*>>): DeliverUndoTask {
TODO("Not yet implemented")
}
override fun serialize(task: DeliverUndoTask): Map<String, PropertyValue<*>> {
TODO("Not yet implemented")
}
} }

View File

@ -18,8 +18,6 @@ package dev.usbharu.hideout.core.external.job
import dev.usbharu.hideout.activitypub.service.common.ActivityType import dev.usbharu.hideout.activitypub.service.common.ActivityType
import dev.usbharu.httpsignature.common.HttpRequest import dev.usbharu.httpsignature.common.HttpRequest
import dev.usbharu.owl.common.property.PropertyValue
import dev.usbharu.owl.common.task.PropertyDefinition
import dev.usbharu.owl.common.task.Task import dev.usbharu.owl.common.task.Task
import dev.usbharu.owl.common.task.TaskDefinition import dev.usbharu.owl.common.task.TaskDefinition
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
@ -33,26 +31,6 @@ data class InboxTask(
@Component @Component
data object InboxTaskDef : TaskDefinition<InboxTask> { data object InboxTaskDef : TaskDefinition<InboxTask> {
override val name: String
get() = TODO("Not yet implemented")
override val priority: Int
get() = TODO("Not yet implemented")
override val maxRetry: Int
get() = TODO("Not yet implemented")
override val retryPolicy: String
get() = TODO("Not yet implemented")
override val timeoutMilli: Long
get() = TODO("Not yet implemented")
override val propertyDefinition: PropertyDefinition
get() = TODO("Not yet implemented")
override val type: Class<InboxTask> override val type: Class<InboxTask>
get() = TODO("Not yet implemented") get() = InboxTask::class.java
override fun serialize(task: InboxTask): Map<String, PropertyValue<*>> {
TODO("Not yet implemented")
}
override fun deserialize(value: Map<String, PropertyValue<*>>): InboxTask {
TODO("Not yet implemented")
}
} }

View File

@ -17,8 +17,6 @@
package dev.usbharu.hideout.core.external.job package dev.usbharu.hideout.core.external.job
import dev.usbharu.hideout.activitypub.domain.model.Follow import dev.usbharu.hideout.activitypub.domain.model.Follow
import dev.usbharu.owl.common.property.PropertyValue
import dev.usbharu.owl.common.task.PropertyDefinition
import dev.usbharu.owl.common.task.Task import dev.usbharu.owl.common.task.Task
import dev.usbharu.owl.common.task.TaskDefinition import dev.usbharu.owl.common.task.TaskDefinition
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
@ -31,26 +29,7 @@ data class ReceiveFollowTask(
@Component @Component
data object ReceiveFollowTaskDef : TaskDefinition<ReceiveFollowTask> { data object ReceiveFollowTaskDef : TaskDefinition<ReceiveFollowTask> {
override val name: String
get() = TODO("Not yet implemented")
override val priority: Int
get() = TODO("Not yet implemented")
override val maxRetry: Int
get() = TODO("Not yet implemented")
override val retryPolicy: String
get() = TODO("Not yet implemented")
override val timeoutMilli: Long
get() = TODO("Not yet implemented")
override val propertyDefinition: PropertyDefinition
get() = TODO("Not yet implemented")
override val type: Class<ReceiveFollowTask> override val type: Class<ReceiveFollowTask>
get() = TODO("Not yet implemented") get() = ReceiveFollowTask::class.java
override fun deserialize(value: Map<String, PropertyValue<*>>): ReceiveFollowTask {
TODO("Not yet implemented")
}
override fun serialize(task: ReceiveFollowTask): Map<String, PropertyValue<*>> {
TODO("Not yet implemented")
}
} }

View File

@ -40,6 +40,7 @@ dependencies {
testImplementation(kotlin("test")) testImplementation(kotlin("test"))
implementation("dev.usbharu:owl-consumer:0.0.1") implementation("dev.usbharu:owl-consumer:0.0.1")
implementation("dev.usbharu:owl-common:0.0.1") implementation("dev.usbharu:owl-common:0.0.1")
implementation("dev.usbharu:owl-common-serialize-jackson:0.0.1")
implementation("dev.usbharu:hideout-core:0.0.1") implementation("dev.usbharu:hideout-core:0.0.1")
implementation("dev.usbharu:http-signature:1.0.0") implementation("dev.usbharu:http-signature:1.0.0")
implementation("org.springframework.boot:spring-boot-starter") implementation("org.springframework.boot:spring-boot-starter")

View File

@ -79,6 +79,7 @@ apache-tika = ["apache-tika-core", "apache-tika-parsers"]
kjob = ["kjon-core", "kjon-mongo"] kjob = ["kjon-core", "kjon-mongo"]
owl-producer = ["owl-producer-api", "owl-producer-default", "owl-producer-embedded"] owl-producer = ["owl-producer-api", "owl-producer-default", "owl-producer-embedded"]
owl-broker = ["owl-broker", "owl-broker-mongodb"] owl-broker = ["owl-broker", "owl-broker-mongodb"]
jackson = ["jackson-databind", "jackson-module-kotlin"]
[plugins] [plugins]

View File

@ -0,0 +1,23 @@
plugins {
kotlin("jvm")
}
group = "dev.usbharu"
version = "0.0.1"
repositories {
mavenCentral()
}
dependencies {
implementation(project(":owl-common"))
testImplementation(kotlin("test"))
implementation(libs.bundles.jackson)
}
tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(21)
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (C) 2024 usbharu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.usbharu
fun main() {
println("Hello World!")
}

View File

@ -0,0 +1,51 @@
/*
* Copyright (C) 2024 usbharu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.usbharu.owl.common.property
import com.fasterxml.jackson.databind.ObjectMapper
class ObjectPropertyValue(override val value: Any) : PropertyValue<Any>() {
override val type: PropertyType
get() = PropertyType.string
}
class ObjectPropertySerializer(private val objectMapper: ObjectMapper) : PropertySerializer<Any> {
override fun isSupported(propertyValue: PropertyValue<*>): Boolean {
return propertyValue is ObjectPropertyValue
}
override fun isSupported(string: String): Boolean {
return string.startsWith("jackson:")
}
override fun serialize(propertyValue: PropertyValue<*>): String {
return "jackson:" + propertyValue.value!!::class.qualifiedName + ":" + objectMapper.writeValueAsString(
propertyValue.value
)
}
override fun deserialize(string: String): PropertyValue<Any> {
return ObjectPropertyValue(
objectMapper.readValue(
string,
Class.forName(string.substringAfter("jackson:").substringBeforeLast(":"))
)
)
}
}

View File

@ -0,0 +1,44 @@
/*
* Copyright (C) 2024 usbharu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.usbharu.owl.common.property
class FloatPropertyValue(override val value: Float) : PropertyValue<Float>() {
override val type: PropertyType
get() = PropertyType.number
}
/**
* [FloatPropertyValue]のシリアライザー
*
*/
class FloatPropertySerializer : PropertySerializer<Float> {
override fun isSupported(propertyValue: PropertyValue<*>): Boolean {
return propertyValue.value is Float
}
override fun isSupported(string: String): Boolean {
return string.startsWith("float:")
}
override fun serialize(propertyValue: PropertyValue<*>): String {
return "float:" + propertyValue.value.toString()
}
override fun deserialize(string: String): PropertyValue<Float> {
return FloatPropertyValue(string.replace("float:", "").toFloat())
}
}

View File

@ -0,0 +1,45 @@
/*
* Copyright (C) 2024 usbharu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.usbharu.owl.common.property
class LongPropertyValue(override val value: Long) : PropertyValue<Long>() {
override val type: PropertyType
get() = PropertyType.number
}
/**
* [LongPropertyValue]のシリアライザー
*
*/
class LongPropertySerializer : PropertySerializer<Long> {
override fun isSupported(propertyValue: PropertyValue<*>): Boolean {
return propertyValue.value is Long
}
override fun isSupported(string: String): Boolean {
return string.startsWith("int64:")
}
override fun serialize(propertyValue: PropertyValue<*>): String {
return "int64:" + propertyValue.value.toString()
}
override fun deserialize(string: String): PropertyValue<Long> {
return LongPropertyValue(string.replace("int64:", "").toLong())
}
}

View File

@ -21,7 +21,7 @@ package dev.usbharu.owl.common.property
* *
* @param T プロパティの型 * @param T プロパティの型
*/ */
sealed class PropertyValue<T> { abstract class PropertyValue<T> {
/** /**
* プロパティ * プロパティ
*/ */

View File

@ -16,7 +16,7 @@
package dev.usbharu.owl.common.task package dev.usbharu.owl.common.task
import dev.usbharu.owl.common.property.PropertyValue import dev.usbharu.owl.common.property.*
/** /**
* タスク定義 * タスク定義
@ -28,16 +28,19 @@ interface TaskDefinition<T : Task> {
* タスク名 * タスク名
*/ */
val name: String val name: String
get() = type.simpleName
/** /**
* 優先度 * 優先度
*/ */
val priority: Int val priority: Int
get() = 0
/** /**
* 最大リトライ数 * 最大リトライ数
*/ */
val maxRetry: Int val maxRetry: Int
get() = 5
/** /**
* リトライポリシー名 * リトライポリシー名
@ -45,16 +48,31 @@ interface TaskDefinition<T : Task> {
* ポリシーの解決は各Brokerに依存しています * ポリシーの解決は各Brokerに依存しています
*/ */
val retryPolicy: String val retryPolicy: String
get() = ""
/** /**
* タスク実行時のタイムアウト(ミリ秒) * タスク実行時のタイムアウト(ミリ秒)
*/ */
val timeoutMilli: Long val timeoutMilli: Long
get() = 1000
/** /**
* プロパティ定義 * プロパティ定義
*/ */
val propertyDefinition: PropertyDefinition val propertyDefinition: PropertyDefinition
get() {
val mapValues = type.fields.associate { it.name to it.type }.mapValues {
when {
it.value === Int::class.java -> PropertyType.number
it.value === String::class.java -> PropertyType.string
it.value === Long::class.java -> PropertyType.number
it.value === Double::class.java -> PropertyType.number
it.value === Float::class.java -> PropertyType.number
else -> PropertyType.binary
}
}
return PropertyDefinition(mapValues)
}
/** /**
* [Task][Class] * [Task][Class]
@ -67,7 +85,19 @@ interface TaskDefinition<T : Task> {
* @param task シリアライズするタスク * @param task シリアライズするタスク
* @return シリアライズされたタスク * @return シリアライズされたタスク
*/ */
fun serialize(task: T): Map<String, PropertyValue<*>> fun serialize(task: T): Map<String, PropertyValue<*>> {
return type.fields.associateBy { it.name }.mapValues {
when {
it.value.type === Int::class.java -> IntegerPropertyValue(it.value.getInt(task))
it.value.type === String::class.java -> StringPropertyValue(it.value.get(task) as String)
it.value.type === Long::class.java -> LongPropertyValue(it.value.getLong(task))
it.value.type === Double::class.java -> DoublePropertyValue(it.value.getDouble(task))
it.value.type === Float::class.java -> FloatPropertyValue(it.value.getFloat(task))
it.value.type === Boolean::class.java -> BooleanPropertyValue(it.value.getBoolean(task))
else -> throw IllegalArgumentException("Unsupported type ${it.value} in ${task.javaClass.name}")
}
}
}
/** /**
* タスクをデシリアライズします * タスクをデシリアライズします
@ -75,5 +105,21 @@ interface TaskDefinition<T : Task> {
* @param value デシリアライズするタスク * @param value デシリアライズするタスク
* @return デシリアライズされたタスク * @return デシリアライズされたタスク
*/ */
fun deserialize(value: Map<String, PropertyValue<*>>): T fun deserialize(value: Map<String, PropertyValue<*>>): T {
val task = type.getDeclaredConstructor().newInstance()
type.fields.associateBy { it.name }.mapValues {
when {
it.value.type === Int::class.java -> it.value.setInt(task, value.getValue(it.key).value as Int)
it.value.type === Double::class.java -> it.value.setDouble(task, value.getValue(it.key).value as Double)
it.value.type === Float::class.java -> it.value.setFloat(task, value.getValue(it.key).value as Float)
it.value.type === String::class.java -> it.value.set(task, value.getValue(it.key).value as String)
it.value.type === Long::class.java -> it.value.setLong(task, value.getValue(it.key).value as Long)
else -> throw IllegalArgumentException("Unsupported type ${it.value} in ${task.javaClass.name}")
}
}
return task
}
} }

View File

@ -18,6 +18,7 @@ package dev.usbharu.owl.producer.embedded
import dev.usbharu.owl.broker.EmptyModuleContext import dev.usbharu.owl.broker.EmptyModuleContext
import dev.usbharu.owl.common.retry.DefaultRetryPolicyFactory import dev.usbharu.owl.common.retry.DefaultRetryPolicyFactory
import dev.usbharu.owl.common.retry.ExponentialRetryPolicy
import dev.usbharu.owl.producer.api.OwlProducerBuilder import dev.usbharu.owl.producer.api.OwlProducerBuilder
class EmbeddedOwlProducerBuilder : OwlProducerBuilder<EmbeddedOwlProducer, EmbeddedOwlProducerConfig> { class EmbeddedOwlProducerBuilder : OwlProducerBuilder<EmbeddedOwlProducer, EmbeddedOwlProducerConfig> {
@ -28,7 +29,7 @@ class EmbeddedOwlProducerBuilder : OwlProducerBuilder<EmbeddedOwlProducer, Embed
with(embeddedOwlProducerConfig) { with(embeddedOwlProducerConfig) {
moduleContext = EmptyModuleContext moduleContext = EmptyModuleContext
retryPolicyFactory = DefaultRetryPolicyFactory(emptyMap()) retryPolicyFactory = DefaultRetryPolicyFactory(mapOf("" to ExponentialRetryPolicy()))
name = "embedded-owl-producer" name = "embedded-owl-producer"
port = "50051" port = "50051"
} }

View File

@ -1,6 +1,17 @@
plugins { plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0" id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
} }
dependencyResolutionManagement {
repositories {
mavenCentral()
}
versionCatalogs {
create("libs") {
from(files("../libs.versions.toml"))
}
}
}
rootProject.name = "owl" rootProject.name = "owl"
include("owl-common") include("owl-common")
include("owl-producer:owl-producer-api") include("owl-producer:owl-producer-api")
@ -12,3 +23,5 @@ include("owl-producer:owl-producer-default")
findProject(":owl-producer:owl-producer-default")?.name = "owl-producer-default" findProject(":owl-producer:owl-producer-default")?.name = "owl-producer-default"
include("owl-consumer") include("owl-consumer")
include("owl-producer:owl-producer-embedded") include("owl-producer:owl-producer-embedded")
include("owl-common:owl-common-serialize-jackson")
findProject(":owl-common:owl-common-serialize-jackson")?.name = "owl-common-serialize-jackson"