Modified: incubator/reef/site/wake.html
URL: 
http://svn.apache.org/viewvc/incubator/reef/site/wake.html?rev=1696854&r1=1696853&r2=1696854&view=diff
==============================================================================
--- incubator/reef/site/wake.html (original)
+++ incubator/reef/site/wake.html Thu Aug 20 20:44:29 2015
@@ -1,523 +1,523 @@
-<!DOCTYPE html>
-<!--
- | Generated by Apache Maven Doxia at 2015-08-19 
- | Rendered using Apache Maven Fluido Skin 1.4
--->
-<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
-  <head>
-    <meta charset="UTF-8" />
-    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
-    <meta name="Date-Revision-yyyymmdd" content="20150819" />
-    <meta http-equiv="Content-Language" content="en" />
-    <title>Apache REEF - Wake</title>
-    <link rel="stylesheet" href="./css/apache-maven-fluido-1.4.min.css" />
-    <link rel="stylesheet" href="./css/site.css" />
-    <link rel="stylesheet" href="./css/print.css" media="print" />
-
-      
-    <script type="text/javascript" 
src="./js/apache-maven-fluido-1.4.min.js"></script>
-
-                          
-        
-<script src="js/release.js" type="text/javascript"></script>
-          
-                  </head>
-        <body class="topBarEnabled">
-          
-                
-                    
-                
-
-    <div id="topbar" class="navbar navbar-fixed-top ">
-      <div class="navbar-inner">
-                <div class="container-fluid">
-        <a data-target=".nav-collapse" data-toggle="collapse" class="btn 
btn-navbar">
-          <span class="icon-bar"></span>
-          <span class="icon-bar"></span>
-          <span class="icon-bar"></span>
-        </a>
-                
-                                <ul class="nav">
-                          <li class="dropdown">
-        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Apache REEF 
<b class="caret"></b></a>
-        <ul class="dropdown-menu">
-        
-                      <li>      <a href="index.html"  
title="Overview">Overview</a>
-</li>
-                  
-                      <li>      <a href="faq.html"  title="FAQ">FAQ</a>
-</li>
-                  
-                      <li>      <a href="license.html"  
title="License">License</a>
-</li>
-                  
-                      <li>      <a href="downloads.html"  
title="Downloads">Downloads</a>
-</li>
-                          </ul>
-      </li>
-                <li class="dropdown">
-        <a href="#" class="dropdown-toggle" 
data-toggle="dropdown">Documentation <b class="caret"></b></a>
-        <ul class="dropdown-menu">
-        
-                      <li>      <a href="introduction.html"  
title="Introduction to REEF">Introduction to REEF</a>
-</li>
-                  
-                      <li>      <a 
href="https://cwiki.apache.org/confluence/display/REEF/Tutorials";  title="REEF 
Tutorial">REEF Tutorial</a>
-</li>
-                  
-                      <li>      <a href="talks.html"  title="Talks">Talks</a>
-</li>
-                  
-                      <li>      <a href="glossary.html"  
title="Glossary">Glossary</a>
-</li>
-                  
-                      <li>      <a href="tang.html"  title="Tang">Tang</a>
-</li>
-                  
-                      <li>      <a href="wake.html"  title="Wake">Wake</a>
-</li>
-                  
-                      <li>      <a href="apidocs/0.10.0-incubating/index.html" 
 title="0.10.0-incubating API">0.10.0-incubating API</a>
-</li>
-                  
-                      <li>      <a href="apidocs/0.11.0-incubating/index.html" 
 title="0.11.0-incubating API">0.11.0-incubating API</a>
-</li>
-                  
-                      <li>      <a href="apidocs/0.12.0-incubating/index.html" 
 title="0.12.0-incubating API">0.12.0-incubating API</a>
-</li>
-                          </ul>
-      </li>
-                <li class="dropdown">
-        <a href="#" class="dropdown-toggle" 
data-toggle="dropdown">Contribution <b class="caret"></b></a>
-        <ul class="dropdown-menu">
-        
-                      <li>      <a 
href="https://cwiki.apache.org/confluence/display/REEF/Contributing";  
title="Contributing">Contributing</a>
-</li>
-                  
-                      <li>      <a 
href="https://cwiki.apache.org/confluence/display/REEF/Committer+Guide";  
title="Committer Guide">Committer Guide</a>
-</li>
-                  
-                      <li>      <a 
href="https://cwiki.apache.org/confluence/display/REEF/Coding+Guidelines";  
title="Coding Guidelines">Coding Guidelines</a>
-</li>
-                          </ul>
-      </li>
-                <li class="dropdown">
-        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Community 
<b class="caret"></b></a>
-        <ul class="dropdown-menu">
-        
-                      <li>      <a href="team.html"  title="Team">Team</a>
-</li>
-                  
-                      <li>      <a href="mailing-list.html"  title="Mailing 
List">Mailing List</a>
-</li>
-                  
-                      <li>      <a 
href="https://issues.apache.org/jira/browse/REEF";  title="Issue Tracker">Issue 
Tracker</a>
-</li>
-                  
-                      <li>      <a 
href="https://cwiki.apache.org/confluence/display/REEF/Powered+by+REEF";  
title="Powered By">Powered By</a>
-</li>
-                          </ul>
-      </li>
-                <li class="dropdown">
-        <a href="#" class="dropdown-toggle" data-toggle="dropdown">ASF <b 
class="caret"></b></a>
-        <ul class="dropdown-menu">
-        
-                      <li>      <a href="http://www.apache.org/foundation/";  
title="Apache Software Foundation">Apache Software Foundation</a>
-</li>
-                  
-                      <li>      <a 
href="http://www.apache.org/foundation/how-it-works.html";  title="How Apache 
Works">How Apache Works</a>
-</li>
-                  
-                      <li>      <a href="http://incubator.apache.org/";  
title="Apache Incubator">Apache Incubator</a>
-</li>
-                  
-                      <li>      <a 
href="http://www.apache.org/licenses/LICENSE-2.0.html";  title="Apache 
License">Apache License</a>
-</li>
-                  
-                      <li>      <a 
href="http://www.apache.org/foundation/sponsorship.html";  
title="Sponsorship">Sponsorship</a>
-</li>
-                  
-                      <li>      <a 
href="http://www.apache.org/foundation/thanks.html";  title="Thanks">Thanks</a>
-</li>
-                          </ul>
-      </li>
-                  </ul>
-          
-          
-          
-                               <ul class="nav pull-right">
-              <li class="dropdown">
-                <a href="#" class="dropdown-toggle" 
data-toggle="dropdown">External Links <b class="caret"></b></a>
-                <ul class="dropdown-menu">
-                      <li>      <a 
href="https://github.com/apache/incubator-reef";  title="Apache REEF 
GitHub">Apache REEF GitHub</a>
-</li>
-      <li>      <a href="http://www.apache.org";  title="Apache">Apache</a>
-</li>
-      <li>      <a href="http://incubator.apache.org/";  title="Apache 
Incubator">Apache Incubator</a>
-</li>
-                  </ul>
-              </li>
-            </ul>
-          
-                      </div>
-          
-        </div>
-      </div>
-    </div>
-    
-        <div class="container-fluid">
-          <div id="banner">
-        <div class="pull-left">
-                                                          <a href="./" 
id="bannerLeft" title="Apache REEF">
-                                                                               
                 <img src="ApacheREEF_logo_no_margin_small.png"  alt="Apache 
