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,143 +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/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
@@ -1,277 +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 'rubygems'
16
- require 'json'
17
-
18
- module Vertx
19
-
20
- # This class represents a distributed lightweight event bus which can encompass multiple vert.x instances.
21
- # It is very useful for otherwise isolated vert.x application instances to communicate with each other.
22
- #
23
- # The event bus implements both publish / subscribe network and point to point messaging.
24
- #
25
- # For publish / subscribe, messages can be published to an address using one of the publish methods. An
26
- # address is a simple String instance. Handlers are registered against an address. There can be multiple handlers
27
- # registered against each address, and a particular handler can be registered against multiple addresses.
28
- # The event bus will route a sent message to all handlers which are registered against that address.
29
-
30
- # For point to point messaging, messages can be sent to an address using the send method.
31
- # The messages will be delivered to a single handler, if one is registered on that address. If more than one
32
- # handler is registered on the same address, Vert.x will choose one and deliver the message to that. Vert.x will
33
- # aim to fairly distribute messages in a round-robin way, but does not guarantee strict round-robin under all
34
- # circumstances.
35
- #
36
- # All messages sent over the bus are transient. On event of failure of all or part of the event bus messages
37
- # may be lost. Applications should be coded to cope with lost messages, e.g. by resending them,
38
- # and making application services idempotent.
39
- #
40
- # The order of messages received by any specific handler from a specific sender should match the order of messages
41
- # sent from that sender.
42
- #
43
- # When sending a message, a reply handler can be provided. If so, it will be called when the reply from the receiver
44
- # has been received. Reply messages can also be replied to, etc, ad infinitum.
45
- #
46
- # Different event bus instances can be clustered together over a network, to give a single logical event bus.
47
- #
48
- # When receiving a message in a handler the received object is an instance of EventBus::Message - this contains
49
- # the actual message plus a reply method which can be used to reply to it.
50
- #
51
- # @author {http://tfox.org Tim Fox}
52
- class EventBus
53
-
54
- @@handler_map = {}
55
-
56
- @@j_eventbus = org.vertx.java.platform.impl.JRubyVerticleFactory.vertx.eventBus()
57
-
58
- # Send a message on the event bus
59
- # @param message [Hash] The message to send
60
- # @param reply_handler [Block] An optional reply handler.
61
- # @param [Integer] timeout if specified sends the message
62
- # It will be called when the reply from a receiver is received.
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
-
71
- self
72
- end
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
-
89
- # Publish a message on the event bus
90
- # @param message [Hash] The message to publish
91
- def EventBus.publish(address, message)
92
- EventBus.send_or_pub(false, address, message)
93
- self
94
- end
95
-
96
- # @private
97
- def EventBus.send_or_pub(send, address, message, reply_handler = nil, timeout = nil)
98
- raise "An address must be specified" if !address
99
- raise "A message must be specified" if message == nil
100
- message = convert_msg(message)
101
- if send
102
- if reply_handler != nil
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
108
- else
109
- @@j_eventbus.send(address, message)
110
- end
111
- else
112
- @@j_eventbus.publish(address, message)
113
- end
114
- self
115
- end
116
-
117
- # Register a handler.
118
- # @param address [String] The address to register for. Messages sent to that address will be
119
- # received by the handler. A single handler can be registered against many addresses.
120
- # @param local_only [Boolean] If true then handler won't be propagated across cluster
121
- # @param message_hndlr [Block] The handler
122
- # @return [FixNum] id of the handler which can be used in {EventBus.unregister_handler}
123
- def EventBus.register_handler(address, local_only = false, &message_hndlr)
124
- raise "An address must be specified" if !address
125
- raise "A message handler must be specified" if !message_hndlr
126
- internal = InternalHandler.new(message_hndlr)
127
- if local_only
128
- @@j_eventbus.registerLocalHandler(address, internal)
129
- else
130
- @@j_eventbus.registerHandler(address, internal)
131
- end
132
- id = java.util.UUID.randomUUID.toString
133
- @@handler_map[id] = [address, internal]
134
- id
135
- end
136
-
137
- # Registers a handler against a uniquely generated address, the address is returned as the id
138
- # received by the handler. A single handler can be registered against many addresses.
139
- # @param local_only [Boolean] If true then handler won't be propagated across cluster
140
- # @param message_hndlr [Block] The handler
141
- # @return [FixNum] id of the handler which can be used in {EventBus.unregister_handler}
142
- def EventBus.register_simple_handler(local_only = false, &message_hndlr)
143
- raise "A message handler must be specified" if !message_hndlr
144
- internal = InternalHandler.new(message_hndlr)
145
- id = java.util.UUID.randomUUID.toString
146
- if local_only
147
- @@j_eventbus.registerLocalHandler(id, internal)
148
- else
149
- @@j_eventbus.registerHandler(id, internal)
150
- end
151
- @@handler_map[id] = [id, internal]
152
- id
153
- end
154
-
155
- # Unregisters a handler
156
- # @param handler_id [FixNum] The id of the handler to unregister. Returned from {EventBus.register_handler}
157
- def EventBus.unregister_handler(handler_id)
158
- raise "A handler_id must be specified" if !handler_id
159
- tuple = @@handler_map.delete(handler_id)
160
- raise "Cannot find handler for id #{handler_id}" if !tuple
161
- @@j_eventbus.unregisterHandler(tuple.first, tuple.last)
162
- self
163
- end
164
-
165
- # @private
166
- def EventBus.convert_msg(message)
167
- if message.is_a? Hash
168
- message = org.vertx.java.core.json.JsonObject.new(JSON.generate(message))
169
- elsif message.is_a? Buffer
170
- message = message._to_java_buffer
171
- elsif message.is_a? Fixnum
172
- message = java.lang.Long.new(message)
173
- elsif message.is_a? Float
174
- message = java.lang.Double.new(message)
175
- end
176
- message
177
- end
178
-
179
- end
180
-
181
- # @private
182
- class InternalHandler
183
- include org.vertx.java.core.Handler
184
-
185
- def initialize(hndlr)
186
- @hndlr = hndlr
187
- end
188
-
189
- def handle(message)
190
- @hndlr.call(Message.new(message))
191
- end
192
- end
193
-
194
-
195
- # Represents a message received from the event bus
196
- # @author {http://tfox.org Tim Fox}
197
- class Message
198
-
199
- attr_reader :body
200
-
201
- # @private
202
- def initialize(message)
203
-
204
- @j_del = message
205
- if message.body.is_a? org.vertx.java.core.json.JsonObject
206
- @body = JSON.parse(message.body.encode)
207
- elsif message.body.is_a? org.vertx.java.core.buffer.Buffer
208
- @body = Buffer.new(message.body)
209
- else
210
- @body = message.body
211
- end
212
- end
213
-
214
- # Reply to this message. If the message was sent specifying a receipt handler, that handler will be
215
- # called when it has received a reply. If the message wasn't sent specifying a receipt handler
216
- # this method does nothing.
217
- # Replying to a message this way is equivalent to sending a message to an address which is the same as the message id
218
- # of the original message.
219
- # @param [Hash] Message send as reply
220
- def reply(reply, timeout = nil, &reply_handler)
221
- raise "A reply message must be specified" if reply == nil
222
- reply = EventBus.convert_msg(reply)
223
- if reply_handler != nil
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
229
- else
230
- @j_del.reply(reply)
231
- end
232
- end
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
-
244
- end
245
-
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
@@ -1,479 +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/wrapped_handler.rb'
17
-
18
- module Vertx
19
-
20
- # Represents the properties of a file on the file system
21
- # @author {http://tfox.org Tim Fox}
22
- class FileProps
23
-
24
- # @private
25
- def initialize(j_props)
26
- @j_props = j_props
27
- end
28
-
29
- # @return [Time] The creation time of the file.
30
- def creation_time
31
- Time.at(@j_props.creationTime.getTime() / 1000)
32
- end
33
-
34
- # @return [Time] The last access time of the file.
35
- def last_access_time
36
- Time.at(@j_props.lastAccessTime.getTime() / 1000)
37
- end
38
-
39
- # @return [Time] The last modified time of the file.
40
- def last_modified_time
41
- Time.at(@j_props.lastModifiedTime.getTime() / 1000)
42
- end
43
-
44
- # @return [Boolean] Is the file a directory?
45
- def directory?
46
- @j_props.isDirectory
47
- end
48
-
49
- # @return [Boolean] Is the file some other file type?
50
- def other?
51
- @j_props.isOther
52
- end
53
-
54
- # @return [Boolean] Is it a regular file?
55
- def regular_file?
56
- @j_props.isRegularFile
57
- end
58
-
59
- # @return [Boolean] Is it a symbolic link?
60
- def symbolic_link?
61
- @j_props.isSymbolicLink
62
- end
63
-
64
- # @return [FixNum] The size of the file, in bytes.
65
- def size
66
- @j_props.size
67
- end
68
-
69
- end
70
-
71
- # Represents the properties of a file system
72
- # @author {http://tfox.org Tim Fox}
73
- class FSProps
74
-
75
- # @private
76
- def initialize(j_props)
77
- @j_props = j_props
78
- end
79
-
80
- # @return [FixNum] The total space on the file system, in bytes.
81
- def total_space
82
- @j_props.totalSpace
83
- end
84
-
85
- # @return [FixNum] Unallocated space on the file system, in bytes.
86
- def unallocated_space
87
- @j_props.unallocatedSpace
88
- end
89
-
90
- # @return [FixNum] Usable space on the file system, in bytes.
91
- def usable_space
92
- @j_props.usableSpace
93
- end
94
-
95
- end
96
-
97
- # Represents a file on the file-system which can be read from, or written to asynchronously.
98
- # The class also includes {ReadStream} and {WriteStream} - this allows the data to be pumped to and from
99
- # other streams, e.g. an {HttpClientRequest} instance, using the {Pump} class
100
- # @author {http://tfox.org Tim Fox}
101
- class AsyncFile
102
-
103
- include ReadStream, WriteStream
104
-
105
- # @private
106
- def initialize(j_file)
107
- @j_del = j_file
108
- end
109
-
110
- # Close the file, asynchronously.
111
- def close(&block)
112
- @j_del.close(ARWrappedHandler.new(block))
113
- end
114
-
115
- # Write a {Buffer} to the file, asynchronously.
116
- # When multiple writes are invoked on the same file
117
- # there are no guarantees as to order in which those writes actually occur.
118
- # @param [Buffer] buffer The buffer to write
119
- # @param [FixNum] position The position in the file where to write the buffer. Position is measured in bytes and
120
- # starts with zero at the beginning of the file.
121
- def write_at_pos(buffer, position, &block)
122
- @j_del.write(buffer._to_java_buffer, position, ARWrappedHandler.new(block))
123
- self
124
- end
125
-
126
- # Reads some data from a file into a buffer, asynchronously.
127
- # When multiple reads are invoked on the same file
128
- # there are no guarantees as to order in which those reads actually occur.
129
- # @param [Buffer] buffer The buffer into which the data which is read is written.
130
- # @param [FixNum] offset The position in the buffer where to start writing the data.
131
- # @param [FixNum] position The position in the file where to read the data.
132
- # @param [FixNum] length The number of bytes to read.
133
- def read_at_pos(buffer, offset, position, length, &block)
134
- @j_del.read(buffer._to_java_buffer, offset, position, length, ARWrappedHandler.new(block) { |j_buff| Buffer.new(j_buff) })
135
- self
136
- end
137
-
138
- # Flush any writes made to this file to underlying persistent storage, asynchronously.
139
- # If the file was opened with flush set to true then calling this method will have no effect.
140
- # @param [Block] hndlr a block representing the handler which is called on completion.
141
- def flush
142
- Future.new(@j_del.flush)
143
- self
144
- end
145
-
146
- end
147
-
148
-
149
- # Represents the file-system and contains a broad set of operations for manipulating files.
150
- # An asynchronous and a synchronous version of each operation is provided.
151
- # The asynchronous versions take a handler as a final argument which is
152
- # called when the operation completes or an error occurs. The handler is called
153
- # with two arguments; the first an exception, this will be nil if the operation has
154
- # succeeded. The second is the result - this will be nil if the operation failed or
155
- # there was no result to return.
156
- # The synchronous versions return the results, or throw exceptions directly.
157
- # @author {http://tfox.org Tim Fox}
158
- class FileSystem
159
-
160
- @@j_fs = org.vertx.java.platform.impl.JRubyVerticleFactory.vertx.fileSystem()
161
-
162
- # Copy a file, asynchronously. The copy will fail if from does not exist, or if to already exists.
163
- # @param [String] from Path of file to copy
164
- # @param [String] to Path of file to copy to
165
- # @param [Block] hndlr a block representing the handler which is called on completion.
166
- def FileSystem.copy(from, to, &block)
167
- @@j_fs.copy(from, to, ARWrappedHandler.new(block))
168
- self
169
- end
170
-
171
- # Synchronous version of {#FileSystem.copy}
172
- def FileSystem.copy_sync(from, to)
173
- @@j_fs.copySync(from, to)
174
- self
175
- end
176
-
177
- # Copy a file recursively, asynchronously. The copy will fail if from does not exist, or if to already exists and is not empty.
178
- # If the source is a directory all contents of the directory will be copied recursively, i.e. the entire directory
179
- # tree is copied.
180
- # @param [String] from Path of file to copy
181
- # @param [String] to Path of file to copy to
182
- def FileSystem.copy_recursive(from, to, &block)
183
- @@j_fs.copy(from, to, true, ARWrappedHandler.new(block))
184
- self
185
- end
186
-
187
- # Synchronous version of {#FileSystem.copy_recursive}
188
- def FileSystem.copy_recursive_sync(from, to)
189
- @@j_fs.copySync(from, to, true)
190
- self
191
- end
192
-
193
- # Move a file, asynchronously. The move will fail if from does not exist, or if to already exists.
194
- # @param [String] from Path of file to move
195
- # @param [String] to Path of file to move to
196
- def FileSystem.move(from, to, &block)
197
- @@j_fs.move(from, to, ARWrappedHandler.new(block))
198
- self
199
- end
200
-
201
- # Synchronous version of {#FileSystem.move}
202
- def FileSystem.move_sync(from, to)
203
- @@j_fs.moveSync(from, to)
204
- self
205
- end
206
-
207
- # Truncate a file, asynchronously. The move will fail if path does not exist.
208
- # @param [String] path Path of file to truncate
209
- # @param [FixNum] len Length to truncate file to. Will fail if len < 0. If len > file size then will do nothing.
210
- def FileSystem.truncate(path, len, &block)
211
- @@j_fs.truncate(path, len, ARWrappedHandler.new(block))
212
- self
213
- end
214
-
215
- # Synchronous version of {#FileSystem.truncate}
216
- def FileSystem.truncate_sync(path, len)
217
- @@j_fs.truncateSync(path, len)
218
- self
219
- end
220
-
221
- # Change the permissions on a file, asynchronously. If the file is directory then all contents will also have their permissions changed recursively.
222
- # @param [String] path Path of file to change permissions
223
- # @param [String] perms A permission string of the form rwxr-x--- as specified in
224
- # {http://download.oracle.com/javase/7/docs/api/java/nio/file/attribute/PosixFilePermissions.html}. This is
225
- # used to set the permissions for any regular files (not directories).
226
- # @param [String] dir_perms A permission string of the form rwxr-x---. Used to set permissions for regular files.
227
- def FileSystem.chmod(path, perms, dir_perms = nil, &block)
228
- @@j_fs.chmod(path, perms, dir_perms, ARWrappedHandler.new(block))
229
- self
230
- end
231
-
232
-
233
- # Synchronous version of {#FileSystem.chmod}
234
- def FileSystem.chmod_sync(path, perms, dir_perms = nil)
235
- @@j_fs.chmodSync(path, perms, dir_perms)
236
- self
237
- end
238
-
239
- # Change the ownership of a file, asynchronously.
240
- # @param [String] path Path of the file
241
- # @param [String] user the user to set the ownership to
242
- # @param [String] group the group to set the ownership to
243
- def FileSystem.chown(path, user, group, &block)
244
- @@j_fs.chown(path, user, group, ARWrappedHandler.new(block))
245
- self
246
- end
247
-
248
- # Synchronous version of {#FileSystem.chown}
249
- def FileSystem.chown_sync(path, user, group)
250
- @@j_fs.chownSync(path, user, group)
251
- self
252
- end
253
-
254
- # Get file properties for a file, asynchronously.
255
- # @param [String] path Path to file
256
- def FileSystem.props(path, &block)
257
- @@j_fs.props(path, ARWrappedHandler.new(block) { |j_props| FileProps.new(j_props) })
258
- self
259
- end
260
-
261
- # Synchronous version of {#FileSystem.props}
262
- def FileSystem.props_sync(path)
263
- j_props = @@j_fs.propsSync(path)
264
- FileProps.new(j_props)
265
- end
266
-
267
- # Create a hard link, asynchronously..
268
- # @param [String] link Path of the link to create.
269
- # @param [String] existing Path of where the link points to.
270
- def FileSystem.link(link, existing, &block)
271
- @@j_fs.link(link, existing, ARWrappedHandler.new(block))
272
- self
273
- end
274
-
275
- # Synchronous version of {#FileSystem.link}
276
- def FileSystem.link_sync(link, existing)
277
- @@j_fs.linkSync(link, existing)
278
- self
279
- end
280
-
281
- # Create a symbolic link, asynchronously.
282
- # @param [String] link Path of the link to create.
283
- # @param [String] existing Path of where the link points to.
284
- def FileSystem.symlink(link, existing, &block)
285
- @@j_fs.symlink(link, existing, ARWrappedHandler.new(block))
286
- self
287
- end
288
-
289
- # Synchronous version of {#FileSystem.symlink}
290
- def FileSystem.symlink_sync(link, existing)
291
- @@j_fs.symlinkSync(link, existing)
292
- self
293
- end
294
-
295
- # Unlink a hard link.
296
- # @param [String] link Path of the link to unlink.
297
- def FileSystem.unlink(link, &block)
298
- @@j_fs.unlink(link, ARWrappedHandler.new(block))
299
- self
300
- end
301
-
302
- # Synchronous version of {#FileSystem.unlink}
303
- def FileSystem.unlinkSync(link)
304
- @@j_fs.unlinkSync(link)
305
- self
306
- end
307
-
308
- # Read a symbolic link, asynchronously. I.e. tells you where the symbolic link points.
309
- # @param [String] link Path of the link to read.
310
- def FileSystem.read_symlink(link, &block)
311
- @@j_fs.readSymlink(link, ARWrappedHandler.new(block))
312
- self
313
- end
314
-
315
- # Synchronous version of {#FileSystem.read_symlink}
316
- def FileSystem.read_symlink_sync(link)
317
- @@j_fs.readSymlinkSync(link)
318
- end
319
-
320
- # Delete a file on the file system, asynchronously.
321
- # The delete will fail if the file does not exist, or is a directory and is not empty.
322
- # @param [String] path Path of the file to delete.
323
- def FileSystem.delete(path, &block)
324
- @@j_fs.delete(path, ARWrappedHandler.new(block))
325
- self
326
- end
327
-
328
- # Synchronous version of {#FileSystem.delete}
329
- def FileSystem.delete_sync(path)
330
- @@j_fs.deleteSync(path)
331
- self
332
- end
333
-
334
- # Delete a file on the file system recursively, asynchronously.
335
- # The delete will fail if the file does not exist. If the file is a directory the entire directory contents
336
- # will be deleted recursively.
337
- # @param [String] path Path of the file to delete.
338
- def FileSystem.delete_recursive(path, &block)
339
- @@j_fs.delete(path, true, ARWrappedHandler.new(block))
340
- self
341
- end
342
-
343
- # Synchronous version of {#FileSystem.delete_recursive}
344
- def FileSystem.delete_recursive_sync(path)
345
- @@j_fs.deleteSync(path, true)
346
- self
347
- end
348
-
349
- # Create a directory, asynchronously.
350
- # The create will fail if the directory already exists, or if it contains parent directories which do not already
351
- # exist.
352
- # @param [String] path Path of the directory to create.
353
- # @param [String] perms. A permission string of the form rwxr-x--- to give directory.
354
- def FileSystem.mkdir(path, perms = nil, &block)
355
- @@j_fs.mkdir(path, perms, ARWrappedHandler.new(block))
356
- self
357
- end
358
-
359
- # Synchronous version of {#FileSystem.mkdir}
360
- def FileSystem.mkdir_sync(path, perms = nil)
361
- @@j_fs.mkdirSync(path, perms)
362
- self
363
- end
364
-
365
- # Create a directory, and create all it's parent directories if they do not already exist, asynchronously.
366
- # The create will fail if the directory already exists.
367
- # @param [String] path Path of the directory to create.
368
- # @param [String] perms. A permission string of the form rwxr-x--- to give the created directory(ies).
369
- def FileSystem.mkdir_with_parents(path, perms = nil, &block)
370
- @@j_fs.mkdir(path, perms, true, ARWrappedHandler.new(block))
371
- self
372
- end
373
-
374
- # Synchronous version of {#FileSystem.mkdir_with_parents}
375
- def FileSystem.mkdir_with_parents_sync(path, perms = nil)
376
- @@j_fs.mkdirSync(path, perms, true)
377
- self
378
- end
379
-
380
- # Read a directory, i.e. list it's contents, asynchronously.
381
- # The read will fail if the directory does not exist.
382
- # @param [String] path Path of the directory to read.
383
- # @param [String] filter A regular expression to filter out the contents of the directory. If the filter is not nil
384
- # then only files which match the filter will be returned.
385
- def FileSystem.read_dir(path, filter = nil, &block)
386
- @@j_fs.readDir(path, filter, ARWrappedHandler.new(block))
387
- self
388
- end
389
-
390
- # Synchronous version of {#FileSystem.read_dir}
391
- def FileSystem.read_dir_sync(path, filter = nil)
392
- @@j_fs.readDirSync(path, filter)
393
- end
394
-
395
- # Read the contents of an entire file as a {Buffer}, asynchronously.
396
- # @param [String] path Path of the file to read.
397
- def FileSystem.read_file_as_buffer(path, &block)
398
- @@j_fs.readFile(path, ARWrappedHandler.new(block) { |j_buff| Buffer.new(j_buff)})
399
- self
400
- end
401
-
402
- # Synchronous version of {#FileSystem.read_file_as_buffer}
403
- def FileSystem.read_file_as_buffer_sync(path)
404
- @@j_fs.readFileSync(path)
405
- end
406
-
407
- # Write a [Buffer] as the entire contents of a file, asynchronously.
408
- # @param [String] path Path of the file to write.
409
- # @param [String] buffer The Buffer to write
410
- def FileSystem.write_buffer_to_file(path, buffer, &block)
411
- @@j_fs.writeFile(path, buffer, ARWrappedHandler.new(block))
412
- self
413
- end
414
-
415
- # Synchronous version of {#FileSystem.write_buffer_to_file}
416
- def FileSystem.write_buffer_to_file_sync(path, buffer)
417
- @@j_fs.writeFileSync(path, buffer)
418
- self
419
- end
420
-
421
- # Open a file on the file system, asynchronously.
422
- # @param [String] path Path of the file to open.
423
- # @param [String] perms If the file does not exist and create_new is true, then the file will be created with these permissions.
424
- # @param [Boolean] read Open the file for reading?
425
- # @param [Boolean] write Open the file for writing?
426
- # @param [Boolean] create_new Create the file if it doesn't already exist?
427
- # @param [Boolean] flush Whenever any data is written to the file, flush all changes to permanent storage immediately?
428
- def FileSystem.open(path, perms = nil, read = true, write = true, create_new = true, flush = false, &block)
429
- @@j_fs.open(path, perms, read, write, create_new, flush, ARWrappedHandler.new(block){ |j_file| AsyncFile.new(j_file)})
430
- self
431
- end
432
-
433
- # Synchronous version of {#FileSystem.open}
434
- def FileSystem.open_sync(path, perms = nil, read = true, write = true, create_new = true, flush = false)
435
- j_af = @@j_fs.open(path, perms, read, write, create_new, flush)
436
- AsyncFile.new(j_af)
437
- end
438
-
439
- # Create a new empty file, asynchronously.
440
- # @param [String] path Path of the file to create.
441
- # @param [String] perms The file will be created with these permissions.
442
- def FileSystem.create_file(path, perms = nil, &block)
443
- @@j_fs.createFile(path, perms, ARWrappedHandler.new(block))
444
- self
445
- end
446
-
447
- # Synchronous version of {#FileSystem.create_file}
448
- def FileSystem.create_file_sync(path, perms = nil)
449
- @@j_fs.createFileSync(path, perms)
450
- self
451
- end
452
-
453
- # Check if a file exists, asynchronously.
454
- # @param [String] path Path of the file to check.
455
- def FileSystem.exists?(path, &block)
456
- @@j_fs.exists(path, ARWrappedHandler.new(block))
457
- self
458
- end
459
-
460
- # Synchronous version of {#FileSystem.exists?}
461
- def FileSystem.exists_sync?(path)
462
- @@j_fs.existsSync(path)
463
- end
464
-
465
- # Get properties for the file system, asynchronously.
466
- # @param [String] path Path in the file system.
467
- def FileSystem.fs_props(path, &block)
468
- @@j_fs.fsProps(path, ARWrappedHandler.new(block) { |j_props| FSProps.new(j_props)})
469
- self
470
- end
471
-
472
- # Synchronous version of {#FileSystem.fs_props}
473
- def FileSystem.fs_props_sync(path)
474
- j_fsprops = @@j_fs.fsPropsSync(path)
475
- FSProps.new(j_fsprops)
476
- end
477
-
478
- end
479
- end