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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +2 -14
  5. data/Guardfile +24 -0
  6. data/README.md +34 -66
  7. data/Rakefile +1 -1
  8. data/examples/chatapp/Gemfile +2 -1
  9. data/examples/chatapp/Gemfile.lock +2 -2
  10. data/examples/chatapp/README.md +2 -14
  11. data/examples/chatapp/app.rb +19 -11
  12. data/examples/chatapp/public/assets/javascripts/application.js +1 -1
  13. data/examples/chatapp/public/assets/javascripts/vertxbus.js +60 -48
  14. data/examples/client/vertxbus.js +60 -48
  15. data/examples/shims_example/log/development.log +0 -0
  16. data/jars/hazelcast-3.5.2.jar +0 -0
  17. data/jars/jackson-annotations-2.6.0.jar +0 -0
  18. data/jars/jackson-core-2.6.1.jar +0 -0
  19. data/jars/jackson-databind-2.6.1.jar +0 -0
  20. data/jars/netty-buffer-4.0.33.Final.jar +0 -0
  21. data/jars/netty-codec-4.0.33.Final.jar +0 -0
  22. data/jars/netty-codec-http-4.0.33.Final.jar +0 -0
  23. data/jars/netty-common-4.0.33.Final.jar +0 -0
  24. data/jars/netty-handler-4.0.33.Final.jar +0 -0
  25. data/jars/netty-transport-4.0.33.Final.jar +0 -0
  26. data/jars/vertx-auth-common-3.2.1.jar +0 -0
  27. data/jars/vertx-core-3.2.1.jar +0 -0
  28. data/jars/vertx-hazelcast-3.2.1.jar +0 -0
  29. data/jars/vertx-lang-ruby-3.2.1.jar +0 -0
  30. data/jars/vertx-web-3.2.1.jar +0 -0
  31. data/jubilee.gemspec +40 -42
  32. data/lib/jubilee.rb +7 -2
  33. data/lib/jubilee/cli.rb +4 -4
  34. data/lib/jubilee/jubilee.jar +0 -0
  35. data/lib/jubilee/response.rb +1 -1
  36. data/lib/jubilee/version.rb +3 -3
  37. data/pom.xml +10 -94
  38. data/spec/apps/rails4/basic/Gemfile +2 -2
  39. data/spec/apps/rails4/basic/Gemfile.lock +5 -6
  40. data/src/main/java/org/jruby/jubilee/Const.java +1 -4
  41. data/src/main/java/org/jruby/jubilee/JubileeVerticle.java +41 -46
  42. data/src/main/java/org/jruby/jubilee/RackApplication.java +37 -57
  43. data/src/main/java/org/jruby/jubilee/RackEnvironment.java +38 -35
  44. data/src/main/java/org/jruby/jubilee/RackEnvironmentHash.java +1 -7
  45. data/src/main/java/org/jruby/jubilee/RubyHttpServerResponse.java +12 -6
  46. data/src/main/java/org/jruby/jubilee/RubyNetSocket.java +9 -12
  47. data/src/main/java/org/jruby/jubilee/RubyPlatformManager.java +39 -43
  48. data/src/main/java/org/jruby/jubilee/impl/RubyIORackInput.java +2 -1
  49. data/src/main/java/org/jruby/jubilee/vertx/JubileeVertx.java +1 -1
  50. metadata +30 -54
  51. data/examples/chatapp/config.json +0 -4
  52. data/jars/annotations-1.3.2.jar +0 -0
  53. data/jars/hazelcast-3.2.3.jar +0 -0
  54. data/jars/jackson-annotations-2.2.2.jar +0 -0
  55. data/jars/jackson-core-2.2.2.jar +0 -0
  56. data/jars/jackson-databind-2.2.2.jar +0 -0
  57. data/jars/lang-jruby-2.1.0-final.jar +0 -0
  58. data/jars/log4j-1.2.16.jar +0 -0
  59. data/jars/netty-all-4.0.20.Final.jar +0 -0
  60. data/jars/slf4j-api-1.6.2.jar +0 -0
  61. data/jars/vertx-core-2.1.2.jar +0 -0
  62. data/jars/vertx-hazelcast-2.1.2.jar +0 -0
  63. data/jars/vertx-platform-2.1.2.jar +0 -0
  64. data/lib/container.rb +0 -117
  65. data/lib/core/buffer.rb +0 -251
  66. data/lib/core/datagram.rb +0 -280
  67. data/lib/core/dns.rb +0 -143
  68. data/lib/core/event_bus.rb +0 -277
  69. data/lib/core/file_system.rb +0 -479
  70. data/lib/core/http.rb +0 -1307
  71. data/lib/core/net.rb +0 -251
  72. data/lib/core/network_support.rb +0 -77
  73. data/lib/core/parsetools.rb +0 -105
  74. data/lib/core/shared_data.rb +0 -214
  75. data/lib/core/sock_js.rb +0 -116
  76. data/lib/core/ssl_support.rb +0 -163
  77. data/lib/core/streams.rb +0 -183
  78. data/lib/core/tcp_support.rb +0 -136
  79. data/lib/core/timers.rb +0 -73
  80. data/lib/core/vertx_require.rb +0 -25
  81. data/lib/core/wrapped_handler.rb +0 -28
  82. data/lib/jubilee/jubilee_require.rb +0 -24
  83. data/lib/test_utils.rb +0 -66
  84. data/lib/vertx.rb +0 -30
  85. data/lib/vertx_tests.rb +0 -8
  86. data/src/main/assembly/mod.xml +0 -21
  87. data/src/main/java/org/jruby/jubilee/JubileeVerticleFactory.java +0 -258
  88. data/src/main/java/org/jruby/jubilee/RubyCallable.java +0 -52
  89. data/src/main/resources/META-INF/services/org.vertx.java.deploy.impl.jruby.JubileeVerticleFactory +0 -1
  90. data/src/main/resources/mod.json +0 -11
  91. data/vertx_classpath.txt +0 -12
