jubilee 2.1.0.beta-java → 2.1.0.rc1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +13 -1
  3. data/README.md +65 -54
  4. data/Rakefile +23 -21
  5. data/examples/chatapp/Gemfile +1 -2
  6. data/examples/chatapp/Gemfile.lock +2 -2
  7. data/examples/chatapp/README.md +14 -2
  8. data/examples/chatapp/app.rb +1 -0
  9. data/examples/chatapp/config.json +4 -0
  10. data/examples/chatapp/config.ru +0 -2
  11. data/jars/annotations-1.3.2.jar +0 -0
  12. data/jars/lang-jruby-2.1.0-final.jar +0 -0
  13. data/jars/log4j-1.2.16.jar +0 -0
  14. data/jars/slf4j-api-1.6.2.jar +0 -0
  15. data/jars/vertx-core-2.1.2.jar +0 -0
  16. data/jars/{vertx-hazelcast-2.1.1.jar → vertx-hazelcast-2.1.2.jar} +0 -0
  17. data/jars/{vertx-platform-2.1.1.jar → vertx-platform-2.1.2.jar} +0 -0
  18. data/lib/container.rb +117 -0
  19. data/lib/{vertx → core}/buffer.rb +1 -1
  20. data/lib/core/datagram.rb +280 -0
  21. data/lib/core/dns.rb +143 -0
  22. data/lib/{vertx → core}/event_bus.rb +79 -8
  23. data/lib/core/file_system.rb +479 -0
  24. data/lib/{vertx → core}/http.rb +635 -5
  25. data/lib/core/net.rb +251 -0
  26. data/lib/core/network_support.rb +77 -0
  27. data/lib/core/parsetools.rb +105 -0
  28. data/lib/{vertx → core}/shared_data.rb +2 -2
  29. data/lib/core/sock_js.rb +116 -0
  30. data/lib/{vertx → core}/ssl_support.rb +21 -1
  31. data/lib/{vertx → core}/streams.rb +32 -21
  32. data/lib/{vertx → core}/tcp_support.rb +22 -36
  33. data/lib/core/timers.rb +73 -0
  34. data/lib/core/vertx_require.rb +25 -0
  35. data/lib/{vertx → core}/wrapped_handler.rb +0 -0
  36. data/lib/jubilee.rb +5 -8
  37. data/lib/jubilee/cli.rb +1 -1
  38. data/lib/jubilee/jubilee.jar +0 -0
  39. data/lib/jubilee/jubilee_require.rb +24 -0
  40. data/lib/jubilee/version.rb +1 -1
  41. data/lib/test_utils.rb +66 -0
  42. data/lib/vertx.rb +13 -10
  43. data/lib/vertx_tests.rb +8 -0
  44. data/pom.xml +351 -0
  45. data/src/main/assembly/mod.xml +21 -0
  46. data/{java/src → src/main/java}/jubilee/JubileeService.java +0 -0
  47. data/{java/src → src/main/java}/org/jruby/jubilee/Const.java +0 -0
  48. data/{java/src → src/main/java}/org/jruby/jubilee/JubileeVerticle.java +12 -2
  49. data/src/main/java/org/jruby/jubilee/JubileeVerticleFactory.java +258 -0
  50. data/{java/src → src/main/java}/org/jruby/jubilee/RackApplication.java +3 -1
  51. data/{java/src → src/main/java}/org/jruby/jubilee/RackEnvironment.java +2 -2
  52. data/{java/src → src/main/java}/org/jruby/jubilee/RackEnvironmentHash.java +0 -0
  53. data/{java/src → src/main/java}/org/jruby/jubilee/RackInput.java +0 -0
  54. data/{java/src → src/main/java}/org/jruby/jubilee/RackResponse.java +0 -0
  55. data/{java/src → src/main/java}/org/jruby/jubilee/RubyCallable.java +0 -0
  56. data/{java/src → src/main/java}/org/jruby/jubilee/RubyHttpServerResponse.java +0 -0
  57. data/{java/src → src/main/java}/org/jruby/jubilee/RubyNetSocket.java +0 -0
  58. data/{java/src → src/main/java}/org/jruby/jubilee/RubyPlatformManager.java +0 -0
  59. data/{java/src → src/main/java}/org/jruby/jubilee/impl/RubyIORackInput.java +0 -0
  60. data/{java/src → src/main/java}/org/jruby/jubilee/impl/RubyNullIO.java +0 -0
  61. data/{java/src → src/main/java}/org/jruby/jubilee/utils/RubyHelper.java +0 -0
  62. data/{java/src → src/main/java}/org/jruby/jubilee/vertx/JubileeVertx.java +0 -0
  63. data/{java → src/main}/resources/META-INF/services/org.vertx.java.core.spi.cluster.ClusterManagerFactory +0 -0
  64. data/src/main/resources/META-INF/services/org.vertx.java.deploy.impl.jruby.JubileeVerticleFactory +1 -0
  65. data/{java → src/main}/resources/default-cluster.xml +0 -0
  66. data/src/main/resources/mod.json +11 -0
  67. data/test/jubilee/test_upload.rb +3 -1
  68. data/vertx_classpath.txt +12 -0
  69. metadata +69 -47
  70. data/Guardfile +0 -24
  71. data/jars/vertx-core-2.1.1.jar +0 -0
  72. data/java/src/org/jruby/jubilee/RubyChannel.java +0 -89
  73. data/lib/vertx/README.md +0 -7
