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.
- checksums.yaml +4 -4
- data/Gemfile.lock +13 -1
- data/README.md +65 -54
- data/Rakefile +23 -21
- data/examples/chatapp/Gemfile +1 -2
- data/examples/chatapp/Gemfile.lock +2 -2
- data/examples/chatapp/README.md +14 -2
- data/examples/chatapp/app.rb +1 -0
- data/examples/chatapp/config.json +4 -0
- data/examples/chatapp/config.ru +0 -2
- data/jars/annotations-1.3.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/slf4j-api-1.6.2.jar +0 -0
- data/jars/vertx-core-2.1.2.jar +0 -0
- data/jars/{vertx-hazelcast-2.1.1.jar → vertx-hazelcast-2.1.2.jar} +0 -0
- data/jars/{vertx-platform-2.1.1.jar → vertx-platform-2.1.2.jar} +0 -0
- data/lib/container.rb +117 -0
- data/lib/{vertx → core}/buffer.rb +1 -1
- data/lib/core/datagram.rb +280 -0
- data/lib/core/dns.rb +143 -0
- data/lib/{vertx → core}/event_bus.rb +79 -8
- data/lib/core/file_system.rb +479 -0
- data/lib/{vertx → core}/http.rb +635 -5
- data/lib/core/net.rb +251 -0
- data/lib/core/network_support.rb +77 -0
- data/lib/core/parsetools.rb +105 -0
- data/lib/{vertx → core}/shared_data.rb +2 -2
- data/lib/core/sock_js.rb +116 -0
- data/lib/{vertx → core}/ssl_support.rb +21 -1
- data/lib/{vertx → core}/streams.rb +32 -21
- data/lib/{vertx → core}/tcp_support.rb +22 -36
- data/lib/core/timers.rb +73 -0
- data/lib/core/vertx_require.rb +25 -0
- data/lib/{vertx → core}/wrapped_handler.rb +0 -0
- data/lib/jubilee.rb +5 -8
- data/lib/jubilee/cli.rb +1 -1
- data/lib/jubilee/jubilee.jar +0 -0
- data/lib/jubilee/jubilee_require.rb +24 -0
- data/lib/jubilee/version.rb +1 -1
- data/lib/test_utils.rb +66 -0
- data/lib/vertx.rb +13 -10
- data/lib/vertx_tests.rb +8 -0
- data/pom.xml +351 -0
- data/src/main/assembly/mod.xml +21 -0
- data/{java/src → src/main/java}/jubilee/JubileeService.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/Const.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/JubileeVerticle.java +12 -2
- data/src/main/java/org/jruby/jubilee/JubileeVerticleFactory.java +258 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/RackApplication.java +3 -1
- data/{java/src → src/main/java}/org/jruby/jubilee/RackEnvironment.java +2 -2
- data/{java/src → src/main/java}/org/jruby/jubilee/RackEnvironmentHash.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/RackInput.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/RackResponse.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/RubyCallable.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/RubyHttpServerResponse.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/RubyNetSocket.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/RubyPlatformManager.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/impl/RubyIORackInput.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/impl/RubyNullIO.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/utils/RubyHelper.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/vertx/JubileeVertx.java +0 -0
- data/{java → src/main}/resources/META-INF/services/org.vertx.java.core.spi.cluster.ClusterManagerFactory +0 -0
- data/src/main/resources/META-INF/services/org.vertx.java.deploy.impl.jruby.JubileeVerticleFactory +1 -0
- data/{java → src/main}/resources/default-cluster.xml +0 -0
- data/src/main/resources/mod.json +11 -0
- data/test/jubilee/test_upload.rb +3 -1
- data/vertx_classpath.txt +12 -0
- metadata +69 -47
- data/Guardfile +0 -24
- data/jars/vertx-core-2.1.1.jar +0 -0
- data/java/src/org/jruby/jubilee/RubyChannel.java +0 -89
- data/lib/vertx/README.md +0 -7
@@ -0,0 +1,280 @@
|
|
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
|
+
require 'core/buffer'
|
16
|
+
require 'core/wrapped_handler'
|
17
|
+
require 'core/network_support'
|
18
|
+
require 'core/streams'
|
19
|
+
require 'socket'
|
20
|
+
|
21
|
+
module Vertx
|
22
|
+
|
23
|
+
|
24
|
+
#
|
25
|
+
# A Datagram socket which can be used to send data to remote Datagram servers and receive [DatagramPacket]s .
|
26
|
+
#
|
27
|
+
# Usually you use a Datragram Client to send UDP over the wire. UDP is connection-less which means you are not connected
|
28
|
+
# to the remote peer in a persistent way. Because of this you have to supply the address and port of the remote peer
|
29
|
+
# when sending data.
|
30
|
+
#
|
31
|
+
# You can send data to ipv4 or ipv6 addresses, which also include multicast addresses.
|
32
|
+
#
|
33
|
+
# @author Norman Maurer
|
34
|
+
class DatagramSocket
|
35
|
+
include ReadSupport, DrainSupport, NetworkSupport
|
36
|
+
|
37
|
+
def initialize(ipv4=nil)
|
38
|
+
if ipv4 == nil
|
39
|
+
family = nil
|
40
|
+
elsif ipv4
|
41
|
+
family = org.vertx.java.core.datagram.InternetProtocolFamily::IPv4
|
42
|
+
else
|
43
|
+
family = org.vertx.java.core.datagram.InternetProtocolFamily::IPv6
|
44
|
+
end
|
45
|
+
@j_del = org.vertx.java.platform.impl.JRubyVerticleFactory.vertx.createDatagramSocket(family)
|
46
|
+
@local_address = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
# Write the given {@link org.vertx.java.core.buffer.Buffer} to the {@link java.net.InetSocketAddress}. The {@link org.vertx.java.core.Handler} will be notified once the
|
50
|
+
# write completes.
|
51
|
+
#
|
52
|
+
# @param [String] host the host address of the remote peer
|
53
|
+
# @param [FixNum] port the host port of the remote peer
|
54
|
+
# @param [Buffer] packet the buffer to write
|
55
|
+
# @param [Block] hndlr the handler to notify once the write completes.
|
56
|
+
# @return [DatagramSocket] self itself for method chaining
|
57
|
+
def send(host, port, packet, &hndlr)
|
58
|
+
@j_del.send(packet._to_java_buffer, host, port, ARWrappedHandler.new(hndlr) { |j_del| self })
|
59
|
+
self
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# Write the given {@link String} to the {@link InetSocketAddress} using UTF8 encoding. The {@link Handler} will be notified once the
|
64
|
+
# write completes.
|
65
|
+
#
|
66
|
+
#
|
67
|
+
# @param [String] host the host address of the remote peer
|
68
|
+
# @param [FixNum] port the host port of the remote peer
|
69
|
+
# @param [String] str the data to send
|
70
|
+
# @param [String] enc the charset to use to encode the data
|
71
|
+
# @param [Block] hndlr the handler to notify once the write completes.
|
72
|
+
# @return [DatagramSocket] self itself for method chaining
|
73
|
+
def send_str(host, port, str, enc = 'UTF-8', &hndlr)
|
74
|
+
@j_del.send(str, enc, host, port, ARWrappedHandler.new(hndlr) { |j_del| self })
|
75
|
+
self
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# set the {@link java.net.StandardSocketOptions#SO_BROADCAST} option.
|
80
|
+
#
|
81
|
+
def broadcast=(val)
|
82
|
+
@j_del.setBroadcast(val)
|
83
|
+
self
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# set the {@link java.net.StandardSocketOptions#SO_BROADCAST} option.
|
88
|
+
#
|
89
|
+
def broadcast?
|
90
|
+
@j_del.isBroadcast
|
91
|
+
end
|
92
|
+
|
93
|
+
#
|
94
|
+
# Set the {@link java.net.StandardSocketOptions#IP_MULTICAST_LOOP} option.
|
95
|
+
#
|
96
|
+
def multicast_loopback_mode=(val)
|
97
|
+
@j_del.setMulticastLoopbackMode(val)
|
98
|
+
self
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# Set the {@link java.net.StandardSocketOptions#IP_MULTICAST_LOOP} option.
|
103
|
+
#
|
104
|
+
def multicast_loopback_mode?
|
105
|
+
@j_del.isMulticastLoopbackMode
|
106
|
+
end
|
107
|
+
|
108
|
+
#
|
109
|
+
# Set the {@link java.net.StandardSocketOptions#IP_MULTICAST_TTL} option.
|
110
|
+
#
|
111
|
+
def multicast_time_to_live=(val)
|
112
|
+
@j_del.setMulticastTimeToLive(val)
|
113
|
+
self
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# Gets the {@link java.net.StandardSocketOptions#IP_MULTICAST_TTL} option.
|
118
|
+
#
|
119
|
+
def multicast_time_to_live
|
120
|
+
@j_del.getMulticastTimeToLive
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# Set the {@link java.net.StandardSocketOptions#IP_MULTICAST_IF} option.
|
125
|
+
#
|
126
|
+
def multicast_network_interface=(val)
|
127
|
+
@j_del.setMulticastNetworkInterface(val)
|
128
|
+
self
|
129
|
+
end
|
130
|
+
|
131
|
+
#
|
132
|
+
# Gets the {@link java.net.StandardSocketOptions#IP_MULTICAST_IF} option.
|
133
|
+
#
|
134
|
+
def multicast_network_interface
|
135
|
+
@j_del.getMulticastNetworkInterface
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
#
|
140
|
+
# Close the socket asynchronous and notifies the handler once done.
|
141
|
+
#
|
142
|
+
# @param [Block] hndlr the handler to notify once the opeation completes.
|
143
|
+
def close(&hndlr)
|
144
|
+
if hndlr
|
145
|
+
@j_del.close(ARWrappedHandler.new(hndlr))
|
146
|
+
else
|
147
|
+
@j_del.close
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
#
|
152
|
+
# Return the Addrinfo to which the local end of the socket is bound
|
153
|
+
#
|
154
|
+
# @return [Addrinfo] local_addr the local address to which the socket is bound if it is bound at all.
|
155
|
+
def local_address
|
156
|
+
if !@local_address
|
157
|
+
addr = j_del.localAddress
|
158
|
+
if addr != null
|
159
|
+
@local_address = Addrinfo.tcp(@local_address.getAddress().getHostAddress(), @@local_address.getPort())
|
160
|
+
end
|
161
|
+
end
|
162
|
+
@local_address
|
163
|
+
end
|
164
|
+
|
165
|
+
#
|
166
|
+
# Joins a multicast group and so start listen for packets send to it. The {@link Handler} is notified once the operation completes.
|
167
|
+
#
|
168
|
+
#
|
169
|
+
# @param [String] multicast_address the address of the multicast group to join
|
170
|
+
# @param [String] source the address of the source for which we will listen for mulicast packets
|
171
|
+
# @param [String] network_interface the network interface on which to listen for packets.
|
172
|
+
# @param [Block] hndlr the handler to notify once the opeation completes.
|
173
|
+
# @return [DatagramSocket] self itself for method chaining
|
174
|
+
def listen_multicast_group(multicast_address, source = nil, network_interface = nil, &hndlr)
|
175
|
+
if network_interface != nil && source != nil
|
176
|
+
@j_del.listenMulticastGroup(multicast_address, network_interface, source, ARWrappedHandler.new(hndlr) { |j_del| self })
|
177
|
+
else
|
178
|
+
@j_del.listenMulticastGroup(multicast_address, ARWrappedHandler.new(hndlr) { |j_del| self })
|
179
|
+
end
|
180
|
+
self
|
181
|
+
end
|
182
|
+
|
183
|
+
#
|
184
|
+
# Leaves a multicast group and so stop listen for packets send to it on the given network interface.
|
185
|
+
# The {@link Handler} is notified once the operation completes.
|
186
|
+
#
|
187
|
+
#
|
188
|
+
# @param [String] multicast_address the address of the multicast group to leave
|
189
|
+
# @param [String] source the address of the source for which we will listen for mulicast packets
|
190
|
+
# @param [String] network_interface the network interface on which to listen for packets.
|
191
|
+
# @param [Block] hndlr the handler to notify once the opeation completes.
|
192
|
+
# @return [DatagramSocket] self itself for method chaining
|
193
|
+
def unlisten_multicast_group(multicast_address, source = nil, network_interface = nil, &hndlr)
|
194
|
+
if network_interface != nil && source != nil
|
195
|
+
@j_del.unlistenMulticastGroup(multicast_address, network_interface, source, ARWrappedHandler.new(hndlr) { |j_del| self })
|
196
|
+
else
|
197
|
+
@j_del.unlistenMulticastGroup(multicast_address, ARWrappedHandler.new(hndlr) { |j_del| self })
|
198
|
+
end
|
199
|
+
self
|
200
|
+
end
|
201
|
+
|
202
|
+
#
|
203
|
+
# Block the given sourceToBlock address for the given multicastAddress on the given network interface and notifies
|
204
|
+
# the {@link Handler} once the operation completes.
|
205
|
+
#
|
206
|
+
#
|
207
|
+
# @param [String] multicast_address the address for which you want to block the sourceToBlock
|
208
|
+
# @param [String] source_to_block the source address which should be blocked. You will not receive an multicast packets
|
209
|
+
# for it anymore.
|
210
|
+
# @param [String] network_interface the network interface on which the blocking should accour.
|
211
|
+
# @param [Block] hndlr the handler to notify once the opeation completes.
|
212
|
+
# @return [DatagramSocket] self itself for method chaining
|
213
|
+
#
|
214
|
+
def block_multicast_group(multicast_address, source_to_block, network_interface = nil, &hndlr)
|
215
|
+
if network_interface != nil
|
216
|
+
@j_del.blockMulticastGroup(multicast_address, network_interface, source_to_block, ARWrappedHandler.new(hndlr) { |j_del| self })
|
217
|
+
else
|
218
|
+
@j_del.blockMulticastGroup(multicast_address, source_to_block, ARWrappedHandler.new(hndlr) { |j_del| self })
|
219
|
+
end
|
220
|
+
self
|
221
|
+
end
|
222
|
+
|
223
|
+
#
|
224
|
+
# Listen for incoming [DatagramPacket]s on the given address and port.
|
225
|
+
#
|
226
|
+
#
|
227
|
+
# @param [FixNum] port the port on which to listen for incoming [DatagramPacket]s
|
228
|
+
# @param [String] address the address on which to listen for incoming [DatagramPacket]s
|
229
|
+
# @param [Block] hndlr the handler to notify once the opeation completes.
|
230
|
+
# @return [DatagramSocket] self itself for method chaining
|
231
|
+
#
|
232
|
+
def listen(port, address = '0.0.0.0', &hndlr)
|
233
|
+
@j_del.listen(address, port, ARWrappedHandler.new(hndlr) { |j_del| self })
|
234
|
+
self
|
235
|
+
end
|
236
|
+
|
237
|
+
|
238
|
+
# Set a data handler. As data is read, the handler will be called with the data.
|
239
|
+
#
|
240
|
+
# @param [Block] hndlr. The data handler
|
241
|
+
def data_handler(&hndlr)
|
242
|
+
@j_del.dataHandler(Proc.new { |j_packet|
|
243
|
+
hndlr.call(DatagramPacket.new(j_packet))
|
244
|
+
})
|
245
|
+
self
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
|
250
|
+
# A received Datagram packet (UDP) which contains the data and information about the sender of the data itself.
|
251
|
+
#
|
252
|
+
# @author Norman Maurer
|
253
|
+
class DatagramPacket
|
254
|
+
def initialize(j_packet)
|
255
|
+
@j_packet = j_packet
|
256
|
+
@sender = nil
|
257
|
+
@data = nil
|
258
|
+
end
|
259
|
+
|
260
|
+
# Return the address of the sender of this [DatagramPacket].
|
261
|
+
#
|
262
|
+
# @return [AddrInfo] addr the address of the sender
|
263
|
+
def sender
|
264
|
+
if !@sender
|
265
|
+
@sender = Addrinfo.tcp(@j_packet.sender().getAddress().getHostAddress(), @j_packet.sender().getPort())
|
266
|
+
end
|
267
|
+
@sender
|
268
|
+
end
|
269
|
+
|
270
|
+
# Return the data which was received
|
271
|
+
#
|
272
|
+
# @return [Buffer] data the data which was received
|
273
|
+
def data
|
274
|
+
if !@data
|
275
|
+
@data = Buffer.new(@j_packet.data())
|
276
|
+
end
|
277
|
+
@data
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
data/lib/core/dns.rb
ADDED
@@ -0,0 +1,143 @@
|
|
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
|
+
require 'core/wrapped_handler'
|
16
|
+
require 'socket'
|
17
|
+
|
18
|
+
module Vertx
|
19
|
+
|
20
|
+
MxRecord = Struct.new(:priority, :name)
|
21
|
+
SrvRecord = Struct.new(:priority, :weight, :port, :name, :protocol, :service, :target)
|
22
|
+
|
23
|
+
# An async DNS Client
|
24
|
+
#
|
25
|
+
# @author Norman Maurer
|
26
|
+
class DnsClient
|
27
|
+
def initialize(*servers)
|
28
|
+
@j_dns = org.vertx.java.platform.impl.JRubyVerticleFactory.vertx.createDnsClient(
|
29
|
+
servers.map { |value| java.net.InetSocketAddress.new(value.ip_address, value.ip_port) }.to_java(java.net.InetSocketAddress))
|
30
|
+
end
|
31
|
+
|
32
|
+
# Try to lookup the A (ipv4) or AAAA (ipv6) record for the given name. The first found will be used.
|
33
|
+
# The handler will be notified once the lookup completes.
|
34
|
+
# @param [Block] hndlr A block to be used as the handler
|
35
|
+
def lookup(name, &hndlr)
|
36
|
+
@j_dns.lookup(name, ARWrappedHandler.new(hndlr) { |addr| addr.getHostAddress()})
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
# Try to lookup the A (ipv4) record for the given name. The first found will be used.
|
41
|
+
# The handler will be notified once the lookup completes.
|
42
|
+
# @param [Block] hndlr A block to be used as the handler
|
43
|
+
def lookup_4(name, &hndlr)
|
44
|
+
@j_dns.lookup4(name, ARWrappedHandler.new(hndlr) { |addr| addr.getHostAddress()})
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
# Try to AAAA (ipv6) record for the given name. The first found will be used.
|
49
|
+
# The handler will be notified once the lookup completes.
|
50
|
+
# @param [Block] hndlr A block to be used as the handler
|
51
|
+
def lookup_6(name, &hndlr)
|
52
|
+
@j_dns.lookup6(name, ARWrappedHandler.new(hndlr) { |addr| addr.getHostAddress()})
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
56
|
+
# Try to resolve all A records for the given name.
|
57
|
+
# The handler will be notified once the operation completes.
|
58
|
+
# @param [Block] hndlr A block to be used as the handler
|
59
|
+
def resolve_a(name, &hndlr)
|
60
|
+
@j_dns.resolveA(name, ARWrappedHandler.new(hndlr) { |j_list|
|
61
|
+
j_list.map { |item|
|
62
|
+
item.getHostAddress()
|
63
|
+
}
|
64
|
+
})
|
65
|
+
self
|
66
|
+
end
|
67
|
+
|
68
|
+
# Try to resolve all AAAA records for the given name.
|
69
|
+
# The handler will be notified once the operation completes.
|
70
|
+
# @param [Block] hndlr A block to be used as the handler
|
71
|
+
def resolve_aaaa(name, &hndlr)
|
72
|
+
@j_dns.resolveAAAA(name, ARWrappedHandler.new(hndlr) { |j_list|
|
73
|
+
j_list.map { |item|
|
74
|
+
item.getHostAddress()
|
75
|
+
}
|
76
|
+
})
|
77
|
+
self
|
78
|
+
end
|
79
|
+
|
80
|
+
# Try to resolve all CNAME records for the given name.
|
81
|
+
# The handler will be notified once the operation completes.
|
82
|
+
# @param [Block] hndlr A block to be used as the handler
|
83
|
+
def resolve_cname(name, &hndlr)
|
84
|
+
@j_dns.resolveCNAME(name, ARWrappedHandler.new(hndlr))
|
85
|
+
self
|
86
|
+
end
|
87
|
+
|
88
|
+
# Try to resolve all MX records for the given name.
|
89
|
+
# The handler will be notified once the operation completes.
|
90
|
+
# @param [Block] hndlr A block to be used as the handler
|
91
|
+
def resolve_mx(name, &hndlr)
|
92
|
+
@j_dns.resolveMX(name, ARWrappedHandler.new(hndlr) { |j_list|
|
93
|
+
j_list.map { |item|
|
94
|
+
MxRecord.new(item.priority(), item.name())
|
95
|
+
}
|
96
|
+
})
|
97
|
+
self
|
98
|
+
end
|
99
|
+
|
100
|
+
# Try to resolve the PTR record for the given name.
|
101
|
+
# The handler will be notified once the operation completes.
|
102
|
+
# @param [Block] hndlr A block to be used as the handler
|
103
|
+
def resolve_ptr(name, &hndlr)
|
104
|
+
@j_dns.resolvePTR(name, ARWrappedHandler.new(hndlr))
|
105
|
+
self
|
106
|
+
end
|
107
|
+
|
108
|
+
# Try to resolve all NS records for the given name.
|
109
|
+
# The handler will be notified once the operation completes.
|
110
|
+
# @param [Block] hndlr A block to be used as the handler
|
111
|
+
def resolve_ns(name, &hndlr)
|
112
|
+
@j_dns.resolveNS(name, ARWrappedHandler.new(hndlr))
|
113
|
+
self
|
114
|
+
end
|
115
|
+
|
116
|
+
def resolve_txt(name, &hndlr)
|
117
|
+
@j_dns.resolveTXT(name, ARWrappedHandler.new(hndlr))
|
118
|
+
self
|
119
|
+
end
|
120
|
+
|
121
|
+
# Try to resolve all SRV records for the given name.
|
122
|
+
# The handler will be notified once the operation completes.
|
123
|
+
# @param [Block] hndlr A block to be used as the handler
|
124
|
+
def resolve_srv(name, &hndlr)
|
125
|
+
@j_dns.resolveSRV(name, ARWrappedHandler.new(hndlr) { |j_list|
|
126
|
+
j_list.map { |item|
|
127
|
+
SrvRecord.new(item.priority(), item.weight(), item.port(), item.name(), item.protocol(), item.service(), item.target())
|
128
|
+
}
|
129
|
+
})
|
130
|
+
self
|
131
|
+
end
|
132
|
+
|
133
|
+
# Try to do a reverse lookup of an ipaddress. This is basically the same as doing trying to resolve a PTR record
|
134
|
+
# but allows you to just pass in the ipaddress and not a valid ptr query string.
|
135
|
+
# The handler will be notified once the operation completes.
|
136
|
+
# @param [Block] hndlr A block to be used as the handler
|
137
|
+
def reverse_lookup(name, &hndlr)
|
138
|
+
@j_dns.reverseLookup(name, ARWrappedHandler.new(hndlr) { |addr| addr.getHostName()})
|
139
|
+
self
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
end
|
@@ -53,17 +53,39 @@ module Vertx
|
|
53
53
|
|
54
54
|
@@handler_map = {}
|
55
55
|
|
56
|
-
@@j_eventbus = org.
|
56
|
+
@@j_eventbus = org.vertx.java.platform.impl.JRubyVerticleFactory.vertx.eventBus()
|
57
57
|
|
58
58
|
# Send a message on the event bus
|
59
59
|
# @param message [Hash] The message to send
|
60
60
|
# @param reply_handler [Block] An optional reply handler.
|
61
|
+
# @param [Integer] timeout if specified sends the message
|
61
62
|
# It will be called when the reply from a receiver is received.
|
62
|
-
def EventBus.send(address, message, &reply_handler)
|
63
|
-
|
63
|
+
def EventBus.send(address, message, timeout = nil, &reply_handler)
|
64
|
+
|
65
|
+
if timeout.nil?
|
66
|
+
EventBus.send_or_pub(true, address, message, reply_handler)
|
67
|
+
else
|
68
|
+
EventBus.send_or_pub(true, address, message, reply_handler, timeout)
|
69
|
+
end
|
70
|
+
|
64
71
|
self
|
65
72
|
end
|
66
73
|
|
74
|
+
# Sets a default timeout, in ms, for replies. If a messages is sent specify a reply handler
|
75
|
+
# but without specifying a timeout, then the reply handler is timed out, i.e. it is automatically unregistered
|
76
|
+
# if a message hasn't been received before timeout.
|
77
|
+
# The default value for default send timeout is -1, which means "never timeout".
|
78
|
+
# @param timeout
|
79
|
+
def EventBus.default_reply_timeout=(timeout)
|
80
|
+
@@j_eventbus.setDefaultReplyTimeout(timeout)
|
81
|
+
self
|
82
|
+
end
|
83
|
+
|
84
|
+
# Gets the default reply timeout value
|
85
|
+
def EventBus.default_reply_timeout
|
86
|
+
@@j_eventbus.getDefaultReplyTimeout
|
87
|
+
end
|
88
|
+
|
67
89
|
# Publish a message on the event bus
|
68
90
|
# @param message [Hash] The message to publish
|
69
91
|
def EventBus.publish(address, message)
|
@@ -72,13 +94,17 @@ module Vertx
|
|
72
94
|
end
|
73
95
|
|
74
96
|
# @private
|
75
|
-
def EventBus.send_or_pub(send, address, message, reply_handler = nil)
|
97
|
+
def EventBus.send_or_pub(send, address, message, reply_handler = nil, timeout = nil)
|
76
98
|
raise "An address must be specified" if !address
|
77
99
|
raise "A message must be specified" if message == nil
|
78
100
|
message = convert_msg(message)
|
79
101
|
if send
|
80
102
|
if reply_handler != nil
|
81
|
-
|
103
|
+
if timeout != nil
|
104
|
+
@@j_eventbus.send_with_timeout address, message, timeout, AsyncInternalHandler.new(reply_handler)
|
105
|
+
else
|
106
|
+
@@j_eventbus.send(address, message, InternalHandler.new(reply_handler))
|
107
|
+
end
|
82
108
|
else
|
83
109
|
@@j_eventbus.send(address, message)
|
84
110
|
end
|
@@ -165,6 +191,7 @@ module Vertx
|
|
165
191
|
end
|
166
192
|
end
|
167
193
|
|
194
|
+
|
168
195
|
# Represents a message received from the event bus
|
169
196
|
# @author {http://tfox.org Tim Fox}
|
170
197
|
class Message
|
@@ -190,17 +217,61 @@ module Vertx
|
|
190
217
|
# Replying to a message this way is equivalent to sending a message to an address which is the same as the message id
|
191
218
|
# of the original message.
|
192
219
|
# @param [Hash] Message send as reply
|
193
|
-
def reply(reply, &reply_handler)
|
220
|
+
def reply(reply, timeout = nil, &reply_handler)
|
194
221
|
raise "A reply message must be specified" if reply == nil
|
195
222
|
reply = EventBus.convert_msg(reply)
|
196
223
|
if reply_handler != nil
|
197
|
-
|
224
|
+
if timeout != nil
|
225
|
+
@j_del.reply_with_timeout reply, timeout, AsyncInternalHandler.new(reply_handler)
|
226
|
+
else
|
227
|
+
@j_del.reply(reply, InternalHandler.new(reply_handler))
|
228
|
+
end
|
198
229
|
else
|
199
230
|
@j_del.reply(reply)
|
200
231
|
end
|
201
232
|
end
|
202
233
|
|
234
|
+
# Gets the address the message was sent to
|
235
|
+
# @return [String] The recipient's address
|
236
|
+
def address
|
237
|
+
@j_del.address
|
238
|
+
end
|
239
|
+
|
240
|
+
def fail(failure_code, message)
|
241
|
+
@j_del.fail failure_code, message
|
242
|
+
end
|
243
|
+
|
203
244
|
end
|
204
245
|
|
205
|
-
end
|
206
246
|
|
247
|
+
# Error when the event bus use timeout and doesn't reply in time
|
248
|
+
# Copied from mod-lang-jython
|
249
|
+
class ReplyError
|
250
|
+
|
251
|
+
TIMEOUT = 0
|
252
|
+
NO_HANDLERS = 1
|
253
|
+
RECIPIENT_FAILURE = 2
|
254
|
+
|
255
|
+
def initialize(exception)
|
256
|
+
@exception = exception
|
257
|
+
end
|
258
|
+
def type
|
259
|
+
@exception.failureType().toInt()
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
# Copied from mod-lang-jython
|
264
|
+
class AsyncInternalHandler
|
265
|
+
include org.vertx.java.core.AsyncResultHandler
|
266
|
+
def initialize(hndlr)
|
267
|
+
@hndlr = hndlr
|
268
|
+
end
|
269
|
+
def handle(result)
|
270
|
+
if result.failed?
|
271
|
+
@hndlr.call(ReplyError.new(result.cause))
|
272
|
+
else
|
273
|
+
@hndlr.call(Message.new(result.result))
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|