Compare commits
2 Commits
08f604be37
...
1e0683bfea
Author | SHA1 | Date |
---|---|---|
olhag | 1e0683bfea | |
olhag | 6493ec8d26 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,2 @@
|
|||
#Sat May 11 14:45:27 CEST 2024
|
||||
gradle.version=7.1
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,3 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="16" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="MavenRepo" />
|
||||
<option name="name" value="MavenRepo" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="MavenLocal" />
|
||||
<option name="name" value="MavenLocal" />
|
||||
<option name="url" value="file:/$MAVEN_REPOSITORY$/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="maven" />
|
||||
<option name="name" value="maven" />
|
||||
<option name="url" value="https://repo.akka.io/maven" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" project-jdk-name="16" project-jdk-type="JavaSDK" />
|
||||
</project>
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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>
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
|
@ -0,0 +1,185 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MSYS* | MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
|
@ -0,0 +1,89 @@
|
|||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
|
@ -10,44 +10,51 @@ import akka.actor.typed.javadsl.Receive;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class AddressBook extends AbstractBehavior<AddressBook.Message> {
|
||||
ArrayList<ActorRef<Customer.Message>> customers = new ArrayList<>();
|
||||
|
||||
public interface Message {}
|
||||
|
||||
//Message, wenn ein Empfänger nach einer Adresse fragt
|
||||
public record CustomerMessage(ActorRef<Customer.Message> fragender, String nameFragender,ActorRef<DeliveryCar.Message> truckReference) implements Message{}
|
||||
// Nachricht, wenn ein Empfänger nach einer Adresse fragt
|
||||
public static final class CustomerMessage implements Message {
|
||||
public final ActorRef<Customer.Message> fragender;
|
||||
public final String nameFragender;
|
||||
public final ActorRef<DeliveryCar.Message> truckReference;
|
||||
|
||||
@Override
|
||||
public Receive<AddressBook.Message> createReceive() {
|
||||
return newReceiveBuilder()
|
||||
.onMessage(CustomerMessage.class, this::onCustomerMessage)
|
||||
.build();
|
||||
public CustomerMessage(ActorRef<Customer.Message> fragender, String nameFragender, ActorRef<DeliveryCar.Message> truckReference) {
|
||||
this.fragender = fragender;
|
||||
this.nameFragender = nameFragender;
|
||||
this.truckReference = truckReference;
|
||||
}
|
||||
}
|
||||
|
||||
//create Methode mit custo = der Liste der Empfänger
|
||||
public static Behavior<AddressBook.Message> create(ArrayList<ActorRef<Customer.Message>> custo){
|
||||
return Behaviors.setup(context -> new AddressBook(context, custo));
|
||||
}
|
||||
|
||||
//Konstruktor von dem Adressbuch, in dem auch jedem Customer direkt eine Hello Nachricht geschickt wird, damit diese
|
||||
//das Adressbuch auch kennen (um nach Empfängern fragen zu können).
|
||||
private AddressBook(ActorContext<AddressBook.Message> context, ArrayList<ActorRef<Customer.Message>> custo){
|
||||
private AddressBook(ActorContext<Message> context, ArrayList<ActorRef<Customer.Message>> custo) {
|
||||
super(context);
|
||||
if(!custo.isEmpty()){
|
||||
if (!custo.isEmpty()) {
|
||||
this.customers.addAll(custo);
|
||||
for (ActorRef<Customer.Message> cst: this.customers) {
|
||||
for (ActorRef<Customer.Message> cst : this.customers) {
|
||||
cst.tell(new Customer.AddressHello(getContext().getSelf()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Methode, um einen zufälligen Empfänger auszugeben
|
||||
public Behavior<Message> onCustomerMessage(CustomerMessage msg){
|
||||
public static Behavior<Message> create(ArrayList<ActorRef<Customer.Message>> custo) {
|
||||
return Behaviors.setup(context -> new AddressBook(context, custo));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Receive<Message> createReceive() {
|
||||
return newReceiveBuilder()
|
||||
.onMessage(CustomerMessage.class, this::onCustomerMessage)
|
||||
.build();
|
||||
}
|
||||
|
||||
// Methode, um einen zufälligen Empfänger auszugeben
|
||||
private Behavior<Message> onCustomerMessage(CustomerMessage msg) {
|
||||
Random random = new Random();
|
||||
int index = random.nextInt(customers.size());
|
||||
var addressOf = customers.get(index);
|
||||
getContext().getLog().info("{} asked for an address",msg.nameFragender);
|
||||
ActorRef<Customer.Message> addressOf = customers.get(index);
|
||||
getContext().getLog().info("{} asked for an address", msg.nameFragender);
|
||||
msg.fragender.tell(new Customer.AddressMessage(addressOf, msg.truckReference));
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@ import akka.actor.typed.Behavior;
|
|||
import akka.actor.typed.javadsl.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class AkkaMainSystem extends AbstractBehavior<AkkaMainSystem.Create> {
|
||||
|
||||
|
@ -25,16 +26,35 @@ public class AkkaMainSystem extends AbstractBehavior<AkkaMainSystem.Create> {
|
|||
return newReceiveBuilder().onMessage(Create.class, this::onCreate).build();
|
||||
}
|
||||
|
||||
|
||||
private Behavior<Create> onCreate(Create command) {
|
||||
//#create-actors
|
||||
ActorRef<Customer.Message> a = this.getContext().spawn(Customer.create("Alice"), "alice");
|
||||
ActorRef<Customer.Message> b = this.getContext().spawn(Customer.create("Bob"), "bob");
|
||||
ActorRef<Customer.Message> c = this.getContext().spawn(Customer.create("Charlie"), "charlie");
|
||||
ActorRef<Customer.Message> d = this.getContext().spawn(Customer.create("Derik"), "derik");
|
||||
ActorRef<ExampleTimerActor.Message> timerActor = this.getContext().spawn(ExampleTimerActor.create(), "timeractor");
|
||||
//#create-actors
|
||||
ArrayList<ActorRef<Customer.Message>> actors = new ArrayList<>(Arrays.asList(a,b,c,d));
|
||||
ActorRef<AddressBook.Message> addressBook = this.getContext().spawn(AddressBook.create(actors), "addressbook");
|
||||
|
||||
// Erstellen des Adressbuchs
|
||||
ArrayList<ActorRef<Customer.Message>> customers = new ArrayList<>();
|
||||
ActorRef<AddressBook.Message> addressBook = getContext().spawn(AddressBook.create(customers), "addressBook");
|
||||
|
||||
// Erstellen von vier Empfänger*innen
|
||||
for (int i = 0; i < 4; i++) {
|
||||
customers.add(getContext().spawn(Customer.create("Customer" + (i + 1)), "customer" + (i + 1)));
|
||||
}
|
||||
|
||||
// Erstellen des Verteilzentrums
|
||||
ActorRef<DistributionCenter.Message> distributionCenter = getContext().spawn(DistributionCenter.create(), "distributionCenter");
|
||||
|
||||
// Erstellen von vier Wagen mit zufälligen Routen
|
||||
for (int i = 0; i < 4; i++) {
|
||||
List<ActorRef<Customer.Message>> route = new ArrayList<>(customers);
|
||||
Collections.shuffle(route);
|
||||
ActorRef<DeliveryCar.Message> truck = getContext().spawn(DeliveryCar.create(route), "truck" + (i + 1));
|
||||
// Erstellen einer leeren Paketliste
|
||||
List<Paket> paketeList = new ArrayList<>();
|
||||
paketeList.add(new Paket("Inhalt 1"));
|
||||
paketeList.add(new Paket("Inhalt 2"));
|
||||
// Beispiel für den Aufruf der ArriveMessage-Nachricht mit korrekten Parametern
|
||||
distributionCenter.tell(new DistributionCenter.ArriveMessage(paketeList, truck));
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,16 +14,30 @@ import java.util.Random;
|
|||
public class Customer extends AbstractBehavior<Customer.Message> {
|
||||
|
||||
String name;
|
||||
|
||||
ActorRef<AddressBook.Message> adrBook;
|
||||
ArrayList<String> gegenstaende = new ArrayList<>(Arrays.asList("Spülmaschine","Altes CD-Regal", "Goldbarren","20kg Hanteln", "Holzkohlegrill","Blumenerde"));
|
||||
|
||||
public interface Message {}
|
||||
|
||||
//Delivery Nachricht Typ
|
||||
public record DeliveryMessage(Paket paket) implements Message {}
|
||||
//Pickup Nachricht Typ
|
||||
public record PickUpMessage(ActorRef<DeliveryCar.Message> truckReference, String someString) implements Message {}
|
||||
public static final class DeliveryMessage implements Message {
|
||||
public final Paket paket;
|
||||
|
||||
public DeliveryMessage(Paket paket) {
|
||||
this.paket = paket;
|
||||
}
|
||||
}
|
||||
|
||||
//Pickup Nachricht Typ
|
||||
public static final class PickUpMessage implements Message {
|
||||
public final ActorRef<DeliveryCar.Message> truckReference;
|
||||
public final String someString;
|
||||
|
||||
public PickUpMessage(ActorRef<DeliveryCar.Message> truckReference, String someString) {
|
||||
this.truckReference = truckReference;
|
||||
this.someString = someString;
|
||||
}
|
||||
}
|
||||
|
||||
public record AddressHello(ActorRef<AddressBook.Message> book) implements Message {}
|
||||
public record AddressMessage(ActorRef<Customer.Message> addresse, ActorRef<DeliveryCar.Message> truckReference) implements Message {}
|
||||
|
@ -64,7 +78,7 @@ public class Customer extends AbstractBehavior<Customer.Message> {
|
|||
//truck wird hier übergeben, damit man im nächsten Schritt wieder auf ihn zugreifen kann.
|
||||
this.adrBook.tell(new AddressBook.CustomerMessage(getContext().getSelf(), this.name, msg.truckReference));
|
||||
}else{
|
||||
msg.truckReference.tell(new DeliveryCar.PickupResponse(null));
|
||||
msg.truckReference.tell(new DeliveryCar.PickupResponse(null));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -4,59 +4,78 @@ import akka.actor.typed.ActorRef;
|
|||
import akka.actor.typed.Behavior;
|
||||
import akka.actor.typed.javadsl.AbstractBehavior;
|
||||
import akka.actor.typed.javadsl.ActorContext;
|
||||
import akka.actor.typed.javadsl.Behaviors;
|
||||
import akka.actor.typed.javadsl.Receive;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
//TODO: Timer Aktivitäten müssen hinzugefügt werden
|
||||
//TODO: Delivery Nachricht für den Fall, dass der Truck ein Paket für den Customer hat, bei dem der Truck gerade ist
|
||||
//Gedanke: Eventuell mit Overseer wie in Blatt 1 arbeiten für das Einhalten der Routen
|
||||
//TODO: Pickup Nachricht an den Customer, wenn der Truck noch freie Plätze hat
|
||||
//TODO: Arrive Nachricht
|
||||
public class DeliveryCar extends AbstractBehavior<DeliveryCar.Message> {
|
||||
|
||||
ArrayList<Paket> pakete;
|
||||
ArrayList<ActorRef<Customer.Message>> route;
|
||||
private final ArrayList<Paket> pakete = new ArrayList<>();
|
||||
private final ArrayList<ActorRef<Customer.Message>> route;
|
||||
private final int maxCapacity = 3;
|
||||
|
||||
public record LoadMessage(ArrayList<Paket> pakete) implements Message{}
|
||||
public interface Message {}
|
||||
|
||||
public record PickupResponse(Paket paket) implements Message{}
|
||||
public record LoadMessage(List<Paket> pakete) implements Message {}
|
||||
|
||||
public record PickupResponse(Paket paket) implements Message {}
|
||||
|
||||
public record ContinueRoute() implements Message {}
|
||||
|
||||
private DeliveryCar(ActorContext<Message> context, ArrayList<ActorRef<Customer.Message>> route) {
|
||||
super(context);
|
||||
this.route = route;
|
||||
}
|
||||
|
||||
public static Behavior<Message> create(List<ActorRef<Customer.Message>> route) {
|
||||
return Behaviors.setup(context -> new DeliveryCar(context, new ArrayList<>(route)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Receive<Message> createReceive() {
|
||||
return newReceiveBuilder()
|
||||
.onMessage(LoadMessage.class, this::onLoadMessage)
|
||||
.onMessage(PickupResponse.class, this::onPickupResponse)
|
||||
.onMessage(ContinueRoute.class, msg -> {
|
||||
deliverPackages();
|
||||
return Behaviors.same();
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
private DeliveryCar(ActorContext<DeliveryCar.Message> context,ArrayList<ActorRef<Customer.Message>> route){
|
||||
super(context);
|
||||
this.route = route;
|
||||
|
||||
}
|
||||
|
||||
//Pakete aus dem Verteilzentrum einladen
|
||||
//TODO: Eventuell das losfahren und handlen, zu welchem Empfänger er fahren muss, mit einem Overseer Actor implementieren
|
||||
public Behavior<DeliveryCar.Message> onLoadMessage(LoadMessage msg){
|
||||
if(!msg.pakete.isEmpty()){
|
||||
this.pakete.addAll(msg.pakete);
|
||||
}
|
||||
//vielleicht sowas wie in Blatt 1 Lösung mit einem Overseer Actor und dann einem overseer Attribut im Konstruktor
|
||||
//this.overseer.tell(new Overseer.LoadedMessage()
|
||||
private Behavior<Message> onLoadMessage(LoadMessage msg) {
|
||||
pakete.addAll(msg.pakete);
|
||||
checkNextStop();
|
||||
return this;
|
||||
}
|
||||
|
||||
//Customer gibt PickupResponse entweder mit einem Paket oder ohne eins
|
||||
//Die Methode kann nur ausgeführt werden, wenn zuvor eine Pickup Nachricht an den Empfänger gesendet wurde und das
|
||||
//impliziert, dass der Truck noch Platz für weitere Pakete hat
|
||||
public Behavior<Message> onPickupResponse(PickupResponse rsp){
|
||||
if(rsp.paket != null){
|
||||
pakete.add(rsp.paket);
|
||||
getContext().getLog().info("Aktuelle Anzahl der Pakete im Truck: {}",pakete.size());
|
||||
}
|
||||
//TODO: Fall behandeln, dass kein Paket übergeben wurde (wahrscheinlich einfach Timer setzen)
|
||||
private Behavior<Message> onPickupResponse(PickupResponse rsp) {
|
||||
pakete.add(rsp.paket);
|
||||
getContext().getLog().info("Aktuelle Anzahl der Pakete im Truck: {}", pakete.size());
|
||||
checkNextStop();
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
private void checkNextStop() {
|
||||
if (pakete.size() >= maxCapacity || route.isEmpty()) {
|
||||
getContext().getSelf().tell(new ContinueRoute());
|
||||
} else {
|
||||
sendPickupMessage();
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPickupMessage() {
|
||||
ActorRef<Customer.Message> nextCustomer = route.remove(0);
|
||||
nextCustomer.tell(new Customer.PickUpMessage(getContext().getSelf(), "Some string"));
|
||||
}
|
||||
|
||||
private void deliverPackages() {
|
||||
ActorRef<Customer.Message> nextCustomer = route.get(0);
|
||||
for (Paket paket : pakete) {
|
||||
nextCustomer.tell(new Customer.DeliveryMessage(paket));
|
||||
}
|
||||
pakete.clear();
|
||||
}
|
||||
}
|
|
@ -1,21 +1,62 @@
|
|||
package com.example;
|
||||
|
||||
import akka.actor.typed.ActorRef;
|
||||
import akka.actor.typed.Behavior;
|
||||
import akka.actor.typed.javadsl.AbstractBehavior;
|
||||
import akka.actor.typed.javadsl.ActorContext;
|
||||
import akka.actor.typed.javadsl.Behaviors;
|
||||
import akka.actor.typed.javadsl.Receive;
|
||||
|
||||
//TODO: Implementierung dieser Klasse
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DistributionCenter extends AbstractBehavior<DistributionCenter.Message> {
|
||||
|
||||
public DistributionCenter(ActorContext<Message> context) {
|
||||
public static class ArriveMessage implements Message {
|
||||
private final List<Paket> pakete;
|
||||
private final ActorRef<DeliveryCar.Message> truck;
|
||||
|
||||
public ArriveMessage(List<Paket> pakete, ActorRef<DeliveryCar.Message> truck) {
|
||||
this.pakete = pakete;
|
||||
this.truck = truck;
|
||||
}
|
||||
|
||||
public List<Paket> getPakete() {
|
||||
return pakete;
|
||||
}
|
||||
|
||||
public ActorRef<DeliveryCar.Message> getTruck() {
|
||||
return truck;
|
||||
}
|
||||
}
|
||||
|
||||
private DistributionCenter(ActorContext<Message> context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
interface Message{}
|
||||
interface Message {}
|
||||
|
||||
public static Behavior<Message> create() {
|
||||
return Behaviors.setup(DistributionCenter::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Receive<Message> createReceive() {
|
||||
return newReceiveBuilder().build();
|
||||
return newReceiveBuilder()
|
||||
.onMessage(ArriveMessage.class, this::onArriveMessage)
|
||||
.build();
|
||||
}
|
||||
|
||||
private Behavior<Message> onArriveMessage(ArriveMessage msg) {
|
||||
// Füge alle Pakete aus der Ankunftsnachricht dem Lagerraum hinzu
|
||||
List<Paket> pakete = msg.getPakete();
|
||||
getContext().getLog().info("Angekommene Pakete: {}", pakete);
|
||||
|
||||
// Hier kann die weitere Logik für die Behandlung der Pakete implementiert werden
|
||||
|
||||
// Beispiel: Senden der Pakete an einen internen Akteur zur weiteren Verarbeitung
|
||||
// ...
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,28 +3,61 @@ package com.example;
|
|||
import akka.actor.typed.ActorRef;
|
||||
import akka.actor.typed.Behavior;
|
||||
import akka.actor.typed.javadsl.*;
|
||||
import akka.io.dns.internal.Message;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
import static com.example.AkkaMainSystem.*;
|
||||
|
||||
public class ExampleActor extends AbstractBehavior<ExampleActor.Message> {
|
||||
|
||||
public interface Message {};
|
||||
public interface Message {}
|
||||
|
||||
public record ExampleMessage(ActorRef<AkkaMainSystem.Create> someReference, String someString) implements Message { }
|
||||
public record ExampleMessage(ActorRef<Create> someReference, String someString) implements Message { }
|
||||
public record Customer(String name, ActorRef<akka.io.dns.internal.Message> reference) {}
|
||||
|
||||
public static Behavior<Message> create(String name) {
|
||||
return Behaviors.setup(context -> new ExampleActor(context, name));
|
||||
// Nachricht, um eine Empfängerreferenz hinzuzufügen
|
||||
public static class AddCustomer implements Message {
|
||||
private final ActorRef<Message> customer;
|
||||
|
||||
public AddCustomer(ActorRef<Message> customer) {
|
||||
this.customer = customer;
|
||||
}
|
||||
|
||||
public ActorRef<Message> getCustomer() {
|
||||
return customer;
|
||||
}
|
||||
}
|
||||
|
||||
private final String name;
|
||||
|
||||
public static class PrintCustomers implements Message {}
|
||||
private final ArrayList<ActorRef<Message>> customers; // ArrayList aller Empfänger*innen
|
||||
private final Random random;
|
||||
public static class PrintRandomCustomer implements Message {}// Nachricht, um einen zufälligen Kunden auszugeben
|
||||
|
||||
|
||||
|
||||
private ExampleActor(ActorContext<Message> context, String name) {
|
||||
super(context);
|
||||
this.name = name;
|
||||
this.customers = new ArrayList<>();
|
||||
this.random = new Random();
|
||||
}
|
||||
|
||||
public static Behavior<Message> create(String name) {
|
||||
return Behaviors.setup(context -> new ExampleActor(context, name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Receive<Message> createReceive() {
|
||||
return newReceiveBuilder()
|
||||
.onMessage(ExampleMessage.class, this::onExampleMessage)
|
||||
.onMessage(AddCustomer.class, this::onAddCustomer)
|
||||
.onMessage(PrintCustomers.class, this::onPrintCustomers)
|
||||
.onMessage(PrintRandomCustomer.class, this::onPrintRandomCustomer)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@ -32,4 +65,27 @@ public class ExampleActor extends AbstractBehavior<ExampleActor.Message> {
|
|||
getContext().getLog().info("I ({}) got a message: ExampleMessage({},{})", this.name, msg.someReference, msg.someString);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Behavior<Message> onAddCustomer(AddCustomer msg) {
|
||||
customers.add(msg.getCustomer());
|
||||
return this;
|
||||
}
|
||||
|
||||
private Behavior<Message> onPrintCustomers(PrintCustomers msg) {
|
||||
for (ActorRef<Message> customer : customers) {
|
||||
getContext().getLog().info("Customer: {}", customer.path().name());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private Behavior<Message> onPrintRandomCustomer(PrintRandomCustomer msg) {
|
||||
if (!customers.isEmpty()) {
|
||||
int randomIndex = random.nextInt(customers.size());
|
||||
ActorRef<Message> randomCustomer = customers.get(randomIndex);
|
||||
getContext().getLog().info("Random Customer: {}", randomCustomer.path().name());
|
||||
} else {
|
||||
getContext().getLog().info("No customers available.");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -2,14 +2,24 @@ package com.example;
|
|||
|
||||
import akka.actor.typed.ActorRef;
|
||||
|
||||
|
||||
public class Paket {
|
||||
String inhalt;
|
||||
String absender;
|
||||
ActorRef<Customer.Message> empfaenger;
|
||||
|
||||
Paket(String inhalt, String absender, ActorRef<Customer.Message> empfaenger){
|
||||
// Konstruktor, der nur den Inhalt annimmt
|
||||
Paket(String inhalt) {
|
||||
this.inhalt = inhalt;
|
||||
this.absender = null; // Absender und Empfänger können optional sein
|
||||
this.empfaenger = null;
|
||||
}
|
||||
|
||||
// Konstruktor mit allen Parametern
|
||||
Paket(String inhalt, String absender, ActorRef<Customer.Message> empfaenger) {
|
||||
this.inhalt = inhalt;
|
||||
this.absender = absender;
|
||||
this.empfaenger = empfaenger;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue