Class: Synapse::Repository::PessimisticLockManager

Inherits:
LockManager
  • Object
show all
Defined in:
lib/synapse/repository/pessimistic_lock_manager.rb

Overview

Implementation of a lock manager that blocks until a lock can be obtained

Instance Method Summary collapse

Constructor Details

#initializePessimisticLockManager

Returns a new instance of PessimisticLockManager.



5
6
7
# File 'lib/synapse/repository/pessimistic_lock_manager.rb', line 5

def initialize
  @aggregates = IdentifierLock.new
end

Instance Method Details

#obtain_lock(aggregate_id) ⇒ undefined

Parameters:

  • aggregate_id (Object)

Returns:

  • (undefined)


17
18
19
# File 'lib/synapse/repository/pessimistic_lock_manager.rb', line 17

def obtain_lock(aggregate_id)
  @aggregates.obtain_lock aggregate_id
end

#release_lock(aggregate_id) ⇒ undefined

Parameters:

  • aggregate_id (Object)

Returns:

  • (undefined)


23
24
25
# File 'lib/synapse/repository/pessimistic_lock_manager.rb', line 23

def release_lock(aggregate_id)
  @aggregates.release_lock aggregate_id
end

#validate_lock(aggregate) ⇒ Boolean

Parameters:

  • aggregate (AggregateRoot)

Returns:

  • (Boolean)


11
12
13
# File 'lib/synapse/repository/pessimistic_lock_manager.rb', line 11

def validate_lock(aggregate)
  @aggregates.owned? aggregate.id
end