diff --git a/broker/src/main/kotlin/dev/usbharu/owl/broker/Main.kt b/broker/src/main/kotlin/dev/usbharu/owl/broker/Main.kt index d5184bd..83cbaac 100644 --- a/broker/src/main/kotlin/dev/usbharu/owl/broker/Main.kt +++ b/broker/src/main/kotlin/dev/usbharu/owl/broker/Main.kt @@ -18,8 +18,6 @@ package dev.usbharu.owl.broker import dev.usbharu.owl.broker.service.DefaultRetryPolicyFactory import dev.usbharu.owl.broker.service.RetryPolicyFactory -import dev.usbharu.owl.common.property.PropertySerializerFactory -import dev.usbharu.owl.common.property.PropertySerializerFactoryImpl import kotlinx.coroutines.runBlocking import org.koin.core.context.startKoin import org.koin.dsl.module @@ -33,9 +31,6 @@ fun main() { printLogger() val module = module { - single { - PropertySerializerFactoryImpl() - } single { DefaultRetryPolicyFactory(emptyMap()) } diff --git a/broker/src/main/kotlin/dev/usbharu/owl/broker/domain/model/task/Task.kt b/broker/src/main/kotlin/dev/usbharu/owl/broker/domain/model/task/Task.kt index 07347c0..8bf3a16 100644 --- a/broker/src/main/kotlin/dev/usbharu/owl/broker/domain/model/task/Task.kt +++ b/broker/src/main/kotlin/dev/usbharu/owl/broker/domain/model/task/Task.kt @@ -31,5 +31,5 @@ data class Task( val nextRetry:Instant, val completedAt: Instant? = null, val attempt: Int, - val properties: Map + val properties: Map> ) diff --git a/broker/src/main/kotlin/dev/usbharu/owl/broker/service/DefaultPropertySerializerFactory.kt b/broker/src/main/kotlin/dev/usbharu/owl/broker/service/DefaultPropertySerializerFactory.kt new file mode 100644 index 0000000..b78fa47 --- /dev/null +++ b/broker/src/main/kotlin/dev/usbharu/owl/broker/service/DefaultPropertySerializerFactory.kt @@ -0,0 +1,9 @@ +package dev.usbharu.owl.broker.service + +import dev.usbharu.owl.common.property.CustomPropertySerializerFactory +import dev.usbharu.owl.common.property.IntegerPropertySerializer +import dev.usbharu.owl.common.property.PropertySerializerFactory +import org.koin.core.annotation.Singleton + +@Singleton(binds = [PropertySerializerFactory::class]) +class DefaultPropertySerializerFactory : CustomPropertySerializerFactory(setOf(IntegerPropertySerializer())) \ No newline at end of file diff --git a/broker/src/main/kotlin/dev/usbharu/owl/broker/service/TaskPublishService.kt b/broker/src/main/kotlin/dev/usbharu/owl/broker/service/TaskPublishService.kt index 1aee8a6..288bc16 100644 --- a/broker/src/main/kotlin/dev/usbharu/owl/broker/service/TaskPublishService.kt +++ b/broker/src/main/kotlin/dev/usbharu/owl/broker/service/TaskPublishService.kt @@ -32,7 +32,7 @@ interface TaskPublishService { data class PublishTask( val name: String, val producerId: UUID, - val properties: Map + val properties: Map> ) data class PublishedTask( diff --git a/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertySerializerFactoryImpl.kt b/common/src/main/kotlin/dev/usbharu/owl/common/property/CustomPropertySerializerFactory.kt similarity index 58% rename from common/src/main/kotlin/dev/usbharu/owl/common/property/PropertySerializerFactoryImpl.kt rename to common/src/main/kotlin/dev/usbharu/owl/common/property/CustomPropertySerializerFactory.kt index f891f7a..3f3e826 100644 --- a/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertySerializerFactoryImpl.kt +++ b/common/src/main/kotlin/dev/usbharu/owl/common/property/CustomPropertySerializerFactory.kt @@ -17,12 +17,13 @@ package dev.usbharu.owl.common.property -class PropertySerializerFactoryImpl : PropertySerializerFactory { - override fun factory(propertyValue: PropertyValue): PropertySerializer { - TODO("Not yet implemented") +open class CustomPropertySerializerFactory(private val propertySerializers: Set>) : + PropertySerializerFactory { + override fun factory(propertyValue: PropertyValue): PropertySerializer { + return propertySerializers.first { it.isSupported(propertyValue) } as PropertySerializer } - override fun factory(string: String): PropertySerializer { - TODO("Not yet implemented") + override fun factory(string: String): PropertySerializer<*> { + return propertySerializers.first { it.isSupported(string) } } } \ No newline at end of file diff --git a/common/src/main/kotlin/dev/usbharu/owl/common/property/IntegerPropertyValue.kt b/common/src/main/kotlin/dev/usbharu/owl/common/property/IntegerPropertyValue.kt index 4098410..331f8f7 100644 --- a/common/src/main/kotlin/dev/usbharu/owl/common/property/IntegerPropertyValue.kt +++ b/common/src/main/kotlin/dev/usbharu/owl/common/property/IntegerPropertyValue.kt @@ -16,7 +16,25 @@ package dev.usbharu.owl.common.property -class IntegerPropertyValue(override val value: Int) : PropertyValue() { +class IntegerPropertyValue(override val value: Int) : PropertyValue() { override val type: PropertyType get() = PropertyType.integer +} + +class IntegerPropertySerializer : PropertySerializer { + override fun isSupported(propertyValue: PropertyValue<*>): Boolean { + return propertyValue.value is Int + } + + override fun isSupported(string: String): Boolean { + return string.startsWith("int32:") + } + + override fun serialize(propertyValue: PropertyValue<*>): String { + return "int32:" + propertyValue.value.toString() + } + + override fun deserialize(string: String): PropertyValue { + return IntegerPropertyValue(string.replace("int32:", "").toInt()) + } } \ No newline at end of file diff --git a/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertySerializeUtils.kt b/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertySerializeUtils.kt index b5e151d..38d7a4b 100644 --- a/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertySerializeUtils.kt +++ b/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertySerializeUtils.kt @@ -19,13 +19,13 @@ package dev.usbharu.owl.common.property object PropertySerializeUtils { fun serialize( serializerFactory: PropertySerializerFactory, - properties: Map + properties: Map> ): Map = properties.map { it.key to serializerFactory.factory(it.value).serialize(it.value) }.toMap() fun deserialize( serializerFactory: PropertySerializerFactory, properties: Map - ): Map = + ): Map> = properties.map { it.key to serializerFactory.factory(it.value).deserialize(it.value) }.toMap() } \ No newline at end of file diff --git a/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertySerializer.kt b/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertySerializer.kt index 85194fe..b1c3bb5 100644 --- a/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertySerializer.kt +++ b/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertySerializer.kt @@ -16,10 +16,10 @@ package dev.usbharu.owl.common.property -interface PropertySerializer { - fun isSupported(propertyValue: PropertyValue): Boolean +interface PropertySerializer { + fun isSupported(propertyValue: PropertyValue<*>): Boolean fun isSupported(string: String): Boolean - fun serialize(propertyValue: PropertyValue): String + fun serialize(propertyValue: PropertyValue<*>): String - fun deserialize(string: String): PropertyValue + fun deserialize(string: String): PropertyValue } \ No newline at end of file diff --git a/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertySerializerFactory.kt b/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertySerializerFactory.kt index 9caaa8a..bc18d27 100644 --- a/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertySerializerFactory.kt +++ b/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertySerializerFactory.kt @@ -17,6 +17,6 @@ package dev.usbharu.owl.common.property interface PropertySerializerFactory { - fun factory(propertyValue: PropertyValue): PropertySerializer - fun factory(string: String): PropertySerializer + fun factory(propertyValue: PropertyValue): PropertySerializer + fun factory(string: String): PropertySerializer<*> } \ No newline at end of file diff --git a/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertyValue.kt b/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertyValue.kt index 6b7f392..440aa35 100644 --- a/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertyValue.kt +++ b/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertyValue.kt @@ -16,7 +16,7 @@ package dev.usbharu.owl.common.property -sealed class PropertyValue { - abstract val value:Any +sealed class PropertyValue { + abstract val value: T abstract val type: PropertyType } \ No newline at end of file diff --git a/common/src/main/kotlin/dev/usbharu/owl/common/task/TaskDefinition.kt b/common/src/main/kotlin/dev/usbharu/owl/common/task/TaskDefinition.kt index 6a8e7f3..8c766c3 100644 --- a/common/src/main/kotlin/dev/usbharu/owl/common/task/TaskDefinition.kt +++ b/common/src/main/kotlin/dev/usbharu/owl/common/task/TaskDefinition.kt @@ -27,6 +27,6 @@ interface TaskDefinition { val timeoutMilli: Long val propertyDefinition: PropertyDefinition - fun serialize(task: T): Map - fun deserialize(value: Map): T + fun serialize(task: T): Map> + fun deserialize(value: Map>): T } \ No newline at end of file