Class List Method List File List

# Class: VertxServiceDiscovery::ServiceReference

Inherits:
  Object
  - Object
  - VertxServiceDiscovery::ServiceReference
  show all
Defined in:
  /Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_reference.rb

## Overview

Once a consumer has chosen a service, it builds a ServiceReference managing the binding with the chosen service provider.

The reference lets the consumer: * access the service (via a proxy or a client) with the #get method * release the reference - so the binding between the consumer and the provider is removed

## Instance Method Summary (collapse)

- - (Object) cached
  Gets the service object if already retrieved.
- - (Object) get
  Gets the object to access the service.
- - (Hash) record
  @return the service record.
- - (void) release
  Releases the reference.

## Instance Method Details

### - (`Object`) cached

Gets the service object if already retrieved. It won't try to acquire the service object if not retrieved yet.

Returns:

- (`Object`) —
  the object, `null` if not yet retrieved

Raises:

- (`ArgumentError`)

    43
    44
    45
    46
    47
    48
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_reference.rb', line 43

    def cached
      if !block_given?
        return ::Vertx::Util::Utils.from_object(@j_del.java_method(:cached, []).call())
      end
      raise ArgumentError, "Invalid arguments when calling cached()"
    end

### - (`Object`) get

Gets the object to access the service. It can be a proxy, a client or whatever object. The type depends on the service type and the server itself.

Returns:

- (`Object`) —
  the object to access the service

Raises:

- (`ArgumentError`)

    35
    36
    37
    38
    39
    40
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_reference.rb', line 35

    def get
      if !block_given?
        return ::Vertx::Util::Utils.from_object(@j_del.java_method(:get, []).call())
      end
      raise ArgumentError, "Invalid arguments when calling get()"
    end

### - (`Hash`) record

@return the service record.

Returns:

- (`Hash`)

Raises:

- (`ArgumentError`)

    23
    24
    25
    26
    27
    28
    29
    30
    31
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_reference.rb', line 23

    def record
      if !block_given?
        if @cached_record != nil
          return @cached_record
        end
        return @cached_record = @j_del.java_method(:record, []).call() != nil ? JSON.parse(@j_del.java_method(:record, []).call().toJson.encode) : nil
      end
      raise ArgumentError, "Invalid arguments when calling record()"
    end

### - (`void`) release

This method returns an undefined value.

Releases the reference. Once released, the consumer must not use the reference anymore. This method must be idempotent and defensive, as multiple call may happen.

Raises:

- (`ArgumentError`)

    52
    53
    54
    55
    56
    57
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_reference.rb', line 52

    def release
      if !block_given?
        return @j_del.java_method(:release, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling release()"
    end