Skip to content

Commit 0982055

Browse files
committed
Update documentation comments
1 parent 24ed8e4 commit 0982055

File tree

10 files changed

+68
-68
lines changed

10 files changed

+68
-68
lines changed

rhea-core/src/main/kotlin/uk/dsxt/rhea/ConfigSource.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ import kotlinx.coroutines.channels.SendChannel
88
*/
99
interface ConfigSource {
1010
/**
11-
* Provides initial values from configuration store for [getNode] and starts a new coroutine that watches changes of configuration values.
11+
* Provides initial values from configuration store for [getNode] and starts a new coroutine in [scope],
12+
* watches changes of configuration values and transfers them through [channelOfChanges] to [ReactiveConfig].
1213
*
13-
* @param channelOfChanges the channel where changes of values will be sent
14+
* @param channelOfChanges the channel where changes of values will be sent to
1415
* @param scope the scope where a new coroutine that watches changes of configuration should be launched
1516
*/
1617
suspend fun subscribe(channelOfChanges: SendChannel<RawProperty>, scope: CoroutineScope)
1718

1819
/**
19-
* Provides initial value of property to construct [Reloadable].
20+
* Provides initial value of property with given [key] to construct [Reloadable].
2021
*
21-
* @param key the key of property
22-
* @return the Node that holds [RawProperty]
22+
* @return [Node] that holds [RawProperty] with initial value
2323
*/
2424
fun getNode(key: String): Node?
2525
}

rhea-core/src/main/kotlin/uk/dsxt/rhea/PropertiesConfigSource.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import java.util.*
1111
import kotlin.collections.HashMap
1212

