Class: Concurrent::JavaExchanger
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
Concurrent::AbstractExchanger
|
Defined in: | lib/concurrent-ruby/concurrent/exchanger.rb |
Overview
**Private Implementation:** This abstraction is a private, internal implementation detail. It should never be used directly.
Constant Summary
AbstractExchanger
- Inherited
Class Attribute Summary
Synchronization::Object
- Inherited
Class Method Summary
- .new ⇒ JavaExchanger constructor
AbstractExchanger
- Inherited
Synchronization::Object
- Inherited
.atomic_attribute?, .atomic_attributes, | |
.attr_atomic | Creates methods for reading and writing to a instance variable with volatile (Java) semantic as |
.attr_volatile | Creates methods for reading and writing (as |
.ensure_safe_initialization_when_final_fields_are_present | For testing purposes, quite slow. |
.new | Has to be called by children. |
.safe_initialization!, .define_initialize_atomic_fields |
Synchronization::AbstractObject
- Inherited
Instance Method Summary
-
#do_exchange(value, timeout) ⇒ Object, CANCEL
private
Waits for another thread to arrive at this exchange point (unless the current thread is interrupted), and then transfers the given object to it, receiving its object in return.
AbstractExchanger
- Inherited
#exchange | Waits for another thread to arrive at this exchange point (unless the current thread is interrupted), and then transfers the given object to it, receiving its object in return. |
#exchange! | Waits for another thread to arrive at this exchange point (unless the current thread is interrupted), and then transfers the given object to it, receiving its object in return. |
#try_exchange | Waits for another thread to arrive at this exchange point (unless the current thread is interrupted), and then transfers the given object to it, receiving its object in return. |
#do_exchange | Waits for another thread to arrive at this exchange point (unless the current thread is interrupted), and then transfers the given object to it, receiving its object in return. |
Synchronization::Object
- Inherited
Synchronization::Volatile
- Included
Synchronization::AbstractObject
- Inherited
Constructor Details
.new ⇒ JavaExchanger
# File 'lib/concurrent-ruby/concurrent/exchanger.rb', line 298
def initialize @exchanger = java.util.concurrent.Exchanger.new end
Instance Method Details
#do_exchange(value, timeout) ⇒ Object, CANCEL
(private)
Waits for another thread to arrive at this exchange point (unless the current thread is interrupted), and then transfers the given object to it, receiving its object in return. The timeout value indicates the approximate number of seconds the method should block while waiting for the exchange. When the timeout value is nil
the method will block indefinitely.
# File 'lib/concurrent-ruby/concurrent/exchanger.rb', line 307
def do_exchange(value, timeout) result = nil if timeout.nil? Synchronization::JRuby.sleep_interruptibly do result = @exchanger.exchange(value) end else Synchronization::JRuby.sleep_interruptibly do result = @exchanger.exchange(value, 1000 * timeout, java.util.concurrent.TimeUnit::MILLISECONDS) end end result rescue java.util.concurrent.TimeoutException CANCEL end