jubilee 2.1.0.rc1-java → 3.0.0.beta2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +2 -14
  5. data/Guardfile +24 -0
  6. data/README.md +34 -66
  7. data/Rakefile +1 -1
  8. data/examples/chatapp/Gemfile +2 -1
  9. data/examples/chatapp/Gemfile.lock +2 -2
  10. data/examples/chatapp/README.md +2 -14
  11. data/examples/chatapp/app.rb +19 -11
  12. data/examples/chatapp/public/assets/javascripts/application.js +1 -1
  13. data/examples/chatapp/public/assets/javascripts/vertxbus.js +60 -48
  14. data/examples/client/vertxbus.js +60 -48
  15. data/examples/shims_example/log/development.log +0 -0
  16. data/jars/hazelcast-3.5.2.jar +0 -0
  17. data/jars/jackson-annotations-2.6.0.jar +0 -0
  18. data/jars/jackson-core-2.6.1.jar +0 -0
  19. data/jars/jackson-databind-2.6.1.jar +0 -0
  20. data/jars/netty-buffer-4.0.33.Final.jar +0 -0
  21. data/jars/netty-codec-4.0.33.Final.jar +0 -0
  22. data/jars/netty-codec-http-4.0.33.Final.jar +0 -0
  23. data/jars/netty-common-4.0.33.Final.jar +0 -0
  24. data/jars/netty-handler-4.0.33.Final.jar +0 -0
  25. data/jars/netty-transport-4.0.33.Final.jar +0 -0
  26. data/jars/vertx-auth-common-3.2.1.jar +0 -0
  27. data/jars/vertx-core-3.2.1.jar +0 -0
  28. data/jars/vertx-hazelcast-3.2.1.jar +0 -0
  29. data/jars/vertx-lang-ruby-3.2.1.jar +0 -0
  30. data/jars/vertx-web-3.2.1.jar +0 -0
  31. data/jubilee.gemspec +40 -42
  32. data/lib/jubilee.rb +7 -2
  33. data/lib/jubilee/cli.rb +4 -4
  34. data/lib/jubilee/jubilee.jar +0 -0
  35. data/lib/jubilee/response.rb +1 -1
  36. data/lib/jubilee/version.rb +3 -3
  37. data/pom.xml +10 -94
  38. data/spec/apps/rails4/basic/Gemfile +2 -2
  39. data/spec/apps/rails4/basic/Gemfile.lock +5 -6
  40. data/src/main/java/org/jruby/jubilee/Const.java +1 -4
  41. data/src/main/java/org/jruby/jubilee/JubileeVerticle.java +41 -46
  42. data/src/main/java/org/jruby/jubilee/RackApplication.java +37 -57
  43. data/src/main/java/org/jruby/jubilee/RackEnvironment.java +38 -35
  44. data/src/main/java/org/jruby/jubilee/RackEnvironmentHash.java +1 -7
  45. data/src/main/java/org/jruby/jubilee/RubyHttpServerResponse.java +12 -6
  46. data/src/main/java/org/jruby/jubilee/RubyNetSocket.java +9 -12
  47. data/src/main/java/org/jruby/jubilee/RubyPlatformManager.java +39 -43
  48. data/src/main/java/org/jruby/jubilee/impl/RubyIORackInput.java +2 -1
  49. data/src/main/java/org/jruby/jubilee/vertx/JubileeVertx.java +1 -1
  50. metadata +30 -54
  51. data/examples/chatapp/config.json +0 -4
  52. data/jars/annotations-1.3.2.jar +0 -0
  53. data/jars/hazelcast-3.2.3.jar +0 -0
  54. data/jars/jackson-annotations-2.2.2.jar +0 -0
  55. data/jars/jackson-core-2.2.2.jar +0 -0
  56. data/jars/jackson-databind-2.2.2.jar +0 -0
  57. data/jars/lang-jruby-2.1.0-final.jar +0 -0
  58. data/jars/log4j-1.2.16.jar +0 -0
  59. data/jars/netty-all-4.0.20.Final.jar +0 -0
  60. data/jars/slf4j-api-1.6.2.jar +0 -0
  61. data/jars/vertx-core-2.1.2.jar +0 -0
  62. data/jars/vertx-hazelcast-2.1.2.jar +0 -0
  63. data/jars/vertx-platform-2.1.2.jar +0 -0
  64. data/lib/container.rb +0 -117
  65. data/lib/core/buffer.rb +0 -251
  66. data/lib/core/datagram.rb +0 -280
  67. data/lib/core/dns.rb +0 -143
  68. data/lib/core/event_bus.rb +0 -277
  69. data/lib/core/file_system.rb +0 -479
  70. data/lib/core/http.rb +0 -1307
  71. data/lib/core/net.rb +0 -251
  72. data/lib/core/network_support.rb +0 -77
  73. data/lib/core/parsetools.rb +0 -105
  74. data/lib/core/shared_data.rb +0 -214
  75. data/lib/core/sock_js.rb +0 -116
  76. data/lib/core/ssl_support.rb +0 -163
  77. data/lib/core/streams.rb +0 -183
  78. data/lib/core/tcp_support.rb +0 -136
  79. data/lib/core/timers.rb +0 -73
  80. data/lib/core/vertx_require.rb +0 -25
  81. data/lib/core/wrapped_handler.rb +0 -28
  82. data/lib/jubilee/jubilee_require.rb +0 -24
  83. data/lib/test_utils.rb +0 -66
  84. data/lib/vertx.rb +0 -30
  85. data/lib/vertx_tests.rb +0 -8
  86. data/src/main/assembly/mod.xml +0 -21
  87. data/src/main/java/org/jruby/jubilee/JubileeVerticleFactory.java +0 -258
  88. data/src/main/java/org/jruby/jubilee/RubyCallable.java +0 -52
  89. data/src/main/resources/META-INF/services/org.vertx.java.deploy.impl.jruby.JubileeVerticleFactory +0 -1
  90. data/src/main/resources/mod.json +0 -11
  91. data/vertx_classpath.txt +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4025890d1a3b94265ecc1baf4b14c29360b2639
