Module: Vertx

Defined in:
src/main/api_shim/core/timers.rb,
src/main/api_shim/core/net.rb,
src/main/api_shim/container.rb,
src/main/api_shim/core/http.rb,
src/main/api_shim/core/buffer.rb,
src/main/api_shim/core/streams.rb,
src/main/api_shim/core/sock_js.rb,
src/main/api_shim/core/event_bus.rb,
src/main/api_shim/core/parsetools.rb,
src/main/api_shim/core/tcp_support.rb,
src/main/api_shim/core/shared_data.rb,
src/main/api_shim/core/ssl_support.rb,
src/main/api_shim/core/file_system.rb,
src/main/api_shim/core/wrapped_handler.rb

Overview

Copyright 2011-2012 the original author or authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Defined Under Namespace

Modules: ClientSSLSupport, ReadStream, SSLSupport, ServerSSLSupport, ServerTCPSupport, TCPSupport, WriteStream Classes: AsyncFile, Buffer, Context, EventBus, FSProps, FileProps, FileSystem, HttpClient, HttpClientRequest, HttpClientResponse, HttpServer, HttpServerFileUpload, HttpServerRequest, HttpServerResponse, Message, MultiMap, NetClient, NetServer, NetSocket, Pump, RecordParser, RouteMatcher, ServerWebSocket, SharedData, SockJSServer, SockJSSocket, WebSocket

Constant Summary

@@j_vertx =
org.vertx.java.platform.impl.JRubyVerticleFactory.vertx()

Class Method Summary (collapse)

Class Method Details

+ (Boolean) cancel_timer(id)

Cancels a timer.

Parameters:

Returns:

  • (Boolean)
    true if the timer was cancelled, false if it wasn't found.


44
45
46
# File 'src/main/api_shim/core/timers.rb', line 44

def Vertx.cancel_timer(id)
  @@j_vertx.cancelTimer(id)
end

+ (Hash) config

Get config for the verticle

Returns:

  • (Hash)
    The JSON config for the verticle


99
100
101
102
103
104
105
# File 'src/main/api_shim/container.rb', line 99

def Vertx.config
  if !defined? @@j_conf
    @@j_conf = org.vertx.java.platform.impl.JRubyVerticleFactory.container.config
    @@j_conf = JSON.parse(@@j_conf.encode) if @@j_conf
  end
  @@j_conf
end

+ (Object) current_context

Get a reference to the current context


58
59
60
# File 'src/main/api_shim/core/timers.rb', line 58

def Vertx.current_context
  Context.new(@@j_vertx.currentContext())
end

+ (Object) deploy_module(module_name, config = nil, instances = 1, &block)

Deploy a module. The actual deploy happens asynchronously the block will be an exception or nil if no failure occurred, the second parameter will be the deployment id

Parameters:

  • module_name (String)
    The name of the module to deploy
  • config (Hash) (defaults to: nil)
    JSON configuration for the module
  • instances (FixNum) (defaults to: 1)
    Number of instances to deploy
  • block (Block)
    Block will be executed when deploy has completed - the first parameter passed to


59
60
61
62
63
64
65
66
67
68
# File 'src/main/api_shim/container.rb', line 59

def Vertx.deploy_module(module_name, config = nil, instances = 1, &block)
  if config
    json_str = JSON.generate(config)
    config = org.vertx.java.core.json.JsonObject.new(json_str)
  end
  if block
    block = ARWrappedHandler.new(block)
  end
  org.vertx.java.platform.impl.JRubyVerticleFactory.container.deployModule(module_name, config, instances, block)
end

+ (Object) deploy_verticle(main, config = nil, instances = 1, &block)

Deploy a verticle. The actual deploy happens asynchronously the block will be an exception or nil if no failure occurred, the second parameter will be the deployment id

Parameters:

  • main (String)
    The main of the verticle to deploy
  • config (Hash) (defaults to: nil)
    JSON configuration for the verticle
  • instances (FixNum) (defaults to: 1)
    Number of instances to deploy
  • block (Block)
    Block will be executed when deploy has completed - the first parameter passed to


25
26
27
28
29
30
31
32
33
34
# File 'src/main/api_shim/container.rb', line 25

def Vertx.deploy_verticle(main, config = nil, instances = 1, &block)
  if config
    json_str = JSON.generate(config)
    config = org.vertx.java.core.json.JsonObject.new(json_str)
  end
  if block
    block = ARWrappedHandler.new(block)
  end
  org.vertx.java.platform.impl.JRubyVerticleFactory.container.deployVerticle(main, config, instances, block)
end

+ (Object) deploy_worker_verticle(main, config = nil, instances = 1, multi_threaded = false, &block)

Deploy a worker verticle. The actual deploy happens asynchronously the block will be an exception or nil if no failure occurred, the second parameter will be the deployment id

