diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2019-05-13 20:28:56 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2019-05-14 12:55:57 +0200 |
| commit | 03acc77d4f2841ea66a9200ab170e33a2d0518aa (patch) | |
| tree | c4d6d8cfa2e47032fe941939a808d92e011542a8 /odcsim-engine-omega/src | |
| parent | 91ea74177ec4cd586036a2151933218e8f39866f (diff) | |
feat: Add support for Async Stacktraces in IntelliJ
Diffstat (limited to 'odcsim-engine-omega/src')
| -rw-r--r-- | odcsim-engine-omega/src/main/kotlin/com/atlarge/odcsim/engine/omega/OmegaActorSystem.kt | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/odcsim-engine-omega/src/main/kotlin/com/atlarge/odcsim/engine/omega/OmegaActorSystem.kt b/odcsim-engine-omega/src/main/kotlin/com/atlarge/odcsim/engine/omega/OmegaActorSystem.kt index ec088b98..dd92f90a 100644 --- a/odcsim-engine-omega/src/main/kotlin/com/atlarge/odcsim/engine/omega/OmegaActorSystem.kt +++ b/odcsim-engine-omega/src/main/kotlin/com/atlarge/odcsim/engine/omega/OmegaActorSystem.kt @@ -39,8 +39,7 @@ import com.atlarge.odcsim.Terminated import com.atlarge.odcsim.empty import com.atlarge.odcsim.internal.BehaviorInterpreter import com.atlarge.odcsim.internal.logging.LoggerImpl -import com.sun.org.apache.xalan.internal.lib.ExsltDatetime.time -import com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl +import org.jetbrains.annotations.Async import org.slf4j.Logger import java.util.Collections import java.util.PriorityQueue @@ -100,7 +99,7 @@ class OmegaActorSystem<in T : Any>(guardianBehavior: Behavior<T>, override val n init { registry[system] = Actor(ActorRefImpl(this, system), empty<Nothing>()) registry[path] = Actor(this, guardianBehavior) - schedule(this, PreStart, .0) + schedule(path, PreStart, .0) } override fun run(until: Duration) { @@ -131,10 +130,7 @@ class OmegaActorSystem<in T : Any>(guardianBehavior: Behavior<T>, override val n time = delivery queue.poll() - val actor = registry[envelope.destination] ?: continue - - // Notice that messages for unknown/terminated actors are ignored for now - actor.isolate { it.interpretMessage(envelope.message) } + processEnvelope(envelope) } // Jump forward in time as the caller expects the system to have run until the specified instant @@ -142,7 +138,7 @@ class OmegaActorSystem<in T : Any>(guardianBehavior: Behavior<T>, override val n time = max(time, until) } - override fun send(msg: T, after: Duration) = schedule(this, msg, after) + override fun send(msg: T, after: Duration) = schedule(path, msg, after) override fun terminate() { registry[path]?.stop(null) @@ -161,6 +157,35 @@ class OmegaActorSystem<in T : Any>(guardianBehavior: Behavior<T>, override val n private var nextId: Long = 0 /** + * Schedule a message to be processed by the engine. + * + * @param path The path to the destination of the message. + * @param message The message to schedule. + * @param delay The time to wait before processing the message. + */ + private fun schedule(@Async.Schedule path: ActorPath, message: Any, delay: Duration) { + require(delay >= .0) { "The given delay must be a non-negative number" } + scheduleEnvelope(EnvelopeImpl(nextId++, path, time + delay, message)) + } + + /** + * Schedule the specified envelope to be processed by the engine. + */ + private fun scheduleEnvelope(@Async.Schedule envelope: EnvelopeImpl) { + queue.add(envelope) + } + + /** + * Process the delivery of a message. + */ + private fun processEnvelope(@Async.Execute envelope: EnvelopeImpl) { + val actor = registry[envelope.destination] ?: return + + // Notice that messages for unknown/terminated actors are ignored for now + actor.isolate { it.interpretMessage(envelope.message) } + } + + /** * An actor as represented in the Omega engine. * * @param self The [ActorRef] to this actor. @@ -184,7 +209,7 @@ class OmegaActorSystem<in T : Any>(guardianBehavior: Behavior<T>, override val n override fun getChild(name: String): ActorRef<*>? = childActors[name]?.self - override fun <U : Any> send(ref: ActorRef<U>, msg: U, after: Duration) = schedule(ref, msg, after) + override fun <U : Any> send(ref: ActorRef<U>, msg: U, after: Duration) = schedule(ref.path, msg, after) override fun <U : Any> spawn(behavior: Behavior<U>, name: String): ActorRef<U> { require(name.isNotEmpty()) { "Actor name may not be empty" } @@ -203,7 +228,7 @@ class OmegaActorSystem<in T : Any>(guardianBehavior: Behavior<T>, override val n val actor = Actor(ref, behavior) registry[ref.path] = actor childActors[name] = actor - schedule(ref, PreStart, .0) + schedule(ref.path, PreStart, .0) actor.start() return ref } @@ -332,27 +357,4 @@ class OmegaActorSystem<in T : Any>(guardianBehavior: Behavior<T>, override val n override val time: Instant, override val message: Any ) : Envelope<Any> - - /** - * Schedule a message to be processed by the engine. - * - * @param destination The destination of the message. - * @param message The message to schedule. - * @param delay The time to wait before processing the message. - */ - private fun schedule(destination: ActorRef<*>, message: Any, delay: Duration) { - schedule(destination.path, message, delay) - } - - /** - * Schedule a message to be processed by the engine. - * - * @param path The path to the destination of the message. - * @param message The message to schedule. - * @param delay The time to wait before processing the message. - */ - private fun schedule(path: ActorPath, message: Any, delay: Duration) { - require(delay >= .0) { "The given delay must be a non-negative number" } - queue.add(EnvelopeImpl(nextId++, path, time + delay, message)) - } } |
