summaryrefslogtreecommitdiff
path: root/odcsim-core/src/main
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2019-03-04 13:03:41 +0100
committerFabian Mastenbroek <mail.fabianm@gmail.com>2019-05-13 20:26:46 +0200
commitf0a8f3906d6f4d94900117b4d9f0bd9e58f33e10 (patch)
tree0d54cdf852c0ca409d36bf0755eb2d732985a2dc /odcsim-core/src/main
parentec89945d499e6aa1e686f2d6b6a9e13a67e02bb0 (diff)
feat: Add initial interface for parallel simulations
This change adds the initial interface design for parallel simulations, which requires explicit synchronization between actors in order to establish consistent virtual time between them.
Diffstat (limited to 'odcsim-core/src/main')
-rw-r--r--odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorContext.kt37
-rw-r--r--odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt5
2 files changed, 42 insertions, 0 deletions
diff --git a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorContext.kt b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorContext.kt
index b10287ad..deccedd1 100644
--- a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorContext.kt
+++ b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorContext.kt
@@ -56,4 +56,41 @@ interface ActorContext<T : Any> {
* @return `true` if the ref points to a child actor, otherwise `false`.
*/
fun stop(child: ActorRef<*>): Boolean
+
+ /**
+ * Synchronize the local virtual time of this target with the other referenced actor's local virtual time.
+ *
+ * By default, actors are not guaranteed to be synchronized, meaning that for some implementations, virtual time may
+ * drift between different actors. Synchronization between two actors ensures that virtual time remains consistent
+ * between at least the two actors.
+ *
+ * Be aware that this method may cause a jump in virtual time in order to get consistent with [target].
+ * Furthermore, please note that synchronization might incur performance degradation and should only be used
+ * when necessary.
+ *
+ * @param target The reference to the target actor to synchronize with.
+ */
+ fun sync(target: ActorRef<*>)
+
+ /**
+ * Desynchronize virtual time between two actors if possible.
+ *
+ * Please note that this method only provides a hint to the [ActorSystem] that it may drop synchronization between
+ * the actors, but [ActorSystem] is not compelled to actually do so (i.e. in the case where synchronization is
+ * always guaranteed).
+ *
+ * Furthermore, if [target] is already desychronized, the method should return without error. [ActorContext.isSync]
+ * may be used to determine if an actor is synchronized.
+ *
+ * @param target The reference to the target actor to desynchronize with.
+ */
+ fun unsync(target: ActorRef<*>)
+
+ /**
+ * Determine whether this actor and [target] are synchronized in virtual time.
+ *
+ * @param target The target to check for synchronization.
+ * @return `true` if [target] is synchronized with this actor, `false` otherwise.
+ */
+ fun isSync(target: ActorRef<*>): Boolean
}
diff --git a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt
index 3f01e409..bc81813b 100644
--- a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt
+++ b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt
@@ -36,6 +36,11 @@ interface ActorRef<in T : Any> {
/**
* Send the specified message to the actor referenced by this [ActorRef].
*
+ * Please note that callees must guarantee that messages are sent strictly in increasing time.
+ * If so, this method guarantees that:
+ * - A message will never be received earlier than specified
+ * - A message might arrive later than specified if the two actors are not synchronized.
+ *
* @param msg The message to send to the referenced actor.
* @param after The delay after which the message should be received by the actor.
*/