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; public class GCD extends AbstractBehavior { public interface Message {}; public record GCDMessage(int a, int b, ActorRef cust) implements Message { } public static Behavior create() { return Behaviors.setup(GCD::new); } private GCD(ActorContext context) { super(context); } @Override public Receive createReceive() { return newReceiveBuilder() .onMessage(GCDMessage.class, this::onMsg) .build(); } private Behavior onMsg(GCDMessage msg) { if (msg.b == 0) { msg.cust.tell(new GCDReceiver.GCDResult(msg.a)); } else { this.getContext().getSelf().tell(new GCDMessage(msg.b, msg.a % msg.b, msg.cust)); } return this; } }