jubilee 2.1.0.beta-java → 2.1.0.rc1-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 (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,251 @@
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
+ require 'core/tcp_support'
18
+ require 'core/wrapped_handler'
19
+ require 'socket'
20
+
21
+
22
+ module Vertx
23
+
24
+ # Represents a TCP or SSL Server
25
+ #
26
+ # When connections are accepted by the server
27
+ # they are supplied to the user in the form of a {NetSocket} instance that is passed via the handler
28
+ # set using {#connect_handler}.
29
+ #
30
+ # @author {http://tfox.org Tim Fox}
31
+ class NetServer
32
+
33
+ include SSLSupport, ServerSSLSupport, TCPSupport, ServerTCPSupport
34
+
35
+ # Create a new NetServer
36
+ def initialize
37
+ @j_del = org.vertx.java.platform.impl.JRubyVerticleFactory.vertx.createNetServer
38
+ end
39
+
40
+ # Supply a connect handler for this server. The server can only have at most one connect handler at any one time.
41
+ # As the server accepts TCP or SSL connections it creates an instance of {NetSocket} and passes it to the
42
+ # connect handler.
43
+ # @param [Block] hndlr A block to be used as the handler
44
+ # @return [NetServer] A reference to self so invocations can be chained
45
+ def connect_handler(&hndlr)
46
+ @j_del.connectHandler{ |j_socket| hndlr.call(NetSocket.new(j_socket)) }
47
+ self
48
+ end
49
+
50
+ # Instruct the server to listen for incoming connections.
51
+ # @param [FixNum] port. The port to listen on.
52
+ # @param [FixNum] host. The host name or ip address to listen on.
53
+ # @param [Block] hndlr. The handler will be called when the server is listening or a failure occurred.
54
+ def listen(port, host = "0.0.0.0", &hndlr)
55
+ @j_del.listen(port, host, ARWrappedHandler.new(hndlr) {|j_del| self})
56
+ self
57
+ end
58
+
59
+ # Close the server. The handler will be called when the close is complete.
60
+ def close(&hndlr)
61
+ @j_del.close(ARWrappedHandler.new(hndlr))
62
+ end
63
+
64
+ # Get the port
65
+ def port
66
+ @j_del.port
67
+ end
68
+
69
+ # Get the host
70
+ def host
71
+ @j_del.host
72
+ end
73
+
74
+ end
75
+
76
+ # NetClient is an asynchronous factory for TCP or SSL connections.
77
+ #
78
+ # Multiple connections to different servers can be made using the same instance.
79
+ #
80
+ # @author {http://tfox.org Tim Fox}
81
+ class NetClient
82
+
83
+ include SSLSupport, ClientSSLSupport, TCPSupport
84
+
85
+ # Create a new NetClient
86
+ def initialize
87
+ @j_del = org.vertx.java.platform.impl.JRubyVerticleFactory.vertx.createNetClient
88
+ end
89
+
90
+ # Attempt to open a connection to a server. The connection is opened asynchronously and the result returned in the
91
+ # handler.
92
+ # @param [FixNum] port. The port to connect to.
93
+ # @param [String] host. The host or ip address to connect to.
94
+ # @param [Block] hndlr A block to be used as the handler. The handler will be called with an exception or the
95
+ # {NetSocket}
96
+ # @return [NetClient] A reference to self so invocations can be chained
97
+ def connect(port, host = "localhost", &hndlr)
98
+ hndlr = ARWrappedHandler.new(hndlr) { |j_socket| NetSocket.new(j_socket) }
99
+ @j_del.connect(port, host, hndlr)
100
+ self
101
+ end
102
+
103
+ # Set the reconnect attempts
104
+ def reconnect_attempts=(val)
105
+ @j_del.setReconnectAttempts(val)
106
+ self
107
+ end
108
+
109
+ # Set or Get the reconnect attempts for a fluent API
110
+ def reconnect_attempts(val = nil)
111
+ if val
112
+ @j_del.setReconnectAttempts(val)
113
+ self
114
+ else
115
+ @j_del.getReconnectAttempts
116
+ end
117
+ end
118
+
119
+ # Set the reconnect interval
120
+ def reconnect_interval=(val)
121
+ @j_del.setReconnectInterval(val)
122
+ self
123
+ end
124
+
125
+ # Set or Get the reconnect interval for a fluent API
126
+ def reconnect_interval(val = nil)
127
+ if val
128
+ @j_del.setReconnectInterval(val)
129
+ self
130
+ else
131
+ @j_del.getReconnectInterval
132
+ end
133
+ end
134
+
135
+ # Set the connect timeout
136
+ def connect_timeout=(val)
137
+ @j_del.setConnectTimeout(val)
138
+ self
139
+ end
140
+
141
+ # Set or Get the connect timeout for a fluent API
142
+ def connect_timeout(val = nil)
143
+ if val
144
+ @j_del.setConnectTimeout(val)
145
+ self
146
+ else
147
+ @j_del.getConnectTimeout
148
+ end
149
+ end
150
+
151
+ # Close the NetClient. Any open connections will be closed.
152
+ def close
153
+ @j_del.close
154
+ end
155
+
156
+ end
157
+
158
+
159
+ # NetSocket is a socket-like abstraction used for reading from or writing
160
+ # to TCP connections.
161
+ #
162
+ # @author {http://tfox.org Tim Fox}
163
+ class NetSocket
164
+
165
+ include ReadStream, WriteStream
166
+
167
+ # @private
168
+ def initialize(j_socket)
169
+ @j_del = j_socket
170
+ @local_addr = nil
171
+ @remote_addr = nil
172
+ @write_handler_id = EventBus.register_simple_handler { |msg|
173
+ write(msg.body)
174
+ }
175
+ @j_del.closeHandler(Proc.new {
176
+ EventBus.unregister_handler(@write_handler_id)
177
+ @close_handler.call if @close_handler
178
+ })
179
+ end
180
+
181
+ # Upgrade channel to use SSL/TLS. Be aware that for this to work SSL must be configured.
182
+ def ssl
183
+ raise 'An handler must be provided' unless block_given?
184
+ @j_del.ssl InternalHandler.new(Proc.new)
185
+ self
186
+ end
187
+
188
+ # Returns true if NetSocket is SSL/TSL Encrypted.
189
+ def ssl?
190
+ @j_del.isSsl
191
+ end
192
+
193
+ # Write a String to the socket. The handler will be called when the string has actually been written to the wire.
194
+ # @param [String] str. The string to write.
195
+ # @param [String] enc. The encoding to use.
196
+ def write_str(str, enc = "UTF-8")
197
+ @j_del.write(str, enc)
198
+ self
199
+ end
200
+
201
+ # Set a closed handler on the socket.
202
+ # @param [Block] hndlr A block to be used as the handler
203
+ def close_handler(&hndlr)
204
+ @close_handler = hndlr
205
+ self
206
+ end
207
+
208
+ # Tell the kernel to stream a file directly from disk to the outgoing connection, bypassing userspace altogether
209
+ # (where supported by the underlying operating system. This is a very efficient way to stream files.
210
+ # @param [String] file_path. Path to file to send.
211
+ def send_file(file_path, &block)
212
+ if block.given?
213
+ @j_del.sendFile(file_path, ARWrappedHandler.new(block))
214
+ else
215
+ @j_del.sendFile(file_path)
216
+ end
217
+ self
218
+ end
219
+
220
+ # Close the socket
221
+ def close
222
+ @j_del.close
223
+ end
224
+
225
+ # When a NetSocket is created it automatically registers an event handler with the system. The address of that
226
+ # handler is given by {#write_handler_id}.
227
+ # Given this ID, a different event loop can send a buffer to that event handler using the event bus. This
228
+ # allows you to write data to other connections which are owned by different event loops.
229
+ def write_handler_id
230
+ @write_handler_id
231
+ end
232
+
233
+ # Return the Addrinfo to which the remote end of the socket is bound
234
+ def remote_address
235
+ if !@remote_addr
236
+ @remote_addr = Addrinfo.tcp(@j_del.remoteAddress().getAddress().getHostAddress(), @j_del.remoteAddress().getPort())
237
+ end
238
+ @remote_addr
239
+ end
240
+
241
+
242
+ # Return the Addrinfo to which the local end of the socket is bound
243
+ def local_address
244
+ if !@local_addr
245
+ @local_addr = Addrinfo.tcp(@j_del.localAddress().getAddress().getHostAddress(), @j_del.localAddress().getPort())
246
+ end
247
+ @local_addr
248
+ end
249
+ end
250
+ end
251
+
@@ -0,0 +1,77 @@
1
+ # Copyright 2013 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
+ # Mixin module that provides all the common Network params that can be set.
18
+ #
19
+ # @author {http://tfox.org Tim Fox}
20
+ module NetworkSupport
21
+
22
+ # Set the 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
+ # Get send buffer size for fluent API
31
+ def send_buffer_size
32
+ @j_del.getSendBufferSize
33
+ end
34
+
35
+ # Set the receive buffer size.
36
+ # @param [FixNum] val. The size in bytes.
37
+ # @return [] A reference to self so invocations can be chained
38
+ def receive_buffer_size=(val)
39
+ @j_del.setReceiveBufferSize(val)
40
+ self
41
+ end
42
+
43
+ #
44
+ # Gets the receive buffer size.
45
+ #
46
+ def receive_buffer_size
47
+ @j_del.getReceiveBufferSize
48
+ end
49
+
50
+
51
+ # Set the TCP reuse address setting.
52
+ # @param [Boolean] val. If true, then TCP reuse address will be enabled.
53
+ # @return [] A reference to self so invocations can be chained
54
+ def reuse_address=(val)
55
+ @j_del.setReuseAddress(val)
56
+ self
57
+ end
58
+
59
+ # Get TCP reuse address for fluent API
60
+ def reuse_address?
61
+ @j_del.isReuseAddress
62
+ end
63
+
64
+ # Set the traffic class setting.
65
+ # @param [FixNum] val. The TCP traffic class setting.
66
+ # @return [] A reference to self so invocations can be chained
67
+ def traffic_class=(val)
68
+ @j_del.setTrafficClass(val)
69
+ self
70
+ end
71
+
72
+ # Get traffic class for fluent API
73
+ def traffic_class
74
+ @j_del.getTrafficClass
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,105 @@
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
+ # A helper class which allows you to easily parse protocols which are delimited by a sequence of bytes, or fixed
18
+ # size records.
19
+ #
20
+ # Instances of this class take as input {Buffer} instances containing raw bytes, and output records.
21
+ # For example, if I had a simple ASCII text protocol delimited by '\n' and the input was the following:
22
+ #
23
+ # buffer1:HELLO\nHOW ARE Y
24
+ # buffer2:OU?\nI AM
25
+ # buffer3: DOING OK
26
+ # buffer4:\n
27
+ #
28
+ # Then the output would be:
29
+ #
30
+ # buffer1:HELLO
31
+ # buffer2:HOW ARE YOU?
32
+ # buffer3:I AM DOING OK
33
+ #
34
+ # Instances of this class can be changed between delimited mode and fixed size record mode on the fly as
35
+ # individual records are read, this allows you to parse protocols where, for example, the first 5 records might
36
+ # all be fixed size (of potentially different sizes), followed by some delimited records, followed by more fixed
37
+ # size records.
38
+ #
39
+ # Instances of this class can't currently be used for protocols where the text is encoded with something other than
40
+ # a 1-1 byte-char mapping.
41
+ #
42
+ # @author {http://tfox.org Tim Fox}
43
+ class RecordParser
44
+
45
+ # @private
46
+ def initialize(java_parser)
47
+ @java_parser = java_parser
48
+ end
49
+
50
+ # @private
51
+ def call(data)
52
+ input(data)
53
+ end
54
+
55
+ # Convert it to a Proc
56
+ def to_proc
57
+ return Proc.new do |data|
58
+ input(data)
59
+ end
60
+ end
61
+
62
+ # This method is called to provide the parser with data.
63
+ # @param [Buffer] data. Input data to the parser.
64
+ def input(data)
65
+ @java_parser.handle(data._to_java_buffer)
66
+ end
67
+
68
+ # Create a new RecordParser instance, initially in delimited mode, and where the delimiter can be represented
69
+ # by a delimiter string endcoded in latin-1 . Don't use this if your String contains other than latin-1 characters.
70
+ # @param [String] delim. The delimiter string.
71
+ # @param [Proc] proc A proc to be used as the output handler
72
+ # @param [Block] output_block A block to be used as the output handler
73
+ # @return [RecordParser] a new RecordParser
74
+ def RecordParser.new_delimited(delim, proc = nil, &output_block)
75
+ output_block = proc if proc
76
+ RecordParser.new(org.vertx.java.core.parsetools.RecordParser.newDelimited(delim, output_block))
77
+ end
78
+
79
+ # Create a new RecordParser instance, initially in fixed size mode.
80
+ # @param [FixNum] size. The initial record size.
81
+ # @param [Proc] proc A proc to be used as the output handler
82
+ # @param [Block] output_block A block to be used as the output handler
83
+ # @return [RecordParser] a new RecordParser
84
+ def RecordParser.new_fixed(size, proc = nil, &output_block)
85
+ output_block = proc if proc
86
+ RecordParser.new(org.vertx.java.core.parsetools.RecordParser.newFixed(size, output_block))
87
+ end
88
+
89
+ # Flip the parser into delimited mode. This method can be called multiple times with different values
90
+ # of delim while data is being parsed.
91
+ # @param [String] delim. The delimiter string.
92
+ def delimited_mode(delim)
93
+ @java_parser.delimitedMode(delim)
94
+ end
95
+
96
+ # Flip the parser into fixed size mode. This method can be called multiple times with different values
97
+ # of size while data is being parsed.
98
+ # @param [FixNum] size. The record size.
99
+ def fixed_size_mode(size)
100
+ @java_parser.fixedSizeMode(size)
101
+ end
102
+
103
+ end
104
+
105
+ end
@@ -33,7 +33,7 @@ module Vertx
33
33
  # @author {http://tfox.org Tim Fox}
34
34
  class SharedData
35
35
 
36
- @@j_sd = org.jruby.jubilee.vertx.JubileeVertx.vertx().sharedData()
36
+ @@j_sd = org.vertx.java.platform.impl.JRubyVerticleFactory.vertx.sharedData()
37
37
 
38
38
  # Return a Hash with the specific name. All invocations of this method with the same value of name
39
39
  # are guaranteed to return the same Hash instance.
@@ -211,4 +211,4 @@ module Vertx
211
211
 
212
212
  end
213
213
  end
214
- end
214
+ end