From 918de02c86913b2034f82611927d67ef540b91e5 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sat, 11 May 2024 15:35:42 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20OWL=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=97?= =?UTF-8?q?=E3=81=A6=E3=82=AD=E3=83=A5=E3=83=BC=E3=81=AB=E3=81=84=E3=82=8C?= =?UTF-8?q?=E3=82=8B=E3=81=93=E3=81=A8=E3=81=8C=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 --- hideout-core/build.gradle.kts | 1 + .../core/external/job/DeliverAcceptTask.kt | 34 ++++++++---- .../core/external/job/DeliverCreateTask.kt | 23 +------- .../core/external/job/DeliverDeleteTask.kt | 23 +------- .../core/external/job/DeliverReactionTask.kt | 24 +-------- ...liverRejectJob.kt => DeliverRejectTask.kt} | 24 +-------- .../core/external/job/DeliverUndoTask.kt | 23 +------- .../hideout/core/external/job/InboxTask.kt | 24 +-------- .../core/external/job/ReceiveFollowTask.kt | 23 +------- hideout-worker/build.gradle.kts | 1 + libs.versions.toml | 1 + .../build.gradle.kts | 23 ++++++++ .../src/main/kotlin/dev/usbharu/Main.kt | 21 ++++++++ .../common/property/ObjectPropertyValue.kt | 51 ++++++++++++++++++ .../owl/common/property/FloatPropertyValue.kt | 44 ++++++++++++++++ .../owl/common/property/LongPropertyValue.kt | 45 ++++++++++++++++ .../owl/common/property/PropertyValue.kt | 2 +- .../usbharu/owl/common/task/TaskDefinition.kt | 52 +++++++++++++++++-- .../embedded/EmbeddedOwlProducerBuilder.kt | 3 +- owl/settings.gradle.kts | 15 +++++- 20 files changed, 284 insertions(+), 173 deletions(-) rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/{DeliverRejectJob.kt => DeliverRejectTask.kt} (54%) create mode 100644 owl/owl-common/owl-common-serialize-jackson/build.gradle.kts create mode 100644 owl/owl-common/owl-common-serialize-jackson/src/main/kotlin/dev/usbharu/Main.kt create mode 100644 owl/owl-common/owl-common-serialize-jackson/src/main/kotlin/dev/usbharu/owl/common/property/ObjectPropertyValue.kt create mode 100644 owl/owl-common/src/main/kotlin/dev/usbharu/owl/common/property/FloatPropertyValue.kt create mode 100644 owl/owl-common/src/main/kotlin/dev/usbharu/owl/common/property/LongPropertyValue.kt diff --git a/hideout-core/build.gradle.kts b/hideout-core/build.gradle.kts index ca8e9cf8..e13545a9 100644 --- a/hideout-core/build.gradle.kts +++ b/hideout-core/build.gradle.kts @@ -202,6 +202,7 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-log4j2") 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("software.amazon.awssdk:s3:2.25.23") implementation("org.jsoup:jsoup:1.17.2") diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverAcceptTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverAcceptTask.kt index de3f4332..b7b19949 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverAcceptTask.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverAcceptTask.kt @@ -17,7 +17,7 @@ package dev.usbharu.hideout.core.external.job 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.Task import dev.usbharu.owl.common.task.TaskDefinition @@ -32,25 +32,39 @@ data class DeliverAcceptTask( @Component data object DeliverAcceptTaskDef : TaskDefinition { override val name: String - get() = TODO("Not yet implemented") + get() = "DeliverAccept" override val priority: Int - get() = TODO("Not yet implemented") + get() = 10 override val maxRetry: Int - get() = TODO("Not yet implemented") + get() = 5 override val retryPolicy: String - get() = TODO("Not yet implemented") + get() = "" override val timeoutMilli: Long - get() = TODO("Not yet implemented") + get() = 1000 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 - get() = TODO("Not yet implemented") + get() = DeliverAcceptTask::class.java override fun serialize(task: DeliverAcceptTask): Map> { - 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>): 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, + ) } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverCreateTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverCreateTask.kt index 66a7bce1..b989b782 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverCreateTask.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverCreateTask.kt @@ -17,8 +17,6 @@ package dev.usbharu.hideout.core.external.job 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.TaskDefinition import org.springframework.stereotype.Component @@ -31,26 +29,7 @@ data class DeliverCreateTask( @Component data object DeliverCreateTaskDef : TaskDefinition { - 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 - get() = TODO("Not yet implemented") + get() = DeliverCreateTask::class.java - override fun serialize(task: DeliverCreateTask): Map> { - TODO("Not yet implemented") - } - - override fun deserialize(value: Map>): DeliverCreateTask { - TODO("Not yet implemented") - } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverDeleteTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverDeleteTask.kt index b4b55f51..29fe25d3 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverDeleteTask.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverDeleteTask.kt @@ -17,8 +17,6 @@ package dev.usbharu.hideout.core.external.job 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.TaskDefinition import org.springframework.stereotype.Component @@ -31,26 +29,7 @@ data class DeliverDeleteTask( @Component data object DeliverDeleteTaskDef : TaskDefinition { - 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 - get() = TODO("Not yet implemented") + get() = DeliverDeleteTask::class.java - override fun serialize(task: DeliverDeleteTask): Map> { - TODO("Not yet implemented") - } - - override fun deserialize(value: Map>): DeliverDeleteTask { - TODO("Not yet implemented") - } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverReactionTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverReactionTask.kt index cd122db7..c1c73154 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverReactionTask.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverReactionTask.kt @@ -17,8 +17,6 @@ package dev.usbharu.hideout.core.external.job 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.TaskDefinition import org.springframework.stereotype.Component @@ -31,26 +29,6 @@ data class DeliverReactionTask( @Component data object DeliverReactionTaskDef : TaskDefinition { - 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 - get() = TODO("Not yet implemented") - - override fun deserialize(value: Map>): DeliverReactionTask { - TODO("Not yet implemented") - } - - override fun serialize(task: DeliverReactionTask): Map> { - TODO("Not yet implemented") - } + get() = DeliverReactionTask::class.java } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverRejectJob.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverRejectTask.kt similarity index 54% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverRejectJob.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverRejectTask.kt index b76e9f5e..5bb47432 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverRejectJob.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverRejectTask.kt @@ -17,8 +17,6 @@ package dev.usbharu.hideout.core.external.job 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.TaskDefinition import org.springframework.stereotype.Component @@ -31,26 +29,6 @@ data class DeliverRejectTask( @Component data object DeliverRejectTaskDef : TaskDefinition { - 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 - get() = TODO("Not yet implemented") - - override fun serialize(task: DeliverRejectTask): Map> { - TODO("Not yet implemented") - } - - override fun deserialize(value: Map>): DeliverRejectTask { - TODO("Not yet implemented") - } + get() = DeliverRejectTask::class.java } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverUndoTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverUndoTask.kt index 60ca28ba..69d47260 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverUndoTask.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverUndoTask.kt @@ -17,8 +17,6 @@ package dev.usbharu.hideout.core.external.job 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.TaskDefinition import org.springframework.stereotype.Component @@ -31,26 +29,7 @@ data class DeliverUndoTask( @Component data object DeliverUndoTaskDef : TaskDefinition { - 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 - get() = TODO("Not yet implemented") + get() = DeliverUndoTask::class.java - override fun deserialize(value: Map>): DeliverUndoTask { - TODO("Not yet implemented") - } - - override fun serialize(task: DeliverUndoTask): Map> { - TODO("Not yet implemented") - } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/InboxTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/InboxTask.kt index 9206cc2b..b3e342b0 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/InboxTask.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/InboxTask.kt @@ -18,8 +18,6 @@ package dev.usbharu.hideout.core.external.job import dev.usbharu.hideout.activitypub.service.common.ActivityType 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.TaskDefinition import org.springframework.stereotype.Component @@ -33,26 +31,6 @@ data class InboxTask( @Component data object InboxTaskDef : TaskDefinition { - 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 - get() = TODO("Not yet implemented") - - override fun serialize(task: InboxTask): Map> { - TODO("Not yet implemented") - } - - override fun deserialize(value: Map>): InboxTask { - TODO("Not yet implemented") - } + get() = InboxTask::class.java } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/ReceiveFollowTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/ReceiveFollowTask.kt index d212896b..2792b13e 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/ReceiveFollowTask.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/ReceiveFollowTask.kt @@ -17,8 +17,6 @@ package dev.usbharu.hideout.core.external.job 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.TaskDefinition import org.springframework.stereotype.Component @@ -31,26 +29,7 @@ data class ReceiveFollowTask( @Component data object ReceiveFollowTaskDef : TaskDefinition { - 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 - get() = TODO("Not yet implemented") + get() = ReceiveFollowTask::class.java - override fun deserialize(value: Map>): ReceiveFollowTask { - TODO("Not yet implemented") - } - - override fun serialize(task: ReceiveFollowTask): Map> { - TODO("Not yet implemented") - } } diff --git a/hideout-worker/build.gradle.kts b/hideout-worker/build.gradle.kts index 5397d66e..5ae0e94c 100644 --- a/hideout-worker/build.gradle.kts +++ b/hideout-worker/build.gradle.kts @@ -40,6 +40,7 @@ dependencies { testImplementation(kotlin("test")) implementation("dev.usbharu:owl-consumer: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:http-signature:1.0.0") implementation("org.springframework.boot:spring-boot-starter") diff --git a/libs.versions.toml b/libs.versions.toml index ee3e55dd..2d43afd5 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -79,6 +79,7 @@ apache-tika = ["apache-tika-core", "apache-tika-parsers"] kjob = ["kjon-core", "kjon-mongo"] owl-producer = ["owl-producer-api", "owl-producer-default", "owl-producer-embedded"] owl-broker = ["owl-broker", "owl-broker-mongodb"] +jackson = ["jackson-databind", "jackson-module-kotlin"] [plugins] diff --git a/owl/owl-common/owl-common-serialize-jackson/build.gradle.kts b/owl/owl-common/owl-common-serialize-jackson/build.gradle.kts new file mode 100644 index 00000000..5eed5b43 --- /dev/null +++ b/owl/owl-common/owl-common-serialize-jackson/build.gradle.kts @@ -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) +} \ No newline at end of file diff --git a/owl/owl-common/owl-common-serialize-jackson/src/main/kotlin/dev/usbharu/Main.kt b/owl/owl-common/owl-common-serialize-jackson/src/main/kotlin/dev/usbharu/Main.kt new file mode 100644 index 00000000..64eb428e --- /dev/null +++ b/owl/owl-common/owl-common-serialize-jackson/src/main/kotlin/dev/usbharu/Main.kt @@ -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!") +} \ No newline at end of file diff --git a/owl/owl-common/owl-common-serialize-jackson/src/main/kotlin/dev/usbharu/owl/common/property/ObjectPropertyValue.kt b/owl/owl-common/owl-common-serialize-jackson/src/main/kotlin/dev/usbharu/owl/common/property/ObjectPropertyValue.kt new file mode 100644 index 00000000..10682e1d --- /dev/null +++ b/owl/owl-common/owl-common-serialize-jackson/src/main/kotlin/dev/usbharu/owl/common/property/ObjectPropertyValue.kt @@ -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() { + override val type: PropertyType + get() = PropertyType.string +} + +class ObjectPropertySerializer(private val objectMapper: ObjectMapper) : PropertySerializer { + 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 { + + return ObjectPropertyValue( + objectMapper.readValue( + string, + Class.forName(string.substringAfter("jackson:").substringBeforeLast(":")) + ) + ) + + } +} \ No newline at end of file diff --git a/owl/owl-common/src/main/kotlin/dev/usbharu/owl/common/property/FloatPropertyValue.kt b/owl/owl-common/src/main/kotlin/dev/usbharu/owl/common/property/FloatPropertyValue.kt new file mode 100644 index 00000000..0f18c832 --- /dev/null +++ b/owl/owl-common/src/main/kotlin/dev/usbharu/owl/common/property/FloatPropertyValue.kt @@ -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() { + override val type: PropertyType + get() = PropertyType.number +} + +/** + * [FloatPropertyValue]のシリアライザー + * + */ +class FloatPropertySerializer : PropertySerializer { + 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 { + return FloatPropertyValue(string.replace("float:", "").toFloat()) + } +} \ No newline at end of file diff --git a/owl/owl-common/src/main/kotlin/dev/usbharu/owl/common/property/LongPropertyValue.kt b/owl/owl-common/src/main/kotlin/dev/usbharu/owl/common/property/LongPropertyValue.kt new file mode 100644 index 00000000..660b0b69 --- /dev/null +++ b/owl/owl-common/src/main/kotlin/dev/usbharu/owl/common/property/LongPropertyValue.kt @@ -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() { + + override val type: PropertyType + get() = PropertyType.number +} + +/** + * [LongPropertyValue]のシリアライザー + * + */ +class LongPropertySerializer : PropertySerializer { + 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 { + return LongPropertyValue(string.replace("int64:", "").toLong()) + } +} \ No newline at end of file diff --git a/owl/owl-common/src/main/kotlin/dev/usbharu/owl/common/property/PropertyValue.kt b/owl/owl-common/src/main/kotlin/dev/usbharu/owl/common/property/PropertyValue.kt index c251c54f..90910a8c 100644 --- a/owl/owl-common/src/main/kotlin/dev/usbharu/owl/common/property/PropertyValue.kt +++ b/owl/owl-common/src/main/kotlin/dev/usbharu/owl/common/property/PropertyValue.kt @@ -21,7 +21,7 @@ package dev.usbharu.owl.common.property * * @param T プロパティの型 */ -sealed class PropertyValue { +abstract class PropertyValue { /** * プロパティ */ diff --git a/owl/owl-common/src/main/kotlin/dev/usbharu/owl/common/task/TaskDefinition.kt b/owl/owl-common/src/main/kotlin/dev/usbharu/owl/common/task/TaskDefinition.kt index b96c12de..0b7ec1dd 100644 --- a/owl/owl-common/src/main/kotlin/dev/usbharu/owl/common/task/TaskDefinition.kt +++ b/owl/owl-common/src/main/kotlin/dev/usbharu/owl/common/task/TaskDefinition.kt @@ -16,7 +16,7 @@ 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 { * タスク名 */ val name: String + get() = type.simpleName /** * 優先度 */ val priority: Int + get() = 0 /** * 最大リトライ数 */ val maxRetry: Int + get() = 5 /** * リトライポリシー名 @@ -45,16 +48,31 @@ interface TaskDefinition { * ポリシーの解決は各Brokerに依存しています */ val retryPolicy: String + get() = "" /** * タスク実行時のタイムアウト(ミリ秒) */ val timeoutMilli: Long + get() = 1000 /** * プロパティ定義 */ 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] @@ -67,7 +85,19 @@ interface TaskDefinition { * @param task シリアライズするタスク * @return シリアライズされたタスク */ - fun serialize(task: T): Map> + fun serialize(task: T): Map> { + 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 { * @param value デシリアライズするタスク * @return デシリアライズされたタスク */ - fun deserialize(value: Map>): T + fun deserialize(value: Map>): 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 + } } \ No newline at end of file diff --git a/owl/owl-producer/owl-producer-embedded/src/main/kotlin/dev/usbharu/owl/producer/embedded/EmbeddedOwlProducerBuilder.kt b/owl/owl-producer/owl-producer-embedded/src/main/kotlin/dev/usbharu/owl/producer/embedded/EmbeddedOwlProducerBuilder.kt index 3a73cb08..e92b6fc9 100644 --- a/owl/owl-producer/owl-producer-embedded/src/main/kotlin/dev/usbharu/owl/producer/embedded/EmbeddedOwlProducerBuilder.kt +++ b/owl/owl-producer/owl-producer-embedded/src/main/kotlin/dev/usbharu/owl/producer/embedded/EmbeddedOwlProducerBuilder.kt @@ -18,6 +18,7 @@ package dev.usbharu.owl.producer.embedded import dev.usbharu.owl.broker.EmptyModuleContext import dev.usbharu.owl.common.retry.DefaultRetryPolicyFactory +import dev.usbharu.owl.common.retry.ExponentialRetryPolicy import dev.usbharu.owl.producer.api.OwlProducerBuilder class EmbeddedOwlProducerBuilder : OwlProducerBuilder { @@ -28,7 +29,7 @@ class EmbeddedOwlProducerBuilder : OwlProducerBuilder