Parameters:

  • main (String)
    The main of the verticle to deploy
  • config (Hash) (defaults to: nil)
    JSON configuration for the verticle
  • instances (FixNum) (defaults to: 1)
    Number of instances to deploy
  • block (Block)
    Block will be executed when deploy has completed - the first parameter passed to


42
43
44
45
46
47
48
49
50
51
# File 'src/main/api_shim/container.rb', line 42

def Vertx.deploy_worker_verticle(main, config = nil, instances = 1, multi_threaded = false, &block)
  if config
    json_str = JSON.generate(config)
    config = org.vertx.java.core.json.JsonObject.new(json_str)
  end
  if block
    block = ARWrappedHandler.new(block)
  end
  org.vertx.java.platform.impl.JRubyVerticleFactory.container.deployWorkerVerticle(main, config, instances, multi_threaded, block)
end

+ (Hash) env

Get the environment for the verticle

Returns:

  • (Hash)
    Get the environment for the verticle


108
109
110
# File 'src/main/api_shim/container.rb', line 108

def Vertx.env
  org.vertx.java.platform.impl.JRubyVerticleFactory.container.env
end

+ (Object) exit

Cause the container to exit


93
94
95
# File 'src/main/api_shim/container.rb', line 93

def Vertx.exit
  org.vertx.java.platform.impl.JRubyVerticleFactory.container.exit
end

+ (Logger) logger

Get the logger for the verticle

Returns:

  • (Logger)
    Get the logger for the verticle


113
114
115
# File 'src/main/api_shim/container.rb', line 113

def Vertx.logger
  org.vertx.java.platform.impl.JRubyVerticleFactory.container.logger
end

+ (Object) run_on_context(proc = nil, &hndlr)

Put the handler on the event queue for this loop so it will be run asynchronously ASAP after this event has been processed

Parameters:

  • proc (Proc) (defaults to: nil)
    a proc representing the code that will be run ASAP
  • hndlr (Block)
    a block representing the code that will be run ASAP


52
53
54
55
# File 'src/main/api_shim/core/timers.rb', line 52

def Vertx.run_on_context(proc = nil, &hndlr)
  hndlr = proc if proc
  @@j_vertx.runOnContext(hndlr)
end

+ (FixNum) set_periodic(delay, proc = nil, &hndlr)

Sets a periodic timer. This method will accept either a Proc or a block.

Parameters:

  • delay (FixNum)
    the period of the timer, in milliseconds
  • proc (Proc) (defaults to: nil)
    a proc representing the code that will be run when the timer fires
  • hndlr (Block)
    a block representing the code that will be when the timer fires

Returns:

  • (FixNum)
    the unique id of the timer


36
37
38
39
# File 'src/main/api_shim/core/timers.rb', line 36

def Vertx.set_periodic(delay, proc = nil, &hndlr)
  hndlr = proc if proc
  @@j_vertx.setPeriodic(delay, hndlr)
end

+ (FixNum) set_timer(delay, proc = nil, &hndlr)

Sets a one-shot timer that will fire after a certain delay. This method will accept either a Proc or a block.

Parameters:

  • delay (FixNum)
    the delay, in milliseconds
  • proc (Proc) (defaults to: nil)
    a proc representing the code that will be run after the delay
  • hndlr (Block)
    a block representing the code that will be run after the delay

Returns:

  • (FixNum)
    the unique id of the timer


25
26
27
28
# File 'src/main/api_shim/core/timers.rb', line 25

def Vertx.set_timer(delay, proc = nil, &hndlr)
  hndlr = proc if proc
  @@j_vertx.setTimer(delay, hndlr)
end

+ (Object) undeploy_module(id, &block)

Undeploy a module as the first parameter if undeploy failed

Parameters:

  • id (String)
    The deployment id
  • block (Block)
    Block will be executed when undeploy has completed, an exception will be passed to the block


85
86
87
88
89
90
# File 'src/main/api_shim/container.rb', line 85

def Vertx.undeploy_module(id, &block)
  if block
    block = ARWrappedHandler.new(block)
  end
  org.vertx.java.platform.impl.JRubyVerticleFactory.container.undeployModule(id, block)
end

+ (Object) undeploy_verticle(id, &block)

Undeploy a verticle as the first parameter if undeploy failed

Parameters:

  • id (String)
    The deployment id - the undeploy happens asynchronously
  • block (Block)
    Block will be executed when undeploy has completed, an exception will be passed to the block


74
75
76
77
78
79
# File 'src/main/api_shim/container.rb', line 74

def Vertx.undeploy_verticle(id, &block)
  if block
    block = ARWrappedHandler.new(block)
  end
  org.vertx.java.platform.impl.JRubyVerticleFactory.container.undeployVerticle(id, block)
end