Class: RubyVolt::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_volt/base.rb

Defined Under Namespace

Classes: AsyncCall

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ruby_volt/base.rb', line 31

def initialize(options = {})
  @login_protocol = options[:login_protocol]||
  @procedure_protocol = options[:procedure_protocol]||PROCEDURE_PROTOCOL
  @servicename = options[:servicename]||SERVICE_NAME
  @connect_timeout = options[:connect_timeout]||CONNECT_TIMEOUT # timeout (secs) or Nil for authentication (default=8)
  @procedure_timeout = options[:procedure_timeout]||PROCEDURE_TIMEOUT # timeout (secs) or Nil for procedure call (default=8)
  @requests_queue = Queue.new
  @connection_pool = configure_pool(options)
  # You can create the connection to any of the nodes in the database cluster and your stored procedure will be routed appropriately. In fact, you can create connections to multiple nodes on the server and your subsequent requests will be distributed to the various connections.
  @connection_pool.each do |connection|
    Thread.new do
      begin
        while async_call = @requests_queue.pop
          response_msg = connection.call_procedure(*async_call.args)
          async_call.accept_response(response_msg)
        end
      rescue ThreadError
      end
    end
  end
end

Instance Attribute Details

#connect_timeoutObject (readonly)

Returns the value of attribute connect_timeout.



29
30
31
# File 'lib/ruby_volt/base.rb', line 29

def connect_timeout
  @connect_timeout
end

#connection_poolObject (readonly)

Returns the value of attribute connection_pool.



29
30
31
# File 'lib/ruby_volt/base.rb', line 29

def connection_pool
  @connection_pool
end

#login_protocolObject (readonly)

Returns the value of attribute login_protocol.



29
30
31
# File 'lib/ruby_volt/base.rb', line 29

def 
  @login_protocol
end

#procedure_protocolObject (readonly)

Returns the value of attribute procedure_protocol.



29
30
31
# File 'lib/ruby_volt/base.rb', line 29

def procedure_protocol
  @procedure_protocol
end

#procedure_timeoutObject (readonly)

Returns the value of attribute procedure_timeout.



29
30
31
# File 'lib/ruby_volt/base.rb', line 29

def procedure_timeout
  @procedure_timeout
end

#requests_queueObject (readonly)

Returns the value of attribute requests_queue.



29
30
31
# File 'lib/ruby_volt/base.rb', line 29

def requests_queue
  @requests_queue
end

#servicenameObject (readonly)

Returns the value of attribute servicename.



29
30
31
# File 'lib/ruby_volt/base.rb', line 29

def servicename
  @servicename
end

Instance Method Details

#async_call_procedure(procedure, *parameters) ⇒ Object



53
54
55
56
57
# File 'lib/ruby_volt/base.rb', line 53

def async_call_procedure(procedure, *parameters)
  AsyncCall.new(procedure, *parameters).tap do |async_call|
    @requests_queue.push(async_call)
  end
end

#benchmark(cycle = 1000) ⇒ Object



67
68
69
# File 'lib/ruby_volt/base.rb', line 67

def benchmark(cycle = 1000)
  Helper.benchmark(cycle) {ping} # call @Ping - system stored procedure & dispatch
end

#call_procedure(*args, &block) ⇒ Object



59
60
61
# File 'lib/ruby_volt/base.rb', line 59

def call_procedure(*args, &block)
  async_call_procedure(*args).dispatch(&block)
end

#pingObject



63
64
65
# File 'lib/ruby_volt/base.rb', line 63

def ping
  call_procedure("@Ping")
end