Skip to content

Commit

Permalink
Rename ActorAPI to ActorReference #34
Browse files Browse the repository at this point in the history
  • Loading branch information
Bethibande committed Apr 20, 2024
1 parent 8559d92 commit 91101e9
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.bethibande.actors.system.ActorId
* A reference to a running actor, this reference can be closed and managed independently of the actor.
* The actor will be closed when the last reference to that actor is closed.
*/
abstract class ActorAPI<C, S>(protected val actor: Actor<C, S>) {
abstract class ActorReference<C, S>(protected val actor: Actor<C, S>) {

@Volatile
protected var open = true
Expand Down Expand Up @@ -49,7 +49,7 @@ abstract class ActorAPI<C, S>(protected val actor: Actor<C, S>) {
*/
override fun equals(other: Any?): Boolean {
if (other == null) return false
if (other !is ActorAPI<*, *>) return false
if (other !is ActorReference<*, *>) return false

return actorId() == other.actorId() && actor == other.actor
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.bethibande.actors.actor

import com.bethibande.actors.Actor
import com.bethibande.actors.ActorAPI
import com.bethibande.actors.ActorReference
import com.bethibande.actors.actor.commands.*
import com.bethibande.actors.behavior.BehaviorMap
import com.bethibande.actors.system.ActorSystem
import com.bethibande.actors.system.local.LocalActorSystem
import kotlinx.coroutines.CompletableDeferred

class TestApi(actor: Actor<TestCommand, TestState>): ActorAPI<TestCommand, TestState>(actor) {
class TestReference(actor: Actor<TestCommand, TestState>): ActorReference<TestCommand, TestState>(actor) {

companion object {
val BehaviorMap = BehaviorMap<TestCommand, TestState>()
Expand All @@ -19,8 +19,8 @@ class TestApi(actor: Actor<TestCommand, TestState>): ActorAPI<TestCommand, TestS
.with(TestCommandWait::class.java, TestCommandWait)

@JvmStatic
fun localActorSystem(): ActorSystem<TestApi, TestCommand, TestState> = LocalActorSystem(
::TestApi,
fun localActorSystem(): ActorSystem<TestReference, TestCommand, TestState> = LocalActorSystem(
::TestReference,
BehaviorMap
)
}
Expand Down Expand Up @@ -57,7 +57,7 @@ class TestApi(actor: Actor<TestCommand, TestState>): ActorAPI<TestCommand, TestS
}

override fun equals(other: Any?): Boolean {
if (other !is TestApi) return false
if (other !is TestReference) return false
return other.actor == this.actor
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bethibande.actors.system

import com.bethibande.actors.actor.TestApi
import com.bethibande.actors.actor.TestReference
import com.bethibande.actors.actor.TestState
import com.bethibande.actors.actor.commands.TestCommandClose
import com.bethibande.actors.actor.commands.TestCommandWait
Expand All @@ -14,8 +14,8 @@ import org.junit.jupiter.api.Test
class LocalActorSystemTest {

private val system = LocalActorSystem(
::TestApi,
TestApi.BehaviorMap
::TestReference,
TestReference.BehaviorMap
)

private val stateA = TestState(
Expand Down
8 changes: 3 additions & 5 deletions processor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ Generated actors use no runtime-reflection, just lots of generated source-code.
- [Overview](#overview)

### Overview
For each annotated state class, commands, behaviors, api and an actor class are generated.
For each annotated state class, commands, behaviors, a reference class are generated.
Custom behaviors and commands can be added at any time, see [CustomFunctionality.kt](../example/src/main/kotlin/com/bethibande/example/person/CustomFunctionality.kt).

The generated API class is the class that should be used in applications.
It contains getter & setter functions for all the state fields.
The generated actor class is primarily for internal use and contains the actor loop,
receiving messages and passing them to the configured behavior(s).
The generated reference class is the class that should be used in applications.
It contains getter & setter functions for all the state fields.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ActorGenerator {

private fun generateActor(type: ActorStateType, environment: SymbolProcessorEnvironment) {
CommandGenerator.generate(environment, type)
APIGenerator.generate(environment, type)
ReferenceGenerator.generate(environment, type)
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.bethibande.actors.generation

import com.bethibande.actors.Actor
import com.bethibande.actors.ActorAPI
import com.bethibande.actors.ActorReference
import com.bethibande.actors.behavior.BehaviorMap
import com.bethibande.actors.struct.ActorStateField
import com.bethibande.actors.struct.ActorStateType
Expand All @@ -21,13 +21,13 @@ import com.squareup.kotlinpoet.ksp.toTypeName
import com.squareup.kotlinpoet.ksp.writeTo
import kotlinx.coroutines.CompletableDeferred

object APIGenerator: FileGenerator<ActorStateType> {
object ReferenceGenerator: FileGenerator<ActorStateType> {

private const val PROPERTY_BEHAVIOR_MAP = "BehaviorMap"
private const val CONSTRUCTOR_PROPERTY_ACTOR = "actor"

override fun generate(env: SymbolProcessorEnvironment, value: ActorStateType) {
val className = value.apiType()
val className = value.referenceType()

val constructorSpec = FunSpec.constructorBuilder()
.addParameter(CONSTRUCTOR_PROPERTY_ACTOR, value.actorType())
Expand All @@ -37,7 +37,7 @@ object APIGenerator: FileGenerator<ActorStateType> {

val companionSpec = buildCompanion(value, className)

val apiSuperClass = ActorAPI::class.asTypeName().parameterizedBy(
val apiSuperClass = ActorReference::class.asTypeName().parameterizedBy(
value.commandInterface(),
value.typeName
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ data class ActorStateType(
private val commandClose: ClassName = ClassName(commandPackage, className("CommandClose"))
private val behaviorClose: ClassName = commandClose // companion object of commandClose
private val actorType: TypeName = Actor::class.asTypeName().parameterizedBy(commandInterface, typeName)
private val apiType: ClassName = ClassName(packageName, className(""))
private val referenceType: ClassName = ClassName(packageName, className(""))

private val declaringFile: KSFile = declaration.containingFile!!

Expand All @@ -43,7 +43,7 @@ data class ActorStateType(
fun commandClose(): ClassName = commandClose
fun behaviorClose(): ClassName = behaviorClose
fun actorType(): TypeName = actorType
fun apiType(): ClassName = apiType
fun referenceType(): ClassName = referenceType

fun specBehaviorClose(): TypeSpec = specBehaviorClose

Expand Down

0 comments on commit 91101e9

Please sign in to comment.