@@ -0,0 +1,116 @@
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
+ require 'core/streams'
16
+ require 'core/ssl_support'
17
+ module Vertx
18
+
19
+ # This is an implementation of the server side part of {"https://github.com/sockjs"}
20
+ #
21
+ # SockJS enables browsers to communicate with the server using a simple WebSocket-like api for sending
22
+ # and receiving messages. Under the bonnet SockJS chooses to use one of several protocols depending on browser
23
+ # capabilities and what appears to be working across the network.
24
+ #
25
+ # Available protocols include:
26
+ #
27
+ # WebSockets
28
+ # xhr-polling
29
+ # xhr-streaming
30
+ # json-polling
31
+ # event-source
32
+ # html-file
33
+ #
34
+ # This means, it should just work irrespective of what browser is being used, and whether there are nasty
35
+ # things like proxies and load balancers between the client and the server.
36
+ #
37
+ # For more detailed information on SockJS, see their website.
38
+ #
39
+ # On the server side, you interact using instances of {SockJSSocket} - this allows you to send data to the
40
+ # client or receive data via the {ReadStream#data_handler}.
41
+ #
42
+ # You can register multiple applications with the same SockJSServer, each using different path prefixes, each
43
+ # application will have its own handler, and configuration is described in a Hash.
44
+ #
45
+ # @author {http://tfox.org Tim Fox}
46
+ class SockJSServer
47
+
48
+ # Create a new SockJSServer
49
+ # @param http_server [HttpServer] You must pass in an instance of {HttpServer}
50
+ def initialize(http_server)
51
+ @j_server = org.vertx.java.platform.impl.JRubyVerticleFactory.vertx.createSockJSServer(http_server._to_java_server)
52
+ end
53
+
54
+ # Install an application
55
+ # @param config [Hash] Configuration for the application
56
+ # @param proc [Proc] Proc representing the handler
57
+ # @param hndlr [Block] Handler to call when a new {SockJSSocket is created}
58
+ def install_app(config, proc = nil, &hndlr)
59
+ hndlr = proc if proc
60
+ j_config = org.vertx.java.core.json.JsonObject.new(config)
61
+ @j_server.installApp(j_config) { |j_sock|
62
+ hndlr.call(SockJSSocket.new(j_sock))
63
+ }
64
+ self
65
+ end
66
+
67
+ def bridge(config, inbound_permitted, outbound_permitted, auth_timeout = 5 * 60 * 1000, auth_address = nil)
68
+ j_inbound_permitted = org.vertx.java.core.json.JsonArray.new(inbound_permitted)
69
+ j_outbound_permitted = org.vertx.java.core.json.JsonArray.new(outbound_permitted)
70
+ @j_server.bridge(org.vertx.java.core.json.JsonObject.new(config), j_inbound_permitted,
71
+ j_outbound_permitted, auth_timeout, auth_address)
72
+ self
73
+ end
74
+
75
+ end
76
+
77
+ # You interact with SockJS clients through instances of SockJS socket.
78
+ # The API is very similar to {WebSocket}. It implements both
79
+ # {ReadStream} and {WriteStream} so it can be used with {Pump} to enable
80
+ # flow control.
81
+ #
82
+ # @author {http://tfox.org Tim Fox}
83
+ class SockJSSocket
84
+
85
+ include ReadStream, WriteStream
86
+
87
+ # @private
88
+ def initialize(j_sock)
89
+ @j_del = j_sock
90
+ @handler_id = EventBus.register_simple_handler { |msg|
91
+ write(msg.body)
92
+ }
93
+ end
94
+
95
+ # Close the socket
96
+ def close
97
+ EventBus.unregister_handler(@handler_id)
98
+ @j_del.close
99
+ end
100
+
101
+ # When a SockJSSocket is created it automatically registers an event handler with the system, the ID of that
102
+ # handler is given by {#handler_id}.
103
+ # Given this ID, a different event loop can send a buffer to that event handler using the event bus. This
104
+ # allows you to write data to other SockJSSockets which are owned by different event loops.
105
+ def handler_id
106
+ @handler_id
107
+ end
108
+
109
+ # @private
110
+ def _to_java_socket
111
+ @j_del
112
+ end
113
+
114
+ end
115
+
116
+ end
@@ -121,6 +121,26 @@ module Vertx
121
121
 
