Skip to content

Commit

Permalink
v0.11.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
holgerbrandl committed Aug 31, 2023
1 parent 53a2235 commit 4ca2620
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ plugins {

group = "com.github.holgerbrandl"
//version = "0.8.101"
version = "0.11"
//version = "0.11-SNAPSHOT"
version = "0.11.1"
//version = "0.12-SNAPSHOT"


repositories {
Expand Down
2 changes: 1 addition & 1 deletion docs/userguide/docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
To get started simply add it as a dependency:
```
dependencies {
implementation "com.github.holgerbrandl:kalasim:0.11"
implementation "com.github.holgerbrandl:kalasim:0.11.1"
}
```

Expand Down
39 changes: 29 additions & 10 deletions src/main/kotlin/org/kalasim/State.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package org.kalasim

import org.kalasim.analysis.*
import org.kalasim.analysis.EntityCreatedEvent
import org.kalasim.analysis.StateChangedEvent
import org.kalasim.analysis.snapshot.StateSnapshot
import org.kalasim.misc.*
import org.kalasim.monitors.*
import org.kalasim.misc.DependencyContext
import org.kalasim.misc.StateTrackingConfig
import org.kalasim.monitors.CategoryTimeline
import org.kalasim.monitors.MetricTimeline
import org.kalasim.monitors.NumericStatisticMonitor
import org.koin.core.Koin

/**
Expand All @@ -16,7 +20,7 @@ import org.koin.core.Koin
open class State<T>(
initialValue: T,
name: String? = null,
koin: Koin = DependencyContext.get()
koin: Koin = DependencyContext.get(),
) : SimulationEntity(name, koin) {

private var maxTriggerCxt: Int? = null
Expand All @@ -40,7 +44,7 @@ open class State<T>(

field = value

changeListeners.forEach{ it.stateChanged(this)}
changeListeners.forEach { it.stateChanged(this) }

timeline.addValue(value)

Expand Down Expand Up @@ -116,21 +120,36 @@ open class State<T>(
maxTriggerCxt = null
}

// private fun tryWait(maxHonor: Int = Int.MAX_VALUE) {
// private fun tryWait(maxHonor: Int = Int.MAX_VALUE) {
// var mx = maxHonor
// waiters.q.map { it.component }.takeWhile {
// // wait max times but consider honor return state of tryWait
// if(it.tryWait()) mx--
// mx > 0
// }
// }
// throws concurrent modification exception
// private fun tryWait(maxHonor: Int = Int.MAX_VALUE) {
// var remainingHonor = maxHonor
// val iterator = waiters.q.iterator()
//
// while (remainingHonor > 0 && iterator.hasNext()) {
// val waiter = iterator.next().component
// if (waiter.tryWait()) {
// remainingHonor--
// }
// }
// }
private fun tryWait(maxHonor: Int = Int.MAX_VALUE) {
val copyOfQ = ArrayList(waiters.q) // Make a copy of the collection
var remainingHonor = maxHonor
val iterator = waiters.q.iterator()

while (remainingHonor > 0 && iterator.hasNext()) {
val waiter = iterator.next().component
if (waiter.tryWait()) {
for(waiter in copyOfQ) {
val component = waiter.component
if(remainingHonor <= 0) {
break
}
if(component.tryWait()) {
remainingHonor--
}
}
Expand Down

0 comments on commit 4ca2620

Please sign in to comment.