REEF"/>
-                </a>
-                      </div>
-        <div class="pull-right">                  <a 
href="http://incubator.apache.org/"; id="bannerRight">
-                                                                               
                 <img src="ApacheIncubator.png" />
-                </a>
-      </div>
-        <div class="clear"><hr/></div>
-      </div>
-
-      <div id="breadcrumbs">
-        <ul class="breadcrumb">
-                
-                    
-                              <li class="">
-                    <a href="index.html" title="Apache REEF">
-        Apache REEF</a>
-                    <span class="divider">|</span>
-      </li>
-        <li class="active ">Wake</li>
-        
-                
-                    
-      
-                            </ul>
-      </div>
-
-                  
-      <div class="row-fluid">
-        <div id="leftColumn" class="span2">
-          <div class="well sidebar-nav">
-                
-                    
-                <ul class="nav nav-list">
-                    <li class="nav-header">Apache REEF</li>
-                              
-      <li>
-  
-                          <a href="index.html" title="Overview">
-          <span class="none"></span>
-        Overview</a>
-            </li>
-                
-      <li>
-  
-                          <a href="faq.html" title="FAQ">
-          <span class="none"></span>
-        FAQ</a>
-            </li>
-                
-      <li>
-  
-                          <a href="license.html" title="License">
-          <span class="none"></span>
-        License</a>
-            </li>
-                
-      <li>
-  
-                          <a href="downloads.html" title="Downloads">
-          <span class="none"></span>
-        Downloads</a>
-            </li>
-                              <li class="nav-header">Documentation</li>
-                              
-      <li>
-  
-                          <a href="introduction.html" title="Introduction to 
REEF">
-          <span class="none"></span>
-        Introduction to REEF</a>
-            </li>
-                
-      <li>
-  
-                          <a 
href="https://cwiki.apache.org/confluence/display/REEF/Tutorials"; 
class="externalLink" title="REEF Tutorial">
-          <span class="none"></span>
-        REEF Tutorial</a>
-            </li>
-                
-      <li>
-  
-                          <a href="talks.html" title="Talks">
-          <span class="none"></span>
-        Talks</a>
-            </li>
-                
-      <li>
-  
-                          <a href="glossary.html" title="Glossary">
-          <span class="none"></span>
-        Glossary</a>
-            </li>
-                
-      <li>
-  
-                          <a href="tang.html" title="Tang">
-          <span class="none"></span>
-        Tang</a>
-            </li>
-                
-      <li class="active">
-  
-            <a href="#"><span class="none"></span>Wake</a>
-          </li>
-                
-      <li>
-  
-                          <a href="apidocs/0.10.0-incubating/index.html" 
title="0.10.0-incubating API">
-          <span class="none"></span>
-        0.10.0-incubating API</a>
-            </li>
-                
-      <li>
-  
-                          <a href="apidocs/0.11.0-incubating/index.html" 
title="0.11.0-incubating API">
-          <span class="none"></span>
-        0.11.0-incubating API</a>
-            </li>
-                
-      <li>
-  
-                          <a href="apidocs/0.12.0-incubating/index.html" 
title="0.12.0-incubating API">
-          <span class="none"></span>
-        0.12.0-incubating API</a>
-            </li>
-                              <li class="nav-header">Contribution</li>
-                              
-      <li>
-  
-                          <a 
href="https://cwiki.apache.org/confluence/display/REEF/Contributing"; 
class="externalLink" title="Contributing">
-          <span class="none"></span>
-        Contributing</a>
-            </li>
-                
-      <li>
-  
-                          <a 
href="https://cwiki.apache.org/confluence/display/REEF/Committer+Guide"; 
class="externalLink" title="Committer Guide">
-          <span class="none"></span>
-        Committer Guide</a>
-            </li>
-                
-      <li>
-  
-                          <a 
href="https://cwiki.apache.org/confluence/display/REEF/Coding+Guidelines"; 
class="externalLink" title="Coding Guidelines">
-          <span class="none"></span>
-        Coding Guidelines</a>
-            </li>
-                              <li class="nav-header">Community</li>
-                              
-      <li>
-  
-                          <a href="team.html" title="Team">
-          <span class="none"></span>
-        Team</a>
-            </li>
-                
-      <li>
-  
-                          <a href="mailing-list.html" title="Mailing List">
-          <span class="none"></span>
-        Mailing List</a>
-            </li>
-                
-      <li>
-  
-                          <a href="https://issues.apache.org/jira/browse/REEF"; 
class="externalLink" title="Issue Tracker">
-          <span class="none"></span>
-        Issue Tracker</a>
-            </li>
-                
-      <li>
-  
-                          <a 
href="https://cwiki.apache.org/confluence/display/REEF/Powered+by+REEF"; 
class="externalLink" title="Powered By">
-          <span class="none"></span>
-        Powered By</a>
-            </li>
-                              <li class="nav-header">ASF</li>
-                              
-      <li>
-  
-                          <a href="http://www.apache.org/foundation/"; 
class="externalLink" title="Apache Software Foundation">
-          <span class="none"></span>
-        Apache Software Foundation</a>
-            </li>
-                
-      <li>
-  
-                          <a 
href="http://www.apache.org/foundation/how-it-works.html"; class="externalLink" 
title="How Apache Works">
-          <span class="none"></span>
-        How Apache Works</a>
-            </li>
-                
-      <li>
-  
-                          <a href="http://incubator.apache.org/"; 
class="externalLink" title="Apache Incubator">
-          <span class="none"></span>
-        Apache Incubator</a>
-            </li>
-                
-      <li>
-  
-                          <a 
href="http://www.apache.org/licenses/LICENSE-2.0.html"; class="externalLink" 
title="Apache License">
-          <span class="none"></span>
-        Apache License</a>
-            </li>
-                
-      <li>
-  
-                          <a 
href="http://www.apache.org/foundation/sponsorship.html"; class="externalLink" 
title="Sponsorship">
-          <span class="none"></span>
-        Sponsorship</a>
-            </li>
-                
-      <li>
-  
-                          <a 
href="http://www.apache.org/foundation/thanks.html"; class="externalLink" 
title="Thanks">
-          <span class="none"></span>
-        Thanks</a>
-            </li>
-            </ul>
-                
-                    
-                
-          <hr />
-
-           <div id="poweredBy">
-                            <div class="clear"></div>
-                            <div class="clear"></div>
-                            <div class="clear"></div>
-                            <div class="clear"></div>
-                             <a href="http://maven.apache.org/"; title="Built 
by Maven" class="poweredBy">
-        <img class="builtBy" alt="Built by Maven" 
src="./images/logos/maven-feather.png" />
-      </a>
-                  </div>
-          </div>
-        </div>
-        
-                        
-        <div id="bodyColumn"  class="span10" >
-                                  
-            <!-- Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements.  See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership.  The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License.  You may obtain a copy of the License at
-
-http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied.  See the License for the
-specific language governing permissions and limitations
-under the License. --><h1>Wake</h1>
-<p>Wake is an event-driven framework based on ideas from SEDA, Click, Akka and 
Rx. It is <i>general purpose</i> in the sense that it is designed to support 
computationally intensive applications as well as high performance networking, 
storage, and legacy I/O systems. We implemented Wake to support 
high-performance, scalable analytical processing systems (&#x201c;big 
data&#x201d; applications), and have used it to implement control plane logic 
(which requires high fanout and low latency) and the data plane (which requires 
high-throughput processing as well).</p>
-<div class="section">
-<h2>Background<a name="Background"></a></h2>
-<p>Wake applications consist of asynchronous <i>event handlers</i> that run 
inside of <i>stages</i>. Stages provide scheduling primitives such as thread 
pool sizing and performance isolation between event handlers. In addition to 
event handler and stage APIs, Wake includes profiling tools and a rich standard 
library of primitives for system builders.</p>
-<p>Event driven processing frameworks improve upon the performance of threaded 
architectures in two ways: (1) Event handlers often have lower memory and 
context switching overhead than threaded solutions, and (2) event driven 
systems allow applications to allocate and monitor computational and I/O 
resources in an extremely fine-grained fashion. Modern threading packages have 
done much to address the first concern, and have significantly lowered 
concurrency control and other implementation overheads in recent years. 
However, fine grained resource allocation remains a challenge in threaded 
systems, and is Wake&#x2019;s primary advantage over threading.</p>
-<p>Early event driven systems such as SEDA executed each event handler in a 
dedicated thread pool called a stage. This isolated low-latency event handlers 
(such as cache lookups) from expensive high-latency operations, such as disk 
I/O. With a single thread pool, high-latency I/O operations can easily 
monopolize the thread pool, causing all of the CPUs to block on disk I/O, even 
when there is computation to be scheduled. With separate thread pools, the 
operating system schedules I/O requests and computation separately, 
guaranteeing that runnable computations will not block on I/O requests.</p>
-<p>This is in contrast to event-driven systems such as the Click modular 
router that were designed to maximize throughput for predictable, low latency 
event-handlers. When possible, Click aggressively chains event handlers 
together, reducing the cost of an event dispatch to that of a function call, 
and allowing the compiler to perform optimizations such as inlining and 
constant propagation across event handlers.</p>
-<p>Wake allows developers to trade off between these two extremes by 
explicitly partitioning their event handlers into stages. Within a stage, event 
handlers engage in <i>thread-sharing</i> by simply calling each other directly. 
When an event crosses a stage boundary, it is placed in a queue of similar 
events. The queue is then drained by the threads managed by the receiving 
stage.</p>
-<p>Although event handling systems improve upon threaded performance in 
theory, they are notoriously difficult to reason about. We kept this in mind 
while designing Wake, and have gone to great pains to ensure that its APIs are 
simple and easy to implement without sacrificing our performance goals.</p>
-<p>Other event driven systems provide support for so-called <i>push-based</i> 
and <i>pull-based</i> event handlers. In push-based systems, event sources 
invoke event handlers that are exposed by the events&#x2019; destinations, 
while pull-based APIs have the destination code invoke iterators to obtain the 
next available event from the source.</p>
-<p>Wake is completely push based. This eliminates the need for push and pull 
based variants of event handling logic, and also allowed us to unify all error 
handling in Wake into a single API. It is always possible to convert between 
push and pull based APIs by inserting a queue and a thread boundary between the 
push and pull based code. Wake supports libraries and applications that use 
this trick, since operating systems and legacy code sometimes expose pull-based 
APIs.</p>
-<p>Systems such as Rx allow event handlers to be dynamically registered and 
torn down at runtime, allowing applications to evolve over time. This leads to 
complicated setup and teardown protocols, where event handlers need to reason 
about the state of upstream and downstream handlers, both during setup and 
teardown, but also when routing messages at runtime. It also encourages design 
patterns such as dynamic event dispatching that break standard compiler 
optimizations. In contrast, Wake applications consist of immutable graphs of 
event handlers that are built up from sink to source. This ensures that, once 
an event handler has been instantiated, all downstream handlers are ready to 
receive messages.</p>
-<p>Wake is designed to work with <a href="tang.html">Tang</a>, a dependency 
injection system that focuses on configuration and debuggability. This makes it 
extremely easy to wire up complicated graphs of event handling logic. In 
addition to making it easy to build up event-driven applications, Tang provides 
a range of static analysis tools and provides a simple aspect-style programming 
facility that supports Wake&#x2019;s latency and throughput profilers.</p></div>
-<div class="section">
-<h2>Core API<a name="Core_API"></a></h2>
-<div class="section">
-<h3>Event Handlers<a name="Event_Handlers"></a></h3>
-<p>Wake provides two APIs for event handler implementations. The first is the 
<a class="externalLink" 
href="https://github.com/apache/incubator-reef/blob/master/reef-wake/wake/src/main/java/org/apache/reef/wake/EventHandler.java";>EventHandler</a>
 interface:</p>
-
-<div class="source"><pre class="prettyprint">public interface 
EventHandler&lt;T&gt; {
-  void onNext(T value);
-}
-</pre></div>
-<p>Callers of <tt>onNext()</tt> should assume that it is asynchronous, and 
that it always succeeds. Unrecoverable errors should be reported by throwing a 
runtime exception (which should not be caught, and will instead take down the 
process). Recoverable errors are reported by invoking an event handler that 
contains the appropriate error handling logic.</p>
-<p>The latter approach can be implemented by registering separate event 
handlers for each type of error. However, for convenience, it is formalized in 
Wake&#x2019;s simplified version of the Rx <a class="externalLink" 
href="https://github.com/apache/incubator-reef/blob/master/reef-wake/wake/src/main/java/org/apache/reef/wake/rx/Observer.java";>Observer</a>
 interface:</p>
-
-<div class="source"><pre class="prettyprint">public interface 
Observer&lt;T&gt; {
-  void onNext(final T value);
-  void onError(final Exception error);
-  void onCompleted();
-}
-</pre></div>
-<p>The <tt>Observer</tt> is designed for stateful event handlers that need to 
be explicitly torn down at exit, or when errors occor. Such event handlers may 
maintain open network sockets, write to disk, buffer output, and so on. As with 
<tt>onNext()</tt>, neither <tt>onError()</tt> nor <tt>onCompleted()</tt> throw 
exceptions. Instead, callers should assume that they are asynchronously 
invoked.</p>
-<p><tt>EventHandler</tt> and <tt>Observer</tt> implementations should be 
threadsafe and handle concurrent invocations of <tt>onNext()</tt>. However, it 
is illegal to call <tt>onCompleted()</tt> or <tt>onError()</tt> in race with 
any calls to <tt>onNext()</tt>, and the call to <tt>onCompleted()</tt> or 
<tt>onError()</tt> must be the last call made to the object. Therefore, 
implementations of <tt>onCompleted()</tt> and <tt>onError()</tt> can assume 
they have a lock on <tt>this</tt>, and that <tt>this</tt> has not been torn 
down and is still in a valid state.</p>
-<p>We chose these invariants because they are simple and easy to enforce. In 
most cases, application logic simply limits calls to <tt>onCompleted()</tt> and 
<tt>onError()</tt> to other implementations of <tt>onError()</tt> and 
<tt>onCompleted()</tt>, and relies upon Wake (and any intervening application 
logic) to obey the same protocol.</p></div>
-<div class="section">
-<h3>Stages<a name="Stages"></a></h3>
-<p>Wake Stages are responsible for resource management. The base <a 
class="externalLink" 
href="https://github.com/apache/incubator-reef/blob/master/reef-wake/wake/src/main/java/org/apache/reef/wake/Stage.java";>Stage</a>
 interface is fairly simple:</p>
-
-<div class="source"><pre class="prettyprint">public interface Stage extends 
AutoCloseable { }
-</pre></div>
-<p>The only method it contains is <tt>close()</tt> from auto-closable. This 
reflects the fact that Wake stages can either contain <tt>EventHandler</tt>s, 
as <a class="externalLink" 
href="https://github.com/apache/incubator-reef/blob/master/reef-wake/wake/src/main/java/org/apache/reef/wake/EStage.java";>EStage</a>
 implementations do:</p>
-
-<div class="source"><pre class="prettyprint">public interface EStage&lt;T&gt; 
extends EventHandler&lt;T&gt;, Stage { }
-</pre></div>
-<p>or they can contain <tt>Observable</tt>s, as <a class="externalLink" 
href="https://github.com/apache/incubator-reef/blob/master/reef-wake/wake/src/main/java/org/apache/reef/wake/rx/RxStage.java";>RxStage</a>
 implementations do:</p>
-
-<div class="source"><pre class="prettyprint">public interface RxStage&lt;T&gt; 
extends Observer&lt;T&gt;, Stage { }
-</pre></div>
-<p>In both cases, the stage simply exposes the same API as the event handler 
that it manages. This allows code that produces events to treat downstream 
stages and raw <tt>EventHandlers</tt> / <tt>Observers</tt> interchangebly. 
Recall that Wake implements thread sharing by allowing EventHandlers and 
Observers to directly invoke each other. Since Stages implement the same 
interface as raw EventHandlers and Observers, this pushes the placement of 
thread boundaries and other scheduling tradeoffs to the code that is 
instantiating the application. In turn, this simplifies testing and improves 
the reusability of code written on top of Wake.</p>
-<div class="section">
-<h4>close() vs. onCompleted()<a name="close_vs._onCompleted"></a></h4>
-<p>It may seem strange that Wake RxStage exposes two shutdown methods: 
<tt>close()</tt> and <tt>onCompleted()</tt>. Since <tt>onCompleted()</tt> is 
part of the Observer API, it may be implemented in an asynchronous fashion. 
This makes it difficult for applications to cleanly shut down, since, even 
after <tt>onCompleted()</tt> has returned, resources may still be held by the 
downstream code.</p>
-<p>In contrast, <tt>close()</tt> is synchronous, and is not allowed to return 
until all queued events have been processed, and any resources held by the 
Stage implementation have been released. The upshot is that shutdown sequences 
in Wake work as follows: Once the upstream event sources are done calling 
<tt>onNext()</tt> (and all calls to <tt>onNext()</tt> have returned), 
<tt>onCompleted()</tt> or <tt>onError()</tt> is called exactly once per stage. 
After the <tt>onCompleted()</tt> or <tt>onError()</tt> call to a given stage 
has returned, <tt>close()</tt> must be called. Once <tt>close()</tt> returns, 
all resources have been released, and the JVM may safely exit, or the code that 
is invoking Wake may proceed under the assumption that no resources or memory 
have been leaked. Note that, depending on the implementation of the downstream 
Stage, there may be a delay between the return of calls such as 
<tt>onNext()</tt> or <tt>onCompleted()</tt> and their execution. Therefore, it 
is poss
 ible that the stage will continue to schedule <tt>onNext()</tt> calls after 
<tt>close()</tt> has been invoked. It is illegal for stages to drop events on 
shutdown, so the stage will execute the requests in its queue before it 
releases resources and returns from <tt>close()</tt>.</p>
-<p><tt>Observer</tt> implementations do not expose a <tt>close()</tt> method, 
and generally do not invoke <tt>close()</tt>. Instead, when 
<tt>onCompleted()</tt> is invoked, it should arrange for <tt>onCompleted()</tt> 
to be called on any <tt>Observer</tt> instances that <tt>this</tt> directly 
invokes, free any resources it is holding, and then return. Since the 
downstream <tt>onCompleted()</tt> calls are potentially asynchronous, it cannot 
assume that downstream cleanup completes before it returns.</p>
-<p>In a thread pool <tt>Stage</tt>, the final <tt>close()</tt> call will block 
until there are no more outstanding events queued in the stage. Once 
<tt>close()</tt> has been called (and returns) on each stage, no events are 
left in any queues, and no <tt>Observer</tt> or <tt>EventHandler</tt> objects 
are holding resources or scheduled on any cores, so shutdown is 
compelete.</p></div></div></div>
-<div class="section">
-<h2>Helper libraries<a name="Helper_libraries"></a></h2>
-<p>Wake includes a number of standard library packages:</p>
-
-<ul>
-  
-<li><tt>org.apache.reef.wake.time</tt> allows events to be scheduled in the 
future, and notifies the application when it starts and when it is being torn 
down.</li>
-  
-<li><tt>org.apache.reef.wake.remote</tt> provides networking primitives, 
including hooks into netty (a high-performance event-based networking library 
for Java).</li>
-  
-<li><tt>org.apache.reef.wake.metrics</tt> provides implementations of standard 
latency and throughput instrumentation.</li>
-  
-<li><tt>org.apache.reef.wake.profiler</tt> provides a graphical profiler that 
automatically instruments Tang-based Wake applications.</li>
-</ul></div>
-                  </div>
-            </div>
-          </div>
-
-    <hr/>
-
-    <footer>
-            <div class="container-fluid">
-                      <div class="row-fluid">
-                                                                          
-<div class="container-fluid">
-  <div class="row-fluid">
-    <a href="http://www.apache.org";>Apache Software Foundation</a>
-  </div>
-</div>
-                                                          
-<div class="row span12">Apache REEF, REEF, Apache, the Apache feather logo, 
and the Apache REEF logo are trademarks
-                       of The Apache Software Foundation. All other marks 
mentioned may be trademarks or registered
-                       trademarks of their respective owners.</div>
-                          </div>
-
-        
-                </div>
-    </footer>
-        </body>
+<!DOCTYPE html>
+<!--
+ | Generated by Apache Maven Doxia at 2015-08-20 
+ | Rendered using Apache Maven Fluido Skin 1.4
+-->
+<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
+  <head>
+    <meta charset="UTF-8" />
+    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+    <meta name="Date-Revision-yyyymmdd" content="20150820" />
+    <meta http-equiv="Content-Language" content="en" />
+    <title>Apache REEF - Wake</title>
+    <link rel="stylesheet" href="./css/apache-maven-fluido-1.4.min.css" />
+    <link rel="stylesheet" href="./css/site.css" />
+    <link rel="stylesheet" href="./css/print.css" media="print" />
+
+      
+    <script type="text/javascript" 
src="./js/apache-maven-fluido-1.4.min.js"></script>
+
+                          
+        
+<script src="js/release.js" type="text/javascript"></script>
+          
+                  </head>
+        <body class="topBarEnabled">
+          
+                
+                    
+                
+
+    <div id="topbar" class="navbar navbar-fixed-top ">
+      <div class="navbar-inner">
+                <div class="container-fluid">
+        <a data-target=".nav-collapse" data-toggle="collapse" class="btn 
btn-navbar">
+          <span class="icon-bar"></span>
+          <span class="icon-bar"></span>
+          <span class="icon-bar"></span>
+        </a>
+                
+                                <ul class="nav">
+                          <li class="dropdown">
+        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Apache REEF 
<b class="caret"></b></a>
+        <ul class="dropdown-menu">
+        
+                      <li>      <a href="index.html"  
title="Overview">Overview</a>
+</li>
+                  
+                      <li>      <a href="faq.html"  title="FAQ">FAQ</a>
+</li>
+                  
+                      <li>      <a href="license.html"  
title="License">License</a>
+</li>
+                  
+                      <li>      <a href="downloads.html"  
title="Downloads">Downloads</a>
+</li>
+                          </ul>
+      </li>
+                <li class="dropdown">
+        <a href="#" class="dropdown-toggle" 
data-toggle="dropdown">Documentation <b class="caret"></b></a>
+        <ul class="dropdown-menu">
+        
+                      <li>      <a href="introduction.html"  
title="Introduction to REEF">Introduction to REEF</a>
+</li>
+                  
+                      <li>      <a 
href="https://cwiki.apache.org/confluence/display/REEF/Tutorials";  title="REEF 
Tutorial">REEF Tutorial</a>
+</li>
+                  
+                      <li>      <a href="talks.html"  title="Talks">Talks</a>
+</li>
+                  
+                      <li>      <a href="glossary.html"  
title="Glossary">Glossary</a>
+</li>
+                  
+                      <li>      <a href="tang.html"  title="Tang">Tang</a>
+</li>
+                  
+                      <li>      <a href="wake.html"  title="Wake">Wake</a>
+</li>
+                  
+                      <li>      <a href="apidocs/0.10.0-incubating/index.html" 
 title="0.10.0-incubating API">0.10.0-incubating API</a>
+</li>
+                  
+                      <li>      <a href="apidocs/0.11.0-incubating/index.html" 
 title="0.11.0-incubating API">0.11.0-incubating API</a>
+</li>
+                  
+                      <li>      <a href="apidocs/0.12.0-incubating/index.html" 
 title="0.12.0-incubating API">0.12.0-incubating API</a>
+</li>
+                          </ul>
+      </li>
+                <li class="dropdown">
+        <a href="#" class="dropdown-toggle" 
data-toggle="dropdown">Contribution <b class="caret"></b></a>
+        <ul class="dropdown-menu">
+        
+                      <li>      <a 
href="https://cwiki.apache.org/confluence/display/REEF/Contributing";  
title="Contributing">Contributing</a>
+</li>
+                  
+                      <li>      <a 
href="https://cwiki.apache.org/confluence/display/REEF/Committer+Guide";  
title="Committer Guide">Committer Guide</a>
+</li>
+                  
+                      <li>      <a 
href="https://cwiki.apache.org/confluence/display/REEF/Coding+Guidelines";  
title="Coding Guidelines">Coding Guidelines</a>
+</li>
+                          </ul>
+      </li>
+                <li class="dropdown">
+        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Community 
<b class="caret"></b></a>
+        <ul class="dropdown-menu">
+        
+                      <li>      <a href="team.html"  title="Team">Team</a>
+</li>
+                  
+                      <li>      <a href="mailing-list.html"  title="Mailing 
List">Mailing List</a>
+</li>
+                  
+                      <li>      <a 
href="https://issues.apache.org/jira/browse/REEF";  title="Issue Tracker">Issue 
Tracker</a>
+</li>
+                  
+                      <li>      <a 
href="https://cwiki.apache.org/confluence/display/REEF/Powered+by+REEF";  
title="Powered By">Powered By</a>
+</li>
+                          </ul>
+      </li>
+                <li class="dropdown">
+        <a href="#" class="dropdown-toggle" data-toggle="dropdown">ASF <b 
class="caret"></b></a>
+        <ul class="dropdown-menu">
+        
+                      <li>      <a href="http://www.apache.org/foundation/";  
title="Apache Software Foundation">Apache Software Foundation</a>
+</li>
+                  
+                      <li>      <a 
href="http://www.apache.org/foundation/how-it-works.html";  title="How Apache 
Works">How Apache Works</a>
+</li>
+                  
+                      <li>      <a href="http://incubator.apache.org/";  
title="Apache Incubator">Apache Incubator</a>
+</li>
+                  
+                      <li>      <a 
href="http://www.apache.org/licenses/LICENSE-2.0.html";  title="Apache 
License">Apache License</a>
+</li>
+                  
+                      <li>      <a 
href="http://www.apache.org/foundation/sponsorship.html";  
title="Sponsorship">Sponsorship</a>
+</li>
+                  
+                      <li>      <a 
href="http://www.apache.org/foundation/thanks.html";  title="Thanks">Thanks</a>
+</li>
+                          </ul>
+      </li>
+                  </ul>
+          
+          
+          
+                               <ul class="nav pull-right">
+              <li class="dropdown">
+                <a href="#" class="dropdown-toggle" 
data-toggle="dropdown">External Links <b class="caret"></b></a>
+                <ul class="dropdown-menu">
+                      <li>      <a 
href="https://github.com/apache/incubator-reef";  title="Apache REEF 
GitHub">Apache REEF GitHub</a>
+</li>
+      <li>      <a href="http://www.apache.org";  title="Apache">Apache</a>
+</li>
+      <li>      <a href="http://incubator.apache.org/";  title="Apache 
Incubator">Apache Incubator</a>
+</li>
+                  </ul>
+              </li>
+            </ul>
+          
+                      </div>
+          
+        </div>
+      </div>
+    </div>
+    
+        <div class="container-fluid">
+          <div id="banner">
+        <div class="pull-left">
+                                                          <a href="./" 
id="bannerLeft" title="Apache REEF">
+                                                                               
                 <img src="ApacheREEF_logo_no_margin_small.png"  alt="Apache 
REEF"/>
+                </a>
+                      </div>
+        <div class="pull-right">                  <a 
href="http://incubator.apache.org/"; id="bannerRight">
+                                                                               
                 <img src="ApacheIncubator.png" />
+                </a>
+      </div>
+        <div class="clear"><hr/></div>
+      </div>
+
+      <div id="breadcrumbs">
+        <ul class="breadcrumb">
+                
+                    
+                              <li class="">
+                    <a href="index.html" title="Apache REEF">
+        Apache REEF</a>
+                    <span class="divider">|</span>
+      </li>
+        <li class="active ">Wake</li>
+        
+                
+                    
+      
+                            </ul>
+      </div>
+
+                  
+      <div class="row-fluid">
+        <div id="leftColumn" class="span2">
+          <div class="well sidebar-nav">
+                
+                    
+                <ul class="nav nav-list">
+                    <li class="nav-header">Apache REEF</li>
+                              
+      <li>
+  
+                          <a href="index.html" title="Overview">
+          <span class="none"></span>
+        Overview</a>
+            </li>
+                
+      <li>
+  
+                          <a href="faq.html" title="FAQ">
+          <span class="none"></span>
+        FAQ</a>
+            </li>
+                
+      <li>
+  
+                          <a href="license.html" title="License">
+          <span class="none"></span>
+        License</a>
+            </li>
+                
+      <li>
+  
+                          <a href="downloads.html" title="Downloads">
+          <span class="none"></span>
+        Downloads</a>
+            </li>
+                              <li class="nav-header">Documentation</li>
+                              
+      <li>
+  
+                          <a href="introduction.html" title="Introduction to 
REEF">
+          <span class="none"></span>
+        Introduction to REEF</a>
+            </li>
+                
+      <li>
+  
+                          <a 
href="https://cwiki.apache.org/confluence/display/REEF/Tutorials"; 
class="externalLink" title="REEF Tutorial">
+          <span class="none"></span>
+        REEF Tutorial</a>
+            </li>
+                
+      <li>
+  
+                          <a href="talks.html" title="Talks">
+          <span class="none"></span>
+        Talks</a>
+            </li>
+                
+      <li>
+  
+                          <a href="glossary.html" title="Glossary">
+          <span class="none"></span>
+        Glossary</a>
+            </li>
+                
+      <li>
+  
+                          <a href="tang.html" title="Tang">
+          <span class="none"></span>
+        Tang</a>
+            </li>
+                
+      <li class="active">
+  
+            <a href="#"><span class="none"></span>Wake</a>
+          </li>
+                
+      <li>
+  
+                          <a href="apidocs/0.10.0-incubating/index.html" 
title="0.10.0-incubating API">
+          <span class="none"></span>
+        0.10.0-incubating API</a>
+            </li>
+                
+      <li>
+  
+                          <a href="apidocs/0.11.0-incubating/index.html" 
title="0.11.0-incubating API">
+          <span class="none"></span>
+        0.11.0-incubating API</a>
+            </li>
+                
+      <li>
+  
+                          <a href="apidocs/0.12.0-incubating/index.html" 
title="0.12.0-incubating API">
+          <span class="none"></span>
+        0.12.0-incubating API</a>
+            </li>
+                              <li class="nav-header">Contribution</li>
+                              
+      <li>
+  
+                          <a 
href="https://cwiki.apache.org/confluence/display/REEF/Contributing"; 
class="externalLink" title="Contributing">
+          <span class="none"></span>
+        Contributing</a>
+            </li>
+                
+      <li>
+  
+                          <a 
href="https://cwiki.apache.org/confluence/display/REEF/Committer+Guide"; 
class="externalLink" title="Committer Guide">
+          <span class="none"></span>
+        Committer Guide</a>
+            </li>
+                
+      <li>
+  
+                          <a 
href="https://cwiki.apache.org/confluence/display/REEF/Coding+Guidelines"; 
class="externalLink" title="Coding Guidelines">
+          <span class="none"></span>
+        Coding Guidelines</a>
+            </li>
+                              <li class="nav-header">Community</li>
+                              
+      <li>
+  
+                          <a href="team.html" title="Team">
+          <span class="none"></span>
+        Team</a>
+            </li>
+                
+      <li>
+  
+                          <a href="mailing-list.html" title="Mailing List">
+          <span class="none"></span>
+        Mailing List</a>
+            </li>
+                
+      <li>
+  
+                          <a href="https://issues.apache.org/jira/browse/REEF"; 
class="externalLink" title="Issue Tracker">
+          <span class="none"></span>
+        Issue Tracker</a>
+            </li>
+                
+      <li>
+  
+                          <a 
href="https://cwiki.apache.org/confluence/display/REEF/Powered+by+REEF"; 
class="externalLink" title="Powered By">
+          <span class="none"></span>
+        Powered By</a>
+            </li>
+                              <li class="nav-header">ASF</li>
+                              
+      <li>
+  
+                          <a href="http://www.apache.org/foundation/"; 
class="externalLink" title="Apache Software Foundation">
+          <span class="none"></span>
+        Apache Software Foundation</a>
+            </li>
+                
+      <li>
+  
+                          <a 
href="http://www.apache.org/foundation/how-it-works.html"; class="externalLink" 
title="How Apache Works">
+          <span class="none"></span>
+        How Apache Works</a>
+            </li>
+                
+      <li>
+  
+                          <a href="http://incubator.apache.org/"; 
class="externalLink" title="Apache Incubator">
+          <span class="none"></span>
+        Apache Incubator</a>
+            </li>
+                
+      <li>
+  
+                          <a 
href="http://www.apache.org/licenses/LICENSE-2.0.html"; class="externalLink" 
title="Apache License">
+          <span class="none"></span>
+        Apache License</a>
+            </li>
+                
+      <li>
+  
+                          <a 
href="http://www.apache.org/foundation/sponsorship.html"; class="externalLink" 
title="Sponsorship">
+          <span class="none"></span>
+        Sponsorship</a>
+            </li>
+                
+      <li>
+  
+                          <a 
href="http://www.apache.org/foundation/thanks.html"; class="externalLink" 
title="Thanks">
+          <span class="none"></span>
+        Thanks</a>
+            </li>
+            </ul>
+                
+                    
+                
+          <hr />
+
+           <div id="poweredBy">
+                            <div class="clear"></div>
+                            <div class="clear"></div>
+                            <div class="clear"></div>
+                            <div class="clear"></div>
+                             <a href="http://maven.apache.org/"; title="Built 
by Maven" class="poweredBy">
+        <img class="builtBy" alt="Built by Maven" 
src="./images/logos/maven-feather.png" />
+      </a>
+                  </div>
+          </div>
+        </div>
+        
+                        
+        <div id="bodyColumn"  class="span10" >
+                                  
+            <!-- Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License. --><h1>Wake</h1>
+<p>Wake is an event-driven framework based on ideas from SEDA, Click, Akka and 
Rx. It is <i>general purpose</i> in the sense that it is designed to support 
computationally intensive applications as well as high performance networking, 
storage, and legacy I/O systems. We implemented Wake to support 
high-performance, scalable analytical processing systems (&#x201c;big 
data&#x201d; applications), and have used it to implement control plane logic 
(which requires high fanout and low latency) and the data plane (which requires 
high-throughput processing as well).</p>
+<div class="section">
+<h2>Background<a name="Background"></a></h2>
+<p>Wake applications consist of asynchronous <i>event handlers</i> that run 
inside of <i>stages</i>. Stages provide scheduling primitives such as thread 
pool sizing and performance isolation between event handlers. In addition to 
event handler and stage APIs, Wake includes profiling tools and a rich standard 
library of primitives for system builders.</p>
+<p>Event driven processing frameworks improve upon the performance of threaded 
architectures in two ways: (1) Event handlers often have lower memory and 
context switching overhead than threaded solutions, and (2) event driven 
systems allow applications to allocate and monitor computational and I/O 
resources in an extremely fine-grained fashion. Modern threading packages have 
done much to address the first concern, and have significantly lowered 
concurrency control and other implementation overheads in recent years. 
However, fine grained resource allocation remains a challenge in threaded 
systems, and is Wake&#x2019;s primary advantage over threading.</p>
+<p>Early event driven systems such as SEDA executed each event handler in a 
dedicated thread pool called a stage. This isolated low-latency event handlers 
(such as cache lookups) from expensive high-latency operations, such as disk 
I/O. With a single thread pool, high-latency I/O operations can easily 
monopolize the thread pool, causing all of the CPUs to block on disk I/O, even 
when there is computation to be scheduled. With separate thread pools, the 
operating system schedules I/O requests and computation separately, 
guaranteeing that runnable computations will not block on I/O requests.</p>
+<p>This is in contrast to event-driven systems such as the Click modular 
router that were designed to maximize throughput for predictable, low latency 
event-handlers. When possible, Click aggressively chains event handlers 
together, reducing the cost of an event dispatch to that of a function call, 
and allowing the compiler to perform optimizations such as inlining and 
constant propagation across event handlers.</p>
+<p>Wake allows developers to trade off between these two extremes by 
explicitly partitioning their event handlers into stages. Within a stage, event 
handlers engage in <i>thread-sharing</i> by simply calling each other directly. 
When an event crosses a stage boundary, it is placed in a queue of similar 
events. The queue is then drained by the threads managed by the receiving 
stage.</p>
+<p>Although event handling systems improve upon threaded performance in 
theory, they are notoriously difficult to reason about. We kept this in mind 
while designing Wake, and have gone to great pains to ensure that its APIs are 
simple and easy to implement without sacrificing our performance goals.</p>
+<p>Other event driven systems provide support for so-called <i>push-based</i> 
and <i>pull-based</i> event handlers. In push-based systems, event sources 
invoke event handlers that are exposed by the events&#x2019; destinations, 
while pull-based APIs have the destination code invoke iterators to obtain the 
next available event from the source.</p>
+<p>Wake is completely push based. This eliminates the need for push and pull 
based variants of event handling logic, and also allowed us to unify all error 
handling in Wake into a single API. It is always possible to convert between 
push and pull based APIs by inserting a queue and a thread boundary between the 
push and pull based code. Wake supports libraries and applications that use 
this trick, since operating systems and legacy code sometimes expose pull-based 
APIs.</p>
+<p>Systems such as Rx allow event handlers to be dynamically registered and 
torn down at runtime, allowing applications to evolve over time. This leads to 
complicated setup and teardown protocols, where event handlers need to reason 
about the state of upstream and downstream handlers, both during setup and 
teardown, but also when routing messages at runtime. It also encourages design 
patterns such as dynamic event dispatching that break standard compiler 
optimizations. In contrast, Wake applications consist of immutable graphs of 
event handlers that are built up from sink to source. This ensures that, once 
an event handler has been instantiated, all downstream handlers are ready to 
receive messages.</p>
+<p>Wake is designed to work with <a href="tang.html">Tang</a>, a dependency 
injection system that focuses on configuration and debuggability. This makes it 
extremely easy to wire up complicated graphs of event handling logic. In 
addition to making it easy to build up event-driven applications, Tang provides 
a range of static analysis tools and provides a simple aspect-style programming 
facility that supports Wake&#x2019;s latency and throughput profilers.</p></div>
+<div class="section">
+<h2>Core API<a name="Core_API"></a></h2>
+<div class="section">
+<h3>Event Handlers<a name="Event_Handlers"></a></h3>
+<p>Wake provides two APIs for event handler implementations. The first is the 
<a class="externalLink" 
href="https://github.com/apache/incubator-reef/blob/master/reef-wake/wake/src/main/java/org/apache/reef/wake/EventHandler.java";>EventHandler</a>
 interface:</p>
+
+<div class="source"><pre class="prettyprint">public interface 
EventHandler&lt;T&gt; {
+  void onNext(T value);
+}
+</pre></div>
+<p>Callers of <tt>onNext()</tt> should assume that it is asynchronous, and 
that it always succeeds. Unrecoverable errors should be reported by throwing a 
runtime exception (which should not be caught, and will instead take down the 
process). Recoverable errors are reported by invoking an event handler that 
contains the appropriate error handling logic.</p>
+<p>The latter approach can be implemented by registering separate event 
handlers for each type of error. However, for convenience, it is formalized in 
Wake&#x2019;s simplified version of the Rx <a class="externalLink" 
href="https://github.com/apache/incubator-reef/blob/master/reef-wake/wake/src/main/java/org/apache/reef/wake/rx/Observer.java";>Observer</a>
 interface:</p>
+
+<div class="source"><pre class="prettyprint">public interface 
Observer&lt;T&gt; {
+  void onNext(final T value);
+  void onError(final Exception error);
+  void onCompleted();
+}
+</pre></div>
+<p>The <tt>Observer</tt> is designed for stateful event handlers that need to 
be explicitly torn down at exit, or when errors occor. Such event handlers may 
maintain open network sockets, write to disk, buffer output, and so on. As with 
<tt>onNext()</tt>, neither <tt>onError()</tt> nor <tt>onCompleted()</tt> throw 
exceptions. Instead, callers should assume that they are asynchronously 
invoked.</p>
+<p><tt>EventHandler</tt> and <tt>Observer</tt> implementations should be 
threadsafe and handle concurrent invocations of <tt>onNext()</tt>. However, it 
is illegal to call <tt>onCompleted()</tt> or <tt>onError()</tt> in race with 
any calls to <tt>onNext()</tt>, and the call to <tt>onCompleted()</tt> or 
<tt>onError()</tt> must be the last call made to the object. Therefore, 
implementations of <tt>onCompleted()</tt> and <tt>onError()</tt> can assume 
they have a lock on <tt>this</tt>, and that <tt>this</tt> has not been torn 
down and is still in a valid state.</p>
+<p>We chose these invariants because they are simple and easy to enforce. In 
most cases, application logic simply limits calls to <tt>onCompleted()</tt> and 
<tt>onError()</tt> to other implementations of <tt>onError()</tt> and 
<tt>onCompleted()</tt>, and relies upon Wake (and any intervening application 
logic) to obey the same protocol.</p></div>
+<div class="section">
+<h3>Stages<a name="Stages"></a></h3>
+<p>Wake Stages are responsible for resource management. The base <a 
class="externalLink" 
href="https://github.com/apache/incubator-reef/blob/master/reef-wake/wake/src/main/java/org/apache/reef/wake/Stage.java";>Stage</a>
 interface is fairly simple:</p>
+
+<div class="source"><pre class="prettyprint">public interface Stage extends 
AutoCloseable { }
+</pre></div>
+<p>The only method it contains is <tt>close()</tt> from auto-closable. This 
reflects the fact that Wake stages can either contain <tt>EventHandler</tt>s, 
as <a class="externalLink" 
href="https://github.com/apache/incubator-reef/blob/master/reef-wake/wake/src/main/java/org/apache/reef/wake/EStage.java";>EStage</a>
 implementations do:</p>
+
+<div class="source"><pre class="prettyprint">public interface EStage&lt;T&gt; 
extends EventHandler&lt;T&gt;, Stage { }
+</pre></div>
+<p>or they can contain <tt>Observable</tt>s, as <a class="externalLink" 
href="https://github.com/apache/incubator-reef/blob/master/reef-wake/wake/src/main/java/org/apache/reef/wake/rx/RxStage.java";>RxStage</a>
 implementations do:</p>
+
+<div class="source"><pre class="prettyprint">public interface RxStage&lt;T&gt; 
extends Observer&lt;T&gt;, Stage { }
+</pre></div>
+<p>In both cases, the stage simply exposes the same API as the event handler 
that it manages. This allows code that produces events to treat downstream 
stages and raw <tt>EventHandlers</tt> / <tt>Observers</tt> interchangebly. 
Recall that Wake implements thread sharing by allowing EventHandlers and 
Observers to directly invoke each other. Since Stages implement the same 
interface as raw EventHandlers and Observers, this pushes the placement of 
thread boundaries and other scheduling tradeoffs to the code that is 
instantiating the application. In turn, this simplifies testing and improves 
the reusability of code written on top of Wake.</p>
+<div class="section">
+<h4>close() vs. onCompleted()<a name="close_vs._onCompleted"></a></h4>
+<p>It may seem strange that Wake RxStage exposes two shutdown methods: 
<tt>close()</tt> and <tt>onCompleted()</tt>. Since <tt>onCompleted()</tt> is 
part of the Observer API, it may be implemented in an asynchronous fashion. 
This makes it difficult for applications to cleanly shut down, since, even 
after <tt>onCompleted()</tt> has returned, resources may still be held by the 
downstream code.</p>
+<p>In contrast, <tt>close()</tt> is synchronous, and is not allowed to return 
until all queued events have been processed, and any resources held by the 
Stage implementation have been released. The upshot is that shutdown sequences 
in Wake work as follows: Once the upstream event sources are done calling 
<tt>onNext()</tt> (and all calls to <tt>onNext()</tt> have returned), 
<tt>onCompleted()</tt> or <tt>onError()</tt> is called exactly once per stage. 
After the <tt>onCompleted()</tt> or <tt>onError()</tt> call to a given stage 
has returned, <tt>close()</tt> must be called. Once <tt>close()</tt> returns, 
all resources have been released, and the JVM may safely exit, or the code that 
is invoking Wake may proceed under the assumption that no resources or memory 
have been leaked. Note that, depending on the implementation of the downstream 
Stage, there may be a delay between the return of calls such as 
<tt>onNext()</tt> or <tt>onCompleted()</tt> and their execution. Therefore, it 
is poss
 ible that the stage will continue to schedule <tt>onNext()</tt> calls after 
<tt>close()</tt> has been invoked. It is illegal for stages to drop events on 
shutdown, so the stage will execute the requests in its queue before it 
releases resources and returns from <tt>close()</tt>.</p>
+<p><tt>Observer</tt> implementations do not expose a <tt>close()</tt> method, 
and generally do not invoke <tt>close()</tt>. Instead, when 
<tt>onCompleted()</tt> is invoked, it should arrange for <tt>onCompleted()</tt> 
to be called on any <tt>Observer</tt> instances that <tt>this</tt> directly 
invokes, free any resources it is holding, and then return. Since the 
downstream <tt>onCompleted()</tt> calls are potentially asynchronous, it cannot 
assume that downstream cleanup completes before it returns.</p>
+<p>In a thread pool <tt>Stage</tt>, the final <tt>close()</tt> call will block 
until there are no more outstanding events queued in the stage. Once 
<tt>close()</tt> has been called (and returns) on each stage, no events are 
left in any queues, and no <tt>Observer</tt> or <tt>EventHandler</tt> objects 
are holding resources or scheduled on any cores, so shutdown is 
compelete.</p></div></div></div>
+<div class="section">
+<h2>Helper libraries<a name="Helper_libraries"></a></h2>
+<p>Wake includes a number of standard library packages:</p>
+
+<ul>
+  
+<li><tt>org.apache.reef.wake.time</tt> allows events to be scheduled in the 
future, and notifies the application when it starts and when it is being torn 
down.</li>
+  
+<li><tt>org.apache.reef.wake.remote</tt> provides networking primitives, 
including hooks into netty (a high-performance event-based networking library 
for Java).</li>
+  
+<li><tt>org.apache.reef.wake.metrics</tt> provides implementations of standard 
latency and throughput instrumentation.</li>
+  
+<li><tt>org.apache.reef.wake.profiler</tt> provides a graphical profiler that 
automatically instruments Tang-based Wake applications.</li>
+</ul></div>
+                  </div>
+            </div>
+          </div>
+
+    <hr/>
+
+    <footer>
+            <div class="container-fluid">
+                      <div class="row-fluid">
+                                                                          
+<div class="container-fluid">
+  <div class="row-fluid">
+    <a href="http://www.apache.org";>Apache Software Foundation</a>
+  </div>
+</div>
+                                                          
+<div class="row span12">Apache REEF, REEF, Apache, the Apache feather logo, 
and the Apache REEF logo are trademarks
+                       of The Apache Software Foundation. All other marks 
mentioned may be trademarks or registered
+                       trademarks of their respective owners.</div>
+                          </div>
+
+        
+                </div>
+    </footer>
+        </body>
 </html>
\ No newline at end of file


Reply via email to