Class: Sunspot::SessionProxy::ThreadLocalSessionProxy
- Inherits:
-
AbstractSessionProxy
- Object
- AbstractSessionProxy
- Sunspot::SessionProxy::ThreadLocalSessionProxy
- Defined in:
- sunspot/lib/sunspot/session_proxy/thread_local_session_proxy.rb
Overview
This class implements a session proxy that creates a different Session object for each thread. Any multithreaded application should use this proxy.
Constant Summary
- FINALIZER =
Proc.new do |object_id| Thread.current[:sunspot_session_#{object_id}"] = nil end
- @@next_id =
0
Instance Attribute Summary (collapse)
-
- (Object) config
readonly
The configuration with which the thread-local sessions are initialized.
Instance Method Summary (collapse)
-
- (ThreadLocalSessionProxy) initialize(config = Sunspot::Configuration.new)
constructor
Optionally pass an existing Sunspot::Configuration object.
-
- (Object) session
:nodoc:.
Methods inherited from AbstractSessionProxy
Constructor Details
- (ThreadLocalSessionProxy) initialize(config = Sunspot::Configuration.new)
Optionally pass an existing Sunspot::Configuration object. If none is passed, a default configuration is used; it can then be modified using the #config attribute.
27 28 29 30 |
# File 'sunspot/lib/sunspot/session_proxy/thread_local_session_proxy.rb', line 27 def initialize(config = Sunspot::Configuration.new) @config = config ObjectSpace.define_finalizer(self, FINALIZER) end |
Instance Attribute Details
- (Object) config (readonly)
The configuration with which the thread-local sessions are initialized.
17 18 19 |
# File 'sunspot/lib/sunspot/session_proxy/thread_local_session_proxy.rb', line 17 def config @config end |
Instance Method Details
- (Object) session
:nodoc:
32 33 34 |
# File 'sunspot/lib/sunspot/session_proxy/thread_local_session_proxy.rb', line 32 def session #:nodoc: Thread.current[:sunspot_session_#{object_id}"] ||= Session.new(config) end |