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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -14
- data/Guardfile +24 -0
- data/README.md +34 -66
- data/Rakefile +1 -1
- data/examples/chatapp/Gemfile +2 -1
- data/examples/chatapp/Gemfile.lock +2 -2
- data/examples/chatapp/README.md +2 -14
- data/examples/chatapp/app.rb +19 -11
- data/examples/chatapp/public/assets/javascripts/application.js +1 -1
- data/examples/chatapp/public/assets/javascripts/vertxbus.js +60 -48
- data/examples/client/vertxbus.js +60 -48
- data/examples/shims_example/log/development.log +0 -0
- data/jars/hazelcast-3.5.2.jar +0 -0
- data/jars/jackson-annotations-2.6.0.jar +0 -0
- data/jars/jackson-core-2.6.1.jar +0 -0
- data/jars/jackson-databind-2.6.1.jar +0 -0
- data/jars/netty-buffer-4.0.33.Final.jar +0 -0
- data/jars/netty-codec-4.0.33.Final.jar +0 -0
- data/jars/netty-codec-http-4.0.33.Final.jar +0 -0
- data/jars/netty-common-4.0.33.Final.jar +0 -0
- data/jars/netty-handler-4.0.33.Final.jar +0 -0
- data/jars/netty-transport-4.0.33.Final.jar +0 -0
- data/jars/vertx-auth-common-3.2.1.jar +0 -0
- data/jars/vertx-core-3.2.1.jar +0 -0
- data/jars/vertx-hazelcast-3.2.1.jar +0 -0
- data/jars/vertx-lang-ruby-3.2.1.jar +0 -0
- data/jars/vertx-web-3.2.1.jar +0 -0
- data/jubilee.gemspec +40 -42
- data/lib/jubilee.rb +7 -2
- data/lib/jubilee/cli.rb +4 -4
- data/lib/jubilee/jubilee.jar +0 -0
- data/lib/jubilee/response.rb +1 -1
- data/lib/jubilee/version.rb +3 -3
- data/pom.xml +10 -94
- data/spec/apps/rails4/basic/Gemfile +2 -2
- data/spec/apps/rails4/basic/Gemfile.lock +5 -6
- data/src/main/java/org/jruby/jubilee/Const.java +1 -4
- data/src/main/java/org/jruby/jubilee/JubileeVerticle.java +41 -46
- data/src/main/java/org/jruby/jubilee/RackApplication.java +37 -57
- data/src/main/java/org/jruby/jubilee/RackEnvironment.java +38 -35
- data/src/main/java/org/jruby/jubilee/RackEnvironmentHash.java +1 -7
- data/src/main/java/org/jruby/jubilee/RubyHttpServerResponse.java +12 -6
- data/src/main/java/org/jruby/jubilee/RubyNetSocket.java +9 -12
- data/src/main/java/org/jruby/jubilee/RubyPlatformManager.java +39 -43
- data/src/main/java/org/jruby/jubilee/impl/RubyIORackInput.java +2 -1
- data/src/main/java/org/jruby/jubilee/vertx/JubileeVertx.java +1 -1
- metadata +30 -54
- data/examples/chatapp/config.json +0 -4
- data/jars/annotations-1.3.2.jar +0 -0
- data/jars/hazelcast-3.2.3.jar +0 -0
- data/jars/jackson-annotations-2.2.2.jar +0 -0
- data/jars/jackson-core-2.2.2.jar +0 -0
- data/jars/jackson-databind-2.2.2.jar +0 -0
- data/jars/lang-jruby-2.1.0-final.jar +0 -0
- data/jars/log4j-1.2.16.jar +0 -0
- data/jars/netty-all-4.0.20.Final.jar +0 -0
- data/jars/slf4j-api-1.6.2.jar +0 -0
- data/jars/vertx-core-2.1.2.jar +0 -0
- data/jars/vertx-hazelcast-2.1.2.jar +0 -0
- data/jars/vertx-platform-2.1.2.jar +0 -0
- data/lib/container.rb +0 -117
- data/lib/core/buffer.rb +0 -251
- data/lib/core/datagram.rb +0 -280
- data/lib/core/dns.rb +0 -143
- data/lib/core/event_bus.rb +0 -277
- data/lib/core/file_system.rb +0 -479
- data/lib/core/http.rb +0 -1307
- data/lib/core/net.rb +0 -251
- data/lib/core/network_support.rb +0 -77
- data/lib/core/parsetools.rb +0 -105
- data/lib/core/shared_data.rb +0 -214
- data/lib/core/sock_js.rb +0 -116
- data/lib/core/ssl_support.rb +0 -163
- data/lib/core/streams.rb +0 -183
- data/lib/core/tcp_support.rb +0 -136
- data/lib/core/timers.rb +0 -73
- data/lib/core/vertx_require.rb +0 -25
- data/lib/core/wrapped_handler.rb +0 -28
- data/lib/jubilee/jubilee_require.rb +0 -24
- data/lib/test_utils.rb +0 -66
- data/lib/vertx.rb +0 -30
- data/lib/vertx_tests.rb +0 -8
- data/src/main/assembly/mod.xml +0 -21
- data/src/main/java/org/jruby/jubilee/JubileeVerticleFactory.java +0 -258
- data/src/main/java/org/jruby/jubilee/RubyCallable.java +0 -52
- data/src/main/resources/META-INF/services/org.vertx.java.deploy.impl.jruby.JubileeVerticleFactory +0 -1
- data/src/main/resources/mod.json +0 -11
- data/vertx_classpath.txt +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fe8cb673337ec15f7ae0dd2bb5291a722a13a3a
|
4
|
+
data.tar.gz: 6ee67cbbee89d6847bbef2acf72ec61b04d7509f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3a2de6d05ebb28515f9daa5fa05ca35a9a55332fd2b5d0f879427953f1fbe4f32d1c5f05bb8b310ef7d5517b7e50c04e0e975890c0507ffcc12b3838face9e1
|
7
|
+
data.tar.gz: 387b046ef5c369b25ed92b78ae020f606087d37375a8af6ff8a36f909dec0af2c3768ddea058bd774b0eb89c18d5a8dfb2fb752eba877f04582b7b246a51e94c
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
jruby-
|
1
|
+
jruby-9.0.5.0
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
GEM
|
2
|
-
remote:
|
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.
|
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)
|
data/Guardfile
ADDED
@@ -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
|
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
|
-
|
9
|
+
Why another rack server?
|
10
|
+
------------------------
|
7
11
|
|
8
|
-
>
|
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
|
-
|
11
|
-
|
16
|
+
By using Vertx, jubilee inherent advantages in terms of performance, and all
|
17
|
+
the other cool features of Vertx:
|
12
18
|
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
25
|
+
Get started
|
26
|
+
------------
|
27
|
+
|
28
|
+
Make sure you have JDK 8 and jruby 1.7.20+ installed.
|
26
29
|
|
27
30
|
```shell
|
28
|
-
|
31
|
+
bundle && bundle exec rake install
|
29
32
|
```
|
30
33
|
|
31
|
-
|
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
|
-
|
38
|
+
Rails
|
39
|
+
-----
|
35
40
|
|
36
|
-
|
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
|
-
|
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
|
-
|
48
|
+
If your OS memory is quite limited, please run jubilee with
|
44
49
|
|
45
|
-
|
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
|
-
|
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
|
-
$
|
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
data/examples/chatapp/Gemfile
CHANGED
@@ -4,7 +4,7 @@ GEM
|
|
4
4
|
ffi (1.9.3-java)
|
5
5
|
haml (4.0.4)
|
6
6
|
tilt
|
7
|
-
jubilee (
|
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
|
data/examples/chatapp/README.md
CHANGED
@@ -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
|
-
|
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
|
-
|
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.
|
data/examples/chatapp/app.rb
CHANGED
@@ -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(
|
7
|
-
|
8
|
-
shared_set.each{ |item| ret << item}
|
9
|
-
ret
|
5
|
+
def to_a(users)
|
6
|
+
users.split("\0")
|
10
7
|
end
|
11
8
|
|
12
|
-
|
13
|
-
|
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
|
-
|
22
|
+
event_bus.consumer('login') do |message|
|
18
23
|
user = message.body
|
19
|
-
|
24
|
+
chat_data = sd.get_local_map("chat")
|
25
|
+
users = chat_data.get("users") || ""
|
20
26
|
message.reply(users: to_a(users))
|
21
|
-
|
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 " +
|
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
|
-
*
|
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
|
-
*
|
5
|
-
*
|
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
|
-
*
|
11
|
+
* The Apache License v2.0 is available at
|
12
|
+
* http://www.opensource.org/licenses/apache2.0.php
|
9
13
|
*
|
10
|
-
*
|
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.
|
45
|
-
sendOrPub("send",
|
46
|
-
|
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
|
61
|
-
sendOrPub("publish", address, message,
|
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
|
106
|
+
// Send the first ping then send a ping every pingInterval milliseconds
|
113
107
|
sendPing();
|
114
|
-
pingTimerID = setInterval(sendPing,
|
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
|
-
|
152
|
-
if (
|
155
|
+
handlers = replyHandlers[address];
|
156
|
+
if (handlers) {
|
153
157
|
delete replyHandlers[address];
|
154
|
-
handler
|
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 (
|
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;
|