File | Date | Author | Commit |
---|---|---|---|
.idea | 2018-05-22 | Yarhoslav ME | [fb60a6] Convert project to Intellij |
src | 2018-05-23 | Yarhoslav ME | [8b5461] Creating Readme - Continues... |
.gitignore | 2017-12-13 | yarhoslavme | [196143] Test for SimpleMinion Class |
.travis.yml | 2017-12-05 | yarhoslavme | [bfac45] Fix Travis configuration to skip signing packages |
LICENSE | 2017-01-27 | Yarhoslav ME | [ef9546] Initial commit |
README.md | 2018-05-23 | Yarhoslav ME | [8b5461] Creating Readme - Continues... |
YMActors.iml | 2018-05-22 | Yarhoslav ME | [a1cc7c] Creating README file |
nbactions-allow-snapshots.xml | 2017-12-05 | yarhoslavme | [51559b] Modify POM to Upload to Central Maven Repository |
nbactions.xml | 2017-01-27 | Yarhoslav ME | [90734c] Initial commit |
pom.xml | 2018-02-08 | Yarhoslav ME | [d41f43] Add constant NAME to NULLACTOR. |
Goals:
- Create a pure/lightweight Java actor framework, easy to use.
- 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.
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);
<!-- https://mvnrepository.com/artifact/me.yarhoslav/YMActors -->
<dependency>
<groupId>me.yarhoslav</groupId>
<artifactId>YMActors</artifactId>
<version>0.2.2</version>
</dependency>
Check Github releases
Check this general repository
Comming soon.
In heavy development... New features every day!. Stay tuned. 👍