doc: ドキュメントを追加

This commit is contained in:
usbharu 2024-04-22 12:28:37 +09:00
parent c76f9e36f0
commit 67e5dd3c1d
Signed by: usbharu
GPG Key ID: 8CB1087135660B8D
5 changed files with 57 additions and 7 deletions

View File

@ -16,6 +16,11 @@
package dev.usbharu.owl.common.property package dev.usbharu.owl.common.property
/**
* プロパティで使用される値
*
* @param T プロパティの型
*/
sealed class PropertyValue<T> { sealed class PropertyValue<T> {
abstract val value: T abstract val value: T
abstract val type: PropertyType abstract val type: PropertyType

View File

@ -25,12 +25,19 @@ import io.grpc.ManagedChannelBuilder
import java.nio.file.Path import java.nio.file.Path
import java.util.* import java.util.*
/**
* 単独で起動できるConsumer
*
* @property config Consumerの起動構成
* @property propertySerializerFactory [dev.usbharu.owl.common.property.PropertyValue]のシリアライザーのファクトリ
*/
class StandaloneConsumer( class StandaloneConsumer(
private val config: StandaloneConsumerConfig, private val config: StandaloneConsumerConfig,
private val propertySerializerFactory: PropertySerializerFactory private val propertySerializerFactory: PropertySerializerFactory
) { ) {
constructor( constructor(
path: Path, propertySerializerFactory: PropertySerializerFactory = CustomPropertySerializerFactory( path: Path,
propertySerializerFactory: PropertySerializerFactory = CustomPropertySerializerFactory(
emptySet() emptySet()
) )
) : this(StandaloneConsumerConfigLoader.load(path), propertySerializerFactory) ) : this(StandaloneConsumerConfigLoader.load(path), propertySerializerFactory)
@ -52,18 +59,27 @@ class StandaloneConsumer(
.associateBy { it.name } .associateBy { it.name }
private val consumer = Consumer( private val consumer = Consumer(
subscribeStub, subscribeTaskStub = subscribeStub,
assignmentTaskStub, assignmentTaskStub = assignmentTaskStub,
taskResultStub, taskResultStub = taskResultStub,
taskRunnerMap, runnerMap = taskRunnerMap,
propertySerializerFactory, propertySerializerFactory = propertySerializerFactory,
ConsumerConfig(config.concurrency) consumerConfig = ConsumerConfig(config.concurrency)
) )
/**
* Consumerを初期化します
*
*/
suspend fun init() { suspend fun init() {
consumer.init(config.name, config.hostname) consumer.init(config.name, config.hostname)
} }
/**
* Consumerのワーカーを起動しタスクの受付を開始します
*
* シャットダウンフックに[stop]が登録されます
*/
suspend fun start() { suspend fun start() {
consumer.start() consumer.start()
Runtime.getRuntime().addShutdownHook(Thread { Runtime.getRuntime().addShutdownHook(Thread {
@ -71,6 +87,10 @@ class StandaloneConsumer(
}) })
} }
/**
* Consumerを停止します
*
*/
fun stop() { fun stop() {
consumer.stop() consumer.stop()
} }

View File

@ -16,6 +16,15 @@
package dev.usbharu.owl.consumer package dev.usbharu.owl.consumer
/**
* 単独で起動できるConsumerの構成
*
* @property address brokerのアドレス
* @property port brokerのポート
* @property name Consumerの名前
* @property hostname Consumerのホスト名
* @property concurrency ConsumerのWorkerの最大同時実行数
*/
data class StandaloneConsumerConfig( data class StandaloneConsumerConfig(
val address: String, val address: String,
val port: Int, val port: Int,

View File

@ -20,7 +20,16 @@ import java.nio.file.Files
import java.nio.file.Path import java.nio.file.Path
import java.util.* import java.util.*
/**
* 単独で起動できるConsumerの構成のローダー
*/
object StandaloneConsumerConfigLoader { object StandaloneConsumerConfigLoader {
/**
* [Path]から構成を読み込みます
*
* @param path 読み込むパス
* @return 読み込まれた構成
*/
fun load(path: Path): StandaloneConsumerConfig { fun load(path: Path): StandaloneConsumerConfig {
val properties = Properties() val properties = Properties()

View File

@ -18,6 +18,13 @@ package dev.usbharu.owl.consumer
import dev.usbharu.owl.common.property.PropertyValue import dev.usbharu.owl.common.property.PropertyValue
/**
* タスクの実行結果
*
* @property success 成功したらtrue
* @property result タスクの実行結果のMap
* @property message その他メッセージ
*/
data class TaskResult( data class TaskResult(
val success: Boolean, val success: Boolean,
val result: Map<String, PropertyValue<*>>, val result: Map<String, PropertyValue<*>>,