Class: WorkflowRb::SingleNodeLockProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/workflow_rb/services/single_node_lock_provider.rb

Instance Method Summary collapse

Constructor Details

#initializeSingleNodeLockProvider

Returns a new instance of SingleNodeLockProvider.



6
7
8
9
# File 'lib/workflow_rb/services/single_node_lock_provider.rb', line 6

def initialize
  @semaphore = Mutex.new
  @named_locks = []
end

Instance Method Details

#acquire_lock(id) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/workflow_rb/services/single_node_lock_provider.rb', line 11

def acquire_lock(id)
  @semaphore.synchronize do
    if @named_locks.include?(id)
      return false
    end
    @named_locks << id
    return true
  end
end

#release_lock(id) ⇒ Object



21
22
23
24
25
# File 'lib/workflow_rb/services/single_node_lock_provider.rb', line 21

def release_lock(id)
  @semaphore.synchronize do
    @named_locks.delete(id)
  end
end