From 5a5e04b0a1a3e869026b20a581079d7b4a3df73e Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 20 Sep 2023 18:47:10 +0100 Subject: [PATCH] updated spring example --- .../example/cookbook/lottery/LotteryApp.java | 13 +++++ .../example/cookbook/lottery/LotteryGame.java | 9 ++++ .../example/cookbook/lottery/Ticket.java | 4 ++ .../example/cookbook/lottery/TicketStore.java | 11 ++++ .../lottery/nodes/LotteryGameNode.java | 36 +++++++++++++ .../lottery/nodes/TicketStoreNode.java | 53 +++++++++++++++++++ 6 files changed, 126 insertions(+) create mode 100644 cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/LotteryApp.java create mode 100644 cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/LotteryGame.java create mode 100644 cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/Ticket.java create mode 100644 cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/TicketStore.java create mode 100644 cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/nodes/LotteryGameNode.java create mode 100644 cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/nodes/TicketStoreNode.java diff --git a/cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/LotteryApp.java b/cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/LotteryApp.java new file mode 100644 index 0000000..e2cd46c --- /dev/null +++ b/cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/LotteryApp.java @@ -0,0 +1,13 @@ +package com.fluxtion.example.cookbook.lottery; + +import com.fluxtion.compiler.Fluxtion; +import com.fluxtion.example.cookbook.lottery.nodes.LotteryGameNode; +import com.fluxtion.runtime.EventProcessor; + +public class LotteryApp { + + public void start(){ + EventProcessor lotteryGame = Fluxtion.interpret(new LotteryGameNode()); +// lotteryGame.getExportedService() + } +} diff --git a/cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/LotteryGame.java b/cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/LotteryGame.java new file mode 100644 index 0000000..c361cf2 --- /dev/null +++ b/cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/LotteryGame.java @@ -0,0 +1,9 @@ +package com.fluxtion.example.cookbook.lottery; + +import java.util.function.Consumer; + +public interface LotteryGame { + + void pickTicket(); + void setResultPublisher(Consumer resultPublisher); +} diff --git a/cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/Ticket.java b/cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/Ticket.java new file mode 100644 index 0000000..752677f --- /dev/null +++ b/cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/Ticket.java @@ -0,0 +1,4 @@ +package com.fluxtion.example.cookbook.lottery; + +public record Ticket(int number) { +} diff --git a/cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/TicketStore.java b/cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/TicketStore.java new file mode 100644 index 0000000..7b41512 --- /dev/null +++ b/cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/TicketStore.java @@ -0,0 +1,11 @@ +package com.fluxtion.example.cookbook.lottery; + +import java.util.function.Consumer; + +public interface TicketStore { + boolean buyTicket(Ticket ticket); + void openStore(); + void closeStore(); + + void setTicketSalesPublisher(Consumer receiptReceiver); +} diff --git a/cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/nodes/LotteryGameNode.java b/cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/nodes/LotteryGameNode.java new file mode 100644 index 0000000..e65ae5a --- /dev/null +++ b/cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/nodes/LotteryGameNode.java @@ -0,0 +1,36 @@ +package com.fluxtion.example.cookbook.lottery.nodes; + +import com.fluxtion.example.cookbook.lottery.LotteryGame; +import com.fluxtion.runtime.annotations.ExportService; +import com.fluxtion.runtime.annotations.OnTrigger; + +import java.util.function.Consumer; + +public class LotteryGameNode implements @ExportService LotteryGame { + + private final TicketStoreNode ticketStoreNode; + private Consumer resultPublisher; + + public LotteryGameNode(){ + this(new TicketStoreNode()); + } + + public LotteryGameNode(TicketStoreNode ticketStoreNode) { + this.ticketStoreNode = ticketStoreNode; + } + + @Override + public void setResultPublisher(Consumer resultPublisher) { + this.resultPublisher = resultPublisher; + } + + @OnTrigger + public boolean newTicketSale(){ + return false; + } + + @Override + public void pickTicket() { + + } +} diff --git a/cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/nodes/TicketStoreNode.java b/cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/nodes/TicketStoreNode.java new file mode 100644 index 0000000..6da0df8 --- /dev/null +++ b/cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/nodes/TicketStoreNode.java @@ -0,0 +1,53 @@ +package com.fluxtion.example.cookbook.lottery.nodes; + +import com.fluxtion.example.cookbook.lottery.Ticket; +import com.fluxtion.example.cookbook.lottery.TicketStore; +import com.fluxtion.runtime.annotations.ExportService; +import com.fluxtion.runtime.annotations.NoPropagateFunction; +import com.fluxtion.runtime.annotations.Start; + +import java.util.Objects; +import java.util.function.Consumer; + +public class TicketStoreNode implements @ExportService TicketStore { + + private boolean storeOpen; + private Consumer receiptReceiver; + private Ticket ticket; + + @Override + @NoPropagateFunction + public void setTicketSalesPublisher(Consumer receiptReceiver) { + this.receiptReceiver = receiptReceiver; + } + + @Start + public void start(){ + Objects.requireNonNull(receiptReceiver, "must have a receipt publisher set"); + storeOpen = false; + } + + @Override + public boolean buyTicket(Ticket ticket) { + if(storeOpen){ + this.ticket = ticket; + } + return storeOpen; + } + + public Ticket lastTicketSold(){ + return ticket; + } + + @Override + @NoPropagateFunction + public void openStore() { + storeOpen = true; + } + + @Override + @NoPropagateFunction + public void closeStore() { + storeOpen = false; + } +}