class Vertx::SharedData

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.

@author {tfox.org Tim Fox}

Public Class Methods

check_obj(obj) click to toggle source

Convert to corresponding Java objects And make copies where appropriate (the underlying java map will also make copies for some data types too) @private

# 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) click to toggle source

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. @param [String] key. Get the hash with the key. @return [Hash] the hash.

# 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) click to toggle source

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. @param [String] key. Get the set with the key. @return [SharedSet] the set.

# 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) click to toggle source

Remove the hash @param [String] key. The key of the hash.

# File lib/vertx/shared_data.rb, line 58
def SharedData.remove_hash(key)
  @@j_sd.removeMap(key)
end
remove_set(key) click to toggle source

Remove the set @param [String] key. The key of the set.

# File lib/vertx/shared_data.rb, line 64
def SharedData.remove_set(key)
  @@j_sd.removeSet(key)
end