Class: Riak::Client::Pool::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/riak/client/pool.rb

Overview

An element of the pool. Comprises an object with an owning thread.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Element) initialize(object)

A new instance of Element



19
20
21
22
# File 'lib/riak/client/pool.rb', line 19

def initialize(object)
  @object = object
  @owner = owner
end

Instance Attribute Details

- (Object) object

Returns the value of attribute object



17
18
19
# File 'lib/riak/client/pool.rb', line 17

def object
  @object
end

- (Object) owner

Returns the value of attribute owner



18
19
20
# File 'lib/riak/client/pool.rb', line 18

def owner
  @owner
end

Instance Method Details

- (Object) lock

Claims this element of the pool for the current Thread.



25
26
27
# File 'lib/riak/client/pool.rb', line 25

def lock
  self.owner = Thread.current
end

- (Boolean) locked?

Is this element locked/claimed?

Returns:

  • (Boolean)


30
31
32
# File 'lib/riak/client/pool.rb', line 30

def locked?
  not owner.nil?
end

- (Object) unlock

Releases this element of the pool from the current Thread.



35
36
37
# File 'lib/riak/client/pool.rb', line 35

def unlock
  self.owner = nil
end

- (Boolean) unlocked?

Is this element available for use?

Returns:

  • (Boolean)


40
41
42
# File 'lib/riak/client/pool.rb', line 40

def unlocked?
  owner.nil?
end