class Account extends BaseActor {
public static final Logout logout = new Logout();
static final LoginSuccess success = new LoginSuccess();
final String login;
String password;
{
behavior(State.FREE)
.Case(
auth -> {
if(password.equals(auth.password)) {
reply(success);
become(State.AUTH);
} else
reply(LoginFail.WRONG_PASSWORD);
},
Auth.class
);
behavior(State.AUTH)
.Case(
auth -> reply(LoginFail.IN_USE),
Auth.class
)
.Case(
logout -> become(State.FREE),
Logout.class
);
...
}
enum State {
FREE,
AUTH,
BLOCK,
...
}
public static class Auth {
final String password;
}
public static class LoginSuccess {
}
public static class Logout {
}
public static enum LoginFail {
IN_USE,
WRONG_PASSWORD,
....
}
}
public static void main(String...args) {
ActorSystem.launch(system -> {
system.create(Ping.class, "ping", system.create(Pong.class, "pong"));
});
}
system.create(Pong.class, "pong")
system.create(Ping.class, "ping", system.create(Pong.class, "pong"))
public Ping(Actor actor) {
pong = actor;
}
public static void main(String...args) {
ActorSystem.launch(new Consumer<Actor>() {
@Override
public void accept(Actor system) {
Actor pong = system.create(Pong.class, "pong");
Actor ping = system.create(Ping.class, "ping", pong);
}
});
}
IBehavior behavior = behavior();
behavior.Case(value -> {
...произвести действия
}, Integer.class);
become(behavior);
public static class Pong extends BaseActor {
{
become(
behavior().
Case(
value -> {
System.out.println(value);
sender().send("pong", 1000);
},
String.class
)
);
}
}
public static class Ping extends BaseActor {
Actor pong;
public Ping(Actor actor) {
pong = actor;
}
{
become(
behavior().
Define(
d -> pong.send("ping")
).
Case(
value -> {
System.out.println(value);
pong.send("ping", 1000);
},
String.class
)
);
}
}
behavior().
Case(
define -> {
pong.send("ping")
},
Actor.Define.class
);
send(1);
send(1, 2, 3, 4);
public void define() {
}
public class Define {
public void define() {
System.out.println("hello actor!");
}
public static void main(String...args) {
Model.launch(new Define());
}
}
public class Console implements Context {
public void define() {
final Reference console = create("console", System.out);
for(char c : "hello world!".toCharArray())
console.send("println", c);
}
public static void main(String...args) {
Model.launch(new Console());
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?