Browse files

added enum

  • Loading branch information...
1 parent 344d0ff commit 0ed32d5b3f5c71b41c7589cc59c89bce031be27c @leonlee committed Dec 16, 2012
View
5 build.gradle
@@ -97,5 +97,10 @@ subprojects {
}
}
+configure(subprojects.findAll {it.name != 'common'}) {
+ dependencies {
+ compile project(':common')
+ }
+}
View
0 common/gradle.properties
No changes.
View
19 common/src/main/groovy/org/riderzen/ogs/common/AE.groovy
@@ -0,0 +1,19 @@
+package org.riderzen.ogs.common
+
+/**
+ * User: Leon Lee <mail.lgq@gmail.com>
+ * Date: 12-12-16
+ */
+enum AE {
+ appProtocol("org.riderzen.ogs.protocol")
+ public String val;
+
+ AE(String val) {
+ this.val = val
+ }
+
+ @Override
+ public String toString() {
+ return val;
+ }
+}
View
8 protocol/src/main/groovy/org/riderzen/ogs/protocol/ProtocolParser.groovy
@@ -12,6 +12,7 @@ import org.vertx.java.core.buffer.Buffer
import org.vertx.java.core.eventbus.Message
import org.vertx.java.core.parsetools.RecordParser
import com.google.gson.Gson
+import org.riderzen.ogs.common.AE
/**
* User: Leon Lee <mail.lgq@gmail.com>
@@ -29,7 +30,7 @@ class ProtocolParser extends BusModBase {
}
def init() {
- address = getOptionalStringConfig("address", "org.riderzen.ogs.protocol")
+ address = getOptionalStringConfig("address", AE.appProtocol.val)
def msgHandler = { Buffer message ->
@@ -50,6 +51,11 @@ class ProtocolParser extends BusModBase {
logger.debug("message: $gson")
println("message: $tokens")
+
+ Buffer result = new Buffer("OK".getBytes())
+ event.reply(result)
+
+ logger.debug("result was sent")
}
})
}
View
13 protocol/src/test/groovy/org/riderzen/ogs/protocol/ProtocolParserTest.groovy
@@ -7,7 +7,9 @@ import org.msgpack.MessagePack
import org.msgpack.packer.Packer
import org.slf4j.Logger
import org.slf4j.LoggerFactory
+import org.vertx.java.core.Handler
import org.vertx.java.core.buffer.Buffer
+import org.vertx.java.core.eventbus.Message
import org.vertx.java.test.TestVerticle
import org.vertx.java.test.VertxConfiguration
import org.vertx.java.test.VertxTestBase
@@ -20,7 +22,7 @@ import org.vertx.java.test.junit.VertxJUnit4ClassRunner
@RunWith(VertxJUnit4ClassRunner.class)
@VertxConfiguration
//@TestModule(name = 'org.riderzen.ogs.protocol-v1.0')
-@TestVerticle(main = 'deployer.js')
+@TestVerticle(main = 'deployer.js',worker = true)
class ProtocolParserTest extends VertxTestBase {
static Logger logger = LoggerFactory.getLogger(ProtocolParserTest.class)
long timeout = 10L
@@ -38,8 +40,13 @@ class ProtocolParserTest extends VertxTestBase {
packer.write("['hello', [1, 2, 3, 'world']]")
- getVertx().eventBus().send("org.riderzen.ogs.protocol", new Buffer(packer.toByteArray()))
-
+ getVertx().eventBus().send("org.riderzen.ogs.protocol", new Buffer(packer.toByteArray()), new Handler<Message<Buffer>>() {
+ @Override
+ void handle(Message<Buffer> event) {
+ logger.debug("result: ${event.body.toString()}")
+ }
+ })
+ logger.debug("the message was sent")
}
}
View
2 settings.gradle
@@ -1 +1 @@
-include 'bootstrap', 'tcp-server', 'protocol'
+include 'common', 'bootstrap', 'tcp-server', 'protocol'
View
2 tcp-server/build.gradle
@@ -0,0 +1,2 @@
+dependencies {
+}
View
6 tcp-server/src/main/groovy/org/riderzen/ogs/tcp/TcpServer.groovy
@@ -1,7 +1,7 @@
package org.riderzen.ogs.tcp
import org.vertx.java.busmods.BusModBase
-
+import org.riderzen.ogs.common.AE
/**
* User: Leon Lee <mail.lgq@gmail.com>
* Date: 12-12-7
@@ -22,7 +22,9 @@ class TcpServer extends BusModBase {
def onConnected = { sock ->
sock.dataHandler { buffer ->
logger.debug("received ${buffer.lenght} bytes of data")
- eb.publish("app.protocol", buffer)
+ eb.send(AE.appProtocol.val, buffer) { message ->
+ sock << message
+ }
}
sock.exceptionHandler { e ->
logger.error("caught error", e)

0 comments on commit 0ed32d5

Please sign in to comment.