Created
December 30, 2014 16:25
-
-
Save maxant/d3809690e249557a65e3 to your computer and use it in GitHub Desktop.
HttpActor for handling requests and routing them to the actors encapsulating the trading engines
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
private static class HttpActor extends AbstractActor { | |
private static final HttpProtocol HTTP_1_1 = HttpProtocols.HTTP$div1$u002E1(); | |
public HttpActor() { | |
final Router router = partitionAndCreateRouter(); | |
receive(ReceiveBuilder | |
.match(HttpRequest.class, r -> { | |
int id = Constants.ID.getAndIncrement(); | |
String path = String.valueOf(r.uri().path()); | |
if("/sell".equals(path)){ | |
String productId = r.uri().query().get("productId").get(); | |
... | |
SalesOrder so = new SalesOrder(price, productId, quantity, id); | |
so.setSeller(new Seller(who)); | |
router.route(so, self()); | |
replyOK(id); | |
}else if("/buy".equals(path)){ | |
... | |
}else{ | |
handleUnexpected(r); | |
} | |
}).match(Tcp.Connected.class, r ->{ | |
sender().tell(new Http.Register(self(), Http.EmptyFastPath$.MODULE$), self()); //tell that connection will be handled here! | |
}).build()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment