Skip to content

Commit

Permalink
added publish to client side event bus API
Browse files Browse the repository at this point in the history
  • Loading branch information
purplefox committed Jul 10, 2012
1 parent 70d05b2 commit d9a20e7
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 219 deletions.
42 changes: 23 additions & 19 deletions src/client/vertxbus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;
22 changes: 3 additions & 19 deletions src/examples/groovy/eventbusbridge/index.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
<!--
~ Copyright 2011-2012 the original author or authors.
~
~ 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.
-->

<html>
<head>
<title></title>
Expand Down Expand Up @@ -94,10 +78,10 @@

var eb = null;

function send(address, message) {
function publish(address, message) {
if (eb) {
var json = {text: message};
eb.send(address, json);
eb.publish(address, json);
$('#sent').append($("<code>").text("Address:" + address + " Message:" + message));
$('#sent').append($("</code><br>"));
}
Expand Down Expand Up @@ -136,7 +120,7 @@

$(document).ready(function() {
$("#sendButton").click(function() {
send($("#sendAddress").val(), $("#sendMessage").val());
publish($("#sendAddress").val(), $("#sendMessage").val());
});

$("#subscribeButton").click(function() {
Expand Down
6 changes: 3 additions & 3 deletions src/examples/java/eventbusbridge/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@

var eb = null;

function send(address, message) {
function publish(address, message) {
if (eb) {
var json = {text: message};
eb.send(address, json);
eb.publish(address, json);
$('#sent').append($("<code>").text("Address:" + address + " Message:" + message));
$('#sent').append($("</code><br>"));
}
Expand Down Expand Up @@ -120,7 +120,7 @@

$(document).ready(function() {
$("#sendButton").click(function() {
send($("#sendAddress").val(), $("#sendMessage").val());
publish($("#sendAddress").val(), $("#sendMessage").val());
});

$("#subscribeButton").click(function() {
Expand Down
6 changes: 3 additions & 3 deletions src/examples/javascript/eventbusbridge/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@

var eb = null;

function send(address, message) {
function publish(address, message) {
if (eb) {
var json = {text: message};
eb.send(address, json);
eb.publish(address, json);
$('#sent').append($("<code>").text("Address:" + address + " Message:" + message));
$('#sent').append($("</code><br>"));
}
Expand Down Expand Up @@ -120,7 +120,7 @@

$(document).ready(function() {
$("#sendButton").click(function() {
send($("#sendAddress").val(), $("#sendMessage").val());
publish($("#sendAddress").val(), $("#sendMessage").val());
});

$("#subscribeButton").click(function() {
Expand Down
6 changes: 3 additions & 3 deletions src/examples/python/eventbusbridge/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@

var eb = null;

function send(address, message) {
function publish(address, message) {
if (eb) {
var json = {text: message};
eb.send(address, json);
eb.publish(address, json);
$('#sent').append($("<code>").text("Address:" + address + " Message:" + message));
$('#sent').append($("</code><br>"));
}
Expand Down Expand Up @@ -120,7 +120,7 @@

$(document).ready(function() {
$("#sendButton").click(function() {
send($("#sendAddress").val(), $("#sendMessage").val());
publish($("#sendAddress").val(), $("#sendMessage").val());
});

$("#subscribeButton").click(function() {
Expand Down
169 changes: 0 additions & 169 deletions src/examples/python/eventbusbridge/vertxbus.js

This file was deleted.

6 changes: 3 additions & 3 deletions src/examples/ruby/eventbusbridge/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@

var eb = null;

function send(address, message) {
function publish(address, message) {
if (eb) {
var json = {text: message};
eb.send(address, json);
eb.publish(address, json);
$('#sent').append($("<code>").text("Address:" + address + " Message:" + message));
$('#sent').append($("</code><br>"));
}
Expand Down Expand Up @@ -120,7 +120,7 @@

$(document).ready(function() {
$("#sendButton").click(function() {
send($("#sendAddress").val(), $("#sendMessage").val());
publish($("#sendAddress").val(), $("#sendMessage").val());
});

$("#subscribeButton").click(function() {
Expand Down

0 comments on commit d9a20e7

Please sign in to comment.