Class: Vertx::SharedData
- Inherits:
-
Object
- Object
- Vertx::SharedData
- Defined in:
- lib/vertx/shared_data.rb
Overview
Sometimes it is desirable to share immutable data between different event loops, for example to implement a cache of data.
This class allows data structures to be looked up and used from different event loops. The data structures themselves will only allow certain data types to be stored into them. This shields the user from worrying about any thread safety issues might occur if mutable objects were shared between event loops.
The following types can be stored in a shareddata data structure:
String
FixNum
Float
{Buffer} this will be automatically copied, and the copy will be stored in the structure.
Defined Under Namespace
Classes: SharedHash, SharedSet
Constant Summary collapse
- @@j_sd =
org.jruby.jubilee.vertx.JubileeVertx.vertx().sharedData()
Class Method Summary collapse
-
.check_obj(obj) ⇒ Object
Convert to corresponding Java objects And make copies where appropriate (the underlying java map will also make copies for some data types too).
-
.get_hash(key) ⇒ Hash
Return a Hash with the specific name.
-
.get_set(key) ⇒ SharedSet
Return a Set with the specific name.
-
.remove_hash(key) ⇒ Object
Remove the hash.
-
.remove_set(key) ⇒ Object
Remove the set.
Class Method Details
.check_obj(obj) ⇒ Object
Convert to corresponding Java objects And make copies where appropriate (the underlying java map will also make copies for some data types too)
71 72 73 74 75 76 |
# File 'lib/vertx/shared_data.rb', line 71 def SharedData.check_obj(obj) if obj.is_a?(Buffer) obj = obj._to_java_buffer end obj end |
.get_hash(key) ⇒ Hash
Return a Hash with the specific name. All invocations of this method with the same value of name are guaranteed to return the same Hash instance.
42 43 44 45 |
# File 'lib/vertx/shared_data.rb', line 42 def SharedData.get_hash(key) map = @@j_sd.getMap(key) SharedHash.new(map) end |
.get_set(key) ⇒ SharedSet
Return a Set with the specific name. All invocations of this method with the same value of name are guaranteed to return the same Set instance.
51 52 53 54 |
# File 'lib/vertx/shared_data.rb', line 51 def SharedData.get_set(key) set = @@j_sd.getSet(key) SharedSet.new(set) end |
.remove_hash(key) ⇒ Object
Remove the hash
58 59 60 |
# File 'lib/vertx/shared_data.rb', line 58 def SharedData.remove_hash(key) @@j_sd.removeMap(key) end |
.remove_set(key) ⇒ Object
Remove the set
64 65 66 |
# File 'lib/vertx/shared_data.rb', line 64 def SharedData.remove_set(key) @@j_sd.removeSet(key) end |