122
122
  end
123
123
 
124
+ # A mixin module allowing Server SSL attributes to be set on classes
125
+ #
126
+ # @author {http://tfox.org Tim Fox}
127
+ module ServerSSLSupport
128
+
129
+ def client_auth_required=(val)
130
+ @j_del.setClientAuthRequired(val)
131
+ self
132
+ end
133
+
134
+ def client_auth_required(val = nil)
135
+ if val
136
+ @j_del.setClientAuthRequired(val)
137
+ self
138
+ else
139
+ @j_del.isClientAuthRequired
140
+ end
141
+ end
142
+ end
143
+
124
144
  # A mixin module allowing Client SSL attributes to be set on classes
125
145
  #
126
146
  # @author {http://tfox.org Tim Fox}
@@ -140,4 +160,4 @@ module Vertx
140
160
  end
141
161
  end
142
162
  end
143
- end
163
+ end
@@ -14,21 +14,7 @@
14
14
 
15
15
  module Vertx
16
16
 
17
- # A mixin module which represents a stream of data that can be written to.
18
- #
19
- # Any class that mixes in this module can be used by a {Pump} to pump data from a {ReadStream} to it.
20
- #
21
- # @author {http://tfox.org Tim Fox}
22
- module WriteStream
23
-
24
- # Write some data to the stream. The data is put on an internal write queue, and the write actually happens
25
- # asynchronously. To avoid running out of memory by putting too much on the write queue,
26
- # check the {#write_queue_full?} method before writing. This is done automatically if using a {Pump}.
27
- # @param [Buffer]. The buffer to write.
28
- def write(buff)
29
- @j_del.write(buff._to_java_buffer)
30
- self
31
- end
17
+ module DrainSupport
32
18
 
33
19
  # Set the maximum size of the write queue. You will still be able to write to the stream even
34
20
  # if there is more data than this in the write queue. This is used as an indicator by classes such as
@@ -64,6 +50,25 @@ module Vertx
64
50
  @j_del.exceptionHandler(hndlr)
65
51
  self
66
52
  end
53
+ end
54
+
55
+ # A mixin module which represents a stream of data that can be written to.
56
+ #
57
+ # Any class that mixes in this module can be used by a {Pump} to pump data from a {ReadStream} to it.
58
+ #
59
+ # @author {http://tfox.org Tim Fox}
60
+ module WriteStream
61
+
62
+ include DrainSupport
63
+
64
+ # Write some data to the stream. The data is put on an internal write queue, and the write actually happens
65
+ # asynchronously. To avoid running out of memory by putting too much on the write queue,
66
+ # check the {#write_queue_full?} method before writing. This is done automatically if using a {Pump}.
67
+ # @param [Buffer]. The buffer to write.
68
+ def write(buff)
69
+ @j_del.write(buff._to_java_buffer)
70
+ self
71
+ end
67
72
 
68
73
  # @private
69
74
  def _to_write_stream
@@ -72,12 +77,8 @@ module Vertx
72
77
 
73
78
  end
74
79
 
75
- # A mixin module which represents a stream of data that can be read from.
76
- #
77
- # Any class that mixes in this module can be used by a {Pump} to pump data from a {ReadStream} to it.
78
- #
79
- # @author {http://tfox.org Tim Fox}
80
- module ReadStream
80
+
81
+ module ReadSupport
81
82
 
82
83
  # Set a data handler. As data is read, the handler will be called with the data.
83
84
  # @param [Block] hndlr. The data handler
