blob: bc0a14615c3f9a1c661ce1b487abd2f83d8abc7b [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Class: Qpid::Proton::WorkQueue
&mdash; Qpid Proton Ruby API
</title>
<link rel="stylesheet" href="../../css/style.css" type="text/css" />
<link rel="stylesheet" href="../../css/common.css" type="text/css" />
<script type="text/javascript">
pathId = "Qpid::Proton::WorkQueue";
relpath = '../../';
</script>
<script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>
</head>
<body>
<div class="nav_wrap">
<iframe id="nav" src="../../class_list.html?1"></iframe>
<div id="resizer"></div>
</div>
<div id="main" tabindex="-1">
<div id="header">
<div id="menu">
<a href="../../_index.html">Index (W)</a> &raquo;
<span class='title'><span class='object_link'><a href="../../Qpid.html" title="Qpid (module)">Qpid</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../Proton.html" title="Qpid::Proton (module)">Proton</a></span></span>
&raquo;
<span class="title">WorkQueue</span>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="../../class_list.html">
<svg width="24" height="24">
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
</svg>
</a>
</div>
<div class="clear"></div>
</div>
<div id="content"><h1>Class: Qpid::Proton::WorkQueue
</h1>
<div class="box_info">
<dl>
<dt>Inherits:</dt>
<dd>
<span class="inheritName">Object</span>
<ul class="fullTree">
<li>Object</li>
<li class="next">Qpid::Proton::WorkQueue</li>
</ul>
<a href="#" class="inheritanceTree">show all</a>
</dd>
</dl>
<dl>
<dt>Defined in:</dt>
<dd>lib/core/work_queue.rb</dd>
</dl>
</div>
<h2>Overview</h2><div class="docstring">
<div class="discussion">
<p>A thread-safe queue of work for multi-threaded programs.</p>
<p>A <span class='object_link'><a href="Container.html" title="Qpid::Proton::Container (class)">Container</a></span> can have multiple threads calling <span class='object_link'><a href="Container.html#run-instance_method" title="Qpid::Proton::Container#run (method)">Container#run</a></span> The container ensures that work associated with a single <span class='object_link'><a href="Connection.html" title="Qpid::Proton::Connection (class)">Connection</a></span> or <span class='object_link'><a href="Listener.html" title="Qpid::Proton::Listener (class)">Listener</a></span> is <em>serialized</em> - two threads will never concurrently call handlers associated with the same object.</p>
<p>To have your own code serialized in the same, add a block to the connection&#39;s <span class='object_link'><a href="" title="Qpid::Proton::WorkQueue (class)">WorkQueue</a></span>. The block will be invoked as soon as it is safe to do so.</p>
<p>A <span class='object_link'><a href="Connection.html" title="Qpid::Proton::Connection (class)">Connection</a></span> and the objects associated with it (<span class='object_link'><a href="Session.html" title="Qpid::Proton::Session (class)">Session</a></span>, <span class='object_link'><a href="Sender.html" title="Qpid::Proton::Sender (class)">Sender</a></span>, <span class='object_link'><a href="Receiver.html" title="Qpid::Proton::Receiver (class)">Receiver</a></span>, <span class='object_link'><a href="Delivery.html" title="Qpid::Proton::Delivery (class)">Delivery</a></span>, <span class='object_link'><a href="Tracker.html" title="Qpid::Proton::Tracker (class)">Tracker</a></span>) are not thread safe, so if you have multiple threads calling <span class='object_link'><a href="Container.html#run-instance_method" title="Qpid::Proton::Container#run (method)">Container#run</a></span> or if you want to affect objects managed by the container from non-container threads you need to use the <span class='object_link'><a href="" title="Qpid::Proton::WorkQueue (class)">WorkQueue</a></span></p>
</div>
</div>
<div class="tags">
</div><h2>Defined Under Namespace</h2>
<p class="children">
<strong class="classes">Classes:</strong> <span class='object_link'><a href="WorkQueue/StoppedError.html" title="Qpid::Proton::WorkQueue::StoppedError (class)">StoppedError</a></span>
</p>
<h2>
Instance Method Summary
<small><a href="#" class="summary_toggle">collapse</a></small>
</h2>
<ul class="summary">
<li class="public ">
<span class="summary_signature">
<a href="#add-instance_method" title="#add (instance method)">#<strong>add</strong> {|| ... } </a>
</span>
<span class="summary_desc"><div class='inline'>
<p>Add a block of code to be invoked in sequence.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#schedule-instance_method" title="#schedule (instance method)">#<strong>schedule</strong>(at) {|| ... } </a>
</span>
<span class="summary_desc"><div class='inline'>
<p>Schedule a block to be invoked at a certain time.</p>
</div></span>
</li>
</ul>
<div id="instance_method_details" class="method_details_list">
<h2>Instance Method Details</h2>
<div class="method_details first">
<h3 class="signature first" id="add-instance_method">
#<strong>add</strong> {|| ... }
</h3><div class="docstring">
<div class="discussion">
<div class="note notetag">
<strong>Note:</strong>
<div class='inline'>
<p>Thread Safe: may be called in any thread.</p>
</div>
</div>
<p class="note returns_void">This method returns an undefined value.</p>
<p>Add a block of code to be invoked in sequence.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Yields:</p>
<ul class="yield">
<li>
<span class='type'>(<tt></tt>)</span>
&mdash;
<div class='inline'>
<p>the block will be invoked with no parameters in the appropriate thread context</p>
</div>
</li>
</ul>
<p class="tag_title">Raises:</p>
<ul class="raise">
<li>
<span class='type'>(<tt><span class='object_link'><a href="WorkQueue/StoppedError.html" title="Qpid::Proton::WorkQueue::StoppedError (class)">StoppedError</a></span></tt>)</span>
&mdash;
<div class='inline'>
<p>if the queue is closed and cannot accept more work</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
49
50
51</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/core/work_queue.rb', line 49</span>
<span class='kw'>def</span> <span class='id identifier rubyid_add'>add</span><span class='lparen'>(</span><span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_schedule'>schedule</span><span class='lparen'>(</span><span class='int'>0</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="schedule-instance_method">
#<strong>schedule</strong>(at) {|| ... }
</h3><div class="docstring">
<div class="discussion">
<div class="note notetag">
<strong>Note:</strong>
<div class='inline'>
<p>Thread Safe: may be called in any thread.</p>
</div>
</div>
<p class="note returns_void">This method returns an undefined value.</p>
<p>Schedule a block to be invoked at a certain time.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>at</span>
<span class='type'>(<tt>Time</tt>)</span>
&mdash;
<div class='inline'>
<p>Invoke block as soon as possible after Time <code>at</code></p>
</div>
</li>
<li>
<span class='name'>at</span>
<span class='type'>(<tt>Numeric</tt>)</span>
&mdash;
<div class='inline'>
<p>Invoke block after a delay of <code>at</code> seconds from now</p>
</div>
</li>
</ul>
<p class="tag_title">Yields:</p>
<ul class="yield">
<li>
<span class='type'>(<tt></tt>)</span>
&mdash;
<div class='inline'>
<p>(see #add)</p>
</div>
</li>
</ul>
<p class="tag_title">Raises:</p>
<ul class="raise">
<li>
<span class='type'>(<tt><span class='object_link'><a href="WorkQueue/StoppedError.html" title="Qpid::Proton::WorkQueue::StoppedError (class)">StoppedError</a></span></tt>)</span>
&mdash;
<div class='inline'>
<p>if the queue is closed and cannot accept more work</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
61
62
63
64
65
66
67
68</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/core/work_queue.rb', line 61</span>
<span class='kw'>def</span> <span class='id identifier rubyid_schedule'>schedule</span><span class='lparen'>(</span><span class='id identifier rubyid_at'>at</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="ArgumentError.html" title="Qpid::Proton::ArgumentError (class)">ArgumentError</a></span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>no block</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_block_given?'>block_given?</span>
<span class='ivar'>@lock</span><span class='period'>.</span><span class='id identifier rubyid_synchronize'>synchronize</span> <span class='kw'>do</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='ivar'>@closed</span> <span class='kw'>if</span> <span class='ivar'>@closed</span>
<span class='ivar'>@schedule</span><span class='period'>.</span><span class='id identifier rubyid_insert'>insert</span><span class='lparen'>(</span><span class='id identifier rubyid_at'>at</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='ivar'>@container</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span> <span class='symbol'>:wake</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
</div>
<div id="footer">
Generated on Wed Nov 11 12:57:53 2020 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.24 (ruby-2.7.2).
</div>
</div>
</body>
</html>