Skip to content

Commit ad79c89

Browse files
committed
refactor: add environment docs
1 parent 496e24c commit ad79c89

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

serverhost-runtime/src/main/kotlin/app/simplecloud/droplet/serverhost/runtime/runner/ServerEnvironment.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,44 @@ abstract class ServerEnvironment(
1111
protected open val runtimeRepository: GroupRuntimeDirectory,
1212
private val environmentRepository: EnvironmentConfigRepository
1313
) {
14+
/**
15+
* Starts a [Server] and returns true if the server is successfully started
16+
*/
1417
abstract suspend fun startServer(server: Server): Boolean
18+
19+
/**
20+
* Stops a [Server] and returns true if the server is successfully stopped
21+
*/
1522
abstract suspend fun stopServer(server: Server): Boolean
23+
24+
/**
25+
* Get a [Server] by unique id (returns null if the server is not running on this environment)
26+
*/
1627
abstract fun getServer(uniqueId: String): Server?
28+
29+
/**
30+
* Reattaches a [Server] and returns true if the server is successfully reattached
31+
*/
1732
abstract fun reattachServer(server: Server): Boolean
33+
34+
/**
35+
* Executes a command on a [Server] and returns true if execution is successful
36+
*/
1837
abstract fun executeCommand(server: Server, command: String): Boolean
38+
39+
/**
40+
* Returns a never ending stream for server logs
41+
*/
1942
abstract fun streamLogs(server: Server): Flow<ServerHostStreamServerLogsResponse>
43+
44+
/**
45+
* Precondition if the current environment is valid for a given [EnvironmentConfig]
46+
*/
2047
abstract fun appliesFor(env: EnvironmentConfig): Boolean
48+
49+
/**
50+
* Starts the server update checker. This will stop offline servers and update servers by the ping response of the server.
51+
*/
2152
abstract fun startServerStateChecker(): Job
2253

2354
fun getEnvironment(server: Server): EnvironmentConfig? {

serverhost-runtime/src/main/kotlin/app/simplecloud/droplet/serverhost/runtime/runner/ServerEnvironments.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,16 @@ class ServerEnvironments(
3131
default
3232
)
3333

34+
/**
35+
* Gets the environment a server is running on or null if the server is not running in any environment
36+
*/
3437
fun of(server: Server): ServerEnvironment? {
3538
return of(server.uniqueId)
3639
}
3740

41+
/**
42+
* Gets the environment a server is running on or null if the server is not running in any environment
43+
*/
3844
fun of(uniqueId: String): ServerEnvironment? {
3945
return envs.firstOrNull {
4046
it.getServer(uniqueId)?.let { server ->
@@ -48,6 +54,9 @@ class ServerEnvironments(
4854
return envs
4955
}
5056

57+
/**
58+
* Returns the initial environment used for the server
59+
*/
5160
fun firstFor(server: Server): ServerEnvironment {
5261
return envs.firstOrNull { it.getEnvironment(server)?.let { env -> it.appliesFor(env) } ?: false } ?: default
5362
}

0 commit comments

Comments
 (0)