Blanko projekt
This commit is contained in:
commit
799e9adcb9
|
@ -0,0 +1,22 @@
|
|||
apply plugin: 'java'
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'application'
|
||||
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.typesafe.akka:akka-actor-typed_2.13:2.8.0'
|
||||
implementation 'ch.qos.logback:logback-classic:1.2.3'
|
||||
testImplementation 'com.typesafe.akka:akka-actor-testkit-typed_2.13:2.8.0'
|
||||
testImplementation 'junit:junit:4.13.1'
|
||||
}
|
||||
|
||||
mainClassName = "com.example.AkkaStart"
|
||||
|
||||
run {
|
||||
standardInput = System.in
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.example;
|
||||
|
||||
import akka.actor.typed.ActorRef;
|
||||
import akka.actor.typed.Behavior;
|
||||
import akka.actor.typed.javadsl.*;
|
||||
|
||||
public class AkkaMainSystem extends AbstractBehavior<AkkaMainSystem.Create> {
|
||||
|
||||
public static class Create {
|
||||
}
|
||||
|
||||
public static Behavior<Create> create() {
|
||||
return Behaviors.setup(AkkaMainSystem::new);
|
||||
}
|
||||
|
||||
private AkkaMainSystem(ActorContext<Create> context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Receive<Create> createReceive() {
|
||||
return newReceiveBuilder().onMessage(Create.class, this::onCreate).build();
|
||||
}
|
||||
|
||||
private Behavior<Create> onCreate(Create command) {
|
||||
//#create-actors
|
||||
ActorRef<ExampleActor.Message> a = this.getContext().spawn(ExampleActor.create("Alice"), "alice");
|
||||
//#create-actors
|
||||
|
||||
a.tell(new ExampleActor.ExampleMessage(this.getContext().getSelf(),"Test123"));
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.example;
|
||||
|
||||
import akka.actor.typed.ActorSystem;
|
||||
|
||||
import java.io.IOException;
|
||||
public class AkkaStart {
|
||||
public static void main(String[] args) {
|
||||
final ActorSystem<AkkaMainSystem.Create> messageMain = ActorSystem.create(AkkaMainSystem.create(), "akkaMainSystem");
|
||||
|
||||
messageMain.tell(new AkkaMainSystem.Create());
|
||||
|
||||
try {
|
||||
System.out.println(">>> Press ENTER to exit <<<");
|
||||
System.in.read();
|
||||
} catch (IOException ignored) {
|
||||
} finally {
|
||||
messageMain.terminate();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.example;
|
||||
|
||||
import akka.actor.typed.ActorRef;
|
||||
import akka.actor.typed.Behavior;
|
||||
import akka.actor.typed.javadsl.*;
|
||||
|
||||
public class ExampleActor extends AbstractBehavior<ExampleActor.Message> {
|
||||
|
||||
public interface Message {};
|
||||
|
||||
public record ExampleMessage(ActorRef<AkkaMainSystem.Create> someReference, String someString) implements Message { }
|
||||
|
||||
public static Behavior<Message> create(String name) {
|
||||
return Behaviors.setup(context -> new ExampleActor(context, name));
|
||||
}
|
||||
|
||||
private final String name;
|
||||
|
||||
private ExampleActor(ActorContext<Message> context, String name) {
|
||||
super(context);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Receive<Message> createReceive() {
|
||||
return newReceiveBuilder()
|
||||
.onMessage(ExampleMessage.class, this::onExampleMessage)
|
||||
.build();
|
||||
}
|
||||
|
||||
private Behavior<Message> onExampleMessage(ExampleMessage msg) {
|
||||
getContext().getLog().info("I ({}) got a message: ExampleMessage({},{})", this.name, msg.someReference, msg.someString);
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<!-- This is a development logging configuration that logs to standard out, for an example of a production
|
||||
logging config, see the Akka docs: https://doc.akka.io/docs/akka/2.6/typed/logging.html#logback -->
|
||||
<appender name="STDOUT" target="System.out" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>[%date{ISO8601}] [%level] [%logger] [%thread] [%X{akkaSource}] - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
|
||||
<queueSize>1024</queueSize>
|
||||
<neverBlock>true</neverBlock>
|
||||
<appender-ref ref="STDOUT" />
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="ASYNC"/>
|
||||
</root>
|
||||
|
||||
</configuration>
|
Loading…
Reference in New Issue