{"id":20801158,"url":"https://github.com/pothos-dev/protoactor-kotlin","last_synced_at":"2025-09-01T02:37:59.621Z","repository":{"id":129131373,"uuid":"83942797","full_name":"pothos-dev/protoactor-kotlin","owner":"pothos-dev","description":"Ultra-fast distributed actors, ported to Kotlin","archived":false,"fork":false,"pushed_at":"2017-03-05T04:48:04.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-12T02:45:22.937Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pothos-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-05T03:50:17.000Z","updated_at":"2017-03-05T03:50:24.000Z","dependencies_parsed_at":"2023-05-24T12:15:49.670Z","dependency_job_id":null,"html_url":"https://github.com/pothos-dev/protoactor-kotlin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pothos-dev/protoactor-kotlin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pothos-dev%2Fprotoactor-kotlin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pothos-dev%2Fprotoactor-kotlin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pothos-dev%2Fprotoactor-kotlin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pothos-dev%2Fprotoactor-kotlin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pothos-dev","download_url":"https://codeload.github.com/pothos-dev/protoactor-kotlin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pothos-dev%2Fprotoactor-kotlin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273067117,"owners_count":25039738,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-01T02:00:09.058Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T18:16:53.546Z","updated_at":"2025-09-01T02:37:59.600Z","avatar_url":"https://github.com/pothos-dev.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Asynchronous Actors for Kotlin\n\nThis work is in very early stages of development. It should absolutely not be used for anything serious.\n\n## What is an Actor?\nActors are self-contained workers that communicate via messages.  \nWhen an actor receives a message, it can react by performing any kind of computation, sending messages to other actors, creating other actors, manipulate its internal state or produce any kind of side-effects, like updating UI, moving a robot arm or talking to a database.\n\nActors are single-threaded, so every internal processing in the actor is inherently threadsafe. In this way, they are comparable to coroutines, but provide a more comprehensive framework to work with largely distributed and scalable systems.\n\n## Creating an Actor\n\nThe simplest way to create an actor is the `spawn` function.\n\n```kotlin\nval actor = spawn { message -\u003e\n    when (message) {\n        \n        // An example of this actor sending a message to another actor\n        is Juliet -\u003e tell(romeo, SecretMessage(\"Meet me at the balcony!\"))\n\n        // An example of this actor spawning another actor as its child\n        is Faust -\u003e spawnChild(mephisto)\n\n        // An example of this actor changing its behavior\n        // (Ungeziefer would be a behavior function just like this one)\n        is GeorgSamsa -\u003e replaceBehavior(Ungeziefer)\n    }\n}\n``` \n\nThe return value of `spawn` is a `PID` (Process identifier). This is a lightweight data object that describes how to find an actor:\n```kotlin\ndata class PID(val address: String, val id: String)\n```\n\nEach actor has an id (which can be automatically generated or chosen beforehand) and an address where it is hosted. This is usually an IP Address. We can send messages to the actor, knowing nothing more than the `PID`, by delegating all the networking concerns to the routing system of ProtoActor.\n\n## Sending messages\n\nWe have already seen a use of `tell`, the main function used to send a message to an actor.\n```kotlin\nfun tell(receiver: PID, message: Any)\n```\nMessage can be any type of object. However, **it is very important** to just use immutable data objects (often referred to as DTO, POCO or POJO), otherwise our threadsafeness-guarantees are voided. This is also required when sending messages across the network, where the messages must be serialized (via [Protobuf](https://github.com/google/protobuf)). More about this later.\n\n# Configuring Actors\n\n## The Mailbox\n\nWhen we sent a message to an actor, it first gets delivered to its mailbox. The mailbox orders messages that might come from many different threads and puts them into a queue for the actor to process. The default Mailbox uses a simple FIFO queue (first in, first out), but other implementations, such as a priority queue are available as well.\n\n## Behavior\n\nEach actor has exactly one behavior (a function which acts on the current context) at a time. But this behavior can change over time. An actor can be built like a state machine, assuming a new behavior in reaction to some message, maybe reverting back to the old behavior at a later stage.\n\n```kotlin\n// Behavior is defined as an extension method to Context, so we can directly \n// access the context from inside the funtion.\ntypealias Behavior = Context.() -\u003e Unit\n\n// Replaces the whole behavior stack with a single behavior and makes it active.\nfun Context.replaceBehavior(behavior: (Context) -\u003e Unit)\n\n// Adds the given behavior to the stack and makes it active.\nfun Context.pushBehavior(behavior: (Context) -\u003e Unit)\n\n// Removes the active behavior from the stack and makes the previous behavior active.\nfun Context.popBehavior()\n```\n\n## Supervision\n\nFailures happen. This realisation is built into the actor model. When an actor crashes, its supervisor is activated to handle the error.  \n**TODO**\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpothos-dev%2Fprotoactor-kotlin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpothos-dev%2Fprotoactor-kotlin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpothos-dev%2Fprotoactor-kotlin/lists"}