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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,136 +0,0 @@
1
- # Copyright 2011-2012 the original author or authors.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- module Vertx
16
- require 'core/network_support'
17
-
18
- # Mixin module that provides all the common TCP params that can be set.
19
- #
20
- # @author {http://tfox.org Tim Fox}
21
- module TCPSupport
22
-
23
- include NetworkSupport
24
-
25
- # Set the TCP keep alive setting.
26
- # @param [Boolean] val. If true, then TCP keep alive will be enabled.
27
- # @return [] A reference to self so invocations can be chained
28
- def tcp_keep_alive=(val)
29
- @j_del.setTCPKeepAlive(val)
30
- self
31
- end
32
-
33
- # Set or get TCP keep alive for fluent API
34
- def tcp_keep_alive(val = nil)
35
- if val
36
- @j_del.setTCPKeepAlive(val)
37
- self
38
- else
39
- @j_del.getTCPKeepAlive
40
- end
41
- end
42
-
43
- # Set the TCP reuse address setting.
44
- # @param [Boolean] val. If true, then TCP reuse address will be enabled.
45
- # @return [] A reference to self so invocations can be chained
46
- def reuse_address=(val)
47
- @j_del.setReuseAddress(val)
48
- self
49
- end
50
-
51
- # Set or get TCP reuse address for fluent API
52
- def reuse_address(val = nil)
53
- if val
54
- @j_del.setReuseAddress(val)
55
- self
56
- else
57
- @j_del.isReuseAddress
58
- end
59
- end
60
-
61
- # Set the TCP so linger setting.
62
- # @param [FixNum] val. Set TCP soLinger
63
- # @return [] A reference to self so invocations can be chained
64
- def so_linger=(val)
65
- @j_del.setSoLinger(val)
66
- self
67
- end
68
-
69
- # Set or get TCP so linger for fluent API
70
- def so_linger(val = nil)
71
- if val
72
- @j_del.setSoLinger(val)
73
- self
74
- else
75
- @j_del.getSoLinger
76
- end
77
- end
78
-
79
- # Set the TCP traffic class setting.
80
- # @param [FixNum] val. The TCP traffic class setting.
81
- # @return [] A reference to self so invocations can be chained
82
- def traffic_class=(val)
83
- @j_del.setTrafficClass(val)
84
- self
85
- end
86
-
87
- # Set or get TCP traffic class for fluent API
88
- def traffic_class(val = nil)
89
- if val
90
- @j_del.setTrafficClass(val)
91
- self
92
- else
93
- @j_del.getTrafficClass
94
- end
95
- end
96
-
97
- # Set to use pooled buffers
98
- # @param [Boolean] val.
99
- # @return [] A reference to self so invocations can be chained
100
- def use_pooled_buffers=(val)
101
- @j_del.setUsedPooledBuffers(val)
102
- self
103
- end
104
-
105
- # Set or get use_pooled_buffers for fluent API
106
- def use_pooled_buffers(val = nil)
107
- if val
108
- @j_del.setUsePooledBuffers(val)
109
- self
110
- else
111
- @j_del.isUsePooledBuffers
112
- end
113
- end
114
-
115
- end
116
-
117
- module ServerTCPSupport
118
- # Set the accept backlog
119
- # @param [FixNum] val.
120
- # @return [] A reference to self so invocations can be chained
121
- def accept_backlog=(val)
122
- @j_del.setAcceptBacklog(val)
123
- self
124
- end
125
-
126
- # Set or get the accept backlog for fluent API
127
- def accept_backlog(val = nil)
128
- if val
129
- @j_del.setAcceptBacklog(val)
130
- self
131
- else
132
- @j_del.getAcceptBacklog
133
- end
134
- end
135
- end
136
- end
@@ -1,73 +0,0 @@
1
- # Copyright 2011 the original author or authors.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- module Vertx
16
-
17
- @@j_vertx = org.vertx.java.platform.impl.JRubyVerticleFactory.vertx()
18
-
19
- # Sets a one-shot timer that will fire after a certain delay.
20
- # This method will accept either a Proc or a block.
21
- # @param [FixNum] delay the delay, in milliseconds
22
- # @param [Proc] proc a proc representing the code that will be run after the delay
23
- # @param [Block] hndlr a block representing the code that will be run after the delay
24
- # @return [FixNum] the unique id of the timer
25
- def Vertx.set_timer(delay, proc = nil, &hndlr)
26
- hndlr = proc if proc
27
- @@j_vertx.setTimer(delay, hndlr)
28
- end
29
-
30
- # Sets a periodic timer.
31
- # This method will accept either a Proc or a block.
32
- # @param [FixNum] delay the period of the timer, in milliseconds
33
- # @param [Proc] proc a proc representing the code that will be run when the timer fires
34
- # @param [Block] hndlr a block representing the code that will be when the timer fires
35
- # @return [FixNum] the unique id of the timer
36
- def Vertx.set_periodic(delay, proc = nil, &hndlr)
37
- hndlr = proc if proc
38
- @@j_vertx.setPeriodic(delay, hndlr)
39
- end
40
-
41
- # Cancels a timer.
42
- # @param [FixNum] id the id of the timer, as returned from {Vertx.set_timer} or {Vertx.set_periodic}
43
- # @return [Boolean] true if the timer was cancelled, false if it wasn't found.
44
- def Vertx.cancel_timer(id)
45
- @@j_vertx.cancelTimer(id)
46
- end
47
-
48
- # Put the handler on the event queue for this loop so it will be run asynchronously
49
- # ASAP after this event has been processed
50
- # @param [Proc] proc a proc representing the code that will be run ASAP
51
- # @param [Block] hndlr a block representing the code that will be run ASAP
52
- def Vertx.run_on_context(proc = nil, &hndlr)
53
- hndlr = proc if proc
54
- @@j_vertx.runOnContext(hndlr)
55
- end
56
-
57
- # Get a reference to the current context
58
- def Vertx.current_context
59
- Context.new(@@j_vertx.currentContext())
60
- end
61
-
62
- class Context
63
- # @private
64
- def initialize(j_del)
65
- @j_del = j_del
66
- end
67
-
68
- def run_on_context(&hndlr)
69
- @j_del.runOnContext(hndlr)
70
- end
71
- end
72
-
73
- end
@@ -1,25 +0,0 @@
1
- # Redefine the require and load methods so we can make them synchronized
2
-
3
- require 'jruby/synchronized'
4
-
5
- module Kernel
6
- # make an alias of the original require
7
- alias_method :original_require, :require
8
- alias_method :original_load, :load
9
-
10
- def require name
11
- org.vertx.java.platform.impl.JRubyVerticleFactory.requireCallback do
12
- #puts "in require callback"
13
- original_require name
14
- end
15
- end
16
-
17
- def load name
18
- org.vertx.java.platform.impl.JRubyVerticleFactory.requireCallback do
19
- #puts "in require callback"
20
- original_load name
21
- end
22
- end
23
-
24
- end
25
-
@@ -1,28 +0,0 @@
1
- module Vertx
2
-
3
- # @private
4
- class ARWrappedHandler
5
- include org.vertx.java.core.AsyncResultHandler
6
-
7
- def initialize(handler, &result_converter)
8
- @handler = handler
9
- @result_converter = result_converter
10
- end
11
-
12
- def handle(future_result)
13
- if @handler
14
- if future_result.succeeded
15
- if @result_converter
16
- @handler.call(nil, @result_converter.call(future_result.result))
17
- else
18
- @handler.call(nil, future_result.result)
19
- end
20
- else
21
- @handler.call(future_result.cause, nil)
22
- end
23
- end
24
- end
25
-
26
- end
27
-
28
- end
@@ -1,24 +0,0 @@
1
- # Redefine the require and load methods so we can make them synchronized
2
-
3
- require 'jruby/synchronized'
4
-
5
- module Kernel
6
- # make an alias of the original require
7
- alias_method :original_require, :require
8
- alias_method :original_load, :load
9
-
10
- def require(*params)
11
- org.vertx.java.platform.impl.JRubyVerticleFactory.requireCallback do
12
- #puts "in require callback"
13
- original_require(*params)
14
- end
15
- end
16
-
17
- def load(*params)
18
- org.vertx.java.platform.impl.JRubyVerticleFactory.requireCallback do
19
- #puts "in require callback"
20
- original_load(*params)
21
- end
22
- end
23
-
24
- end
@@ -1,66 +0,0 @@
1
- class TestUtils
2
- def initialize
3
- @j_tu = org.vertx.java.testframework.TestUtils.new( org.vertx.java.platform.impl.JRubyVerticleFactory.vertx)
4
- end
5
-
6
- def azzert(result, message = nil)
7
- begin
8
- if message
9
- @j_tu.azzert(result, message)
10
- else
11
- @j_tu.azzert(result)
12
- end
13
- rescue java.lang.RuntimeException
14
- # Rethrow as a ruby exception so we see nice Ruby backtrace
15
- raise "Assertion Failed #{message}"
16
- end
17
- end
18
-
19
- def app_ready
20
- @j_tu.appReady
21
- end
22
-
23
- def app_stopped
24
- @j_tu.appStopped
25
- end
26
-
27
- def test_complete()
28
- @j_tu.testComplete
29
- end
30
-
31
- def register(test_name, &test_handler)
32
- @j_tu.register(test_name, test_handler)
33
- end
34
-
35
- def register_all(object)
36
- methods = object.methods
37
- methods.each do |meth|
38
- if meth.to_s.start_with? 'test_'
39
- register(meth) {
40
- object.method(meth).call
41
- }
42
- end
43
- end
44
- end
45
-
46
- def unregister_all
47
- @j_tu.unregisterAll
48
- end
49
-
50
- def TestUtils.gen_buffer(size)
51
- j_buff = org.vertx.java.testframework.TestUtils.generateRandomBuffer(size)
52
- Vertx::Buffer.new(j_buff)
53
- end
54
-
55
- def TestUtils.random_unicode_string(size)
56
- org.vertx.java.testframework.TestUtils.randomUnicodeString(size)
57
- end
58
-
59
- def TestUtils.buffers_equal(buff1, buff2)
60
- org.vertx.java.testframework.TestUtils.buffersEqual(buff1._to_java_buffer, buff2._to_java_buffer)
61
- end
62
-
63
- def check_thread
64
- @j_tu.checkThread
65
- end
66
- end
@@ -1,30 +0,0 @@
1
- # Copyright 2011 the original author or authors.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- include Java
16
-
17
- require 'container'
18
- require 'core/timers'
19
- require 'core/buffer'
20
- require 'core/file_system'
21
- require 'core/http'
22
- require 'core/net'
23
- require 'core/parsetools'
24
- require 'core/streams'
25
- require 'core/shared_data'
26
- require 'core/event_bus'
27
- require 'core/sock_js'
28
- require 'core/dns'
29
- require 'core/datagram'
30
-
@@ -1,8 +0,0 @@
1
- VertxAssert = Java::OrgVertxTesttools::VertxAssert
2
-
3
- VertxAssert.initialize(org.vertx.java.platform.impl.JRubyVerticleFactory.vertx)
4
-
5
- def start_tests(top)
6
- method_name = Vertx.config['methodName']
7
- self.send(method_name)
8
- end
@@ -1,21 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
3
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
- xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
5
-
6
- <formats>
7
- <format>zip</format>
8
- </formats>
9
-
10
- <includeBaseDirectory>false</includeBaseDirectory>
11
-
12
- <fileSets>
13
- <fileSet>
14
- <outputDirectory></outputDirectory>
15
- <directory>${mods.directory}/${module.name}</directory>
16
- <includes>
17
- <include>**</include>
18
- </includes>
19
- </fileSet>
20
- </fileSets>
21
- </assembly>
@@ -1,258 +0,0 @@
1
- /*
2
- * Copyright 2011-2012 the original author or authors.
3
- *
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
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
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.
15
- */
16
-
17
- package org.jruby.jubilee;
18
-
19
- import org.jruby.*;
20
- import org.jruby.embed.EvalFailedException;
21
- import org.jruby.embed.InvokeFailedException;
22
- import org.jruby.embed.LocalContextScope;
23
- import org.jruby.embed.ScriptingContainer;
24
- import org.jruby.exceptions.RaiseException;
25
- import org.jruby.runtime.builtin.IRubyObject;
26
- import org.vertx.java.core.Handler;
27
- import org.vertx.java.core.Vertx;
28
- import org.vertx.java.core.VertxException;
29
- import org.vertx.java.core.http.HttpServer;
30
- import org.vertx.java.core.http.HttpServerRequest;
31
- import org.vertx.java.core.json.JsonArray;
32
- import org.vertx.java.core.json.JsonObject;
33
- import org.vertx.java.core.logging.Logger;
34
- import org.vertx.java.platform.Container;
35
- import org.vertx.java.platform.Verticle;
36
- import org.vertx.java.platform.VerticleFactory;
37
- import org.vertx.java.platform.impl.WrappedVertx;
38
- import org.vertx.java.platform.impl.JRubyVerticleFactory;
39
-
40
- import java.io.*;
41
- import java.util.List;
42
- import java.util.concurrent.atomic.AtomicInteger;
43
-
44
- public class JubileeVerticleFactory implements VerticleFactory {
45
-
46
- private ClassLoader cl;
47
- private ScriptingContainer scontainer;
48
- private static final AtomicInteger seq = new AtomicInteger();
49
-
50
- public static Vertx vertx;
51
- public static Container container;
52
-
53
- public JubileeVerticleFactory() {
54
- }
55
-
56
- @Override
57
- public void init(Vertx vertx, Container container, ClassLoader cl) {
58
- this.cl = cl;
59
- // These statics are used by the Rhino scripts to look up references to vertx and the container
60
- JRubyVerticleFactory.vertx = vertx;
61
- JubileeVerticleFactory.vertx = vertx;
62
- JubileeVerticleFactory.container = container;
63
- ClassLoader old = Thread.currentThread().getContextClassLoader();
64
- try {
65
- Thread.currentThread().setContextClassLoader(cl);
66
- this.scontainer = new ScriptingContainer(LocalContextScope.SINGLETHREAD);
67
- scontainer.setCompatVersion(CompatVersion.RUBY1_9);
68
- //Prevent JRuby from logging errors to stderr - we want to log ourselves
69
- scontainer.setErrorWriter(new NullWriter());
70
- } finally {
71
- Thread.currentThread().setContextClassLoader(old);
72
- }
73
- }
74
-
75
- @Override
76
- public Verticle createVerticle(String rackup) throws Exception {
77
- return new RackVerticle(rackup);
78
- }
79
-
80
- public void reportException(Logger logger, Throwable t) {
81
- RaiseException je = null;
82
- if (t instanceof EvalFailedException) {
83
- EvalFailedException e = (EvalFailedException)t;
84
- Throwable cause = e.getCause();
85
- if (cause instanceof RaiseException) {
86
- je = (RaiseException)cause;
87
- }
88
- } else if (t instanceof RaiseException) {
89
- je = (RaiseException)t;
90
- }
91
-
92
- if (je != null) {
93
-
94
- RubyException re = je.getException();
95
-
96
- String msg;
97
- if (re instanceof RubyNameError) {
98
- RubyNameError rne = (RubyNameError)re;
99
- msg = "Invalid or undefined name: " + rne.name().toString();
100
- } else {
101
- msg = re.message.toString();
102
- }
103
-
104
- StringBuilder backtrace = new StringBuilder();
105
- IRubyObject bt = re.backtrace();
106
-
107
- if (bt instanceof List) {
108
- for (Object obj : (List<?>)bt) {
109
- if (obj instanceof String) {
110
- String line = (String)obj;
111
- addToBackTrace(backtrace, line);
112
- }
113
- }
114
- }
115
- logger.error("Exception in Ruby verticle: " + msg +
116
- "\n" + backtrace);
117
- } else {
118
- logger.error("Unexpected exception in Ruby verticle", t);
119
- }
120
- }
121
-
122
- private void addToBackTrace(StringBuilder backtrace, String line) {
123
- if (line.contains(".rb")) {
124
- //We filter out any Java stack trace
125
- backtrace.append(line).append('\n');
126
- }
127
- }
128
-
129
- // This method synchronizes the callback into the JRuby code to make sure we don't have concurrent requires
130
- // or loads occurring in the same JRuby container
131
- public static synchronized void requireCallback(Runnable runnable) {
132
- runnable.run();
133
- }
134
-
135
- // This MUST be static or we will get a leak since JRuby maintains it and a non static will hold a reference
136
- // to this
137
- private static class NullWriter extends Writer {
138
-
139
- public void write(char[] cbuf, int off, int len) throws IOException {
140
- }
141
-
142
- public void flush() throws IOException {
143
- }
144
-
145
- public void close() throws IOException {
146
- }
147
- }
148
-
149
- public void close() {
150
- scontainer.clear();
151
- // JRuby keeps a static reference to a runtime - we must clear this manually to avoid a leak
152
- Ruby.clearGlobalRuntime();
153
- }
154
- public class RackVerticle extends Verticle {
155
- public RackVerticle(String rackup) {
156
- this.rackup = rackup;
157
- this.vertx = JubileeVerticleFactory.vertx;
158
- this.container = JubileeVerticleFactory.container;
159
- }
160
-
161
- public void start() {
162
- JsonObject config = container.config();
163
- synchronized (JubileeVerticleFactory.class) {
164
- try (InputStream is = cl.getResourceAsStream(rackup)) {
165
- if (is == null) {
166
- throw new IllegalArgumentException("Cannot find verticle: " + rackup);
167
- }
168
- modName = "Mod___VertxInternalVert__" + seq.incrementAndGet();
169
- StringBuilder svert = new StringBuilder( "require 'jubilee/jubilee_require'\n").append("module ").append(modName).append(";extend self;");
170
- String rackScript = "require 'rack'\n" +
171
- "require 'jubilee'\n" +
172
- "app, _ = Rack::Builder.parse_file('" + rackup + "')\n";
173
- if (!config.getBoolean("quiet", true) && config.getString("environment").equals("development")) {
174
- rackScript += "logger = STDOUT\n" +
175
- "app = Rack::CommonLogger.new(app, logger)\n";
176
- }
177
- rackScript += "Jubilee::Application.new(app)\n";
178
- svert.append(rackScript);
179
- svert.append("end");
180
- rackApplication = (IRubyObject)scontainer.runScriptlet(new StringReader(svert.toString()), rackup);
181
- } catch (Exception e) {
182
- throw new VertxException(e);
183
- }
184
- }
185
- httpServer = vertx.createHttpServer();
186
-
187
- final RackApplication app;
188
- boolean ssl = config.getBoolean("ssl", false);
189
- try {
190
- app = new RackApplication((WrappedVertx) vertx, rackApplication.getRuntime().getCurrentContext(), rackApplication, config);
191
- httpServer.setAcceptBacklog(10000);
192
- httpServer.requestHandler(new Handler<HttpServerRequest>() {
193
- public void handle(final HttpServerRequest req) {
194
- app.call(req);
195
- }
196
- });
197
- if (config.containsField("event_bus")) {
198
- JsonArray allowAll = new JsonArray();
199
- allowAll.add(new JsonObject());
200
-
201
- JsonArray incomingAllowed;
202
- JsonArray outgoingAllowed;
203
-
204
- if (config.containsField("event_bus_security")) {
205
- JsonObject securitySettings = config.getObject("event_bus_security");
206
- incomingAllowed = securitySettings.getArray("incoming", allowAll);
207
- outgoingAllowed = securitySettings.getArray("outgoing", allowAll);
208
- } else {
209
- incomingAllowed = allowAll;
210
- outgoingAllowed = allowAll;
211
- }
212
- JsonObject ebconf = new JsonObject();
213
- ebconf.putString("prefix", config.getString("event_bus"));
214
- vertx.createSockJSServer(httpServer).bridge(ebconf, incomingAllowed, outgoingAllowed);
215
-
216
- }
217
- if (ssl) httpServer.setSSL(true).setKeyStorePath(config.getString("keystore_path"))
218
- .setKeyStorePassword(config.getString("keystore_password"));
219
- httpServer.listen(config.getInteger("port", 8080), config.getString("host", "localhost"));
220
- } catch (IOException e) {
221
- container.logger().fatal("Failed to create RackApplication");
222
- }
223
- }
224
-
225
- @Override
226
- public void stop() {
227
- if (this.httpServer != null)
228
- this.httpServer.close();
229
- if (rackApplication != null) {
230
- try {
231
- // We call the script with receiver = null - this causes the method to be called on the top level
232
- // script
233
- scontainer.callMethod(rackApplication, "vertx_stop");
234
- } catch (InvokeFailedException e) {
235
- Throwable cause = e.getCause();
236
- if (cause instanceof RaiseException) {
237
- // Gosh, this is a bit long winded!
238
- RaiseException re = (RaiseException) cause;
239
- String msg = "(NoMethodError) undefined method `vertx_stop'";
240
- if (re.getMessage().startsWith(msg)) {
241
- // OK - method is not mandatory
242
- return;
243
- }
244
- }
245
- throw e;
246
- } finally {
247
- // Remove the module const
248
- scontainer.runScriptlet("Object.send(:remove_const, :" + modName + ")");
249
- }
250
- }
251
- }
252
-
253
- private String rackup;
254
- private IRubyObject rackApplication;
255
- private String modName;
256
- private HttpServer httpServer;
257
- }
258
- }