Class: Copland::ServiceModel::ThreadedServiceModel

Inherits:
AbstractServiceModel show all
Defined in:
lib/copland/models/threaded.rb

Overview

The threaded service model is much like the singleton service model, except it has one instance of the service point per thread.

Instance Attribute Summary

Attributes inherited from AbstractServiceModel

#service_point

Instance Method Summary collapse

Methods inherited from AbstractServiceModel

#initialize, register_as

Constructor Details

This class inherits a constructor from Copland::ServiceModel::AbstractServiceModel

Instance Method Details

#instance(&init) ⇒ Object

Return the current thread’s instance of the service point. If no such instance exists, instantiate one.



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/copland/models/threaded.rb', line 46

def instance( &init )
  Thread.current[ :threaded_services ] ||= Hash.new
  service =
    Thread.current[ :threaded_services ][ @service_point.full_name ]

  unless service
    service = Proxy.new( @service_point, &init ) 
    Thread.current[ :threaded_services ][ @service_point.full_name ] =
      service
  end

  return service
end