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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -14
- data/Guardfile +24 -0
- data/README.md +34 -66
- data/Rakefile +1 -1
- data/examples/chatapp/Gemfile +2 -1
- data/examples/chatapp/Gemfile.lock +2 -2
- data/examples/chatapp/README.md +2 -14
- data/examples/chatapp/app.rb +19 -11
- data/examples/chatapp/public/assets/javascripts/application.js +1 -1
- data/examples/chatapp/public/assets/javascripts/vertxbus.js +60 -48
- data/examples/client/vertxbus.js +60 -48
- data/examples/shims_example/log/development.log +0 -0
- data/jars/hazelcast-3.5.2.jar +0 -0
- data/jars/jackson-annotations-2.6.0.jar +0 -0
- data/jars/jackson-core-2.6.1.jar +0 -0
- data/jars/jackson-databind-2.6.1.jar +0 -0
- data/jars/netty-buffer-4.0.33.Final.jar +0 -0
- data/jars/netty-codec-4.0.33.Final.jar +0 -0
- data/jars/netty-codec-http-4.0.33.Final.jar +0 -0
- data/jars/netty-common-4.0.33.Final.jar +0 -0
- data/jars/netty-handler-4.0.33.Final.jar +0 -0
- data/jars/netty-transport-4.0.33.Final.jar +0 -0
- data/jars/vertx-auth-common-3.2.1.jar +0 -0
- data/jars/vertx-core-3.2.1.jar +0 -0
- data/jars/vertx-hazelcast-3.2.1.jar +0 -0
- data/jars/vertx-lang-ruby-3.2.1.jar +0 -0
- data/jars/vertx-web-3.2.1.jar +0 -0
- data/jubilee.gemspec +40 -42
- data/lib/jubilee.rb +7 -2
- data/lib/jubilee/cli.rb +4 -4
- data/lib/jubilee/jubilee.jar +0 -0
- data/lib/jubilee/response.rb +1 -1
- data/lib/jubilee/version.rb +3 -3
- data/pom.xml +10 -94
- data/spec/apps/rails4/basic/Gemfile +2 -2
- data/spec/apps/rails4/basic/Gemfile.lock +5 -6
- data/src/main/java/org/jruby/jubilee/Const.java +1 -4
- data/src/main/java/org/jruby/jubilee/JubileeVerticle.java +41 -46
- data/src/main/java/org/jruby/jubilee/RackApplication.java +37 -57
- data/src/main/java/org/jruby/jubilee/RackEnvironment.java +38 -35
- data/src/main/java/org/jruby/jubilee/RackEnvironmentHash.java +1 -7
- data/src/main/java/org/jruby/jubilee/RubyHttpServerResponse.java +12 -6
- data/src/main/java/org/jruby/jubilee/RubyNetSocket.java +9 -12
- data/src/main/java/org/jruby/jubilee/RubyPlatformManager.java +39 -43
- data/src/main/java/org/jruby/jubilee/impl/RubyIORackInput.java +2 -1
- data/src/main/java/org/jruby/jubilee/vertx/JubileeVertx.java +1 -1
- metadata +30 -54
- data/examples/chatapp/config.json +0 -4
- data/jars/annotations-1.3.2.jar +0 -0
- data/jars/hazelcast-3.2.3.jar +0 -0
- data/jars/jackson-annotations-2.2.2.jar +0 -0
- data/jars/jackson-core-2.2.2.jar +0 -0
- data/jars/jackson-databind-2.2.2.jar +0 -0
- data/jars/lang-jruby-2.1.0-final.jar +0 -0
- data/jars/log4j-1.2.16.jar +0 -0
- data/jars/netty-all-4.0.20.Final.jar +0 -0
- data/jars/slf4j-api-1.6.2.jar +0 -0
- data/jars/vertx-core-2.1.2.jar +0 -0
- data/jars/vertx-hazelcast-2.1.2.jar +0 -0
- data/jars/vertx-platform-2.1.2.jar +0 -0
- data/lib/container.rb +0 -117
- data/lib/core/buffer.rb +0 -251
- data/lib/core/datagram.rb +0 -280
- data/lib/core/dns.rb +0 -143
- data/lib/core/event_bus.rb +0 -277
- data/lib/core/file_system.rb +0 -479
- data/lib/core/http.rb +0 -1307
- data/lib/core/net.rb +0 -251
- data/lib/core/network_support.rb +0 -77
- data/lib/core/parsetools.rb +0 -105
- data/lib/core/shared_data.rb +0 -214
- data/lib/core/sock_js.rb +0 -116
- data/lib/core/ssl_support.rb +0 -163
- data/lib/core/streams.rb +0 -183
- data/lib/core/tcp_support.rb +0 -136
- data/lib/core/timers.rb +0 -73
- data/lib/core/vertx_require.rb +0 -25
- data/lib/core/wrapped_handler.rb +0 -28
- data/lib/jubilee/jubilee_require.rb +0 -24
- data/lib/test_utils.rb +0 -66
- data/lib/vertx.rb +0 -30
- data/lib/vertx_tests.rb +0 -8
- data/src/main/assembly/mod.xml +0 -21
- data/src/main/java/org/jruby/jubilee/JubileeVerticleFactory.java +0 -258
- data/src/main/java/org/jruby/jubilee/RubyCallable.java +0 -52
- data/src/main/resources/META-INF/services/org.vertx.java.deploy.impl.jruby.JubileeVerticleFactory +0 -1
- data/src/main/resources/mod.json +0 -11
- data/vertx_classpath.txt +0 -12
data/lib/core/sock_js.rb
DELETED
@@ -1,116 +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
|
-
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
|
data/lib/core/ssl_support.rb
DELETED
@@ -1,163 +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
|
-
|
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 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
|
-
|
144
|
-
# A mixin module allowing Client SSL attributes to be set on classes
|
145
|
-
#
|
146
|
-
# @author {http://tfox.org Tim Fox}
|
147
|
-
module ClientSSLSupport
|
148
|
-
|
149
|
-
def trust_all=(val)
|
150
|
-
@j_del.setTrustAll(val)
|
151
|
-
self
|
152
|
-
end
|
153
|
-
|
154
|
-
def trust_all(val = nil)
|
155
|
-
if val
|
156
|
-
@j_del.setTrustAll(val)
|
157
|
-
self
|
158
|
-
else
|
159
|
-
@j_del.isTrustAll
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
data/lib/core/streams.rb
DELETED
@@ -1,183 +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
|
-
module DrainSupport
|
18
|
-
|
19
|
-
# Set the maximum size of the write queue. You will still be able to write to the stream even
|
20
|
-
# if there is more data than this in the write queue. This is used as an indicator by classes such as
|
21
|
-
# {Pump} to provide flow control.
|
22
|
-
# @param [FixNum] size. The maximum size, in bytes.
|
23
|
-
def write_queue_max_size=(size)
|
24
|
-
@j_del.setWriteQueueMaxSize(size)
|
25
|
-
end
|
26
|
-
|
27
|
-
# For a fluent API
|
28
|
-
def write_queue_max_size(size)
|
29
|
-
@j_del.setWriteQueueMaxSize(size)
|
30
|
-
self
|
31
|
-
end
|
32
|
-
|
33
|
-
# Is the write queue full?
|
34
|
-
# @return [Boolean] true if there are more bytes in the write queue than the max write queue size.
|
35
|
-
def write_queue_full?
|
36
|
-
@j_del.writeQueueFull
|
37
|
-
end
|
38
|
-
|
39
|
-
# Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write
|
40
|
-
# queue has been reduced to maxSize / 2. See {Pump} for an example of this being used.
|
41
|
-
# @param [Block] hndlr. The drain handler
|
42
|
-
def drain_handler(&hndlr)
|
43
|
-
@j_del.drainHandler(hndlr)
|
44
|
-
self
|
45
|
-
end
|
46
|
-
|
47
|
-
# Set an exception handler on the stream.
|
48
|
-
# @param [Block] hndlr. The exception handler
|
49
|
-
def exception_handler(&hndlr)
|
50
|
-
@j_del.exceptionHandler(hndlr)
|
51
|
-
self
|
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
|
72
|
-
|
73
|
-
# @private
|
74
|
-
def _to_write_stream
|
75
|
-
@j_del
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
module ReadSupport
|
82
|
-
|
83
|
-
# Set a data handler. As data is read, the handler will be called with the data.
|
84
|
-
# @param [Block] hndlr. The data handler
|
85
|
-
def data_handler(&hndlr)
|
86
|
-
@j_del.dataHandler(Proc.new { |j_buff|
|
87
|
-
hndlr.call(Buffer.new(j_buff))
|
88
|
-
})
|
89
|
-
self
|
90
|
-
end
|
91
|
-
|
92
|
-
# Pause the ReadStream. After calling this, the ReadStream will aim to send no more data to the {#data_handler}
|
93
|
-
def pause
|
94
|
-
@j_del.pause
|
95
|
-
self
|
96
|
-
end
|
97
|
-
|
98
|
-
# Resume reading. If the ReadStream has been paused, reading will recommence on it.
|
99
|
-
def resume
|
100
|
-
@j_del.resume
|
101
|
-
self
|
102
|
-
end
|
103
|
-
|
104
|
-
# Set an execption handler on the stream.
|
105
|
-
# @param [Block] hndlr. The exception handler
|
106
|
-
def exception_handler(&hndlr)
|
107
|
-
@j_del.exceptionHandler(hndlr)
|
108
|
-
self
|
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
|
120
|
-
|
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.
|
122
|
-
# @param [Block] hndlr. The exception handler
|
123
|
-
def end_handler(&hndlr)
|
124
|
-
@j_del.endHandler(hndlr)
|
125
|
-
self
|
126
|
-
end
|
127
|
-
|
128
|
-
# @private
|
129
|
-
def _to_read_stream
|
130
|
-
@j_del
|
131
|
-
end
|
132
|
-
|
133
|
-
end
|
134
|
-
|
135
|
-
# Pumps data from a {ReadStream} to a {WriteStream} and performs flow control where necessary to
|
136
|
-
# prevent the write stream from getting overloaded.
|
137
|
-
#
|
138
|
-
# Instances of this class read bytes from a ReadStream and write them to a WriteStream. If data
|
139
|
-
# can be read faster than it can be written this could result in the write queue of the WriteStream growing
|
140
|
-
# without bound, eventually causing it to exhaust all available RAM.
|
141
|
-
# To prevent this, after each write, instances of this class check whether the write queue of the WriteStream
|
142
|
-
# is full, and if so, the ReadStream is paused, and a {WriteStream#drain_handler} is set on the WriteStream.
|
143
|
-
# When the WriteStream has processed half of its backlog, the drain_handler will be called,
|
144
|
-
# which results in the pump resuming the ReadStream.
|
145
|
-
#
|
146
|
-
# This class can be used to pump from any {ReadStream} to any { WriteStream},
|
147
|
-
# e.g. from an {HttpServerRequest} to an {AsyncFile}, or from {NetSocket} to a {WebSocket}.
|
148
|
-
#
|
149
|
-
# @author {http://tfox.org Tim Fox}
|
150
|
-
class Pump
|
151
|
-
def initialize(read_stream, write_stream)
|
152
|
-
raise "read_stream is not a ReadStream" if !read_stream.is_a? ReadStream
|
153
|
-
raise "write_stream is not a WriteStream" if !write_stream.is_a? WriteStream
|
154
|
-
j_rs = read_stream._to_read_stream
|
155
|
-
j_ws = write_stream._to_write_stream
|
156
|
-
@j_pump = org.vertx.java.core.streams.Pump.createPump(j_rs, j_ws)
|
157
|
-
end
|
158
|
-
|
159
|
-
# Set the write queue max size
|
160
|
-
# @param [FixNum] The write queue max size
|
161
|
-
def write_queue_max_size=(val)
|
162
|
-
@j_pump.setWriteQueueMaxSize(val)
|
163
|
-
self
|
164
|
-
end
|
165
|
-
|
166
|
-
# Start the Pump. The Pump can be started and stopped multiple times.
|
167
|
-
def start
|
168
|
-
@j_pump.start
|
169
|
-
self
|
170
|
-
end
|
171
|
-
|
172
|
-
# Stop the Pump. The Pump can be started and stopped multiple times.
|
173
|
-
def stop
|
174
|
-
@j_pump.stop
|
175
|
-
self
|
176
|
-
end
|
177
|
-
|
178
|
-
# @return [FixNum] Return the total number of bytes pumped by this pump.
|
179
|
-
def bytes_pumped
|
180
|
-
@j_pump.bytesPumped
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|