Class: Sunspot::SessionProxy::MasterSlaveSessionProxy

Inherits:
AbstractSessionProxy show all
Defined in:
lib/sunspot/session_proxy/master_slave_session_proxy.rb

Overview

This session proxy implementation allows Sunspot to be used with a master/slave Solr deployment. All write methods are delegated to a master session, and read methods are delegated to a slave session.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractSessionProxy

delegate, not_supported

Constructor Details

#initialize(master_session, slave_session) ⇒ MasterSlaveSessionProxy

Returns a new instance of MasterSlaveSessionProxy.



26
27
28
# File 'lib/sunspot/session_proxy/master_slave_session_proxy.rb', line 26

def initialize(master_session, slave_session)
  @master_session, @slave_session = master_session, slave_session
end

Instance Attribute Details

#master_sessionObject (readonly)

The session that connects to the master Solr instance.



14
15
16
# File 'lib/sunspot/session_proxy/master_slave_session_proxy.rb', line 14

def master_session
  @master_session
end

#slave_sessionObject (readonly)

The session that connects to the slave Solr instance.



18
19
20
# File 'lib/sunspot/session_proxy/master_slave_session_proxy.rb', line 18

def slave_session
  @slave_session
end

Instance Method Details

#config(delegate = :master) ⇒ Object

By default, return the configuration for the master session. If the delegate param is :slave, then return config for the slave session.



34
35
36
37
38
39
40
# File 'lib/sunspot/session_proxy/master_slave_session_proxy.rb', line 34

def config(delegate = :master)
  case delegate
  when :master then @master_session.config
  when :slave then  @slave_session.config
  else raise(ArgumentError, "Expected :master or :slave")
  end
end