Class: Optimizely::DefaultCmabService

Inherits:
Object
  • Object
show all
Defined in:
lib/optimizely/cmab/cmab_service.rb

Overview

Default CMAB service implementation

Constant Summary collapse

NUM_LOCK_STRIPES =

Initializes a new instance of the CmabService.

Raises:

  • (ArgumentError)

    If cmab_cache is not an instance of LRUCache.

  • (ArgumentError)

    If cmab_client is not an instance of DefaultCmabClient.

1000

Instance Method Summary collapse

Constructor Details

#initialize(cmab_cache, cmab_client, logger = nil) ⇒ DefaultCmabService

Returns a new instance of DefaultCmabService.



49
50
51
52
53
54
# File 'lib/optimizely/cmab/cmab_service.rb', line 49

def initialize(cmab_cache, cmab_client, logger = nil)
  @cmab_cache = cmab_cache
  @cmab_client = cmab_client
  @logger = logger || NoOpLogger.new
  @locks = Array.new(NUM_LOCK_STRIPES) { Mutex.new }
end

Instance Method Details

#get_decision(project_config, user_context, rule_id, options) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/optimizely/cmab/cmab_service.rb', line 56

def get_decision(project_config, user_context, rule_id, options)
  lock_index = get_lock_index(user_context.user_id, rule_id)

  @locks[lock_index].synchronize do
    get_decision_impl(project_config, user_context, rule_id, options)
  end
end