@@ -106,6 +107,16 @@ module Vertx
106
107
  @j_del.exceptionHandler(hndlr)
107
108
  self
108
109
  end
110
+ end
111
+
112
+ # A mixin module which represents a stream of data that can be read from.
113
+ #
114
+ # Any class that mixes in this module can be used by a {Pump} to pump data from a {ReadStream} to it.
115
+ #
116
+ # @author {http://tfox.org Tim Fox}
117
+ module ReadStream
118
+
119
+ include ReadSupport
109
120
 
110
121
  # Set an end handler on the stream. Once the stream has ended, and there is no more data to be read, this handler will be called.
111
122
  # @param [Block] hndlr. The exception handler
@@ -13,47 +13,14 @@
13
13
  # limitations under the License.
14
14
 
15
15
  module Vertx
16
+ require 'core/network_support'
16
17
 
17
18
  # Mixin module that provides all the common TCP params that can be set.
18
19
  #
19
20
  # @author {http://tfox.org Tim Fox}
20
21
  module TCPSupport
21
22
 
22
- # Set the TCP send buffer size.
23
- # @param [FixNum] val. The size in bytes.
24
- # @return [] A reference to self so invocations can be chained
25
- def send_buffer_size=(val)
26
- @j_del.setSendBufferSize(val)
27
- self
28
- end
29
-
30
- # Set or get send buffer size for fluent API
31
- def send_buffer_size(val = nil)
32
- if val
33
- @j_del.setSendBufferSize(val)
34
- self
35
- else
36
- @j_del.getSendBufferSize
37
- end
38
- end
39
-
40
- # Set the TCP receive buffer size.
41
- # @param [FixNum] val. The size in bytes.
42
- # @return [] A reference to self so invocations can be chained
43
- def receive_buffer_size=(val)
44
- @j_del.setReceiveBufferSize(val)
45
- self
46
- end
47
-
48
- # Set or get send buffer size for fluent API
49
- def send_receive_size(val = nil)
50
- if val
51
- @j_del.setReceiveBufferSize(val)
52
- self
53
- else
54
- @j_del.getReceiveBufferSize
55
- end
56
- end
23
+ include NetworkSupport
57
24
 
58
25
  # Set the TCP keep alive setting.
59
26
  # @param [Boolean] val. If true, then TCP keep alive will be enabled.
@@ -147,4 +114,23 @@ module Vertx
147
114
 
148
115
  end
149
116
 
150
- end
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
@@ -0,0 +1,73 @@
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
@@ -0,0 +1,25 @@
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
+
File without changes
@@ -1,11 +1,5 @@
1
- require File.join(File.dirname(__FILE__), "../jars/jackson-core-2.2.2.jar")
2
- require File.join(File.dirname(__FILE__), "../jars/jackson-databind-2.2.2.jar")
3
- require File.join(File.dirname(__FILE__), "../jars/jackson-annotations-2.2.2.jar")
4
- require File.join(File.dirname(__FILE__), "../jars/hazelcast-3.2.3.jar")
5
- require File.join(File.dirname(__FILE__), "../jars/vertx-core-2.1.1.jar")
6
- require File.join(File.dirname(__FILE__), "../jars/vertx-hazelcast-2.1.1.jar")
7
- require File.join(File.dirname(__FILE__), "../jars/vertx-platform-2.1.1.jar")
8
- require File.join(File.dirname(__FILE__), "../jars/netty-all-4.0.20.Final.jar")
1
+ # this is only used when it's running as a rubygem
2
+ Dir[File.expand_path("../../jars/*.jar", __FILE__)].each{|jar| require jar}
9
3
 
10
4
  require 'jubilee/jubilee.jar'
11
5
  require 'rack'
@@ -16,3 +10,6 @@ require 'jubilee/application'
16
10
  require 'jubilee/configuration'
17
11
  require 'jubilee/response'
18
12
  require 'rack/handler/jubilee'
13
+
14
+ module Jubilee
15
+ end
@@ -129,7 +129,7 @@ module Jubilee
129
129
  end
130
130
 
131
131
  o.on "-v", "--version", "Print the version information" do
132
- puts "jubilee version #{Jubilee::Version::STRING} on Vert.x 2.1.1"
132
+ puts "jubilee version #{Jubilee::Version::STRING} on Vert.x 2.1.2"
133
133
  exit 0
134
134
  end
135
135
  end
Binary file
@@ -0,0 +1,24 @@
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