Class: VertxServiceDiscovery::ServiceReference

Inherits:
Object
  • Object
show all
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/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

Constant Summary

@@j_api_type =
Object.new

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)


23
24
25
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-service-discovery/service_reference.rb', line 23

def @@j_api_type.accept?(obj)
  obj.class == ServiceReference
end

+ (Object) j_api_type



32
33
34
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-service-discovery/service_reference.rb', line 32

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class



35
36
37
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-service-discovery/service_reference.rb', line 35

def self.j_class
  Java::IoVertxServicediscovery::ServiceReference.java_class
end

+ (Object) unwrap(obj)



29
30
31
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-service-discovery/service_reference.rb', line 29

def @@j_api_type.unwrap(obj)
  obj.j_del
end

+ (Object) wrap(obj)



26
27
28
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-service-discovery/service_reference.rb', line 26

def @@j_api_type.wrap(obj)
  ServiceReference.new(obj)
end

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


70
71
72
73
74
75
76
77
78
79
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-service-discovery/service_reference.rb', line 70

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

- (Object) cachedAs(x)

Gets the service object if already retrieved. It won't try to acquire the service object if not retrieved yet. Unlike #cached, this method return the warpped object to the desired (given) type.

Parameters:

  • x (Nil)
    the type of object

Returns:

  • (Object)
    the object, null if not yet retrieved


129
130
131
132
133
134
135
136
137
138
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-service-discovery/service_reference.rb', line 129

def cached_as(*args)
  if args[0].class == Class && !block_given?
    return ::Vertx::Util::Utils.v_type_of(args[0]).wrap(@j_del.java_method(:cachedAs, [Java::JavaLang::Class.java_class]).call(::Vertx::Util::Utils.j_class_of(args[0])))
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling cached_as(#{args[0]})"
  end
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. This method returns the Java version and primary facet of the object, use #get_as to retrieve the polyglot instance of the object or another facet..

Returns:

  • (Object)
    the object to access the service


85
86
87
88
89
90
91
92
93
94
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-service-discovery/service_reference.rb', line 85

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

- (Object) getAs(x)

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. This method wraps the service object into the desired type.

Parameters:

  • x (Nil)
    the type of object

Returns:

  • (Object)
    the object to access the service wrapped to the given type


43
44
45
46
47
48
49
50
51
52
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-service-discovery/service_reference.rb', line 43

def get_as(*args)
  if args[0].class == Class && !block_given?
    return ::Vertx::Util::Utils.v_type_of(args[0]).wrap(@j_del.java_method(:getAs, [Java::JavaLang::Class.java_class]).call(::Vertx::Util::Utils.j_class_of(args[0])))
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling get_as(#{args[0]})"
  end
end

- (true, false) isHolding(object)

Checks whether or not the service reference has the given service object.

Parameters:

  • object (Object)
    the service object, must not be null

Returns:

  • (true, false)
    true if the service reference service object is equal to the given object, false otherwise.


114
115
116
117
118
119
120
121
122
123
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-service-discovery/service_reference.rb', line 114

def holding?(*args)
  if ::Vertx::Util::unknown_type.accept?(args[0]) && !block_given?
    return @j_del.java_method(:isHolding, [Java::java.lang.Object.java_class]).call(::Vertx::Util::Utils.to_object(args[0]))
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling holding?(#{args[0]})"
  end
end

- (Hash{String => Object}) record

Returns the service record.

Returns:

  • (Hash{String => Object})
    the service record.


97
98
99
100
101
102
103
104
105
106
107
108
109
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-service-discovery/service_reference.rb', line 97

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
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling record()"
  end
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.


57
58
59
60
61
62
63
64
65
66
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-service-discovery/service_reference.rb', line 57

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