Class: Java::ComHazelcastClientProxy::ClientLockProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/hazelcast/client/lock.rb

Instance Method Summary collapse

Instance Method Details

#locking(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/hazelcast/client/lock.rb', line 10

def locking(options = {})
  raise 'Must provide a block' unless block_given?
  options = { :tries => 1, :timeout => 5, :unit => :seconds, :failed => false }.update options
  options[:unit] = java.util.concurrent.TimeUnit.const_get(options[:unit].to_s.upcase) if options[:unit].is_a? Symbol

  while options[:tries] > 0
    if try_lock(options[:timeout], options[:unit])
      options[:tries] = 0
      result          = yield
      unlock
      return result
    else
      options[:tries] -= 1
    end
  end
  options[:failed]
end

#unlocked?Boolean

lock() unlock()

Returns:

  • (Boolean)


6
7
8
# File 'lib/hazelcast/client/lock.rb', line 6

def unlocked?
  !locked?
end