-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
greg
committed
Sep 20, 2023
1 parent
6ffd09c
commit 5a5e04b
Showing
6 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/LotteryApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/LotteryGame.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
4 changes: 4 additions & 0 deletions
4
cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/Ticket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
} |
11 changes: 11 additions & 0 deletions
11
cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/TicketStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
36 changes: 36 additions & 0 deletions
36
cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/nodes/LotteryGameNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
|
||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
cookbook/src/main/java/com/fluxtion/example/cookbook/lottery/nodes/TicketStoreNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |