jubilee 2.0.0.beta-java → 2.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb61786745898bab811507f1d76d6bbdc77e5485
4
- data.tar.gz: 03df7c9f9b145f2287a1b453aef1e1159a85a899
3
+ metadata.gz: 31e24331a936300e3f3bb67b16e5b05376fcb2aa
4
+ data.tar.gz: 22ec68885ddfd56a2b0d42fe1be450e40d596e7b
5
5
  SHA512:
6
- metadata.gz: 707de86b4d5b2bda6e5a10726209642f7d703533b59e7b6069683efa4202b960213118a384771150f27d2fa4848547641abb273788f5d64397dee5ca247ac362
7
- data.tar.gz: a2fa31e40c0dae6c7e4e023c3293c157fd54984530277bdc1c586abee40ed6f078ddf228067bf0de2a554d78686954a35c5bb489913018844e07180d0a509b56
6
+ metadata.gz: ad993339e4c2e8ff3314c17836fd8902c83db105b86554b88d90bc38d0117d25548919dcad367cd204f013b39639d4a94191b50d158f5d836906fe045b5d9b5f
7
+ data.tar.gz: 8e3144d4805b226a6e82da0f01ec069402cf21d050eb0df1af16ab89e4dd42c1885c82de3c88ad1773fc46be3d6a5147efbcf470bc1f995a587f8d658067554b
@@ -2,4 +2,4 @@ source "https://rubygems.org"
2
2
  gem 'sinatra'
3
3
  gem 'haml'
4
4
 
5
- gem 'jubilee', '2.0.0.alpha1'
5
+ gem 'jubilee', '2.0.0.beta'
@@ -4,7 +4,7 @@ GEM
4
4
  ffi (1.9.3-java)
5
5
  haml (4.0.4)
6
6
  tilt
