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