Skip to content

Commit

Permalink
Fix #75
Browse files Browse the repository at this point in the history
  • Loading branch information
Woohyeok Choi committed Oct 23, 2020
1 parent 83fce1e commit 15dc641
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/src/main/kotlin/kaist/iclab/abclogger/commons/Errors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,14 @@ open class CollectorError(
qualifiedName = qualifiedName
)

class TurningOnRequestWhenUnavailable(override val qualifiedName: String) : CollectorError(
R.string.error_collector_turning_on_request_when_unavailable,
qualifiedName = qualifiedName
)

companion object {
fun notFound(qualifiedName: String) = NotFound(qualifiedName)
fun turningOnRequestWhenUnavaiable(qualifiedName: String) = TurningOnRequestWhenUnavailable(qualifiedName)
fun changeSettingDuringOperating(qualifiedName: String) =
SettingChangedDuringOperating(qualifiedName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ abstract class AbstractCollector<E : AbstractEntity>(
abstract suspend fun list(limit: Long): Collection<E>

fun start() {
if (!isAvailable()) {
stop(CollectorError.turningOnRequestWhenUnavaiable(qualifiedName))
}

isEnabled = true

lastErrorMessage = ""
Expand All @@ -134,7 +138,7 @@ abstract class AbstractCollector<E : AbstractEntity>(
/**
* function stop is called only by a user's explicit interaction.
*/
fun stop() {
fun stop(throwable: Throwable? = null) {
isEnabled = false

turnedOnTime = Long.MIN_VALUE
Expand All @@ -143,6 +147,7 @@ abstract class AbstractCollector<E : AbstractEntity>(

launch {
onStop()
if (throwable != null) throw throwable
}

scope.cancel()
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@
<string name="error_collector">Collector error</string>
<string name="error_collector_not_found">Corresponding collector not found.</string>
<string name="error_collector_change_setting_during_operating">Cannot change settings during operating.</string>
<string name="error_collector_turning_on_request_when_unavailable">Invalid request for turning on a collector due to unavailability of data collection.</string>

</resources>

0 comments on commit 15dc641

Please sign in to comment.