Class: Sunspot::SessionProxy::MasterSlaveSessionProxy

Inherits:
AbstractSessionProxy show all
Defined in:
sunspot/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

- (MasterSlaveSessionProxy) initialize(master_session, slave_session)

A new instance of MasterSlaveSessionProxy



26
27
28
# File 'sunspot/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

- (Object) master_session (readonly)

The session that connects to the master Solr instance.



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

def master_session
  @master_session
end

- (Object) slave_session (readonly)

The session that connects to the slave Solr instance.



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

def slave_session
  @slave_session
end

Instance Method Details

- (Object) config(delegate = :master)

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 'sunspot/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