-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add http timeout configuration for nodes (#22)
* Add http timeout configuration for nodes * add param in comment for httpTimeout * Update src/main/kotlin/dev/arbjerg/lavalink/client/LavalinkNode.kt Co-authored-by: Duncan Sterken <contact@duncte123.me> * add LavalinkNodeOptions * remove some unused imports in LavalinkClient * update nodeOptions constructor to private, update example JDA bot to use new NodeOptions builder * update builder to set naming --------- Co-authored-by: Duncan Sterken <contact@duncte123.me>
- Loading branch information
Showing
5 changed files
with
94 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/kotlin/dev/arbjerg/lavalink/client/NodeOptions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package dev.arbjerg.lavalink.client | ||
|
||
import dev.arbjerg.lavalink.client.loadbalancing.IRegionFilter | ||
import dev.arbjerg.lavalink.internal.TIMEOUT_MS | ||
import java.net.URI | ||
|
||
data class NodeOptions private constructor(val name: String, | ||
val serverUri: URI, | ||
val password: String, | ||
val regionFilter: IRegionFilter?, | ||
val httpTimeout: Long) { | ||
data class Builder( | ||
private var name: String? = null, | ||
private var serverUri: URI? = null, | ||
private var password: String? = null, | ||
private var regionFilter: IRegionFilter? = null, | ||
private var httpTimeout: Long = TIMEOUT_MS, | ||
) { | ||
fun setName(name: String) = apply { this.name = name } | ||
|
||
/** | ||
* Sets the server URI of the Lavalink Node. | ||
* @param serverUriString - String representation of server uri | ||
*/ | ||
fun setServerUri(serverUriString: String) = apply { this.serverUri = URI(serverUriString) } | ||
/** | ||
* Sets the server URI of the Lavalink Node. | ||
* @param serverUri - Server uri | ||
*/ | ||
fun setServerUri(serverUri: URI) = apply { this.serverUri = serverUri } | ||
/** | ||
* Sets the password to access the node. | ||
* @param password - Server password | ||
*/ | ||
fun setPassword(password: String) = apply { this.password = password } | ||
|
||
/** | ||
* Sets a region filter on the node for regional load balancing (Default: none) | ||
*/ | ||
fun setRegionFilter(regionFilter: IRegionFilter?) = apply { this.regionFilter = regionFilter } | ||
|
||
/** | ||
* Sets the http total call timeout. (Default: 10000ms) | ||
* @param httpTimeout - timeout in ms | ||
*/ | ||
fun setHttpTimeout(httpTimeout: Long) = apply { this.httpTimeout = httpTimeout } | ||
|
||
fun build(): NodeOptions { | ||
requireNotNull(name) { "name is required" } | ||
requireNotNull(serverUri) { "serverUri is required" } | ||
requireNotNull(password) { "password is required" } | ||
|
||
return NodeOptions( | ||
name!!, | ||
serverUri!!, | ||
password!!, | ||
regionFilter, | ||
httpTimeout) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package dev.arbjerg.lavalink.internal | ||
|
||
internal const val TIMEOUT_MS = 5000 | ||
internal const val TIMEOUT_MS = 10000L | ||
internal const val METRIC_MAX_HISTORY = 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters