Menu

Tree [4b8f01] master 0.2.3 0.2.2 /
 History

HTTPS access


File Date Author Commit
 .idea 2018-05-22 Yarhoslav ME Yarhoslav ME [fb60a6] Convert project to Intellij
 src 2018-05-23 Yarhoslav ME Yarhoslav ME [8b5461] Creating Readme - Continues...
 .gitignore 2017-12-13 yarhoslavme yarhoslavme [196143] Test for SimpleMinion Class
 .travis.yml 2017-12-05 yarhoslavme yarhoslavme [bfac45] Fix Travis configuration to skip signing packages
 LICENSE 2017-01-27 Yarhoslav ME Yarhoslav ME [ef9546] Initial commit
 README.md 2018-05-23 Yarhoslav ME Yarhoslav ME [8b5461] Creating Readme - Continues...
 YMActors.iml 2018-05-22 Yarhoslav ME Yarhoslav ME [a1cc7c] Creating README file
 nbactions-allow-snapshots.xml 2017-12-05 yarhoslavme yarhoslavme [51559b] Modify POM to Upload to Central Maven Repository
 nbactions.xml 2017-01-27 Yarhoslav ME Yarhoslav ME [90734c] Initial commit
 pom.xml 2018-02-08 Yarhoslav ME Yarhoslav ME [d41f43] Add constant NAME to NULLACTOR.

Read Me

YMActors

GitHub version
Travis CI
Join the chat at https://gitter.im/YMActors/Lobby

Actors framework for Java

Goals:

  1. Create a pure/lightweight Java actor framework, easy to use.
  2. Inspired by AKKA (See Akka.io) but written from scratch.

The YMActors project gives you all tools you need to write highly resilient/elastic/multithreaded systems, easy and without all the headaches of multithreading programming. Please, refer to project's documentation for further information.

Examples

Simple "Hello World" example.

First, create one actor HelloWorldMind that can accept two messages ("Hello" and "World") and will respond accordingly.

public class HelloWorldMind extends SimpleExternalActorMind {
    private final Logger logger = LoggerFactory.getLogger(HelloWorldMind.class);

    @Override
    public void process() throws Exception {
        String msg = (String) context().envelope().message();
        logger.info("Mensaje {}", msg);

        if (msg.equals("Hello")) {
            context().myself().tell("World", context().myself());
        }
        if (msg.equals("World")) {
            context().myself().tell("Hello", context().myself());
        }
    }
}

Deeper look into the code:

SimpleExternalActorMind is an abstract class that give the Actor the ability to "understand/respond" to one or more messages. In this case, we create a new external "Mind" for the Actor that allows it to understand and respond to both messages "Hello" and "World".

public class HelloWorldMind extends SimpleExternalActorMind {

}

The new class HelloWorldMind must override the method process() and define which messages to handle.

@Override
public void process() throws Exception {
}

Now, we just take the message into a local variable. This is an optional step.

String msg = (String) context().envelope().message();

This step is very important. Here, we are telling the Actor what/how to do with messages.

We are giving to the Actor a new Mind! with "knowledge" about how interact with others actors.

if (msg.equals("Hello")) {
    context().myself().tell("World", context().myself());
}
if (msg.equals("World")) {
    context().myself().tell("Hello", context().myself());
}

At this moment, we can use the HelloWorldMind to create a new Actor into the ActorSystem and send messages to it.

ISystem system = new ActorSystem("DEMO");  //Create a System where Actors can live.
IActorRef hello = system.createActor(new HelloWorldMind(), "HELLOWORLD"); //Create an intelligent Actor with the HelloWorldMind.

To send a message to Actor hello, we just call its "tell" method:

hello.tell("Hello", null);

More examples

Here

Using YMActors framework in your code

Import as Maven library

<!-- https://mvnrepository.com/artifact/me.yarhoslav/YMActors -->
<dependency>
    <groupId>me.yarhoslav</groupId>
    <artifactId>YMActors</artifactId>
    <version>0.2.2</version>
</dependency>

Import as Jar file

YMActors-0.2.2.jar

Github releases

Check Github releases

More import options

Check this general repository

Wiki

Comming soon.

Blog

Yarhoslav's blog

In heavy development... New features every day!. Stay tuned. 👍