4
- data.tar.gz: 12d2da1989239ee2b4d52ab5c64e0c0491713c26
3
+ metadata.gz: 5fe8cb673337ec15f7ae0dd2bb5291a722a13a3a
4
+ data.tar.gz: 6ee67cbbee89d6847bbef2acf72ec61b04d7509f
5
5
  SHA512:
6
- metadata.gz: 3d6b27947fe1717e3e5ff1def31dc325ecc6aa00b560e04789a5723d1c4960ed0c70bd90dbc8bc6f369ad290af89386f179fbc6545dfbfe3fe1f439c3c3ff457
7
- data.tar.gz: 0fe735bc70b1bade1be8ff36062cb65177763944ba74a9b16213c5fb95a26e9bd61bea60030a8f7ac3c0f7931b739b44c37bbd00778ebd3b9afd01a0598a7435
6
+ metadata.gz: b3a2de6d05ebb28515f9daa5fa05ca35a9a55332fd2b5d0f879427953f1fbe4f32d1c5f05bb8b310ef7d5517b7e50c04e0e975890c0507ffcc12b3838face9e1
7
+ data.tar.gz: 387b046ef5c369b25ed92b78ae020f606087d37375a8af6ff8a36f909dec0af2c3768ddea058bd774b0eb89c18d5a8dfb2fb752eba877f04582b7b246a51e94c
@@ -1 +1 @@
1
- jruby-1.7.13
1
+ jruby-9.0.5.0
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source 'http://rubygems.org'
2
2
 
3
3
  gem 'rack', '>= 1.4.1'
4
4
  #gem 'rack', path: "../../ruby/rack"
@@ -1,5 +1,5 @@
1
1
  GEM
2
- remote: https://rubygems.org/
2
+ remote: http://rubygems.org/
3
3
  specs:
4
4
  actionmailer (4.0.2)
5
5
  actionpack (= 4.0.2)
@@ -29,7 +29,6 @@ GEM
29
29
  tzinfo (~> 0.3.37)
30
30
  addressable (2.3.5)
31
31
  arel (4.0.1)
32
- atomic (1.1.14)
33
32
  atomic (1.1.14-java)
34
33
  builder (3.1.4)
35
34
  capybara (2.2.0)
@@ -54,7 +53,6 @@ GEM
54
53
  execjs (2.0.2)
55
54
  faraday (0.8.8)
56
55
  multipart-post (~> 1.2.0)
