Class: Boogaloo::ServiceRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/boogaloo/service_request.rb

Overview

Handles server requests using threads from the thread pool.

Instance Method Summary collapse

Constructor Details

#initialize(obj, pool) ⇒ ServiceRequest

Initialize a new ServiceRequest instance.

Parameters:

obj

The service instance for which to handle the request.

pool

A reference to the thread pool.



14
15
16
17
18
19
# File 'lib/boogaloo/service_request.rb', line 14

def initialize(obj, pool)

    @obj = obj
    @pool = pool

end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *a, &b) ⇒ Object

Forward method calls to the service instance via a WorkerThread.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/boogaloo/service_request.rb', line 22

def method_missing(meth, *a, &b)

    (t_start = Time.now) if $debug
    worker = @pool.pop
    debug("Waited #{"%.5f" % (Time.now - t_start)} seconds for available WorkerThread") if $debug and not t_start.nil?
    worker.use_instance(@obj)
    ret = worker.perform(meth, *a)
    @pool.push worker
    
    raise ret if (ret.is_a?(NoMethodError) or ret.is_a?(TypeError))
    
    ret

end