Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updated to Vert.x 1.2.3

  • Loading branch information...
commit 4bb794327b911a097e86caa10cf7775f204ead2f 1 parent add2d7e
@ohneda ohneda authored
View
10 option8_vertx/README.md
@@ -1,5 +1,5 @@
This is the classic [Backbone Todos app](http://addyosmani.github.com/todomvc),
-backended by a Vert.x EventBus.
+backended by a Vert.x EventBus.
This sample app will show you how to keep collections synced in realtime in different browsers with Vert.x EventBus.
### Dependencies
@@ -8,8 +8,9 @@ First, make sure that you have installed JDK7.
Vert.x requires JDK 1.7.0 or later.
And we use MongoDB as our data store.
-1. Vert.x - http://vertx.io/
-2. MongoDB - http://www.mongodb.org/
+1. Vert.x - <http://vertx.io/>
+ * The app is implemented in Vert.x [1.2.3](http://vertx.io/downloads/vert.x-1.2.3.final.tar.gz.html)
+2. MongoDB - <http://www.mongodb.org/>
By default, the app connects to MongoDB running on localhost with its default port.
@@ -19,5 +20,4 @@ By default, the app connects to MongoDB running on localhost with its default po
$ vertx run app.js
</pre>
-2. Visit [http://localhost:8080](http://localhost:8080)
-
+2. Visit [http://localhost:8080](http://localhost:8080)
View
12 option8_vertx/app.js
@@ -1,6 +1,5 @@
load('vertx.js');
-
-vertx.deployVerticle('mongo-persistor', null, 1, function() {
+vertx.deployModule('vertx.mongo-persistor-v1.0', null, 1, function() {
load('static_data.js');
});
@@ -13,18 +12,23 @@ var webServerConf = {
bridge: true,
- permitted: [
+ inbound_permitted: [
{
address : 'vertx.mongopersistor',
match : {
collection : 'todos'
}
},
+
{
address : 'todos.broadcast.event'
}
+ ],
+
+ outbound_permitted: [
+ {}
]
};
-vertx.deployVerticle('web-server', webServerConf);
+vertx.deployModule('vertx.web-server-v1.0', webServerConf);
View
6 option8_vertx/public/js/custom_sync.js
@@ -44,9 +44,9 @@
}
if(reply.status === 'ok' || reply.status == 'more-exist'){
options.success(data || model, reply.status, options);
- model.eventBus.send('todos.broadcast.event', {model: model, method: method});
+ model.eventBus.publish('todos.broadcast.event', {model: model, method: method});
if(reply.status == 'more-exist'){
- replier(new Object,replyHandler);
+ replier(new Object,replyHandler);
}
}else{
options.error(model, options);
@@ -55,7 +55,7 @@
};
if(params.action){
- model.eventBus.send('vertx.mongopersistor', params, replyHandler);
+ model.eventBus.send('vertx.mongopersistor', params, replyHandler);
}
};
View
42 option8_vertx/public/js/vertxbus.js
@@ -28,20 +28,11 @@ vertx.EventBus = function(url, options) {
that.onclose = null;
that.send = function(address, message, replyHandler) {
- checkSpecified("address", 'string', address);
- checkSpecified("message", 'object', message);
- checkSpecified("replyHandler", 'function', replyHandler, true);
- checkOpen();
- var envelope = { type : "send",
- address: address,
- body: message };
- if (replyHandler) {
- var replyAddress = makeUUID();
- envelope.replyAddress = replyAddress;
- replyHandlers[replyAddress] = replyHandler;
- }
- var str = JSON.stringify(envelope);
- sockJSConn.send(str);
+ sendOrPub("send", address, message, replyHandler)
+ }
+
+ that.publish = function(address, message, replyHandler) {
+ sendOrPub("publish", address, message, replyHandler)
}
that.registerHandler = function(address, handler) {
@@ -135,6 +126,23 @@ vertx.EventBus = function(url, options) {
}
}
+ function sendOrPub(sendOrPub, address, message, replyHandler) {
+ checkSpecified("address", 'string', address);
+ checkSpecified("message", 'object', message);
+ checkSpecified("replyHandler", 'function', replyHandler, true);
+ checkOpen();
+ var envelope = { type : sendOrPub,
+ address: address,
+ body: message };
+ if (replyHandler) {
+ var replyAddress = makeUUID();
+ envelope.replyAddress = replyAddress;
+ replyHandlers[replyAddress] = replyHandler;
+ }
+ var str = JSON.stringify(envelope);
+ sockJSConn.send(str);
+ }
+
function checkOpen() {
if (state != vertx.EventBus.OPEN) {
throw new Error('INVALID_STATE_ERR');
@@ -162,8 +170,4 @@ vertx.EventBus = function(url, options) {
vertx.EventBus.CONNECTING = 0;
vertx.EventBus.OPEN = 1;
vertx.EventBus.CLOSING = 2;
-vertx.EventBus.CLOSED = 3;
-
-
-
-
+vertx.EventBus.CLOSED = 3;
View
4 option8_vertx/static_data.js
@@ -20,10 +20,6 @@ var todos = [
// First delete everything
eb.send(pa, {action: 'delete', collection: 'todos', matcher: {}});
-eb.registerHandler(pa, function(message) {
- vertx.logger.info('Received a message: ' + JSON.stringify(message));
-});
-
for (var i = 0; i < todos.length; i++) {
eb.send(pa, {
action: 'save',
Please sign in to comment.
Something went wrong with that request. Please try again.