7
- jubilee (2.0.0.alpha1-java)
7
+ jubilee (2.0.0.beta-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 (= 2.0.0.alpha1)
26
+ jubilee (= 2.0.0.beta)
27
27
  sinatra
Binary file
@@ -3,7 +3,7 @@ module Jubilee
3
3
  MAJOR = 2
4
4
  MINOR = 0
5
5
  PATCH = 0
6
- BUILD = "beta"
6
+ BUILD = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
9
9
  end
@@ -16,6 +16,7 @@ include Java
16
16
 
17
17
  require 'vertx/buffer'
18
18
  require 'vertx/event_bus'
19
+ require 'vertx/http'
19
20
 
20
21
  # This is the module for vertx related feature like EventBus and SharedData,
21
22
  # these features are built into jubilee server, by requiring 'vertx' in your
@@ -0,0 +1,677 @@
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 'vertx/streams'
16
+ require 'vertx/ssl_support'
17
+ require 'vertx/tcp_support'
18
+ require 'vertx/wrapped_handler'
19
+
20
+ module Vertx
21
+ # An HTTP client.
22
+ # A client maintains a pool of connections to a specific host, at a specific port. The HTTP connections can act
23
+ # as pipelines for HTTP requests.
24
+ # It is used as a factory for {HttpClientRequest} instances which encapsulate the actual HTTP requests. It is also
25
+ # used as a factory for {WebSocket WebSockets}.
26
+ #
27
+ # @author {http://tfox.org Tim Fox}
28
+ class HttpClient
29
+
30
+ include SSLSupport, ClientSSLSupport, TCPSupport
31
+
32
+ # Create a new HttpClient
33
+ def initialize(config = {})
34
+ @j_del = org.jruby.jubilee.vertx.JubileeVertx.vertx().createHttpClient()
35
+ self.compression = config[:try_compression] if config.has_key?(:try_compression)
36
+ end
37
+
38
+ # Enables HTTP compression.
39
+ # exposes a = method to set or unset compression support.
40
+ # @param [Boolean] supported whether enable compression or not
41
+ def compression=(supported)
42
+ @j_del.setTryUseCompression(supported)
43
+ end
44
+
45
+ # Tests if client is trying to use HTTP compression or not
46
+ # @return [Boolean] true if Client is trying using HTTP compression, false if it doesn't
47
+ def compression
48
+ @j_del.getTryUseCompression
49
+ end
50
+
51
+ # Letting the developer choose between compression? or compression while developing
52
+ alias_method :compression?, :compression
53
+
54
+ # Set the exception handler.
55
+ # @param [Block] hndlr A block to be used as the handler
56
+ def exception_handler(&hndlr)
57
+ @j_del.exceptionHandler(hndlr)
58
+ self
59
+ end
60
+
61
+ # Set the maximum pool size.
62
+ # The client will maintain up to this number of HTTP connections in an internal pool
63
+ # @param [FixNum] val. The maximum number of connections (default to 1).
64
+ def max_pool_size=(val)
65
+ @j_del.setMaxPoolSize(val)
66
+ self
67
+ end
68
+
69
+ # Get or set the max pool size
70
+ def max_pool_size(val = nil)
71
+ if val
72
+ @j_del.setMaxPoolSize(val)
73
+ self
74
+ else
75
+ @j_del.getMaxPoolSize
76
+ end
77
+ end
78
+
79
+ # If val is true then, after the request has ended the connection will be returned to the pool
80
+ # where it can be used by another request. In this manner, many HTTP requests can be pipe-lined over an HTTP connection.
81
+ # Keep alive connections will not be closed until the {#close} method is invoked.
82
+ # If val is false then a new connection will be created for each request and it won't ever go in the pool,
83
+ # the connection will closed after the response has been received. Even with no keep alive, the client will not allow more
84
+ # than {#max_pool_size} connections to be created at any one time.
85
+ # @param [Boolean] val. The value to use for keep_alive
86
+ def keep_alive=(val)
87
+ @j_del.setTCPKeepAlive(val)
88
+ self
89
+ end
90
+
91
+ # Get or set keep alive
92
+ def keep_alive(val = nil)
93
+ if val
94
+ @j_del.setKeepAlive(val)
95
+ self
96
+ else
97
+ @j_del.isKeepAlive
98
+ end
99
+ end
100
+
101
+ # Set the port that the client will attempt to connect to on the server on. The default value is 80
102
+ # @param [FixNum] val. The port value.
103
+ def port=(val)
104
+ @j_del.setPort(val)
105
+ self
106
+ end
107
+
108
+ # Get or set port
109
+ def port(val = nil)
110
+ if val
111
+ @j_del.setPort(val)
112
+ self
113
+ else
114
+ @j_del.getPort
115
+ end
116
+ end
117
+
118
+ # Set the host name or ip address that the client will attempt to connect to on the server on.
119
+ # @param [String] host. The host name or ip address to connect to.
120
+ def host=(val)
121
+ @j_del.setHost(val)
122
+ self
123
+ end
124
+
125
+ # Get or set host
126
+ def host(val = nil)
127
+ if val
128
+ @j_del.setHost(val)
129
+ self
130
+ else
131
+ @j_del.getHost
132
+ end
133
+ end
134
+
135
+ # Get or set verify host
136
+ def verify_host(val = nil)
137
+ if val
138
+ @j_del.setVerifyHost(val)
139
+ self
140
+ else
141
+ @j_del.isVerifyHost
142
+ end
143
+ end
144
+
145
+ # Gets the max WebSocket Frame size in bytes
146
+ # @return [int] Max WebSocket frame size
147
+ def max_websocket_frame_size
148
+ @j_del.getMaxWebSocketFrameSize
149
+ end
150
+
151
+ # Sets the maximum WebSocket frame size in bytes. Default is 65536 bytes.
152
+ # @param [int] size
153
+ def max_websocket_frame_size=(size)
154
+ @j_del.setMaxWebSocketFrameSize(size)
155
+ end
156
+
157
+ # Attempt to connect a WebSocket to the specified URI.
158
+ # The connect is done asynchronously and the handler is called with a {WebSocket} on success.
159
+ # @param [String] uri. A relative URI where to connect the WebSocket on the host, e.g. /some/path
160
+ # @param [Block] hndlr. The handler to be called with the {WebSocket}
161
+ def connect_web_socket(uri, &hndlr)
162
+ @j_del.connectWebsocket(uri) { |j_ws| hndlr.call(WebSocket.new(j_ws)) }
163
+ self
164
+ end
165
+
166
+ # This is a quick version of the {#get} method where you do not want to do anything with the request
167
+ # before sending.
168
+ # Normally with any of the HTTP methods you create the request then when you are ready to send it you call
169
+ # {HttpClientRequest#end} on it. With this method the request is immediately sent.
170
+ # When an HTTP response is received from the server the handler is called passing in the response.
171
+ # @param [String] uri. A relative URI where to perform the GET on the server.
172
+ # @param [Hash] headers. A Hash of headers to pass with the request.
173
+ # @param [Block] hndlr. The handler to be called with the {HttpClientResponse}
174
+ def get_now(uri, headers = nil, &hndlr)
175
+ @j_del.getNow(uri, headers, resp_handler(hndlr))
176
+ self
177
+ end
178
+
179
+ # This method returns an {HttpClientRequest} instance which represents an HTTP OPTIONS request with the specified uri.
180
+ # When an HTTP response is received from the server the handler is called passing in the response.
181
+ # @param [String] uri. A relative URI where to perform the OPTIONS on the server.
182
+ # @param [Block] hndlr. The handler to be called with the {HttpClientResponse}
183
+ def options(uri, &hndlr)
184
+ HttpClientRequest.new(@j_del.options(uri, resp_handler(hndlr)))
185
+ end
186
+
187
+ # This method returns an {HttpClientRequest} instance which represents an HTTP GET request with the specified uri.
188
+ # When an HTTP response is received from the server the handler is called passing in the response.
189
+ # @param [String] uri. A relative URI where to perform the GET on the server.
190
+ # @param [Block] hndlr. The handler to be called with the {HttpClientResponse}
191
+ def get(uri, &hndlr)
192
+ HttpClientRequest.new(@j_del.get(uri, resp_handler(hndlr)))
193
+ end
194
+
195
+ # This method returns an {HttpClientRequest} instance which represents an HTTP HEAD request with the specified uri.
196
+ # When an HTTP response is received from the server the handler is called passing in the response.
197
+ # @param [String] uri. A relative URI where to perform the HEAD on the server.
198
+ # @param [Block] hndlr. The handler to be called with the {HttpClientResponse}
199
+ def head(uri, &hndlr)
200
+ HttpClientRequest.new(@j_del.head(uri, resp_handler(hndlr)))
201
+ end
202
+
203
+ # This method returns an {HttpClientRequest} instance which represents an HTTP POST request with the specified uri.
204
+ # When an HTTP response is received from the server the handler is called passing in the response.
205
+ # @param [String] uri. A relative URI where to perform the POST on the server.
206
+ # @param [Block] hndlr. The handler to be called with the {HttpClientResponse}
207
+ def post(uri, &hndlr)
208
+ HttpClientRequest.new(@j_del.post(uri, resp_handler(hndlr)))
209
+ end
210
+
211
+ # This method returns an {HttpClientRequest} instance which represents an HTTP PUT request with the specified uri.
212
+ # When an HTTP response is received from the server the handler is called passing in the response.
213
+ # @param [String] uri. A relative URI where to perform the PUT on the server.
214
+ # @param [Block] hndlr. The handler to be called with the {HttpClientResponse}
215
+ def put(uri, &hndlr)
216
+ HttpClientRequest.new(@j_del.put(uri, resp_handler(hndlr)))
217
+ end
218
+
219
+ # This method returns an {HttpClientRequest} instance which represents an HTTP DELETE request with the specified uri.
220
+ # When an HTTP response is received from the server the handler is called passing in the response.
221
+ # @param [String] uri. A relative URI where to perform the DELETE on the server.
222
+ # @param [Block] hndlr. The handler to be called with the {HttpClientResponse}
223
+ def delete(uri, &hndlr)
224
+ HttpClientRequest.new(@j_del.delete(uri, resp_handler(hndlr)))
225
+ end
226
+
227
+ # This method returns an {HttpClientRequest} instance which represents an HTTP TRACE request with the specified uri.
228
+ # When an HTTP response is received from the server the handler is called passing in the response.
229
+ # @param [String] uri. A relative URI where to perform the TRACE on the server.
230
+ # @param [Block] hndlr. The handler to be called with the {HttpClientResponse}
231
+ def trace(uri, &hndlr)
232
+ HttpClientRequest.new(@j_del.trace(uri, resp_handler(hndlr)))
233
+ end
234
+
235
+ # This method returns an {HttpClientRequest} instance which represents an HTTP CONNECT request with the specified uri.
236
+ # When an HTTP response is received from the server the handler is called passing in the response.
237
+ # @param [String] uri. A relative URI where to perform the CONNECT on the server.
238
+ # @param [Block] hndlr. The handler to be called with the {HttpClientResponse}
239
+ def connect(uri, &hndlr)
240
+ HttpClientRequest.new(@j_del.connect(uri, resp_handler(hndlr)))
241
+ end
242
+
243
+ # This method returns an {HttpClientRequest} instance which represents an HTTP PATCH request with the specified uri.
244
+ # When an HTTP response is received from the server the handler is called passing in the response.
245
+ # @param [String] uri. A relative URI where to perform the PATCH on the server.
246
+ # @param [Block] hndlr. The handler to be called with the {HttpClientResponse}
247
+ def patch(uri, &hndlr)
248
+ HttpClientRequest.new(@j_del.patch(uri, resp_handler(hndlr)))
249
+ end
250
+
251
+ # This method returns an {HttpClientRequest} instance which represents an HTTP request with the specified method and uri.
252
+ # When an HTTP response is received from the server the handler is called passing in the response.
253
+ # @param [String] method. The HTTP method. Can be one of OPTIONS, HEAD, GET, POST, PUT, DELETE, TRACE, CONNECT.
254
+ # @param [String] uri. A relative URI where to perform the OPTIONS on the server.
255
+ # @param [Block] hndlr. The handler to be called with the {HttpClientResponse}
256
+ def request(method, uri, &hndlr)
257
+ HttpClientRequest.new(@j_del.request(method, uri, resp_handler(hndlr)))
258
+ end
259
+
260
+ # Close the client. Any unclosed connections will be closed.
261
+ def close
262
+ @j_del.close
263
+ end
264
+
265
+ # @private
266
+ def resp_handler(hndlr)
267
+ Proc.new { |j_del| hndlr.call(HttpClientResponse.new(j_del)) }
268
+ end
269
+
270
+ private :resp_handler
271
+
272
+ end
273
+
274
+ # Encapsulates a client-side HTTP request.
275
+ #
276
+ # Instances of this class are created by an {HttpClient} instance, via one of the methods corresponding to the
277
+ # specific HTTP methods, or the generic {HttpClient#request} method.
278
+ #
279
+ # Once an instance of this class has been obtained, headers can be set on it, and data can be written to its body,
280
+ # if required. Once you are ready to send the request, the {#end} method must called.
281
+ #
282
+ # Nothing is sent until the request has been internally assigned an HTTP connection. The {HttpClient} instance
283
+ # will return an instance of this class immediately, even if there are no HTTP connections available in the pool. Any requests
284
+ # sent before a connection is assigned will be queued internally and actually sent when an HTTP connection becomes
285
+ # available from the pool.
286
+ #
287
+ # The headers of the request are actually sent either when the {#end} method is called, or, when the first
288
+ # part of the body is written, whichever occurs first.
289
+ #
290
+ # This class supports both chunked and non-chunked HTTP.
291
+ #
292
+ # @author {http://tfox.org Tim Fox}
293
+ class HttpClientRequest
294
+
295
+ include WriteStream
296
+
297
+ # @private
298
+ def initialize(j_del)
299
+ @j_del = j_del
300
+ end
301
+
302
+ # MultiMap of headers for the request
303
+ def headers
304
+ if !@headers
305
+ @headers = MultiMap.new(@j_del.headers)
306
+ end
307
+ @headers
308
+ end
309
+
310
+ # Inserts a header into the request.
311
+ # @param [String] key The header key
312
+ # @param [Object] value The header value. to_s will be called on the value to determine the actual String value to insert.
313
+ # @return [HttpClientRequest] self So multiple operations can be chained.
314
+ def put_header(key, value)
315
+ @j_del.putHeader(key, value.to_s)
316
+ self
317
+ end
318
+
319
+ # Write a [String] to the request body.
320
+ # @param [String] str. The string to write.
321
+ # @param [String] enc. The encoding to use.
322
+ # @return [HttpClientRequest] self So multiple operations can be chained.
323
+ def write_str(str, enc = "UTF-8")
324
+ @j_del.write(str, enc)
325
+ self
326
+ end
327
+
328
+ # Forces the head of the request to be written before {#end} is called on the request. This is normally used
329
+ # to implement HTTP 100-continue handling, see {#continue_handler} for more information.
330
+ # @return [HttpClientRequest] self So multiple operations can be chained.
331
+ def send_head
332
+ @j_del.sendHead
333
+ self
334
+ end
335
+
336
+ # Ends the request. If no data has been written to the request body, and {#send_head} has not been called then
337
+ # the actual request won't get written until this method gets called.
338
+ # Once the request has ended, it cannot be used any more, and if keep alive is true the underlying connection will
339
+ # be returned to the {HttpClient} pool so it can be assigned to another request.
340
+ def end
341
+ @j_del.end
342
+ self
343
+ end
344
+
345
+ # Same as {#write_buffer_and_end} but writes a String
346
+ # @param [String] str The String to write
347
+ # @param [String] enc The encoding
348
+ def write_str_and_end(str, enc = "UTF-8")
349
+ @j_del.end(str, enc)
350
+ self
351
+ end
352
+
353
+ # Same as {#end} but writes some data to the response body before ending. If the response is not chunked and
354
+ # no other data has been written then the Content-Length header will be automatically set
355
+ # @param [Buffer] chunk The Buffer to write
356
+ def write_buffer_and_end(chunk)
357
+ @j_del.end(chunk._to_java_buffer)
358
+ self
359
+ end
360
+
361
+ # Sets whether the request should used HTTP chunked encoding or not.
362
+ # @param [Boolean] val. If val is true, this request will use HTTP chunked encoding, and each call to write to the body
363
+ # will correspond to a new HTTP chunk sent on the wire. If chunked encoding is used the HTTP header
364
+ # 'Transfer-Encoding' with a value of 'Chunked' will be automatically inserted in the request.
365
+ # If chunked is false, this request will not use HTTP chunked encoding, and therefore if any data is written the
366
+ # body of the request, the total size of that data must be set in the 'Content-Length' header before any
367
+ # data is written to the request body.
368
+ # @return [HttpClientRequest] self So multiple operations can be chained.
369
+ def chunked=(val)
370
+ @j_del.setChunked(val)
371
+ self
372
+ end
373
+
374
+ # Get or set chunked
375
+ def chunked(val = nil)
376
+ if val
377
+ @j_del.setChunked(val)
378
+ self
379
+ else
380
+ @j_del.getChunked
381
+ end
382
+ end
383
+
384
+ # If you send an HTTP request with the header 'Expect' set to the value '100-continue'
385
+ # and the server responds with an interim HTTP response with a status code of '100' and a continue handler
386
+ # has been set using this method, then the handler will be called.
387
+ # You can then continue to write data to the request body and later end it. This is normally used in conjunction with
388
+ # the {#send_head} method to force the request header to be written before the request has ended.
389
+ # @param [Block] hndlr. The handler
390
+ def continue_handler(&hndlr)
391
+ @j_del.continueHandler(hndlr)
392
+ self
393
+ end
394
+
395
+ # Get or set timeout
396
+ def timeout(val = nil)
397
+ if val
398
+ @j_del.setTimeout(val)
399
+ self
400
+ else
401
+ @j_del.getTimeout
402
+ end
403
+ end
404
+
405
+ end
406
+
407
+ # Encapsulates a client-side HTTP response.
408
+ #
409
+ # An instance of this class is provided to the user via a handler that was specified when one of the
410
+ # HTTP method operations, or the generic {HttpClient#request} method was called on an instance of {HttpClient}.
411
+ #
412
+ # @author {http://tfox.org Tim Fox}
413
+ class HttpClientResponse
414
+
415
+ include ReadStream
416
+
417
+ # @private
418
+ def initialize(j_del)
419
+ @j_del = j_del
420
+ end
421
+
422
+ # @return [FixNum] the HTTP status code of the response.
423
+ def status_code
424
+ @j_del.statusCode
425
+ end
426
+
427
+ # @return [String] the status message
428
+ def status_message
429
+ @j_del.statusMessage
430
+ end
431
+
432
+ # Get a header value
433
+ # @param [String] key. The key of the header.
434
+ # @return [String] the header value.
435
+ def header(key)
436
+ @j_del.getHeader(key)
437
+ end
438
+
439
+ # Get all the headers in the response.
440
+ # @return [MultiMap]. The headers
441
+ def headers
442
+ if !@headers
443
+ @headers = MultiMap.new(@j_del.headers)
444
+ end
445
+ @headers
446
+ end
447
+
448
+ # Get all the trailers in the response.
449
+ # @return [MultiMap]. The trailers
450
+ def trailers
451
+ if !@trailers
452
+ @trailers = MultiMap.new(@j_del.trailers)
453
+ end
454
+ @trailers
455
+ end
456
+
457
+ # Get all cookies
458
+ def cookies
459
+ if !@cookies
460
+ @cookies = @j_del.cookies
461
+ end
462
+ @cookies
463
+ end
464
+
465
+ # Set a handler to receive the entire body in one go - do not use this for large bodies
466
+ def body_handler(&hndlr)
467
+ @j_del.bodyHandler(hndlr)
468
+ self
469
+ end
470
+
471
+ end
472
+
473
+ # Represents a WebSocket.
474
+ #
475
+ # Instances of this class are created by an {HttpClient} instance when a client succeeds in a WebSocket handshake with a server.
476
+ # Once an instance has been obtained it can be used to send or receive buffers of data from the connection,
477
+ # a bit like a TCP socket.
478
+ #
479
+ # @author {http://tfox.org Tim Fox}
480
+ class WebSocket
481
+
482
+ include ReadStream, WriteStream
483
+
484
+ # @private
485
+ def initialize(j_ws)
486
+ @j_del = j_ws
487
+ @binary_handler_id = EventBus.register_simple_handler { |msg|
488
+ write_binary_frame(msg.body)
489
+ }
490
+ @text_handler_id = EventBus.register_simple_handler { |msg|
491
+ write_text_frame(msg.body)
492
+ }
493
+ @j_del.closeHandler(Proc.new {
494
+ EventBus.unregister_handler(@binary_handler_id)
495
+ EventBus.unregister_handler(@text_handler_id)
496
+ @close_handler.call if @close_handler
497
+ })
498
+ end
499
+
500
+ # Write data to the WebSocket as a binary frame
501
+ # @param [Buffer] buffer. Data to write.
502
+ def write_binary_frame(buffer)
503
+ @j_del.writeBinaryFrame(buffer._to_java_buffer)
504
+ self
505
+ end
506
+
507
+ # Write data to the WebSocket as a text frame
508
+ # @param [String] str. String to write.
509
+ def write_text_frame(str)
510
+ @j_del.writeTextFrame(str)
511
+ self
512
+ end
513
+
514
+ # Close the WebSocket
515
+ def close
516
+ @j_del.close
517
+ end
518
+
519
+ # When a Websocket is created it automatically registers an event handler with the system, the ID of that
520
+ # handler is given by {#binary_handler_id}.
521
+ # Given this ID, a different event loop can send a binary frame to that event handler using the event bus. This
522
+ # allows you to write data to other WebSockets which are owned by different event loops.
523
+ def binary_handler_id
524
+ @binary_handler_id
525
+ end
526
+
527
+ # When a Websocket is created it automatically registers an event handler with the system, the ID of that
528
+ # handler is given by {#text_handler_id}.
529
+ # Given this ID, a different event loop can send a text frame to that event handler using the event bus. This
530
+ # allows you to write data to other WebSockets which are owned by different event loops.
531
+ def text_handler_id
532
+ @text_handler_id
533
+ end
534
+
535
+ # Set a closed handler on the WebSocket.
536
+ # @param [Block] hndlr A block to be used as the handler
537
+ def close_handler(&hndlr)
538
+ @close_handler = hndlr;
539
+ end
540
+
541
+ end
542
+
543
+ # A map which can hold multiple values for one name / key
544
+ #
545
+ # @author Norman Maurer
546
+ class MultiMap
547
+
548
+ # @private
549
+ def initialize(j_map)
550
+ @j_map = j_map
551
+ end
552
+
553
+ # Call the handler for each header name and its value. If there are multiple values are stored for
554
+ # a header name it will be called for each of them
555
+ #
556
+ def each(&hndlr)
557
+ names.each do |name|
558
+ values = @j_map.getAll(name)
559
+ for v in values
560
+ hndlr.call(name, v)
561
+ end
562
+ end
563
+ end
564
+
565
+ # Returns the value of with the specified name. If there are
566
+ # more than one values for the specified name, the first value is returned.
567
+ #
568
+ # @param name The name of the header to search
569
+ # @return The first header value or nil if there is no such entry
570
+ def get(name)
571
+ @j_map.get(name)
572
+ end
573
+
574
+ # Returns the value of with the specified name. If there are
575
+ # more than one values for the specified name, the first value is returned.
576
+ #
577
+ # @param name The name of the header to search
578
+ # @return The first header value or nil if there is no such entry
579
+ def [](name)
580
+ @j_map.get(name)
581
+ end
582
+
583
+
584
+ # Set a value with the specified name and value.
585
+ #
586
+ # @param name The name
587
+ # @param value The value being added
588
+ # @return self
589
+ def []=(name, value)
590
+ @j_map.set(name, value)
591
+ self
592
+ end
593
+
594
+ # Returns the values with the specified name
595
+ #
596
+ # @param name The name to search
597
+ # @return [Array] A immutable array of values which will be empty if no values
598
+ # are found
599
+ def get_all(name)
600
+ @j_map.getAll(name).to_a
601
+ end
602
+
603
+ # Returns true if an entry with the given name was found
604
+ def contains(name)
605
+ @j_map.contains(name)
606
+ end
607
+
608
+ # Returns true if the map is empty
609
+ def empty?
610
+ @j_map.isEmpty()
611
+ end
612
+
613
+ # Return a Set which holds all names of the entries
614
+ #
615
+ # @return [Set] The set which holds all names or an empty set if it is empty
616
+ def names
617
+ @j_map.names()
618
+ end
619
+
620
+
621
+ # Adds a new value with the specified name and value.
622
+ #
623
+ # @param name The name
624
+ # @param value The value being added
625
+ # @return self
626
+ def add(name, value)
627
+ @j_map.add(name, value)
628
+ self
629
+ end
630
+
631
+ # Set a value with the specified name and value.
632
+ #
633
+ # @param name The name
634
+ # @param value The value being added
635
+ # @return self
636
+ def set(name, value)
637
+ @j_map.set(name, value)
638
+ self
639
+ end
640
+
641
+ # Set a value with the specified name and value.
642
+ #
643
+ # @param name The name
644
+ # @param value The value being added
645
+ # @return self
646
+ def set_all(map)
647
+ @j_map.set(map._j_map)
648
+ self
649
+ end
650
+
651
+ # Remove the values with the given name
652
+ #
653
+ # @param name The name
654
+ # @return self
655
+ def remove(name)
656
+ @j_map.remove(name)
657
+ self
658
+ end
659
+
660
+ # Remove all entries
661
+ #
662
+ # @return self
663
+ def clear
664
+ @j_map.clear()
665
+ self
666
+ end
667
+
668
+ # Return the number of names in this instance
669
+ def size
670
+ @j_map.size()
671
+ end
672
+
673
+ def _j_map
674
+ @j_map
675
+ end
676
+ end
677
+ end
@@ -0,0 +1,143 @@
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
+
16
+ module Vertx
17
+
18
+ # A mixin module allowing SSL attributes to be set on classes
19
+ #
20
+ # @author {http://tfox.org Tim Fox}
21
+ module SSLSupport
22
+
23
+ # Set whether the server or client will use SSL.
24
+ # @param [Boolean] val. If true then ssl will be used.
25
+ # @return [] self. So multiple invocations can be chained.
26
+ def ssl=(val)
27
+ @j_del.setSSL(val)
28
+ self
29
+ end
30
+
31
+ # Set or get ssl for fluent API
32
+ def ssl(ssl = nil)
33
+ if ssl
34
+ @j_del.setSSL(ssl)
35
+ self
36
+ else
37
+ @j_del.isSSL
38
+ end
39
+ end
40
+
41
+ # Set the path to the SSL key store. This method should only be used with the client/server in SSL mode, i.e. after {#ssl=}
42
+ # has been set to true.
43
+ # The SSL key store is a standard Java Key Store, and should contain the client/server certificate. For a client, it's only necessary to supply
44
+ # a client key store if the server requires client authentication via client certificates.
45
+ # @param [String] val. The path to the key store
46
+ # @return [] self. So multiple invocations can be chained.
47
+ def key_store_path=(val)
48
+ @j_del.setKeyStorePath(val)
49
+ self
50
+ end
51
+
52
+ # Set or get key store path for fluent API
53
+ def key_store_path(path = nil)
54
+ if path
55
+ @j_del.setKeyStorePath(path)
56
+ self
57
+ else
58
+ @j_del.getKeyStorePath
59
+ end
60
+ end
61
+
62
+ # Set the password for the SSL key store. This method should only be used with the client in SSL mode, i.e. after {#ssl=}
63
+ # has been set to true.
64
+ # @param [String] val. The password.
65
+ # @return [] self. So multiple invocations can be chained.
66
+ def key_store_password=(val)
67
+ @j_del.setKeyStorePassword(val)
68
+ self
69
+ end
70
+
71
+ # Set or get key store password for fluent API
72
+ def key_store_password(password = nil)
73
+ if password
74
+ @j_del.setKeyStorePassword(password)
75
+ self
76
+ else
77
+ @j_del.getKeyStorePassword
78
+ end
79
+ end
80
+
81
+ # Set the path to the SSL trust store. This method should only be used with the client/server in SSL mode, i.e. after {#ssl=}
82
+ # has been set to true.
83
+ # The SSL trust store is a standard Java Key Store, and should contain the certificate(s) of the clients/servers that the server/client trusts. The SSL
84
+ # handshake will fail if the server provides a certificate that the client does not trust, or if client authentication is used,
85
+ # if the client provides a certificate the server does not trust.<p>
86
+ # @param [String] val. The path to the trust store
87
+ # @return [] self. So multiple invocations can be chained.
88
+ def trust_store_path=(val)
89
+ @j_del.setTrustStorePath(val)
90
+ self
91
+ end
92
+
93
+ # Set or get trust store path for fluent API
94
+ def trust_store_path(path = nil)
95
+ if path
96
+ @j_del.setTrustStorePath(path)
97
+ self
98
+ else
99
+ @j_del.getTrustStorePath
100
+ end
101
+ end
102
+
103
+ # Set the password for the SSL trust store. This method should only be used with the client in SSL mode, i.e. after {#ssl=}
104
+ # has been set to true.
105
+ # @param [String] val. The password.
106
+ # @return [] self. So multiple invocations can be chained.
107
+ def trust_store_password=(val)
108
+ @j_del.setTrustStorePassword(val)
109
+ self
110
+ end
111
+
112
+ # Set or get trust store password for fluent API
113
+ def trust_store_password(password = nil)
114
+ if password
115
+ @j_del.setTrustStorePassword(password)
116
+ self
117
+ else
118
+ @j_del.getTrustStorePassword
119
+ end
120
+ end
121
+
122
+ end
123
+
124
+ # A mixin module allowing Client SSL attributes to be set on classes
125
+ #
126
+ # @author {http://tfox.org Tim Fox}
127
+ module ClientSSLSupport
128
+
129
+ def trust_all=(val)
130
+ @j_del.setTrustAll(val)
131
+ self
132
+ end
133
+
134
+ def trust_all(val = nil)
135
+ if val
136
+ @j_del.setTrustAll(val)
137
+ self
138
+ else
139
+ @j_del.isTrustAll
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,172 @@
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 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
32
+
33
+ # Set the maximum size of the write queue. You will still be able to write to the stream even
34
+ # if there is more data than this in the write queue. This is used as an indicator by classes such as
35
+ # {Pump} to provide flow control.
36
+ # @param [FixNum] size. The maximum size, in bytes.
37
+ def write_queue_max_size=(size)
38
+ @j_del.setWriteQueueMaxSize(size)
39
+ end
40
+
41
+ # For a fluent API
42
+ def write_queue_max_size(size)
43
+ @j_del.setWriteQueueMaxSize(size)
44
+ self
45
+ end
46
+
47
+ # Is the write queue full?
48
+ # @return [Boolean] true if there are more bytes in the write queue than the max write queue size.
49
+ def write_queue_full?
50
+ @j_del.writeQueueFull
51
+ end
52
+
53
+ # Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write
54
+ # queue has been reduced to maxSize / 2. See {Pump} for an example of this being used.
55
+ # @param [Block] hndlr. The drain handler
56
+ def drain_handler(&hndlr)
57
+ @j_del.drainHandler(hndlr)
58
+ self
59
+ end
60
+
61
+ # Set an exception handler on the stream.
62
+ # @param [Block] hndlr. The exception handler
63
+ def exception_handler(&hndlr)
64
+ @j_del.exceptionHandler(hndlr)
65
+ self
66
+ end
67
+
68
+ # @private
69
+ def _to_write_stream
70
+ @j_del
71
+ end
72
+
73
+ end
74
+
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
81
+
82
+ # Set a data handler. As data is read, the handler will be called with the data.
83
+ # @param [Block] hndlr. The data handler
84
+ def data_handler(&hndlr)
85
+ @j_del.dataHandler(Proc.new { |j_buff|
86
+ hndlr.call(Buffer.new(j_buff))
87
+ })
88
+ self
89
+ end
90
+
91
+ # Pause the ReadStream. After calling this, the ReadStream will aim to send no more data to the {#data_handler}
92
+ def pause
93
+ @j_del.pause
94
+ self
95
+ end
96
+
97
+ # Resume reading. If the ReadStream has been paused, reading will recommence on it.
98
+ def resume
99
+ @j_del.resume
100
+ self
101
+ end
102
+
103
+ # Set an execption handler on the stream.
104
+ # @param [Block] hndlr. The exception handler
105
+ def exception_handler(&hndlr)
106
+ @j_del.exceptionHandler(hndlr)
107
+ self
108
+ end
109
+
110
+ # 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
+ # @param [Block] hndlr. The exception handler
112
+ def end_handler(&hndlr)
113
+ @j_del.endHandler(hndlr)
114
+ self
115
+ end
116
+
117
+ # @private
118
+ def _to_read_stream
119
+ @j_del
120
+ end
121
+
122
+ end
123
+
124
+ # Pumps data from a {ReadStream} to a {WriteStream} and performs flow control where necessary to
125
+ # prevent the write stream from getting overloaded.
126
+ #
127
+ # Instances of this class read bytes from a ReadStream and write them to a WriteStream. If data
128
+ # can be read faster than it can be written this could result in the write queue of the WriteStream growing
129
+ # without bound, eventually causing it to exhaust all available RAM.
130
+ # To prevent this, after each write, instances of this class check whether the write queue of the WriteStream
131
+ # is full, and if so, the ReadStream is paused, and a {WriteStream#drain_handler} is set on the WriteStream.
132
+ # When the WriteStream has processed half of its backlog, the drain_handler will be called,
133
+ # which results in the pump resuming the ReadStream.
134
+ #
135
+ # This class can be used to pump from any {ReadStream} to any { WriteStream},
136
+ # e.g. from an {HttpServerRequest} to an {AsyncFile}, or from {NetSocket} to a {WebSocket}.
137
+ #
138
+ # @author {http://tfox.org Tim Fox}
139
+ class Pump
140
+ def initialize(read_stream, write_stream)
141
+ raise "read_stream is not a ReadStream" if !read_stream.is_a? ReadStream
142
+ raise "write_stream is not a WriteStream" if !write_stream.is_a? WriteStream
143
+ j_rs = read_stream._to_read_stream
144
+ j_ws = write_stream._to_write_stream
145
+ @j_pump = org.vertx.java.core.streams.Pump.createPump(j_rs, j_ws)
146
+ end
147
+
148
+ # Set the write queue max size
149
+ # @param [FixNum] The write queue max size
150
+ def write_queue_max_size=(val)
151
+ @j_pump.setWriteQueueMaxSize(val)
152
+ self
153
+ end
154
+
155
+ # Start the Pump. The Pump can be started and stopped multiple times.
156
+ def start
157
+ @j_pump.start
158
+ self
159
+ end
160
+
161
+ # Stop the Pump. The Pump can be started and stopped multiple times.
162
+ def stop
163
+ @j_pump.stop
164
+ self
165
+ end
166
+
167
+ # @return [FixNum] Return the total number of bytes pumped by this pump.
168
+ def bytes_pumped
169
+ @j_pump.bytesPumped
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,150 @@
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
+
17
+ # Mixin module that provides all the common TCP params that can be set.
18
+ #
19
+ # @author {http://tfox.org Tim Fox}
20
+ module TCPSupport
21
+
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
57
+
58
+ # Set the TCP keep alive setting.
59
+ # @param [Boolean] val. If true, then TCP keep alive will be enabled.
60
+ # @return [] A reference to self so invocations can be chained
61
+ def tcp_keep_alive=(val)
62
+ @j_del.setTCPKeepAlive(val)
63
+ self
64
+ end
65
+
66
+ # Set or get TCP keep alive for fluent API
67
+ def tcp_keep_alive(val = nil)
68
+ if val
69
+ @j_del.setTCPKeepAlive(val)
70
+ self
71
+ else
72
+ @j_del.getTCPKeepAlive
73
+ end
74
+ end
75
+
76
+ # Set the TCP reuse address setting.
77
+ # @param [Boolean] val. If true, then TCP reuse address will be enabled.
78
+ # @return [] A reference to self so invocations can be chained
79
+ def reuse_address=(val)
80
+ @j_del.setReuseAddress(val)
81
+ self
82
+ end
83
+
84
+ # Set or get TCP reuse address for fluent API
85
+ def reuse_address(val = nil)
86
+ if val
87
+ @j_del.setReuseAddress(val)
88
+ self
89
+ else
90
+ @j_del.isReuseAddress
91
+ end
92
+ end
93
+
94
+ # Set the TCP so linger setting.
95
+ # @param [FixNum] val. Set TCP soLinger
96
+ # @return [] A reference to self so invocations can be chained
97
+ def so_linger=(val)
98
+ @j_del.setSoLinger(val)
99
+ self
100
+ end
101
+
102
+ # Set or get TCP so linger for fluent API
103
+ def so_linger(val = nil)
104
+ if val
105
+ @j_del.setSoLinger(val)
106
+ self
107
+ else
108
+ @j_del.getSoLinger
109
+ end
110
+ end
111
+
112
+ # Set the TCP traffic class setting.
113
+ # @param [FixNum] val. The TCP traffic class setting.
114
+ # @return [] A reference to self so invocations can be chained
115
+ def traffic_class=(val)
116
+ @j_del.setTrafficClass(val)
117
+ self
118
+ end
119
+
120
+ # Set or get TCP traffic class for fluent API
121
+ def traffic_class(val = nil)
122
+ if val
123
+ @j_del.setTrafficClass(val)
124
+ self
125
+ else
126
+ @j_del.getTrafficClass
127
+ end
128
+ end
129
+
130
+ # Set to use pooled buffers
131
+ # @param [Boolean] val.
132
+ # @return [] A reference to self so invocations can be chained
133
+ def use_pooled_buffers=(val)
134
+ @j_del.setUsedPooledBuffers(val)
135
+ self
136
+ end
137
+
138
+ # Set or get use_pooled_buffers for fluent API
139
+ def use_pooled_buffers(val = nil)
140
+ if val
141
+ @j_del.setUsePooledBuffers(val)
142
+ self
143
+ else
144
+ @j_del.isUsePooledBuffers
145
+ end
146
+ end
147
+
148
+ end
149
+
150
+ end
@@ -0,0 +1,28 @@
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jubilee
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta
4
+ version: 2.0.0
5
5
  platform: java
6
6
  authors:
7
7
  - Isaiah Peng
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-26 00:00:00.000000000 Z
11
+ date: 2014-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -130,7 +130,12 @@ files:
130
130
  - lib/vertx/README.md
131
131
  - lib/vertx/buffer.rb
132
132
  - lib/vertx/event_bus.rb
133
+ - lib/vertx/http.rb
133
134
  - lib/vertx/shared_data.rb
135
+ - lib/vertx/ssl_support.rb
136
+ - lib/vertx/streams.rb
137
+ - lib/vertx/tcp_support.rb
138
+ - lib/vertx/wrapped_handler.rb
134
139
  - spec/apps/rack/basic/config.ru
135
140
  - spec/apps/rails4/basic/.gitignore
136
141
  - spec/apps/rails4/basic/Gemfile
@@ -231,9 +236,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
231
236
  version: '0'
232
237
  required_rubygems_version: !ruby/object:Gem::Requirement
233
238
  requirements:
234
- - - '>'
239
+ - - '>='
235
240
  - !ruby/object:Gem::Version
236
- version: 1.3.1
241
+ version: '0'
237
242
  requirements: []
238
243
  rubyforge_project:
239
244
  rubygems_version: 2.1.9