57
- ffi (1.9.3)
58
56
  ffi (1.9.3-java)
59
57
  formatador (0.2.4)
60
58
  git (1.2.6)
@@ -96,7 +94,6 @@ GEM
96
94
  jquery-rails (3.0.4)
97
95
  railties (>= 3.0, < 5.0)
98
96
  thor (>= 0.14, < 2.0)
99
- json (1.8.1)
100
97
  json (1.8.1-java)
101
98
  jwt (0.1.8)
102
99
  multi_json (>= 1.5)
@@ -114,7 +111,6 @@ GEM
114
111
  multi_json (1.8.2)
115
112
  multi_xml (0.5.5)
116
113
  multipart-post (1.2.0)
117
- nokogiri (1.5.10)
118
114
  nokogiri (1.5.10-java)
119
115
  oauth2 (0.9.2)
120
116
  faraday (~> 0.8)
@@ -129,10 +125,6 @@ GEM
129
125
  multi_json (~> 1.0)
130
126
  websocket-driver (>= 0.2.0)
131
127
  polyglot (0.3.3)
132
- pry (0.9.12.4)
133
- coderay (~> 1.0)
134
- method_source (~> 0.8)
135
- slop (~> 3.4)
136
128
  pry (0.9.12.4-java)
137
129
  coderay (~> 1.0)
138
130
  method_source (~> 0.8)
@@ -156,11 +148,10 @@ GEM
156
148
  activesupport (= 4.0.2)
157
149
  rake (>= 0.8.7)
158
150
  thor (>= 0.18.1, < 2.0)
159
- rake (10.3.2)
151
+ rake (10.1.1)
160
152
  rb-fsevent (0.9.4)
161
153
  rb-inotify (0.9.3)
162
154
  ffi (>= 0.5.0)
163
- rcov (0.9.11)
164
155
  rcov (0.9.11-java)
165
156
  rdoc (4.1.0)
166
157
  json (~> 1.4)
@@ -197,8 +188,6 @@ GEM
197
188
  therubyrhino_jar (>= 1.7.3)
198
189
  therubyrhino_jar (1.7.4)
199
190
  thor (0.18.1)
200
- thread_safe (0.1.3)
201
- atomic
202
191
  thread_safe (0.1.3-java)
203
192
  atomic
204
193
  tilt (1.4.1)
@@ -212,7 +201,6 @@ GEM
212
201
  uglifier (2.4.0)
213
202
  execjs (>= 0.3.0)
214
203
  json (>= 1.8.0)
215
- websocket-driver (0.3.2)
216
204
  websocket-driver (0.3.2-java)
217
205
  xpath (2.0.0)
