From baf99dc266ccfd6506d2b6a7a4652fe3cfde5959 Mon Sep 17 00:00:00 2001 From: Dico Date: Sun, 26 Aug 2018 19:52:41 +0100 Subject: Refactor some stuff, make classes that really dont need to be sealed something else --- .../io/dico/parcels2/blockvisitor/WorktimeLimiter.kt | 18 +++++++++--------- .../io/dico/parcels2/storage/exposed/IdTables.kt | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/io/dico/parcels2/blockvisitor/WorktimeLimiter.kt b/src/main/kotlin/io/dico/parcels2/blockvisitor/WorktimeLimiter.kt index 30eaabd..33ac351 100644 --- a/src/main/kotlin/io/dico/parcels2/blockvisitor/WorktimeLimiter.kt +++ b/src/main/kotlin/io/dico/parcels2/blockvisitor/WorktimeLimiter.kt @@ -17,22 +17,22 @@ typealias WorkerUpdateLister = Worker.(Double, Long) -> Unit data class TickWorktimeOptions(var workTime: Int, var tickInterval: Int) -sealed class WorktimeLimiter { +interface WorktimeLimiter { /** * Submit a [task] that should be run synchronously, but limited such that it does not stall the server * a bunch */ - abstract fun submit(task: TimeLimitedTask): Worker + fun submit(task: TimeLimitedTask): Worker /** * Get a list of all workers */ - abstract val workers: List + val workers: List /** * Attempts to complete any remaining tasks immediately, without suspension. */ - abstract fun completeAllTasks() + fun completeAllTasks() } interface Timed { @@ -94,7 +94,7 @@ interface WorkerScope : Timed { fun setProgress(progress: Double) } -private interface WorkerContinuation : Worker, WorkerScope { +interface WorkerInternal : Worker, WorkerScope { /** * Start or resumes the execution of this worker * and returns true if the worker completed @@ -113,15 +113,15 @@ private interface WorkerContinuation : Worker, WorkerScope { * There is a configurable maxiumum amount of milliseconds that can be allocated to all workers together in each server tick * This object attempts to split that maximum amount of milliseconds equally between all jobs */ -class TickWorktimeLimiter(private val plugin: ParcelsPlugin, var options: TickWorktimeOptions) : WorktimeLimiter() { +class TickWorktimeLimiter(private val plugin: ParcelsPlugin, var options: TickWorktimeOptions) : WorktimeLimiter { // The currently registered bukkit scheduler task private var bukkitTask: BukkitTask? = null // The workers. - private val _workers = LinkedList() + private val _workers = LinkedList() override val workers: List = _workers override fun submit(task: TimeLimitedTask): Worker { - val worker: WorkerContinuation = WorkerImpl(plugin.functionHelper, task) + val worker: WorkerInternal = WorkerImpl(plugin.functionHelper, task) _workers.addFirst(worker) if (bukkitTask == null) bukkitTask = plugin.functionHelper.scheduleRepeating(0, options.tickInterval) { tickJobs() } return worker @@ -166,7 +166,7 @@ class TickWorktimeLimiter(private val plugin: ParcelsPlugin, var options: TickWo } private class WorkerImpl(val functionHelper: FunctionHelper, - val task: TimeLimitedTask) : WorkerContinuation { + val task: TimeLimitedTask) : WorkerInternal { override var job: Job? = null; private set override val elapsedTime diff --git a/src/main/kotlin/io/dico/parcels2/storage/exposed/IdTables.kt b/src/main/kotlin/io/dico/parcels2/storage/exposed/IdTables.kt index 33314aa..0aa4ba0 100644 --- a/src/main/kotlin/io/dico/parcels2/storage/exposed/IdTables.kt +++ b/src/main/kotlin/io/dico/parcels2/storage/exposed/IdTables.kt @@ -11,7 +11,7 @@ import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.statements.UpdateBuilder import java.util.UUID -sealed class IdTransactionsTable, QueryObj>(tableName: String, columnName: String) +abstract class IdTransactionsTable, QueryObj>(tableName: String, columnName: String) : Table(tableName) { val id = integer(columnName).autoIncrement().primaryKey() -- cgit v1.2.3