Permalink
Browse files

initial sample for the trader client

  • Loading branch information...
1 parent e549458 commit e2deb6202eaf1f569bec518df6ccb21afea081cb @jettro committed Jun 1, 2012
View
@@ -0,0 +1,63 @@
+package traderclient
+
+import org.vertx.groovy.core.http.RouteMatcher
+import org.vertx.groovy.core.eventbus.EventBus
+import org.vertx.groovy.core.buffer.Buffer
+
+/**
+ * @author Jettro Coenradie
+ */
+EventBus eventBus = vertx.eventBus
+def server = vertx.createHttpServer()
+//def sockJSBridgeConfig = ["prefix":"/eventbus"]
+vertx.createSockJSServer(server).bridge(prefix:'/eventbus',[[:]])
+
+def routeMatcher = new RouteMatcher()
+
+routeMatcher.get("/trades") {req ->
+ def query = ["action":"find","collection":"tradeExecutedEntry","matcher":[:]]
+ eventBus.send("vertx.mongopersistor",query) {message ->
+ def buffer = new Buffer();
+ buffer.appendBytes(new File('traderclient/header.tpl').readBytes())
+
+ buffer.appendString("<table class='table table-striped'><thead><tr><th>Company</th><th>amount</th><th>prize</th></tr></thead><tbody>")
+ def results = message.body.results
+ results.each { item ->
+ buffer.appendString("<tr><td>${item.companyName}</td><td>${item.tradeCount}</td><td>${item.tradePrice}</td></tr>")
+ }
+ buffer.appendString("</tbody></table>")
+
+ buffer.appendBytes(new File('traderclient/footer.tpl').readBytes())
+ req.response.end buffer
+ }
+}
+
+routeMatcher.get("/orders/:type") {req ->
+ def type = req.params["type"]
+ if (type == "sell")
+ req.response.end "You requested buy orders"
+ else if (type == "buy")
+ req.response.end "You requested sell orders"
+ else
+ req.response.end "You requested orders of unknown type"
+}
+
+routeMatcher.get("/") { req ->
+ req.response.sendFile("traderclient/static/index.html")
+}
+
+routeMatcher.getWithRegEx("^\\/static\\/.*") { req ->
+ req.response.sendFile("traderclient/" + req.path.substring(1))
+}
+
+//routeMatcher.noMatch{ req ->
+// req.response.end "Sorry I cannot help you"
+//}
+
+server.requestHandler(routeMatcher.asClosure()).listen(8080, "localhost")
+
+def mongoConfig = ["db_name":"axontrader"]
+
+container.with {
+ deployVerticle('mongo-persistor', mongoConfig)
+}
@@ -0,0 +1,35 @@
+package traderclient
+
+import org.vertx.groovy.core.eventbus.EventBus
+import org.vertx.groovy.core.http.RouteMatcher
+
+def server = vertx.createHttpServer()
+def routeMatcher = new RouteMatcher()
+
+routeMatcher.get("/") { req ->
+ req.response.sendFile("traderclient/static/socketDemo.html")
+}
+
+routeMatcher.getWithRegEx("^\\/static\\/.*") { req ->
+ req.response.sendFile("traderclient/" + req.path.substring(1))
+}
+
+server.requestHandler(routeMatcher.asClosure())
+
+vertx.createSockJSServer(server).bridge(prefix: '/eventbus', [[:]])
+
+server.listen(9090)
+
+EventBus eb = vertx.eventBus
+vertx.setPeriodic(1000l) {
+ def query = ["action": "find", "collection": "tradeExecutedEntry", "matcher": [:]]
+
+ eb.send("vertx.mongopersistor", query) {message ->
+ eb.send("updates.trades", message.body)
+ }
+}
+
+def mongoConfig = ["db_name": "axontrader"]
+container.with {
+ deployVerticle('mongo-persistor', mongoConfig)
+}
View
@@ -0,0 +1,8 @@
+</div> <!-- /container -->
+
+ <!-- Le javascript
+ ================================================== -->
+ <!-- Placed at the end of the document so the pages load faster -->
+ <script src="/static/js/bootstrap.min.js"></script>
+</body>
+</html>
View
@@ -0,0 +1,41 @@
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <title>Bootstrap, from Twitter</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <meta name="description" content="">
+ <meta name="author" content="">
+
+ <!-- Le styles -->
+ <link href="/static/css/bootstrap.min.css" rel="stylesheet">
+ <style>
+ body {
+ padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
+ }
+ </style>
+
+ <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
+ <!--[if lt IE 9]>
+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
+ <![endif]-->
+
+ </head>
+
+<body>
+<div class="navbar navbar-fixed-top">
+ <div class="navbar-inner">
+ <div class="container">
+ <a class="brand" href="#">Vert.x Sample</a>
+ <div class="nav-collapse">
+ <ul class="nav">
+ <li><a href="/">Home</a></li>
+ <li><a href="/trades">Trades</a></li>
+ <li><a href="/orders/sell">Sell orders</a></li>
+ <li><a href="/orders/buy">Buy orders</a></li>
+ </ul>
+ </div><!--/.nav-collapse -->
+ </div>
+ </div>
+ </div>
+
+ <div class="container">
Oops, something went wrong.

0 comments on commit e2deb62

Please sign in to comment.