Class: Agent::Pop
- Inherits:
-
Object
- Object
- Agent::Pop
- Defined in:
- lib/agent/pop.rb
Instance Attribute Summary collapse
-
#blocking_once ⇒ Object
readonly
Returns the value of attribute blocking_once.
-
#notifier ⇒ Object
readonly
Returns the value of attribute notifier.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(options = {}) ⇒ Pop
constructor
A new instance of Pop.
- #received? ⇒ Boolean
- #send ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Pop
Returns a new instance of Pop.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/agent/pop.rb', line 7 def initialize(={}) @object = nil @uuid = [:uuid] || UUID.generate @blocking_once = [:blocking_once] @notifier = [:notifier] @mutex = Mutex.new @cvar = ConditionVariable.new @received = false @closed = false end |
Instance Attribute Details
#blocking_once ⇒ Object (readonly)
Returns the value of attribute blocking_once.
5 6 7 |
# File 'lib/agent/pop.rb', line 5 def blocking_once @blocking_once end |
#notifier ⇒ Object (readonly)
Returns the value of attribute notifier.
5 6 7 |
# File 'lib/agent/pop.rb', line 5 def notifier @notifier end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
5 6 7 |
# File 'lib/agent/pop.rb', line 5 def object @object end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
5 6 7 |
# File 'lib/agent/pop.rb', line 5 def uuid @uuid end |
Instance Method Details
#close ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/agent/pop.rb', line 59 def close @mutex.synchronize do return if @received @closed = true @cvar.broadcast @notifier.notify(self) if @notifier end end |
#closed? ⇒ Boolean
22 23 24 |
# File 'lib/agent/pop.rb', line 22 def closed? @closed end |
#received? ⇒ Boolean
18 19 20 |
# File 'lib/agent/pop.rb', line 18 def received? @received end |
#send ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/agent/pop.rb', line 36 def send @mutex.synchronize do if @blocking_once _, error = @blocking_once.perform do @object = yield unless @closed @received = true @cvar.signal @notifier.notify(self) if @notifier end return error else begin @object = yield unless @closed @received = true @cvar.signal @notifier.notify(self) if @notifier rescue Errors::Rollback end end end end |
#wait ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/agent/pop.rb', line 26 def wait @mutex.synchronize do until @received || @closed @cvar.wait(@mutex) end return false if @closed received? end end |