1313
/**
14-
* [ConfigSource] that reads configuration from .properties.
14+
* [ConfigSource] that reads configuration from .properties
1515
*/
1616
class PropertiesConfigSource(directory: Path, fileName: String) : ConfigSource {
1717
private var file: File

rhea-core/src/main/kotlin/uk/dsxt/rhea/PropertyGroup.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package uk.dsxt.rhea
33
import kotlin.reflect.KProperty
44

55
/**
6-
* Allows to define hierarchies of properties
6+
* Allows to define hierarchies of properties.
77
*/
88
open class PropertyGroup {
99
private fun outer(): String? {

rhea-core/src/main/kotlin/uk/dsxt/rhea/PropertyTypes.kt

+10-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ sealed class ParseResult<T> {
1313
}
1414

1515
/**
16-
* @return [PropertyType] that allows value to be null
16+
* @return [PropertyType] that allows value to be null.
1717
*/
1818
fun <T> PropertyType<T>.nullable(): PropertyType<T?> {
1919
return PropertyType(initial, { node: Node? ->
@@ -26,10 +26,13 @@ fun <T> PropertyType<T>.nullable(): PropertyType<T?> {
2626
})
2727
}
2828

29+
/**
30+
* Represents type of property that has some default value [initial] and [parse] function.
31+
*/
2932
class PropertyType<T>(val initial: T, val parse: (Node?) -> ParseResult<T?>)
3033

3134
/**
32-
* The type of string property
35+
* The type of string property.
3336
*/
3437
@JvmField
3538
val stringType: PropertyType<String> = PropertyType("", { node: Node? ->
@@ -40,7 +43,7 @@ val stringType: PropertyType<String> = PropertyType("", { node: Node? ->
4043
})
4144

4245
/**
43-
* The type of int property
46+
* The type of int property.
4447
*/
4548
@JvmField
4649
val intType: PropertyType<Int> = PropertyType(0, { node: Node? ->
@@ -56,7 +59,7 @@ val intType: PropertyType<Int> = PropertyType(0, { node: Node? ->
5659
})
5760

5861
/**
59-
* The type of long property
62+
* The type of long property.
6063
*/
6164
@JvmField
6265
val longType: PropertyType<Long> = PropertyType(0L, { node: Node? ->
@@ -72,7 +75,7 @@ val longType: PropertyType<Long> = PropertyType(0L, { node: Node? ->
7275
})
7376

7477
/**
75-
* The type of float property
78+
* The type of float property.
7679
*/
7780
@JvmField
7881
val floatType: PropertyType<Float> = PropertyType(0.0F, { node: Node? ->
@@ -88,7 +91,7 @@ val floatType: PropertyType<Float> = PropertyType(0.0F, { node: Node? ->
8891
})
8992

9093
/**
91-
* The type of double property
94+
* The type of double property.
9295
*/
9396
@JvmField
9497
val doubleType: PropertyType<Double> = PropertyType(0.0, { node: Node? ->
@@ -104,7 +107,7 @@ val doubleType: PropertyType<Double> = PropertyType(0.0, { node: Node? ->
104107
})
105108

106109
/**
107-
* The type of boolean property
110+
* The type of boolean property.
108111
*/
109112
@JvmField
110113
val booleanType: PropertyType<Boolean> = PropertyType(false, { node: Node? ->
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package uk.dsxt.rhea
22

33
/**
4-
* Holds key and value of property from [ConfigSource]
5-
*
6-
* @param key key of property
7-
* @param value [Node] that holds value of property
4+
* Holds property's [key] and [value] wrapped in [Node].
85
*/
96
class RawProperty(val key: String, val value: Node?)

rhea-core/src/main/kotlin/uk/dsxt/rhea/ReactiveConfig.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ class ReactiveConfig private constructor(val manager: ConfigManager) {
4141
}
4242

4343
/**
44-
* @param key the key of property that will be reloadable
45-
* @param type the type of provided property
46-
* @return new instance of [Reloadable]
44+
* @return [Reloadable] that holds the freshest value of property with given [key] and [type].
4745
*/
4846
operator fun <T> get(key: String, type: PropertyType<T>): Reloadable<T>? {
4947
if (manager.mapOfProperties.containsKey(key)) {

rhea-core/src/main/kotlin/uk/dsxt/rhea/Reloadable.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import kotlinx.coroutines.flow.*
66
import kotlinx.coroutines.launch
77

88
/**
9-
* Contains the latest value of type T and updates it every time the value is changed in configuration
9+
* Contains the latest value of type T and updates it every time the value is changed in configuration.
1010
*
11-
* @param T the type of entity
12-
* @param value the latest value of entity
11+
* @param T the type of property
12+
* @param value the latest value of property
1313
* @param flowOfChanges the flow with typed values
1414
* @param scope the scope where coroutines will be launched
1515
*/
@@ -27,7 +27,7 @@ class Reloadable<T>(
2727
}
2828

2929
/**
30-
* @return the latest value of entity
30+
* @return the latest value.
3131
*/
3232
fun get() = value
3333

rhea-jdbc/src/main/kotlin/uk/dsxt/rhea/JDBCConfigSource.kt

+25-24
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,31 @@ import kotlinx.coroutines.delay
66
import kotlinx.coroutines.launch
77
import kotlinx.coroutines.newSingleThreadContext
88
import mu.KotlinLogging
9+
import uk.dsxt.rhea.ReactiveConfig.Builder
910
import java.sql.*
1011

11-
class JDBCConfigSource(private val url : String,private val scheme : String) : ConfigSource {
12-
13-
private lateinit var connection : Connection
12+
/**
13+
* [ConfigSource] that reads configuration from JDBC.
14+
*/
15+
class JDBCConfigSource(private val url: String, private val scheme: String) : ConfigSource {
16+
private lateinit var connection: Connection
1417
private lateinit var channel: SendChannel<RawProperty>
1518
private lateinit var configScope: CoroutineScope
1619
private val map: HashMap<String, Node?> = HashMap()
1720
private val logger = KotlinLogging.logger {}
1821

19-
init{
20-
try{
22+
init {
23+
try {
2124
connection = DriverManager.getConnection(url)
22-
} catch (e : SQLException) {
25+
} catch (e: SQLException) {
2326
logger.error("Couldn't connect to database with this url: \"${url}\". Values from this place are no longer updates")
2427
}
2528
}
2629

27-
constructor(url : String, login : String, password : String, scheme: String) : this(url, scheme){
28-
try{
30+
constructor(url: String, login: String, password: String, scheme: String) : this(url, scheme) {
31+
try {
2932
connection = DriverManager.getConnection(url, login, password)
30-
} catch (e : SQLException) {
33+
} catch (e: SQLException) {
3134
logger.error("Couldn't connect to database with this url: \"${url}\". Values from this place are no longer updates")
3235
}
3336
}
@@ -36,23 +39,23 @@ class JDBCConfigSource(private val url : String,private val scheme : String) : C
3639
channel = channelOfChanges
3740
configScope = scope
3841

39-
if (!connection.isClosed){
42+
if (!connection.isClosed) {
4043
configScope.launch(newSingleThreadContext("watching thread")) {
41-
try{
42-
if (scheme.contains(" ")){
44+
try {
45+
if (scheme.contains(" ")) {
4346
throw error("Incorrect name of scheme: \"${scheme}\". Values from this place are no longer updates")
4447
}
4548
var query = "SELECT * FROM $scheme"
4649
val statement = connection.createStatement()
4750
var result = statement.executeQuery(query)
4851

4952
val columnNumber = result.metaData.columnCount
50-
val updateColumnName : String
53+
val updateColumnName: String
5154
var latestUpdate = 3
5255

53-
while (result.next()){
56+
while (result.next()) {
5457
map[result.getString(1)] = toNode(result.getObject(2))
55-
if (columnNumber == 3){
58+
if (columnNumber == 3) {
5659
with(result.getInt(3)) {
5760
if (this > latestUpdate) {
5861
latestUpdate = this
@@ -66,19 +69,19 @@ class JDBCConfigSource(private val url : String,private val scheme : String) : C
6669
query += " WHERE $updateColumnName > "
6770
}
6871

69-
while(true){
72+
while (true) {
7073
delay(1000)
71-
if (columnNumber == 3){
74+
if (columnNumber == 3) {
7275
result = statement.executeQuery(query + "$latestUpdate")
7376
}
74-
while (result.next()){
77+
while (result.next()) {
7578
val first = result.getString(1)
7679
val second = toNode(result.getObject(2))
77-
if(map[first] != second){
80+
if (map[first] != second) {
7881
map[first] = second
7982
channel.send(RawProperty(first, second))
8083
}
81-
if (columnNumber == 3){
84+
if (columnNumber == 3) {
8285
with(result.getInt(3)) {
8386
if (this > latestUpdate) {
8487
latestUpdate = this
@@ -87,11 +90,9 @@ class JDBCConfigSource(private val url : String,private val scheme : String) : C
8790
}
8891
}
8992
}
90-
}
91-
catch(e : SQLException){
93+
} catch (e: SQLException) {
9294
logger.error("Failed reading from $scheme scheme. Values from this place are no longer updates")
93-
}
94-
catch(e : Exception){
95+
} catch (e: Exception) {
9596
logger.error(e.message)
9697
}
9798
}

rhea-mongo/src/main/kotlin/uk/dsxt/rhea/MongoConfigSource.kt

+13-9
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,26 @@ import kotlinx.coroutines.delay
1313
import kotlinx.coroutines.newSingleThreadContext
1414
import org.bson.Document
1515

16-
class MongoConfigSource(private val url : String,private val database: String, private val scheme : String) : ConfigSource {
16+
/**
17+
* [ConfigSource] that reads configuration from MongoDB.
18+
*/
19+
class MongoConfigSource(private val url: String, private val database: String, private val scheme: String) :
20+
ConfigSource {
1721
private lateinit var channel: SendChannel<RawProperty>
1822
private lateinit var configScope: CoroutineScope
19-
private lateinit var client : MongoClient
20-
private lateinit var db : MongoDatabase
23+
private lateinit var client: MongoClient
24+
private lateinit var db: MongoDatabase
2125
private val map: HashMap<String, Node?> = HashMap()
2226
private val logger = KotlinLogging.logger {}
2327

24-
init{
25-
try{
28+
init {
29+
try {
2630
client = MongoClients.create(url)
27-
}
28-
catch(e : MongoException){
31+
} catch (e: MongoException) {
2932
logger.error("Couldn't connect to database with this url: \"${url}\". Values from this place are no longer updates")
3033
}
3134
}
35+
3236
override suspend fun subscribe(channelOfChanges: SendChannel<RawProperty>, scope: CoroutineScope) {
3337
channel = channelOfChanges
3438
configScope = scope
@@ -78,14 +82,14 @@ class MongoConfigSource(private val url : String,private val database: String, p
7882
is Boolean -> BooleanNode(obj)
7983
is ArrayList<*> -> {
8084
val result = mutableListOf<Node?>()
81-
obj.forEach{
85+
obj.forEach {
8286
result.add(toNode(it))
8387
}
8488
ArrayNode(result)
8589
}
8690
is Document -> {
8791
val result = mutableMapOf<String, Node?>()
88-
obj.forEach{
92+
obj.forEach {
8993
result[it.key] = toNode(it.value)
9094
}
9195
ObjectNode(result)

rhea-vault/src/main/kotlin/uk/dsxt/rhea/VaultConfigSource.kt

+7-10
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ class VaultConfigSource : ConfigSource {
3434
this.secretPath = secretPath
3535
this.reloadTimeMillis = reloadTimeMillis
3636
}
37+
3738
/**
3839
* Builder for [VaultConfigSource].
3940
*
40-
* **Note: provide builder with secretPath and either configured [Vault] or just address and token.
41+
* **Note: please, provide builder with secretPath and either configured [Vault] or just address and token.
4142
*/
4243
class Builder {
4344
private lateinit var vault: Vault
@@ -47,9 +48,8 @@ class VaultConfigSource : ConfigSource {
4748
private var reloadTimeMillis: Long = 0
4849

4950
/**
50-
* Sets Vault address for [VaultConfigSource]s built by the builder.
51+
* Sets Vault [address] for [VaultConfigSource]s built by the builder.
5152
*
52-
* @param address address to use
5353
* @return this instance of builder with Vault address set to provided parameter
5454
*/
5555
fun withAddress(address: String): Builder {
@@ -59,9 +59,8 @@ class VaultConfigSource : ConfigSource {
5959
}
6060

6161
/**
62-
* Sets Vault token for [VaultConfigSource]s built by the builder.
62+
* Sets Vault [token] for [VaultConfigSource]s built by the builder.
6363
*
64-
* @param token token to use
6564
* @return this instance of builder with Vault token set to provided parameter
6665
*/
6766
fun withToken(token: String): Builder {
@@ -71,9 +70,8 @@ class VaultConfigSource : ConfigSource {
7170
}
7271

7372
/**
74-
* Sets Vault secretPath for [VaultConfigSource]s built by the builder.
73+
* Sets Vault [secretPath] for [VaultConfigSource]s built by the builder.
7574
*
76-
* @param secretPath secretPath to use
7775
* @return this instance of builder with Vault secretPath set to provided parameter
7876
*/
7977
fun withSecretPath(secretPath: String): Builder {
@@ -83,7 +81,7 @@ class VaultConfigSource : ConfigSource {
8381
}
8482

8583
/**
86-
* Sets Vault reloadTime for [VaultConfigSource]s built by the builder.
84+
* Sets Vault [reloadTime] for [VaultConfigSource]s built by the builder.
8785
*
8886
* @param reloadTime reloadTime that configures intervals of time in which [VaultConfigSource] checks for changes
8987
* @return this instance of builder with reloadTime set to provided parameter
@@ -95,9 +93,8 @@ class VaultConfigSource : ConfigSource {
9593
}
9694

9795
/**
98-
* Sets Vault for [VaultConfigSource]s built by the builder.
96+
* Sets [vault] for [VaultConfigSource]s built by the builder.
9997
*
100-
* @param vault Vault to use
10198
* @return this instance of builder with Vault set to provided parameter
10299
*/
103100
fun withVault(vault: Vault): Builder {

0 commit comments

Comments
 (0)