Code Monkey home page Code Monkey logo

akka-spawn-protocol's Introduction

Akka Spawn Protocol

License Coverage Vulnerabilities Quality Gate Status

Uses Spawn Protocol to create Akka's Actors from outside. It can be applied at any level of the actors' hierarchy.

I was inspired by Akka's spawn protocol, but I think that any actor could be a spawner if the actor implements a method to spawn the child actors that is why I decided to extend the initial idea.

Setup

Maven Central

dependencies {
    implementation(
            'me.dmmax.akka:akka-spawn-protocol:1.1'
    )
    // ... other dependencies
}

BOM

As an alternative approach you can use BOM to manage the spawn protocol versions in one place

dependencies {
    implementation platform('me.dmmax.akka:akka-spawn-protocol-bom:1.1')
    // Don't need to specify the version for root and extensions
    implementation 'me.dmmax.akka:akka-spawn-protocol'
    implementation 'me.dmmax.akka:akka-spawn-protocol-guice'
    // ... other dependencies
}

BOM includes:

BOM Artifact
Akka spawn protocol modules me.dmmax.akka:akka-spawn-protocol-[module]
Akka BOM com.typesafe.akka:akka-bom_2.12

Example of usage

Create a spawn protocol

// Preconditions
akka.actor.ActorSystem classicActorSystem = akka.actor.ActorSystem.create();
ActorSystem<Void> actorSystem = Adapter.toTyped(classicActorSystem);
Scheduler scheduler = actorSystem.scheduler();
// Actor-specific configuration
Duration askTimeout = Duration.ofSeconds(1);
ActorRef<SpawnerActor.Command> spawnerActor = actorSystem.systemActorOf(SpawnerActor.create(), "rootActor", Props.empty());
// Create the spawn actor
SpawnProtocol<SpawnerActor.Command> spawnProtocol = new SpawnProtocol<>(scheduler, askTimeout, spawnerActor, SpawnActorCommandWrapper::new);

In addition, you need to handle the wrapper message inside the spawner actor

private <CHILD> Behavior<Command> onSpawnActor(SpawnActorCommandWrapper<CHILD> wrapper) {
    SpawnProtocols.spawnChildActor(getContext(), wrapper.spawnActorCommand());
    return this;
}

Now, it is pssible to create child actors using the SpawnProtocol

SpawnProtocol<SpawnerActor.Command> spawnProtocol = ...;
// Create a child actor
SpawnActorInfo<Ping> pingActorInfo = new SpawnActorInfo<>(PingActor.create(), ActorCreationStrategy.unique("pinger"));
ActorRef<Ping> pingActor = spawnPtocol.create(pingActorInfo);

Available extensions

Todo

I have a list of issues which I am planning to work in the nearest future. Feel free to add your own ideas there.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.