@@ -1,4 +0,0 @@
1
- { "host": "0.0.0.0",
2
- "port": 8080,
3
- "event_bus": "/eventbus"
4
- }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,117 +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/wrapped_handler'
16
-
17
- module Vertx
18
-
19
- # Deploy a verticle. The actual deploy happens asynchronously
20
- # @param main [String] The main of the verticle to deploy
21
- # @param config [Hash] JSON configuration for the verticle
22
- # @param instances [FixNum] Number of instances to deploy
23
- # @param block [Block] Block will be executed when deploy has completed - the first parameter passed to
24
- # the block will be an exception or nil if no failure occurred, the second parameter will be the deployment id
25
- def Vertx.deploy_verticle(main, config = nil, instances = 1, &block)
26
- if config
27
- json_str = JSON.generate(config)
28
- config = org.vertx.java.core.json.JsonObject.new(json_str)
29
- end
30
- if block
31
- block = ARWrappedHandler.new(block)
32
- end
33
- org.vertx.java.platform.impl.JRubyVerticleFactory.container.deployVerticle(main, config, instances, block)
34
- end
35
-
36
- # Deploy a worker verticle. The actual deploy happens asynchronously
37
- # @param main [String] The main of the verticle to deploy
38
- # @param config [Hash] JSON configuration for the verticle
39
- # @param instances [FixNum] Number of instances to deploy
40
- # @param block [Block] Block will be executed when deploy has completed - the first parameter passed to
41
- # the block will be an exception or nil if no failure occurred, the second parameter will be the deployment id
42
- def Vertx.deploy_worker_verticle(main, config = nil, instances = 1, multi_threaded = false, &block)
43
- if config
44
- json_str = JSON.generate(config)
45
- config = org.vertx.java.core.json.JsonObject.new(json_str)
46
- end
47
- if block
48
- block = ARWrappedHandler.new(block)
49
- end
50
- org.vertx.java.platform.impl.JRubyVerticleFactory.container.deployWorkerVerticle(main, config, instances, multi_threaded, block)
51
- end
52
-
53
- # Deploy a module. The actual deploy happens asynchronously
54
- # @param module_name [String] The name of the module to deploy
55
- # @param config [Hash] JSON configuration for the module
56
- # @param instances [FixNum] Number of instances to deploy
57
- # @param block [Block] Block will be executed when deploy has completed - the first parameter passed to
58
- # the block will be an exception or nil if no failure occurred, the second parameter will be the deployment id
59
- def Vertx.deploy_module(module_name, config = nil, instances = 1, &block)
60
- if config
61
- json_str = JSON.generate(config)
62
- config = org.vertx.java.core.json.JsonObject.new(json_str)
63
- end
64
- if block
65
- block = ARWrappedHandler.new(block)
66
- end
67
- org.vertx.java.platform.impl.JRubyVerticleFactory.container.deployModule(module_name, config, instances, block)
68
- end
69
-
70
- # Undeploy a verticle
71
- # @param id [String] The deployment id - the undeploy happens asynchronously
72
- # @param block [Block] Block will be executed when undeploy has completed, an exception will be passed to the block
73
- # as the first parameter if undeploy failed
74
- def Vertx.undeploy_verticle(id, &block)
75
- if block
76
- block = ARWrappedHandler.new(block)
77
- end
78
- org.vertx.java.platform.impl.JRubyVerticleFactory.container.undeployVerticle(id, block)
79
- end
80
-
81
- # Undeploy a module
82
- # @param id [String] The deployment id
83
- # @param block [Block] Block will be executed when undeploy has completed, an exception will be passed to the block
84
- # as the first parameter if undeploy failed
85
- def Vertx.undeploy_module(id, &block)
86
- if block
87
- block = ARWrappedHandler.new(block)
88
- end
89
- org.vertx.java.platform.impl.JRubyVerticleFactory.container.undeployModule(id, block)
90
- end
91
-
92
- # Cause the container to exit
93
- def Vertx.exit
94
- org.vertx.java.platform.impl.JRubyVerticleFactory.container.exit
95
- end
96
-
97
- # Get config for the verticle
98
- # @return [Hash] The JSON config for the verticle
99
- def Vertx.config
100
- if !defined? @@j_conf
101
- @@j_conf = org.vertx.java.platform.impl.JRubyVerticleFactory.container.config
102
- @@j_conf = JSON.parse(@@j_conf.encode) if @@j_conf
103
- end
104
- @@j_conf
105
- end
106
-
107
- # @return [Hash] Get the environment for the verticle
108
- def Vertx.env
109
- org.vertx.java.platform.impl.JRubyVerticleFactory.container.env
110
- end
111
-
112
- # @return [Logger] Get the logger for the verticle
113
- def Vertx.logger
114
- org.vertx.java.platform.impl.JRubyVerticleFactory.container.logger
115
- end
116
-
117
- end
@@ -1,251 +0,0 @@
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
- require 'core/shared_data'
16
-
17
- module Vertx
18
-
19
- # A Buffer represents a sequence of zero or more bytes that can be written to or read from, and which expands
20
- # as necessary to accomodate any bytes written to it.
21
- #
22
- # Buffers are used in many places in vert.x, for example to read/write data to/from {NetSocket}, {AsyncFile},
23
- # {WebSocket}, {HttpClientRequest}, {HttpClientResponse}, {HttpServerRequest}, {HttpServerResponse} etc.
24
- #
25
- # There are two ways to write data to a Buffer: The first method involves methods that take the form set_XXX.
26
- # These methods write data into the buffer starting at the specified position. The position does not have to be inside data that
27
- # has already been written to the buffer; the buffer will automatically expand to encompass the position plus any data that needs
28
- # to be written. All positions are measured in bytes and start with zero.
29
- #
30
- # The second method involves methods that take the form append-XXX; these methods append data at the end of the buffer.
31
- # Methods exist to both set and append all primitive types, String and other instances of Buffer.
32
- #
33
- # Data can be read from a buffer by invoking methods which take the form get_XXX. These methods take a parameter
34
- # representing the position in the Buffer from where to read data.
35
- #
36
- # @author {http://tfox.org Tim Fox}
37
- class Buffer
38
-
39
- # @private
40
- def initialize(j_buffer)
41
- @buffer = j_buffer
42
- end
43
-
44
- # Creates a new empty buffer. The {#length} of the buffer immediately after creation will be zero.
45
- # @param initial_size_hint [FixNum] is a hint to the system for how much memory
46
- # to initially allocate to the buffer to prevent excessive automatic re-allocations as data is written to it.
47
- def Buffer.create(initial_size_hint = 0)
48
- Buffer.new(org.vertx.java.core.buffer.Buffer.new(initial_size_hint))
49
- end
50
-
51
- # Create a new Buffer from a String
52
- # @param str [String] The String to encode into the Buffer
53
- # @param enc [String] Encoding to use. Defaults to "UTF-8"
54
- def Buffer.create_from_str(str, enc = "UTF-8")
55
- Buffer.new(org.vertx.java.core.buffer.Buffer.new(str, enc))
56
- end
57
-
58
- # Return a String representation of the buffer.
59
- # @param enc [String] The encoding to use. Defaults to "UTF-8"
60
- # @return [String] a String representation of the buffer.
61
- def to_s(enc = "UTF-8")
62
- @buffer.toString(enc)
63
- end
64
-
65
- # Get the byte at position pos in the buffer.
66
- # @param pos [FixNum] the position in the buffer from where to retrieve the byte
67
- # @return [FixNum] the byte
68
- def get_byte(pos)
69
- @buffer.getByte(pos)
70
- end
71
-
72
- # Get the FixNum represented by a sequence of bytes starting at position pos in the buffer.
73
- # @param pos [FixNum] the position in the buffer from where to retrieve the FixNum.
74
- # @param bytes [FixNum] the number of bytes to retrieve from position pos to create the FixNum. Valid values are 1, 2, 4 and 8.
75
- # @return [FixNum] the FixNum
76
- def get_fixnum(pos, bytes)
77
- case bytes
78
- when 1
79
- @buffer.getByte(pos)
80
- when 2
81
- @buffer.getShort(pos)
82
- when 4
83
- @buffer.getInt(pos)
84
- when 8
85
- @buffer.getLong(pos)
86
- else
87
- raise "bytes must be 1, 2, 4, or 8"
88
- end
89
- end
90
-
91
- # Get the Float represented by a sequence of bytes starting at position pos in the buffer.
92
- # @param pos [Float] the position in the buffer from where to retrieve the Float.
93
- # @param bytes [Float] the number of bytes to retrieve from position pos to create the Float. Valid values are 4 and 8.
94
- # @return [Float] the Float
95
- def get_float(pos, bytes)
96
- case bytes
97
- when 4
98
- @buffer.getFloat(pos)
99
- when 8
100
- @buffer.getDouble(pos)
101
- else
102
- raise "bytes must be 4 or 8"
103
- end
104
- end
105
-
106
- # Return bytes from the buffer interpreted as a String
107
- # @param pos [FixNum] the position in the buffer from where to start reading
108
- # @param end_pos [FixNum] the position in the buffer to end reading
109
- # @param enc [String] The encoding to use
110
- # @return [String] the String
111
- def get_string(pos, end_pos, enc = 'UTF-8')
112
- @buffer.getString(pos, end_pos, enc)
113
- end
114
-
115
- # Return bytes in the buffer as a Buffer
116
- # @param start_pos [FixNum] - the position in this buffer from where to start the copy.
117
- # @param end_pos [FixNum] - the copy will be made up to index end_pos - 1
118
- # @return [Buffer] the copy
119
- def get_buffer(pos, end_pos)
120
- j_buff = @buffer.getBuffer(pos, end_pos)
121
- Buffer.new(j_buff)
122
- end
123
-
124
- # Appends another buffer to the end of this buffer. The buffer will expand as necessary to accomodate any bytes
125
- # written.
126
- # @param buff [Buffer] the buffer to append.
127
- # @return [Buffer] a reference to self so multiple operations can be appended together.
128
- def append_buffer(buff)
129
- @buffer.appendBuffer(buff._to_java_buffer)
130
- self
131
- end
132
-
133
- # Appends a FixNum to the end of this buffer. The buffer will expand as necessary to accomodate any bytes written.
134
- # @param num [FixNum] the fixnum to append.
135
- # @param bytes [FixNum] the number of bytes to write in the buffer to represent the fixnum. Valid values are 1, 2, 4 and 8.
136
- # @return [Buffer] a reference to self so multiple operations can be appended together.
137
- def append_fixnum(num, bytes)
138
- case bytes
139
- when 1
140
- @buffer.appendByte(num)
141
- when 2
142
- @buffer.appendShort(num)
143
- when 4
144
- @buffer.appendInt(num)
145
- when 8
146
- @buffer.appendLong(num)
147
- else
148
- raise "bytes must be 1, 2, 4, or 8"
149
- end
150
- self
151
- end
152
-
153
- # Appends a Float to the end of this buffer. The buffer will expand as necessary to accomodate any bytes written.
154
- # @param num [Float] the float to append.
155
- # @param bytes [FixNum] the number of bytes to write in the buffer to represent the float. Valid values are 4 and 8.
156
- # @return [Buffer] a reference to self so multiple operations can be appended together.
157
- def append_float(num, bytes)
158
- case bytes
159
- when 4
160
- @buffer.appendFloat(num)
161
- when 8
162
- @buffer.appendDouble(num)
163
- else
164
- raise "bytes must be 4 or 8"
165
- end
166
- end
167
-
168
- # Appends a string to the end of this buffer. The buffer will expand as necessary to accomodate any bytes written.
169
- # @param str [String] the string to append.
170
- # @param enc [String] the encoding to use. Defaults to "UTF-8"
171
- # @return [Buffer] a reference to self so multiple operations can be appended together.
172
- def append_str(str, enc = "UTF-8")
173
- @buffer.appendString(str, enc)
174
- self
175
- end
176
-
177
- # Sets bytes in the buffer to a representation of a FixNum. The buffer will expand as necessary to accomodate any bytes written.
178
- # @param pos [FixNum] - the position in the buffer from where to start writing the FixNum
179
- # @param num [FixNum] - the FixNum to write
180
- # @param bytes [FixNum] - the number of bytes to write to represent the FixNum. Valid values are 1, 2, 4, and 8
181
- # @return [Buffer] a reference to self so multiple operations can be appended together.
182
- def set_fixnum(pos, num, bytes)
183
- case bytes
184
- when 1
185
- @buffer.setByte(pos, num)
186
- when 2
187
- @buffer.setShort(pos, num)
188
- when 4
189
- @buffer.setInt(pos, num)
190
- when 8
191
- @buffer.setLong(pos, num)
192
- else
193
- raise "bytes must be 1, 2, 4, or 8"
194
- end
195
- self
196
- end
197
-
198
- # Sets bytes in the buffer to a representation of a Float. The buffer will expand as necessary to accomodate any bytes written.
199
- # @param pos [FixNum] - the position in the buffer from where to start writing the Float
200
- # @param num [Float] - the Float to write
201
- # @param bytes [FixNum] - the number of bytes to write to represent the Float. Valid values are 4 and 8
202
- # @return [Buffer] a reference to self so multiple operations can be appended together.
203
- def set_float(pos, num, bytes)
204
- case bytes
205
- when 4
206
- @buffer.setFloat(pos, num)
207
- when 8
208
- @buffer.setDouble(pos, num)
209
- else
210
- raise "bytes must be 4 or 8"
211
- end
212
- self
213
- end
214
-
215
- # Sets bytes in this buffer to the bytes of the specified buffer. The buffer will expand as necessary to accomodate any bytes written.
216
- # @param pos [FixNum] - the position in this buffer from where to start writing the buffer
217
- # @param buff [Buffer] - the buffer to write into this buffer
218
- # @return [Buffer] a reference to self so multiple operations can be appended together.
219
- def set_buffer(pos, buff)
220
- @buffer.setBytes(pos, buff._to_java_buffer)
221
- self
222
- end
223
-
224
- # Set bytes in the buffer to the string encoding in the specified encoding
225
- # @param pos [FixNum] - the position in this buffer from where to start writing the string
226
- # @param str [String] the string
227
- # @param enc [String] the encoding
228
- # @return [Buffer] a reference to self so multiple operations can be appended together.
229
- def set_string(pos, str, enc = 'UTF-8')
230
- @buffer.setString(pos, str, enc)
231
- self
232
- end
233
-
234
- # @return [FixNum] the length of this buffer, in bytes.
235
- def length
236
- @buffer.length
237
- end
238
-
239
- # Get a copy of the entire buffer.
240
- # @return [Buffer] the copy
241
- def copy
242
- Buffer.new(@buffer.copy())
243
- end
244
-
245
- # @private
246
- def _to_java_buffer
247
- @buffer
248
- end
249
-
250
- end
251
- end
@@ -1,280 +0,0 @@
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