Class: VertxConsul::Watch

Inherits:
Object
  • Object
show all
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/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 WatchResult is invoked. All errors, except java.util.concurrent.TimeoutException, will be handled, with resubscribing with a progressive delay. All timeout errors will be ignored, with resubscribing without any delay. As an example, you could watch the status of health checks and notify when a check is critical.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (::VertxConsul::Watch) events(event = nil, vertx = nil, options = nil)

Creates Watch to monitoring the custom user events. This maps to the /v1/event/list API internally.

Parameters:

  • event (String) (defaults to: nil)
    the event name
  • vertx (::Vertx::Vertx) (defaults to: nil)
    the Vertx instance
  • options (Hash) (defaults to: nil)
    the options to create underlying Consul client

Returns:

Raises:

  • (ArgumentError)

85
86
87
88
89
90
91
92
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-consul/watch.rb', line 85

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

+ (::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/ 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:

Raises:

  • (ArgumentError)

29
30
31
32
33
34
35
36
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-consul/watch.rb', line 29

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) key_prefix(keyPrefix = nil, vertx = nil, options = nil)

Creates Watch to monitoring a prefix of keys in the KV store. This maps to the /v1/kv/ API internally.

Parameters:

  • keyPrefix (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:

Raises:

  • (ArgumentError)

43
44
45
46
47
48
49
50
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-consul/watch.rb', line 43

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

+ (::VertxConsul::Watch) nodes(vertx = nil, options = nil)

Creates Watch to monitoring the list of available nodes. This maps to the /v1/catalog/nodes 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:

Raises:

  • (ArgumentError)

98
99
100
101
102
103
104
105
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-consul/watch.rb', line 98

def self.nodes(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(:nodes, [Java::IoVertxCore::Vertx.java_class]).call(vertx.j_del),::VertxConsul::Watch,::Vertx::Util::data_object_type(Java::IoVertxExtConsul::NodeList))
  elsif vertx.class.method_defined?(:j_del) && options.class == Hash && !block_given?
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtConsul::Watch.java_method(:nodes, [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::NodeList))
  end
  raise ArgumentError, "Invalid arguments when calling nodes(#{vertx},#{options})"
end

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

Creates Watch to monitoring the nodes providing the service. Nodes will be sorted by distance from the consul agent. 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:

Raises:

  • (ArgumentError)

71
72
73
74
75
76
77
78
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-consul/watch.rb', line 71

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:

Raises:

  • (ArgumentError)

56
57
58
59
60
61
62
63
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-consul/watch.rb', line 56

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)

109
110
111
112
113
114
115
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-consul/watch.rb', line 109

def set_handler
  if block_given?
    @j_del.java_method(:setHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::VertxConsul::WatchResult, nil)) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_handler()"
end

- (self) start

Start this Watch

Returns:

  • (self)

Raises:

  • (ArgumentError)

118
119
120
121
122
123
124
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-consul/watch.rb', line 118

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)

127
128
129
130
131
132
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-consul/watch.rb', line 127

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