Class List Method List File List

# Class: Vertx::SharedData

Inherits:
  Object
  - Object
  - Vertx::SharedData
  show all
Defined in:
  src/main/ruby_scripts/core/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 instances of shareddata 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 shareddata 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:

- Tim Fox

## Constant Summary

@@j_sd =

      org.vertx.java.deploy.impl.VertxLocator.vertx.sharedData()

## Class Method Summary (collapse)

- + (Hash) get_hash(key)
  Return a Hash with the specific name.
- + (SharedSet) get_set(key)
  Return a Set with the specific name.
- + (Object) remove_hash(key)
  Remove the hash.
- + (Object) remove_set(key)
  Remove the set.

## Instance Method Summary (collapse)

- - (Object) ==(other)
- - (Object) _to_java_map

## Class Method Details

### + (`Hash`) get_hash(key)

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.

Parameters:

- key. (`String`) —
  Get the hash with the key.

Returns:

- (`Hash`) —
  the hash.

    42
    43
    44
    45

    # File 'src/main/ruby_scripts/core/shared_data.rb', line 42

    def SharedData.get_hash(key)
      map = @@j_sd.getMap(key)
      SharedHash.new(map)
    end

### + (`SharedSet`) get_set(key)

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.

Parameters:

- key. (`String`) —
  Get the set with the key.

Returns:

- (`SharedSet`) —
  the set.

    51
    52
    53
    54

    # File 'src/main/ruby_scripts/core/shared_data.rb', line 51

    def SharedData.get_set(key)
      set = @@j_sd.getSet(key)
      SharedSet.new(set)
    end

### + (`Object`) remove_hash(key)

Remove the hash

Parameters:

- key. (`String`) —
  The key of the hash.

    58
    59
    60

    # File 'src/main/ruby_scripts/core/shared_data.rb', line 58

    def SharedData.remove_hash(key)
      @@j_sd.removeMap(key)
    end

### + (`Object`) remove_set(key)

Remove the set

Parameters:

- key. (`String`) —
  The key of the set.

    64
    65
    66

    # File 'src/main/ruby_scripts/core/shared_data.rb', line 64

    def SharedData.remove_set(key)
      @@j_sd.removeSet(key)
    end

## Instance Method Details

### - (`Object`) ==(other)

    102
    103
    104
    105
    106
    107
    108

    # File 'src/main/ruby_scripts/core/shared_data.rb', line 102

    def ==(other)
      if other.is_a?(SharedHash)
        @hash.equal?(other._to_java_map)
      else
        false
      end
    end

### - (`Object`) _to_java_map

    110
    111
    112

    # File 'src/main/ruby_scripts/core/shared_data.rb', line 110

    def _to_java_map
      @hash
    end