Skip to content

Commit

Permalink
updated spring example
Browse files Browse the repository at this point in the history
  • Loading branch information
greg committed Sep 20, 2023
1 parent 6ffd09c commit 5a5e04b
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.fluxtion.example.cookbook.lottery;

import java.util.function.Consumer;

public interface LotteryGame {

void pickTicket();
void setResultPublisher(Consumer<String> resultPublisher);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.fluxtion.example.cookbook.lottery;

public record Ticket(int number) {
}
Original file line number Diff line number Diff line change
@@ -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<String> receiptReceiver);
}
Original file line number Diff line number Diff line change
@@ -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<String> resultPublisher;

public LotteryGameNode(){
this(new TicketStoreNode());
}

public LotteryGameNode(TicketStoreNode ticketStoreNode) {
this.ticketStoreNode = ticketStoreNode;
}

@Override
public void setResultPublisher(Consumer<String> resultPublisher) {
this.resultPublisher = resultPublisher;
}

@OnTrigger
public boolean newTicketSale(){
return false;
}

@Override
public void pickTicket() {

}
}
Original file line number Diff line number Diff line change
@@ -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<String> receiptReceiver;
private Ticket ticket;

@Override
@NoPropagateFunction
public void setTicketSalesPublisher(Consumer<String> 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;
}
}

0 comments on commit 5a5e04b

Please sign in to comment.