Class: Vertx::WorkerExecutor

Inherits:
Object
  • Object
show all
Includes:
Measured
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/worker_executor.rb

Overview

An executor for executing blocking code in Vert.x .

It provides the same executeBlocking operation than Context and Vertx but on a separate worker pool.

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/worker_executor.rb', line 23

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

+ (Object) j_api_type



32
33
34
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/worker_executor.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/worker_executor.rb', line 35

def self.j_class
  Java::IoVertxCore::WorkerExecutor.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/worker_executor.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/worker_executor.rb', line 26

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

Instance Method Details

- (void) close

This method returns an undefined value.

Close the executor.

Raises:

  • (ArgumentError)


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

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

- (void) execute_blocking(blockingCodeHandler = nil, ordered = nil) { ... }

This method returns an undefined value.

Safely execute some blocking code.

Executes the blocking code in the handler blockingCodeHandler using a thread from the worker pool.

When the code is complete the handler resultHandler will be called with the result on the original context (i.e. on the original event loop of the caller).

A Future instance is passed into blockingCodeHandler. When the blocking code successfully completes, the handler should call the Future#complete or Future#complete method, or the Future#fail method if it failed.

In the blockingCodeHandler the current context remains the original context and therefore any task scheduled in the blockingCodeHandler will be executed on the this context and not on the worker thread.

Parameters:

  • blockingCodeHandler (Proc) (defaults to: nil)
    handler representing the blocking code to run
  • ordered (true, false) (defaults to: nil)
    if true then if executeBlocking is called several times on the same context, the executions for that context will be executed serially, not in parallel. if false then they will be no ordering guarantees

Yields:

  • handler that will be called when the blocking code is complete

Raises:

  • (ArgumentError)


63
64
65
66
67
68
69
70
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/worker_executor.rb', line 63

def execute_blocking(blockingCodeHandler=nil,ordered=nil)
  if blockingCodeHandler.class == Proc && block_given? && ordered == nil
    return @j_del.java_method(:executeBlocking, [Java::IoVertxCore::Handler.java_class,Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| blockingCodeHandler.call(::Vertx::Util::Utils.safe_create(event,::Vertx::Future, nil)) }),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.from_object(ar.result) : nil) }))
  elsif blockingCodeHandler.class == Proc && (ordered.class == TrueClass || ordered.class == FalseClass) && block_given?
    return @j_del.java_method(:executeBlocking, [Java::IoVertxCore::Handler.java_class,Java::boolean.java_class,Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| blockingCodeHandler.call(::Vertx::Util::Utils.safe_create(event,::Vertx::Future, nil)) }),ordered,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.from_object(ar.result) : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling execute_blocking(#{blockingCodeHandler},#{ordered})"
end

- (true, false) metrics_enabled?

Whether the metrics are enabled for this measured object

Returns:

  • (true, false)
    true if metrics are enabled

Raises:

  • (ArgumentError)


40
41
42
43
44
45
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/worker_executor.rb', line 40

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