Class List Method List File List

# Class: VertxConsul::Watch

Inherits:
  Object
  - Object
  - VertxConsul::Watch
  show all
Defined in:
  /Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-consul/watch.rb

## Overview

Watches are a way of specifying a view of data (e.g. list of nodes, KV pairs, health checks) which is monitored for updates. When an update is detected, an `Handler` with `AsyncResult` is invoked. As an example, you could watch the status of health checks and notify when a check is critical.

## Class Method Summary (collapse)

- + (::VertxConsul::Watch) key(key = nil, vertx = nil, options = nil)
  Creates Watch to monitoring a specific key in the KV store.
- + (::VertxConsul::Watch) service(service = nil, vertx = nil, options = nil)
  Creates Watch to monitoring the nodes providing the service.
- + (::VertxConsul::Watch) services(vertx = nil, options = nil)
  Creates Watch to monitoring the list of available services.

## Instance Method Summary (collapse)

- - (self) set_handler { ... }
  Set the result handler.
- - (self) start
  Start this Watch.
- - (void) stop
  Stop the watch and release its resources.

## Class Method Details

### + (`::VertxConsul::Watch`) key(key = nil, vertx = nil, options = nil)

Creates `Watch` to monitoring a specific key in the KV store. This maps to the /v1/kv/<key> API internally.

Parameters:

- key (`String`) (defaults to: `nil`) —
  the key
- vertx (`::Vertx::Vertx`) (defaults to: `nil`) —
  the `Vertx` instance
- options (`Hash`) (defaults to: `nil`) —
  the options to create underlying Consul client

Returns:

- (`::VertxConsul::Watch`) —
  the `Watch` instance

Raises:

- (`ArgumentError`)

    26
    27
    28
    29
    30
    31
    32
    33
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-consul/watch.rb', line 26

    def self.key(key=nil,vertx=nil,options=nil)
      if key.class == String && vertx.class.method_defined?(:j_del) && !block_given? && options == nil
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtConsul::Watch.java_method(:key, [Java::java.lang.String.java_class,Java::IoVertxCore::Vertx.java_class]).call(key,vertx.j_del),::VertxConsul::Watch,::Vertx::Util::data_object_type(Java::IoVertxExtConsul::KeyValue))
      elsif key.class == String && vertx.class.method_defined?(:j_del) && options.class == Hash && !block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtConsul::Watch.java_method(:key, [Java::java.lang.String.java_class,Java::IoVertxCore::Vertx.java_class,Java::IoVertxExtConsul::ConsulClientOptions.java_class]).call(key,vertx.j_del,Java::IoVertxExtConsul::ConsulClientOptions.new(::Vertx::Util::Utils.to_json_object(options))),::VertxConsul::Watch,::Vertx::Util::data_object_type(Java::IoVertxExtConsul::KeyValue))
      end
      raise ArgumentError, "Invalid arguments when calling key(#{key},#{vertx},#{options})"
    end

### + (`::VertxConsul::Watch`) service(service = nil, vertx = nil, options = nil)

Creates `Watch` to monitoring the nodes providing the service. This maps to the /v1/health/service/<service> API internally.

Parameters:

- service (`String`) (defaults to: `nil`) —
  the service name
- vertx (`::Vertx::Vertx`) (defaults to: `nil`) —
  the `Vertx` instance
- options (`Hash`) (defaults to: `nil`) —
  the options to create underlying Consul client

Returns:

- (`::VertxConsul::Watch`) —
  the `Watch` instance

Raises:

- (`ArgumentError`)

    53
    54
    55
    56
    57
    58
    59
    60
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-consul/watch.rb', line 53

    def self.service(service=nil,vertx=nil,options=nil)
      if service.class == String && vertx.class.method_defined?(:j_del) && !block_given? && options == nil
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtConsul::Watch.java_method(:service, [Java::java.lang.String.java_class,Java::IoVertxCore::Vertx.java_class]).call(service,vertx.j_del),::VertxConsul::Watch,::Vertx::Util::data_object_type(Java::IoVertxExtConsul::ServiceEntryList))
      elsif service.class == String && vertx.class.method_defined?(:j_del) && options.class == Hash && !block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtConsul::Watch.java_method(:service, [Java::java.lang.String.java_class,Java::IoVertxCore::Vertx.java_class,Java::IoVertxExtConsul::ConsulClientOptions.java_class]).call(service,vertx.j_del,Java::IoVertxExtConsul::ConsulClientOptions.new(::Vertx::Util::Utils.to_json_object(options))),::VertxConsul::Watch,::Vertx::Util::data_object_type(Java::IoVertxExtConsul::ServiceEntryList))
      end
      raise ArgumentError, "Invalid arguments when calling service(#{service},#{vertx},#{options})"
    end

### + (`::VertxConsul::Watch`) services(vertx = nil, options = nil)

Creates `Watch` to monitoring the list of available services. This maps to the /v1/catalog/services API internally.

Parameters:

- vertx (`::Vertx::Vertx`) (defaults to: `nil`) —
  the `Vertx` instance
- options (`Hash`) (defaults to: `nil`) —
  the options to create underlying Consul client

Returns:

- (`::VertxConsul::Watch`) —
  the `Watch` instance

Raises:

- (`ArgumentError`)

    39
    40
    41
    42
    43
    44
    45
    46
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-consul/watch.rb', line 39

    def self.services(vertx=nil,options=nil)
      if vertx.class.method_defined?(:j_del) && !block_given? && options == nil
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtConsul::Watch.java_method(:services, [Java::IoVertxCore::Vertx.java_class]).call(vertx.j_del),::VertxConsul::Watch,::Vertx::Util::data_object_type(Java::IoVertxExtConsul::ServiceList))
      elsif vertx.class.method_defined?(:j_del) && options.class == Hash && !block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtConsul::Watch.java_method(:services, [Java::IoVertxCore::Vertx.java_class,Java::IoVertxExtConsul::ConsulClientOptions.java_class]).call(vertx.j_del,Java::IoVertxExtConsul::ConsulClientOptions.new(::Vertx::Util::Utils.to_json_object(options))),::VertxConsul::Watch,::Vertx::Util::data_object_type(Java::IoVertxExtConsul::ServiceList))
      end
      raise ArgumentError, "Invalid arguments when calling services(#{vertx},#{options})"
    end

## Instance Method Details

### - (`self`) set_handler { ... }

Set the result handler. As data is changed, the handler will be called with the result.

Yields:

- the result handler

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    64
    65
    66
    67
    68
    69
    70
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-consul/watch.rb', line 64

    def set_handler
      if block_given?
        @j_del.java_method(:setHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? @j_arg_T.wrap(ar.result) : nil) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling set_handler()"
    end

### - (`self`) start

Start this `Watch`

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    73
    74
    75
    76
    77
    78
    79
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-consul/watch.rb', line 73

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

### - (`void`) stop

This method returns an undefined value.

Stop the watch and release its resources

Raises:

- (`ArgumentError`)

    82
    83
    84
    85
    86
    87
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-consul/watch.rb', line 82

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