Skip to content

Instantly share code, notes, and snippets.

@maxant
Created December 25, 2014 21:39
Show Gist options
  • Save maxant/99a429d20993a362428b to your computer and use it in GitHub Desktop.
Save maxant/99a429d20993a362428b to your computer and use it in GitHub Desktop.
The trading engine actor class.
private static class TradingEngineActor extends AbstractActor {
// STATE
private TradingEngine engine = new TradingEngine(DELAY, TIMEOUT, (type, data) -> handle(type, data), true);
public TradingEngineActor() throws NamingException {
// INBOX
receive(ReceiveBuilder
.match(SalesOrder.class, so -> {
// BEHAVIOUR (delegated to engine)
engine.addSalesOrder(so.getSeller().getName(),
so.getProductId(),
so.getRemainingQuantity(),
so.getPrice(), so.getId());
})
.match(PurchaseOrder.class, po -> {
...
.match(String.class, s -> RUN.equals(s), command -> {
engine.run();
})
.build());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment