Permalink
Browse files

Added some documentation and logging to the vertx verticles

  • Loading branch information...
1 parent 6b78afe commit b0fa09bc625521d680759830d311a2c7b0ad11e5 @jettro jettro committed Jul 2, 2012
Showing with 60 additions and 10 deletions.
  1. +26 −5 vertx-ui/trader/OrderHandler.groovy
  2. +34 −5 vertx-ui/trader/TradeWatcher.groovy
View
31 vertx-ui/trader/OrderHandler.groovy
@@ -1,23 +1,44 @@
+/*
+ * Copyright (c) 2012. Axon Framework
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+def logger = container.logger
def eventBus = vertx.eventBus
-def companies = [:]
+def companies = [:] // Map containing the names of the companies with the id of the orderbook as a key
eventBus.registerHandler("trader.trade.executed") { message ->
- println "Order: ${message.body}"
def result = message.body
+ logger.info "Received an executed trade : ${result}"
+ // Add the name of the company to the obtained result
result.tradeExecuted.companyName = companies.get(result.tradeExecuted.orderbookId)
- eventBus.send("updates.trades", message.body)
+
+ // Put a new message with the result on the event bus to send it to subscribers
+ eventBus.send("updates.trades", result)
}
def mongoConfig = ["db_name": "axontrader"]
container.with {
deployVerticle('mongo-persistor', mongoConfig, 1) {
- println "Mongo is deployed"
+ logger.info "Mongo busmod is deployed"
+
+ // Query for all orderBookEntries to fill the map with orderbookId and Company Name
def query = ["action": "find", "collection": "orderBookEntry", "matcher": [:]]
eventBus.send("vertx.mongopersistor", query) {message ->
message.body.results.each {orderbook ->
- println "Add company for orderbook: ${orderbook._id} - ${orderbook.companyName}"
+ logger.info "Add company for orderbook: ${orderbook._id} - ${orderbook.companyName}"
companies.put(orderbook._id, orderbook.companyName)
}
}
View
39 vertx-ui/trader/TradeWatcher.groovy
@@ -1,17 +1,45 @@
+/*
+ * Copyright (c) 2012. Axon Framework
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
import groovy.json.JsonSlurper
import org.vertx.groovy.core.http.RouteMatcher
+def logger = container.logger
+
def server = vertx.createHttpServer()
def routeMatcher = new RouteMatcher()
def slurper = new JsonSlurper()
-def eb = vertx.eventBus
-
+def eventBus = vertx.eventBus
+
+// Configure the router to accept POST requests to the /executed url. The request must contain a json object with the
+// event. The following code block shows what it looks like.
+//{
+// tradeExecuted :
+// {
+// orderbookId: ... ,
+// count: ... ,
+// price: ...
+// }
+//}
routeMatcher.post("/executed") { request ->
- println "received a trade executed event"
+ logger.info "received a trade executed event from the trader application"
request.bodyHandler { body ->
def received = slurper.parseText(body.toString())
- eb.send("trader.trade.executed", received)
+ eventBus.send("trader.trade.executed", received)
}
request.response.putHeader("Content-Type", "application/json")
@@ -20,11 +48,12 @@ routeMatcher.post("/executed") { request ->
server.requestHandler(routeMatcher.asClosure())
+// Setup the Sockjs connection
vertx.createSockJSServer(server).bridge(prefix: '/eventbus', [[:]])
server.listen(9090)
container.deployVerticle("OrderHandler.groovy") {
- println "OrderHandler verticle is deployed."
+ logger.info "OrderHandler verticle is deployed."
}

0 comments on commit b0fa09b

Please sign in to comment.