项目作者: Smallibs

项目描述 :
Kotlin multiplatform Actor System
高级语言: Kotlin
项目地址: git://github.com/Smallibs/aktor.git
创建时间: 2018-11-25T17:11:06Z
项目社区:https://github.com/Smallibs/aktor

开源协议:Apache License 2.0

下载


Aktor

Build Status

Multiplatform Typed Actor System written in Kotlin.

Relationship

Data relationships has been inspired by Akka System.

Data Relationships

Prototypes

Behavior

  1. typealias CoreReceiver<T> = (Actor<T>, CoreEnvelop<T>) -> Behavior<T>
  2. typealias ProtocolReceiver<T> = (Actor<T>, ProtocolEnvelop<T>) -> Behavior<T>
  3. val core: CoreReceiver<T>
  4. val protocol: ProtocolReceiver<T>
  5. fun onStart(actor: Actor<T>)
  6. fun onStop(actor: Actor<T>)
  7. fun onKill(actor: Actor<T>)

Actor

Behavior management

  1. val context: ActorContext<T>
  2. infix fun become(protocol: ProtocolBehavior<T>): Behavior<T>
  3. fun behavior(): Behavior<T> = same()
  4. fun same(): Behavior<T>
  5. fun kill() : Boolean

Actor Builder

  1. infix fun <R> actorFor(property: ActorProperty<R>): ActorReference<R>
  2. infix fun <R> actorFor(protocolReceiver: ProtocolBehavior<R>): ActorReference<R>
  3. fun <R> actorFor(protocol: ProtocolBehavior<R>, name: String): ActorReference<R>
  4. infix fun <R> actorFor(behavior: Behavior<R>): ActorReference<R>
  5. fun <R> actorFor(behavior: Behavior<R>, name: String): ActorReference<R>

ActorContext

  1. val self: ActorReference<T>
  2. fun parent(): ActorReference<*>?
  3. fun children(): Collection<ActorReference<*>>

ActorReference

  1. val address: ActorAddress
  2. infix fun tell(envelop: Envelop<T>)
  3. infix fun tell(content: T)

ActorAddress

  1. val name: String
  2. val parent: ActorAddress?
  3. infix fun childOf(address: ActorAddress): Boolean
  4. infix fun parentOf(address: ActorAddress): Boolean

Actor Assertions

tell

  1. val called = atomic("")
  2. val system = Aktor.new("example")
  3. val reference = system.actorFor<String> { a, m ->
  4. called.set(m.content)
  5. a.behavior()
  6. }
  7. reference tell "Hello World!"
  8. // called value should be "Hello World!

become

  1. val called = atomic("")
  2. val system = Aktor.new("example")
  3. val reference = system.actorFor<String> { _, m ->
  4. actor become { a, v ->
  5. called.set("$m.content $v.content")
  6. a.same()
  7. }
  8. }
  9. reference tell "Hello"
  10. reference tell "World!"
  11. // called value should be "Hello World!

create

  1. val called = atomic("")
  2. data class Create(name: String)
  3. val system = Aktor.new("example")
  4. val reference = system.actorFor<Create> { a, e ->
  5. a.actorFor<String>({ b, v ->
  6. called.set("$m.content $v.content")
  7. b.same()
  8. }, e.name)
  9. a.same()
  10. }
  11. reference tell Create("Hello")
  12. // ...

Basic Ping Pong Example

  1. data class PingPong(val sender: ActorReference<PingPong>)
  2. fun player(name: String): Receiver<PingPong> = { actor, message ->
  3. println("$name playing ...")
  4. message.content.sender tell PingPong(actor.context.self)
  5. actor.same()
  6. }
  7. fun Game() {
  8. val system = Aktor.new("test")
  9. val ping = system actorFor player("ping")
  10. val pong = system actorFor player("pong")
  11. ping tell PingPong(pong)
  12. }

License

Copyright 2019-2020 D. Plaindoux.

Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  1. http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.