218
206
  nokogiri (~> 1.3)
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'minitest' do
5
+ # with Minitest::Unit
6
+ watch(%r|^test/(.*)\/?test_(.*)\.rb|)
7
+ watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
8
+ watch(%r|^test/test_helper\.rb|) { "test" }
9
+
10
+ # with Minitest::Spec
11
+ # watch(%r|^spec/(.*)_spec\.rb|)
12
+ # watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
13
+ # watch(%r|^spec/spec_helper\.rb|) { "spec" }
14
+
15
+ # Rails 3.2
16
+ # watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/controllers/#{m[1]}_test.rb" }
17
+ # watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" }
18
+ # watch(%r|^app/models/(.*)\.rb|) { |m| "test/unit/#{m[1]}_test.rb" }
19
+
20
+ # Rails
21
+ # watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/functional/#{m[1]}_test.rb" }
22
+ # watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" }
23
+ # watch(%r|^app/models/(.*)\.rb|) { |m| "test/unit/#{m[1]}_test.rb" }
24
+ end
data/README.md CHANGED
@@ -1,49 +1,53 @@
1
1
  [![Build Status](https://travis-ci.org/isaiah/jubilee.png?branch=master)](https://travis-ci.org/isaiah/jubilee)
2
2
 
3
- Jubilee / mod-rack
4
- ==================
3
+ Jubilee server
4
+ =========
5
+
6
+ A rack application compatible http server built on Vertx3. Check out the
7
+ demo [application](https://github.com/isaiah/jubilee/tree/master/examples/chatapp).
5
8
 
6
- > A rack server for jruby.
9
+ Why another rack server?
10
+ ------------------------
7
11
 
8
- > Also works as vertx module.
12
+ > "Vert.x is a lightweight, high performance application platform for the JVM
13
+ > that's designed for modern mobile, web, and enterprise applications."
14
+ > - vertx.io site
9
15
 
10
- Get started
11
- -----------
16
+ By using Vertx, jubilee inherent advantages in terms of performance, and all
17
+ the other cool features of Vertx:
12
18
 
13
- Please checkout the [wiki
14
- page](https://github.com/isaiah/jubilee/wiki/Running-as-vertx-module)
15
- before you proceed.
19
+ * [EventBus](https://github.com/isaiah/jubilee/wiki/Event-Bus)
20
+ * [SharedData](https://github.com/isaiah/jubilee/wiki/SharedData)
21
+ * [Clustering](https://github.com/isaiah/jubilee/wiki/Clustering)
16
22
 
17
- Add the following snippet to ```$VERTX\_HOME/conf/langs.properties```
18
- ```
19
- rackup=isaiah~mod-rack~0.1.2:org.jruby.jubilee.JubileeVerticleFactory
20
- .ru=rackup
21
- ```
22
23
 
23
- Make sure JRUBY_HOME is correctly set, and ```rack``` gem is install before proceed.
24
24
 
25
- Then run the rackup file as a normal verticle,
25
+ Get started
26
+ ------------
27
+
28
+ Make sure you have JDK 8 and jruby 1.7.20+ installed.
26
29
 
27
30
  ```shell
28
- vertx run config.ru
31
+ bundle && bundle exec rake install
29
32
  ```
30
33
 
31
- Build from source
32
- -----------------
34
+ This is the development branch of jubilee, it uses the vertx
35
+ 3.0 for a working version, please check out the
36
+ [2.x branch](https://github.com/isaiah/jubilee/tree/2.x).
33
37
 
34
- First checkout the source from github.
38
+ Rails
39
+ -----
35
40
 
36
- 1. To run as a vertx module, run the following command in the root directory:
41
+ Under the default setup, jubilee runs 4 instances of web
42
+ servers, each with it's own jruby runtime, if you find that jubilee
43
+ crashes or hangs with OutOfMemeoryError, please tune your JVM OPTS
44
+ like this:
37
45
 
38
- ```shell
39
- mvn package
40
- vertx create-module-link org.jruby.jubilee~mod-rack~0.1.3-SNAPSHOT
41
- ```
46
+ $ export JAVA_OPTS="-Xms1024m -Xmx2048m -XX:PermSize=512m -XX:MaxPermSize=512m"
42
47
 
43
- then change your langs.properties file to point to the new module;
48
+ If your OS memory is quite limited, please run jubilee with
44
49
 
45
- 2. To run as rubygem, run ```rake install``` in the root directory, maven is
46
- required.
50
+ $ jubilee -n 1
47
51
 
48
52
  Event Bus
49
53
  =========
@@ -56,18 +60,10 @@ Examples
56
60
  --------
57
61
 
58
62
  Assume necessary javascript files are loaded in the page (they can be found [here](https://github.com/isaiah/jubilee/tree/master/examples/client)),
59
- run rack application with the following config:
60
-
61
- ```
62
- $ cat config.json
63
- { "host": "0.0.0.0",
64
- "port": 8080,
65
- "event_bus": "/eventbus"
66
- }
67
- ```
63
+ start jubilee in a rack application with:
68
64
 
69
65
  ```
70
- $ vertx run config.ru -conf config.json
66
+ $ jubilee --eventbus eventbus
71
67
  ```
72
68
 
73
69
  In one browser:
@@ -92,34 +88,6 @@ In the previous tab it should print the greetings you just sent.
92
88
  For more advanced examples, please checkout the
93
89
  [chatapp](https://github.com/isaiah/jubilee/tree/master/examples/chatapp).
94
90
 
95
- EventBus Security
96
- ------------------
97
-
98
- The EventBus can (and probably should) be secured by passing in parameters in the config.json
99
- object.
100
-
101
- The following config will allow all messages from the browser to `accounts.get_balances` and
102
- only allow messages outward that match the format `accounts.get_balances.*`.
103
-
104
- ```
105
- $ cat config.json
106
- {
107
- "host": "0.0.0.0",
108
- "port": 8080,
109
- "event_bus": "/eventbus",
110
- "event_bus_security":
111
- {
112
- "incoming": [{address: "user_accounts.get_balances"}],
113
- "outgoing": [{address_re: "user_accounts.balances.*"}]
114
- }
115
- }
116
- ```
117
-
118
- More details of parameters can be found in [the VertX docs](http://vertx.io/core_manual_ruby.html#securing-the-bridge)
119
-
120
- By default the bridge is left wide open. Any browser connected to an application can observe *all* messages being
121
- passed on your EventBus.
122
-
123
91
  Performance Tuning
124
92
  -------------------
125
93
 
data/Rakefile CHANGED
@@ -99,7 +99,7 @@ end
99
99
  desc "Build the jar"
100
100
  task :jar => :clean do
101
101
  sh "mvn package"
102
- sh "unzip jars/*.zip *.rb -d lib"
102
+ #sh "unzip jars/*.zip *.rb -d lib"
103
103
  end
104
104
 
105
105
  task :build => :jar
@@ -1,4 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
  gem 'sinatra'
3
3
  gem 'haml'
4
- gem 'jubilee'
4
+
5
+ gem 'jubilee', '3.0.0.beta1'
@@ -4,7 +4,7 @@ GEM
4
4
  ffi (1.9.3-java)
5
5
  haml (4.0.4)
6
6
  tilt
7
- jubilee (2.1.0.beta-java)
7
+ jubilee (3.0.0.beta1-java)
8
8
  rack (>= 1.4.1)
9
9
  spoon (~> 0.0.4)
10
10
  rack (1.5.2)
@@ -23,5 +23,5 @@ PLATFORMS
23
23
 
24
24
  DEPENDENCIES
25
25
  haml
26
- jubilee
26
+ jubilee (= 3.0.0.beta1)
27
27
  sinatra
@@ -6,24 +6,12 @@ application.
6
6
 
7
7
  Make sure you are using jruby 1.7+ (jubilee 1.1.0+ require jruby 1.7.5 or later) and your JDK version is 7+
8
8
 
9
- Install the lastest stable version of vertx(2.1.2), and put the following snippet in your vertx
10
- language configuration, you can find the file under $VERTX\_HOME/conf/langs.properties
11
-
12
- ```
13
- rackup=isaiah~mod-rack~0.1.1:org.jruby.jubilee.JubileeVerticleFactory
14
- .ru=rackup
15
- ```
16
-
17
- and run
9
+ To run the application:
18
10
 
19
11
  ```shell
20
- vertx run config.ru -conf config.json
12
+ bundle && jubilee --eventbus eventbus
21
13
  ```
22
14
 
23
15
  Then go to http://localhost:8080 in your browser, if you have the page
24
16
  opened in multiple tabs or windows you can see the message you sent are
25
17
  broadcasted to all the other tabs.
26
-
27
- Checkout the [wiki
28
- page](https://github.com/isaiah/jubilee/wiki/Running-as-vertx-module) if
29
- you run into any trouble.
@@ -1,24 +1,32 @@
1
1
  require 'bundler/setup'
2
2
  Bundler.require(:default)
3
- require 'vertx'
4
- Vertx.deploy_verticle('test.rb')
3
+ require 'vertx/vertx'
5
4
 
6
- def to_a(shared_set)
7
- ret = []
8
- shared_set.each{ |item| ret << item}
9
- ret
5
+ def to_a(users)
6
+ users.split("\0")
10
7
  end
11
8
 
12
- Vertx::EventBus.register_handler('logout') do |message|
13
- Vertx::SharedData.get_set(:users).delete(message.body)
9
+ vertx = Jubilee.vertx
10
+ event_bus = vertx.event_bus()
11
+ sd = vertx.shared_data()
12
+
13
+ event_bus.consumer('logout') do |message|
14
+ chat_data = sd.get_local_map("chat")
15
+ users = to_a(chat_data.get("users"))
16
+ users.reject!{|u| u == message.body }
17
+ chat_data.put("users", users.join("\0"))
14
18
  end
15
19
 
20
+
16
21
  # register the user and return the previous users
17
- Vertx::EventBus.register_handler('login') do |message|
22
+ event_bus.consumer('login') do |message|
18
23
  user = message.body
19
- users = Vertx::SharedData.get_set(:users).add(user)
24
+ chat_data = sd.get_local_map("chat")
25
+ users = chat_data.get("users") || ""
20
26
  message.reply(users: to_a(users))
21
- Vertx::EventBus.publish("new_user", user)
27
+ users = user + "\0" + users
28
+ chat_data.put("users", users)
29
+ event_bus.publish("new_user", user)
22
30
  end
23
31
 
24
32
 
@@ -50,7 +50,7 @@ $(function() {
50
50
  if ((receiver = $("#receivers").val()) === "all") {
51
51
  eb.publish("chat", {sender: uid, message: msg});
52
52
  } else {
53
- updates.append("<div class='public by_you'><span class='sender'>You said to " + uid + ":</span>" + msg + "</div>");
53
+ updates.append("<div class='public by_you'><span class='sender'>You said to " + receiver + ":</span>" + msg + "</div>");
54
54
  eb.send(receiver, {sender: uid, message: msg});
55
55
  }
56
56
  $("#content").val("");
@@ -1,17 +1,17 @@
1
1
  /*
2
- * Copyright 2011-2012 the original author or authors.
2
+ * Copyright (c) 2011-2015 The original author or authors
3
+ * ------------------------------------------------------
4
+ * All rights reserved. This program and the accompanying materials
5
+ * are made available under the terms of the Eclipse Public License v1.0
6
+ * and Apache License v2.0 which accompanies this distribution.
3
7
  *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
8
+ * The Eclipse Public License is available at
9
+ * http://www.eclipse.org/legal/epl-v10.html
7
10
  *
8
- * http://www.apache.org/licenses/LICENSE-2.0
11
+ * The Apache License v2.0 is available at
12
+ * http://www.opensource.org/licenses/apache2.0.php
9
13
  *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
14
+ * You may elect to redistribute this code under either of these licenses.
15
15
  */
16
16
 
17
17
  var vertx = vertx || {};
@@ -35,31 +35,26 @@ var vertx = vertx || {};
35
35
  var handlerMap = {};
36
36
  var replyHandlers = {};
37
37
  var state = vertx.EventBus.CONNECTING;
38
- var sessionID = null;
39
38
  var pingTimerID = null;
39
+ var pingInterval = null;
40
+ if (options) {
41
+ pingInterval = options['vertxbus_ping_interval'];
42
+ }
43
+ if (!pingInterval) {
44
+ pingInterval = 5000;
45
+ }
40
46
 
41
47
  that.onopen = null;
42
48
  that.onclose = null;
49
+ that.onerror = null;
43
50
 
44
- that.login = function(username, password, replyHandler) {
45
- sendOrPub("send", 'vertx.basicauthmanager.login', {username: username, password: password}, function(reply) {
46
- if (reply.status === 'ok') {
47
- that.sessionID = reply.sessionID;
48
- }
49
- if (replyHandler) {
50
- delete reply.sessionID;
51
- replyHandler(reply)
52
- }
53
- });
54
- }
55
-
56
- that.send = function(address, message, replyHandler) {
57
- sendOrPub("send", address, message, replyHandler)
58
- }
51
+ that.send = function(address, message, replyHandler, failureHandler) {
52
+ sendOrPub("send", address, message, replyHandler, failureHandler)
53
+ };
59
54
 
60
- that.publish = function(address, message, replyHandler) {
61
- sendOrPub("publish", address, message, replyHandler)
62
- }
55
+ that.publish = function(address, message) {
56
+ sendOrPub("publish", address, message, null)
57
+ };
63
58
 
64
59
  that.registerHandler = function(address, handler) {
65
60
  checkSpecified("address", 'string', address);
@@ -76,7 +71,7 @@ var vertx = vertx || {};
76
71
  } else {
77
72
  handlers[handlers.length] = handler;
78
73
  }
79
- }
74
+ };
80
75
 
81
76
  that.unregisterHandler = function(address, handler) {
82
77
  checkSpecified("address", 'string', address);
@@ -95,23 +90,22 @@ var vertx = vertx || {};
95
90
  delete handlerMap[address];
96
91
  }
97
92
  }
98
- }
93
+ };
99
94
 
100
95
  that.close = function() {
101
96
  checkOpen();
102
- if (pingTimerID) clearInterval(pingTimerID);
103
97
  state = vertx.EventBus.CLOSING;
104
98
  sockJSConn.close();
105
- }
99
+ };
106
100
 
107
101
  that.readyState = function() {
108
102
  return state;
109
- }
103
+ };
110
104
 
111
105
  sockJSConn.onopen = function() {
112
- // Send the first ping then send a ping every 5 seconds
106
+ // Send the first ping then send a ping every pingInterval milliseconds
113
107
  sendPing();
114
- pingTimerID = setInterval(sendPing, 5000);
108
+ pingTimerID = setInterval(sendPing, pingInterval);
115
109
  state = vertx.EventBus.OPEN;
116
110
  if (that.onopen) {
117
111
  that.onopen();
@@ -120,6 +114,7 @@ var vertx = vertx || {};
120
114
 
121
115
  sockJSConn.onclose = function() {
122
116
  state = vertx.EventBus.CLOSED;
117
+ if (pingTimerID) clearInterval(pingTimerID);
123
118
  if (that.onclose) {
124
119
  that.onclose();
125
120
  }
@@ -128,6 +123,15 @@ var vertx = vertx || {};
128
123
  sockJSConn.onmessage = function(e) {
129
124
  var msg = e.data;
130
125
  var json = JSON.parse(msg);
126
+ var type = json.type;
127
+ if (type === 'err') {
128
+ if (that.onerror) {
129
+ that.onerror(json.body);
130
+ } else {
131
+ console.error("Error received on connection: " + json.body);
132
+ }
133
+ return;
134
+ }
131
135
  var body = json.body;
132
136
  var replyAddress = json.replyAddress;
133
137
  var address = json.address;
@@ -148,35 +152,43 @@ var vertx = vertx || {};
148
152
  }
149
153
  } else {
150
154
  // Might be a reply message
151
- var handler = replyHandlers[address];
152
- if (handler) {
155
+ handlers = replyHandlers[address];
156
+ if (handlers) {
153
157
  delete replyHandlers[address];
154
- handler(body, replyHandler);
158
+ var handler = handlers.replyHandler;
159
+ if (body) {
160
+ handler(body, replyHandler);
161
+ } else if (typeof json.failureCode != 'undefined') {
162
+ // Check for failure
163
+ var failure = { failureCode: json.failureCode, failureType: json.failureType, message: json.message };
164
+ var failureHandler = handlers.failureHandler;
165
+ if (failureHandler) {
166
+ failureHandler(failure)
167
+ }
168
+ }
155
169
  }
156
170
  }
157
- }
171
+ };
158
172
 
159
173
  function sendPing() {
160
174
  var msg = {
161
175
  type: "ping"
162
- }
176
+ };
163
177
  sockJSConn.send(JSON.stringify(msg));
164
178
  }
165
179
 
166
- function sendOrPub(sendOrPub, address, message, replyHandler) {
180
+ function sendOrPub(sendOrPub, address, message, replyHandler, failureHandler) {
167
181
  checkSpecified("address", 'string', address);
168
182
  checkSpecified("replyHandler", 'function', replyHandler, true);
183
+ checkSpecified("failureHandler", 'function', failureHandler, true);
169
184
  checkOpen();
170
185
  var envelope = { type : sendOrPub,
171
186
  address: address,
172
187
  body: message };
173
- if (that.sessionID) {
174
- envelope.sessionID = that.sessionID;
175
- }
176
- if (replyHandler) {
188
+ if (replyHandler || failureHandler) {
177
189
  var replyAddress = makeUUID();
178
190
  envelope.replyAddress = replyAddress;
179
- replyHandlers[replyAddress] = replyHandler;
191
+ replyHandlers[replyAddress] = { replyHandler: replyHandler, failureHandler: failureHandler };
180
192
  }
181
193
  var str = JSON.stringify(envelope);
182
194
  sockJSConn.send(str);
@@ -204,7 +216,7 @@ var vertx = vertx || {};
204
216
  function makeUUID(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
205
217
  .replace(/[xy]/g,function(a,b){return b=Math.random()*16,(a=="y"?b&3|8:b|0).toString(16)})}
206
218
 
207
- }
219
+ };
208
220
 
209
221
  vertx.EventBus.CONNECTING = 0;
210
222
  vertx.EventBus.OPEN = 1;