You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by jf...@apache.org on 2014/03/05 06:40:02 UTC

svn commit: r1574384 [5/5] - in /thrift/site: ./ content/ content/tutorial/ layouts/ lib/ publish/ publish/about/ publish/developers/ publish/docs/ publish/docs/BuildingFromSource/ publish/docs/HowToContribute/ publish/docs/committers/ publish/docs/com...

Modified: thrift/site/publish/tutorial/php/index.html
URL: http://svn.apache.org/viewvc/thrift/site/publish/tutorial/php/index.html?rev=1574384&r1=1574383&r2=1574384&view=diff
==============================================================================
--- thrift/site/publish/tutorial/php/index.html (original)
+++ thrift/site/publish/tutorial/php/index.html Wed Mar  5 05:40:00 2014
@@ -68,28 +68,252 @@
   	<div class="container">
 		<h2>PHP Tutorial</h2>
 
-<hr><h3>Introduction</h3>
+<hr>
+
+<h3>Introduction</h3>
 
 <p>All Apache Thrift tutorials require that you have:</p>
 
 <ol>
-<li>Built and installed the Apache Thrift Compiler and Libraries, see <a href="/docs/BuildingFromSource/">Building from source</a> for more details. </li>
+<li>Built and installed the Apache Thrift Compiler and Libraries, see <a href="/docs/BuildingFromSource/">Building from source</a> for more details.</li>
 <li>
 <p>Generated the <a href="https://git-wip-us.apache.org/repos/asf?p=thrift.git;a=blob_plain;f=tutorial/tutorial.thrift">tutorial.thrift</a> file as <a href="/tutorial/">discussed here</a></p>
 
 <pre><code>thrift -r --gen php tutorial.thrift
 </code></pre>
 </li>
-<li><p>Followed all prerequesets listed </p></li>
-</ol><h3>Prerequisites</h3>
+<li><p>Followed all prerequesets listed</p></li>
+</ol>
+
+<h3>Prerequisites</h3>
 
 <h3>Client</h3>
 
-<div class="CodeRay"><div class="code"><pre><code class="language-php"></code></pre></div></div>
+<pre><code class="language-php"><span style="font-weight:bold;color:#666">&lt;?php</span>
+
+<span style="color:#080;font-weight:bold">namespace</span> tutorial\php;
+
+<span style="color:#369;font-weight:bold">error_reporting</span>(<span style="color:#C00;font-weight:bold">E_ALL</span>);
+
+<span style="color:#369;font-weight:bold">require_once</span> <span style="color:#069">__DIR__</span>.<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/../../lib/php/lib/Thrift/ClassLoader/ThriftClassLoader.php</span><span style="color:#710">'</span></span>;
+
+<span style="color:#080;font-weight:bold">use</span> <span style="color:#036;font-weight:bold">Thrift</span>\<span style="color:#036;font-weight:bold">ClassLoader</span>\<span style="color:#036;font-weight:bold">ThriftClassLoader</span>;
+
+<span style="color:#963">$GEN_DIR</span> = <span style="color:#369;font-weight:bold">realpath</span>(<span style="color:#369;font-weight:bold">dirname</span>(<span style="color:#069">__FILE__</span>).<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/..</span><span style="color:#710">'</span></span>).<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/gen-php</span><span style="color:#710">'</span></span>;
+
+<span style="color:#963">$loader</span> = <span style="color:#080;font-weight:bold">new</span> <span style="color:#036;font-weight:bold">ThriftClassLoader</span>();
+<span style="color:#963">$loader</span>-&gt;registerNamespace(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Thrift</span><span style="color:#710">'</span></span>, <span style="color:#069">__DIR__</span> . <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/../../lib/php/lib</span><span style="color:#710">'</span></span>);
+<span style="color:#963">$loader</span>-&gt;registerDefinition(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">shared</span><span style="color:#710">'</span></span>, <span style="color:#963">$GEN_DIR</span>);
+<span style="color:#963">$loader</span>-&gt;registerDefinition(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">tutorial</span><span style="color:#710">'</span></span>, <span style="color:#963">$GEN_DIR</span>);
+<span style="color:#963">$loader</span>-&gt;register();
+
+<span style="color:#777">/*
+ * 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.
+ */</span>
+
+<span style="color:#080;font-weight:bold">use</span> <span style="color:#036;font-weight:bold">Thrift</span>\<span style="color:#036;font-weight:bold">Protocol</span>\<span style="color:#036;font-weight:bold">TBinaryProtocol</span>;
+<span style="color:#080;font-weight:bold">use</span> <span style="color:#036;font-weight:bold">Thrift</span>\<span style="color:#036;font-weight:bold">Transport</span>\<span style="color:#036;font-weight:bold">TSocket</span>;
+<span style="color:#080;font-weight:bold">use</span> <span style="color:#036;font-weight:bold">Thrift</span>\<span style="color:#036;font-weight:bold">Transport</span>\<span style="color:#036;font-weight:bold">THttpClient</span>;
+<span style="color:#080;font-weight:bold">use</span> <span style="color:#036;font-weight:bold">Thrift</span>\<span style="color:#036;font-weight:bold">Transport</span>\<span style="color:#036;font-weight:bold">TBufferedTransport</span>;
+<span style="color:#080;font-weight:bold">use</span> <span style="color:#036;font-weight:bold">Thrift</span>\<span style="color:#069">Exception</span>\<span style="color:#036;font-weight:bold">TException</span>;
+
+<span style="color:#080;font-weight:bold">try</span> {
+  <span style="color:#080;font-weight:bold">if</span> (<span style="color:#369;font-weight:bold">array_search</span>(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">--http</span><span style="color:#710">'</span></span>, <span style="color:#369;font-weight:bold">$argv</span>)) {
+    <span style="color:#963">$socket</span> = <span style="color:#080;font-weight:bold">new</span> <span style="color:#036;font-weight:bold">THttpClient</span>(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">localhost</span><span style="color:#710">'</span></span>, <span style="color:#00D">8080</span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/php/PhpServer.php</span><span style="color:#710">'</span></span>);
+  } <span style="color:#080;font-weight:bold">else</span> {
+    <span style="color:#963">$socket</span> = <span style="color:#080;font-weight:bold">new</span> <span style="color:#036;font-weight:bold">TSocket</span>(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">localhost</span><span style="color:#710">'</span></span>, <span style="color:#00D">9090</span>);
+  }
+  <span style="color:#963">$transport</span> = <span style="color:#080;font-weight:bold">new</span> <span style="color:#036;font-weight:bold">TBufferedTransport</span>(<span style="color:#963">$socket</span>, <span style="color:#00D">1024</span>, <span style="color:#00D">1024</span>);
+  <span style="color:#963">$protocol</span> = <span style="color:#080;font-weight:bold">new</span> <span style="color:#036;font-weight:bold">TBinaryProtocol</span>(<span style="color:#963">$transport</span>);
+  <span style="color:#963">$client</span> = <span style="color:#080;font-weight:bold">new</span> \tutorial\<span style="color:#036;font-weight:bold">CalculatorClient</span>(<span style="color:#963">$protocol</span>);
+
+  <span style="color:#963">$transport</span>-&gt;open();
+
+  <span style="color:#963">$client</span>-&gt;ping();
+  <span style="color:#369;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">ping()</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>;
+
+  <span style="color:#963">$sum</span> = <span style="color:#963">$client</span>-&gt;add(<span style="color:#00D">1</span>,<span style="color:#00D">1</span>);
+  <span style="color:#369;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">1+1=</span><span style="color:#963">$sum</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>;
+
+  <span style="color:#963">$work</span> = <span style="color:#080;font-weight:bold">new</span> \tutorial\<span style="color:#036;font-weight:bold">Work</span>();
+
+  <span style="color:#963">$work</span>-&gt;op = \tutorial\<span style="color:#036;font-weight:bold">Operation</span>::<span style="color:#036;font-weight:bold">DIVIDE</span>;
+  <span style="color:#963">$work</span>-&gt;num1 = <span style="color:#00D">1</span>;
+  <span style="color:#963">$work</span>-&gt;num2 = <span style="color:#00D">0</span>;
+
+  <span style="color:#080;font-weight:bold">try</span> {
+    <span style="color:#963">$client</span>-&gt;calculate(<span style="color:#00D">1</span>, <span style="color:#963">$work</span>);
+    <span style="color:#369;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Whoa! We can divide by zero?</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>;
+  } <span style="color:#080;font-weight:bold">catch</span> (\tutorial\<span style="color:#036;font-weight:bold">InvalidOperation</span> <span style="color:#963">$io</span>) {
+    <span style="color:#369;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">InvalidOperation: </span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="color:#963">$io</span>-&gt;why</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>;
+  }
+
+  <span style="color:#963">$work</span>-&gt;op = \tutorial\<span style="color:#036;font-weight:bold">Operation</span>::<span style="color:#036;font-weight:bold">SUBTRACT</span>;
+  <span style="color:#963">$work</span>-&gt;num1 = <span style="color:#00D">15</span>;
+  <span style="color:#963">$work</span>-&gt;num2 = <span style="color:#00D">10</span>;
+  <span style="color:#963">$diff</span> = <span style="color:#963">$client</span>-&gt;calculate(<span style="color:#00D">1</span>, <span style="color:#963">$work</span>);
+  <span style="color:#369;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">15-10=</span><span style="color:#963">$diff</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>;
+
+  <span style="color:#963">$log</span> = <span style="color:#963">$client</span>-&gt;getStruct(<span style="color:#00D">1</span>);
+  <span style="color:#369;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Log: </span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="color:#963">$log</span>-&gt;value</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>;
+
+  <span style="color:#963">$transport</span>-&gt;close();
+
+} <span style="color:#080;font-weight:bold">catch</span> (<span style="color:#036;font-weight:bold">TException</span> <span style="color:#963">$tx</span>) {
+  <span style="color:#369;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">TException: </span><span style="color:#710">'</span></span>.<span style="color:#963">$tx</span>-&gt;getMessage().<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>;
+}
+
+<span style="font-weight:bold;color:#666">?&gt;</span></code></pre>
 
 <h3>Server</h3>
 
+<pre><code class="language-php"><span style="font-weight:bold;color:#666">&lt;?php</span>
+
+<span style="color:#080;font-weight:bold">namespace</span> tutorial\php;
+
+<span style="color:#369;font-weight:bold">error_reporting</span>(<span style="color:#C00;font-weight:bold">E_ALL</span>);
+
+<span style="color:#369;font-weight:bold">require_once</span> <span style="color:#069">__DIR__</span>.<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/../../lib/php/lib/Thrift/ClassLoader/ThriftClassLoader.php</span><span style="color:#710">'</span></span>;
+
+<span style="color:#080;font-weight:bold">use</span> <span style="color:#036;font-weight:bold">Thrift</span>\<span style="color:#036;font-weight:bold">ClassLoader</span>\<span style="color:#036;font-weight:bold">ThriftClassLoader</span>;
+
+<span style="color:#963">$GEN_DIR</span> = <span style="color:#369;font-weight:bold">realpath</span>(<span style="color:#369;font-weight:bold">dirname</span>(<span style="color:#069">__FILE__</span>).<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/..</span><span style="color:#710">'</span></span>).<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/gen-php</span><span style="color:#710">'</span></span>;
+
+<span style="color:#963">$loader</span> = <span style="color:#080;font-weight:bold">new</span> <span style="color:#036;font-weight:bold">ThriftClassLoader</span>();
+<span style="color:#963">$loader</span>-&gt;registerNamespace(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Thrift</span><span style="color:#710">'</span></span>, <span style="color:#069">__DIR__</span> . <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/../../lib/php/lib</span><span style="color:#710">'</span></span>);
+<span style="color:#963">$loader</span>-&gt;registerDefinition(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">shared</span><span style="color:#710">'</span></span>, <span style="color:#963">$GEN_DIR</span>);
+<span style="color:#963">$loader</span>-&gt;registerDefinition(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">tutorial</span><span style="color:#710">'</span></span>, <span style="color:#963">$GEN_DIR</span>);
+<span style="color:#963">$loader</span>-&gt;register();
+
+<span style="color:#777">/*
+ * 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.
+ */</span>
+
+<span style="color:#777">/*
+ * This is not a stand-alone server.  It should be run as a normal
+ * php web script (like through Apache's mod_php) or as a cgi script
+ * (like with the included runserver.py).  You can connect to it with
+ * THttpClient in any language that supports it.  The PHP tutorial client
+ * will work if you pass it the argument "--http".
+ */</span>
+
+<span style="color:#080;font-weight:bold">if</span> (<span style="color:#369;font-weight:bold">php_sapi_name</span>() == <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">cli</span><span style="color:#710">'</span></span>) {
+  ini_set(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">display_errors</span><span style="color:#710">"</span></span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">stderr</span><span style="color:#710">"</span></span>);
+}
+
+<span style="color:#080;font-weight:bold">use</span> <span style="color:#036;font-weight:bold">Thrift</span>\<span style="color:#036;font-weight:bold">Protocol</span>\<span style="color:#036;font-weight:bold">TBinaryProtocol</span>;
+<span style="color:#080;font-weight:bold">use</span> <span style="color:#036;font-weight:bold">Thrift</span>\<span style="color:#036;font-weight:bold">Transport</span>\<span style="color:#036;font-weight:bold">TPhpStream</span>;
+<span style="color:#080;font-weight:bold">use</span> <span style="color:#036;font-weight:bold">Thrift</span>\<span style="color:#036;font-weight:bold">Transport</span>\<span style="color:#036;font-weight:bold">TBufferedTransport</span>;
+
+<span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">CalculatorHandler</span> <span style="color:#080;font-weight:bold">implements</span> \tutorial\<span style="color:#036;font-weight:bold">CalculatorIf</span> {
+  <span style="color:#080;font-weight:bold">protected</span> <span style="color:#963">$log</span> = <span style="color:#369;font-weight:bold">array</span>();
+
+  <span style="color:#080;font-weight:bold">public</span> <span style="color:#080;font-weight:bold">function</span> <span style="color:#06B;font-weight:bold">ping</span>() {
+    <span style="color:#369;font-weight:bold">error_log</span>(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">ping()</span><span style="color:#710">"</span></span>);
+  }
+
+  <span style="color:#080;font-weight:bold">public</span> <span style="color:#080;font-weight:bold">function</span> <span style="color:#06B;font-weight:bold">add</span>(<span style="color:#963">$num1</span>, <span style="color:#963">$num2</span>) {
+    <span style="color:#369;font-weight:bold">error_log</span>(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">add(</span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="color:black">{</span><span style="color:#963">$num1</span><span style="color:black">}</span></span><span style="color:#D20">, </span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="color:black">{</span><span style="color:#963">$num2</span><span style="color:black">}</span></span><span style="color:#D20">)</span><span style="color:#710">"</span></span>);
+    <span style="color:#080;font-weight:bold">return</span> <span style="color:#963">$num1</span> + <span style="color:#963">$num2</span>;
+  }
+
+  <span style="color:#080;font-weight:bold">public</span> <span style="color:#080;font-weight:bold">function</span> <span style="color:#06B;font-weight:bold">calculate</span>(<span style="color:#963">$logid</span>, \tutorial\<span style="color:#036;font-weight:bold">Work</span> <span style="color:#963">$w</span>) {
+    <span style="color:#369;font-weight:bold">error_log</span>(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">calculate(</span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="color:black">{</span><span style="color:#963">$logid</span><span style="color:black">}</span></span><span style="color:#D20">, </span><span style="color:#D20">{</span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="color:black">{</span><span style="color:#963">$w</span>-&gt;op<span style="color:black">}</span></span><span style="color:#D20">, </span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="color:black">{</span><span style="color:#963">$w</span>-&gt;num1<span style="color:black">}</span></span><span style="color:#D20">, </span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="color:black">{</span><span style="color:#963">$w</span>-&gt;num
 2<span style="color:black">}</span></span><span style="color:#D20">})</span><span style="color:#710">"</span></span>);
+    <span style="color:#080;font-weight:bold">switch</span> (<span style="color:#963">$w</span>-&gt;op) {
+      <span style="color:#080;font-weight:bold">case</span> \tutorial\<span style="color:#036;font-weight:bold">Operation</span>::<span style="color:#036;font-weight:bold">ADD</span>:
+        <span style="color:#963">$val</span> = <span style="color:#963">$w</span>-&gt;num1 + <span style="color:#963">$w</span>-&gt;num2;
+        <span style="color:#080;font-weight:bold">break</span>;
+      <span style="color:#080;font-weight:bold">case</span> \tutorial\<span style="color:#036;font-weight:bold">Operation</span>::<span style="color:#036;font-weight:bold">SUBTRACT</span>:
+        <span style="color:#963">$val</span> = <span style="color:#963">$w</span>-&gt;num1 - <span style="color:#963">$w</span>-&gt;num2;
+        <span style="color:#080;font-weight:bold">break</span>;
+      <span style="color:#080;font-weight:bold">case</span> \tutorial\<span style="color:#036;font-weight:bold">Operation</span>::<span style="color:#036;font-weight:bold">MULTIPLY</span>:
+        <span style="color:#963">$val</span> = <span style="color:#963">$w</span>-&gt;num1 * <span style="color:#963">$w</span>-&gt;num2;
+        <span style="color:#080;font-weight:bold">break</span>;
+      <span style="color:#080;font-weight:bold">case</span> \tutorial\<span style="color:#036;font-weight:bold">Operation</span>::<span style="color:#036;font-weight:bold">DIVIDE</span>:
+        <span style="color:#080;font-weight:bold">if</span> (<span style="color:#963">$w</span>-&gt;num2 == <span style="color:#00D">0</span>) {
+          <span style="color:#963">$io</span> = <span style="color:#080;font-weight:bold">new</span> \tutorial\<span style="color:#036;font-weight:bold">InvalidOperation</span>();
+          <span style="color:#963">$io</span>-&gt;what = <span style="color:#963">$w</span>-&gt;op;
+          <span style="color:#963">$io</span>-&gt;why = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Cannot divide by 0</span><span style="color:#710">"</span></span>;
+          <span style="color:#080;font-weight:bold">throw</span> <span style="color:#963">$io</span>;
+        }
+        <span style="color:#963">$val</span> = <span style="color:#963">$w</span>-&gt;num1 / <span style="color:#963">$w</span>-&gt;num2;
+        <span style="color:#080;font-weight:bold">break</span>;
+      <span style="color:#080;font-weight:bold">default</span>:
+        <span style="color:#963">$io</span> = <span style="color:#080;font-weight:bold">new</span> \tutorial\<span style="color:#036;font-weight:bold">InvalidOperation</span>();
+        <span style="color:#963">$io</span>-&gt;what = <span style="color:#963">$w</span>-&gt;op;
+        <span style="color:#963">$io</span>-&gt;why = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Invalid Operation</span><span style="color:#710">"</span></span>;
+        <span style="color:#080;font-weight:bold">throw</span> <span style="color:#963">$io</span>;
+    }
+
+    <span style="color:#963">$log</span> = <span style="color:#080;font-weight:bold">new</span> \shared\<span style="color:#036;font-weight:bold">SharedStruct</span>();
+    <span style="color:#963">$log</span>-&gt;<span style="color:#369;font-weight:bold">key</span> = <span style="color:#963">$logid</span>;
+    <span style="color:#963">$log</span>-&gt;value = (<span style="color:#0a5;font-weight:bold">string</span>)<span style="color:#963">$val</span>;
+    <span style="color:#963">$this</span>-&gt;<span style="color:#369;font-weight:bold">log</span>[<span style="color:#963">$logid</span>] = <span style="color:#963">$log</span>;
+
+    <span style="color:#080;font-weight:bold">return</span> <span style="color:#963">$val</span>;
+  }
+
+  <span style="color:#080;font-weight:bold">public</span> <span style="color:#080;font-weight:bold">function</span> <span style="color:#06B;font-weight:bold">getStruct</span>(<span style="color:#963">$key</span>) {
+    <span style="color:#369;font-weight:bold">error_log</span>(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">getStruct(</span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="color:black">{</span><span style="color:#963">$key</span><span style="color:black">}</span></span><span style="color:#D20">)</span><span style="color:#710">"</span></span>);
+    <span style="color:#777">// This actually doesn't work because the PHP interpreter is</span>
+    <span style="color:#777">// restarted for every request.</span>
+    <span style="color:#777">//return $this-&gt;log[$key];</span>
+    <span style="color:#080;font-weight:bold">return</span> <span style="color:#080;font-weight:bold">new</span> \shared\<span style="color:#036;font-weight:bold">SharedStruct</span>(<span style="color:#369;font-weight:bold">array</span>(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">key</span><span style="color:#710">"</span></span> =&gt; <span style="color:#963">$key</span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">value</span><span style="color:#710">"</span></span> =&gt; <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">PHP is stateless!</span><span style="color:#710">"</span></span>));
+  }
+
+  <span style="color:#080;font-weight:bold">public</span> <span style="color:#080;font-weight:bold">function</span> <span style="color:#06B;font-weight:bold">zip</span>() {
+    <span style="color:#369;font-weight:bold">error_log</span>(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">zip()</span><span style="color:#710">"</span></span>);
+  }
+
+};
+
+<span style="color:#369;font-weight:bold">header</span>(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Content-Type</span><span style="color:#710">'</span></span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">application/x-thrift</span><span style="color:#710">'</span></span>);
+<span style="color:#080;font-weight:bold">if</span> (<span style="color:#369;font-weight:bold">php_sapi_name</span>() == <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">cli</span><span style="color:#710">'</span></span>) {
+  <span style="color:#369;font-weight:bold">echo</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#b0b">\r</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>;
+}
+
+<span style="color:#963">$handler</span> = <span style="color:#080;font-weight:bold">new</span> <span style="color:#036;font-weight:bold">CalculatorHandler</span>();
+<span style="color:#963">$processor</span> = <span style="color:#080;font-weight:bold">new</span> \tutorial\<span style="color:#036;font-weight:bold">CalculatorProcessor</span>(<span style="color:#963">$handler</span>);
+
+<span style="color:#963">$transport</span> = <span style="color:#080;font-weight:bold">new</span> <span style="color:#036;font-weight:bold">TBufferedTransport</span>(<span style="color:#080;font-weight:bold">new</span> <span style="color:#036;font-weight:bold">TPhpStream</span>(<span style="color:#036;font-weight:bold">TPhpStream</span>::<span style="color:#036;font-weight:bold">MODE_R</span> | <span style="color:#036;font-weight:bold">TPhpStream</span>::<span style="color:#036;font-weight:bold">MODE_W</span>));
+<span style="color:#963">$protocol</span> = <span style="color:#080;font-weight:bold">new</span> <span style="color:#036;font-weight:bold">TBinaryProtocol</span>(<span style="color:#963">$transport</span>, <span style="color:#069">true</span>, <span style="color:#069">true</span>);
+
+<span style="color:#963">$transport</span>-&gt;open();
+<span style="color:#963">$processor</span>-&gt;process(<span style="color:#963">$protocol</span>, <span style="color:#963">$protocol</span>);
+<span style="color:#963">$transport</span>-&gt;close();</code></pre>
+
 <h2>Additional Information</h2>
+
 	</div>
 	<div class="container">
 	<hr>

Modified: thrift/site/publish/tutorial/py/index.html
URL: http://svn.apache.org/viewvc/thrift/site/publish/tutorial/py/index.html?rev=1574384&r1=1574383&r2=1574384&view=diff
==============================================================================
--- thrift/site/publish/tutorial/py/index.html (original)
+++ thrift/site/publish/tutorial/py/index.html Wed Mar  5 05:40:00 2014
@@ -68,28 +68,171 @@
   	<div class="container">
 		<h2>Python Tutorial</h2>
 
-<hr><h3>Introduction</h3>
+<hr>
+
+<h3>Introduction</h3>
 
 <p>All Apache Thrift tutorials require that you have:</p>
 
 <ol>
-<li>Built and installed the Apache Thrift Compiler and Libraries, see <a href="/docs/BuildingFromSource/">Building from source</a> for more details. </li>
+<li>Built and installed the Apache Thrift Compiler and Libraries, see <a href="/docs/BuildingFromSource/">Building from source</a> for more details.</li>
 <li>
 <p>Generated the <a href="https://git-wip-us.apache.org/repos/asf?p=thrift.git;a=blob_plain;f=tutorial/tutorial.thrift">tutorial.thrift</a> file as <a href="/tutorial/">discussed here</a></p>
 
 <pre><code>thrift -r --gen py tutorial.thrift
 </code></pre>
 </li>
-<li><p>Followed all prerequesets listed </p></li>
-</ol><h3>Prerequisites</h3>
+<li><p>Followed all prerequesets listed</p></li>
+</ol>
+
+<h3>Prerequisites</h3>
 
 <h3>Client</h3>
 
-<div class="CodeRay"><div class="code"><pre><code class="language-python"></code></pre></div></div>
+<pre><code class="language-python"><span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">sys</span>, <span style="color:#B44;font-weight:bold">glob</span>
+sys.path.append(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">gen-py</span><span style="color:#710">'</span></span>)
+sys.path.insert(<span style="color:#00D">0</span>, glob.glob(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">../../lib/py/build/lib.*</span><span style="color:#710">'</span></span>)[<span style="color:#00D">0</span>])
+
+<span style="color:#080;font-weight:bold">from</span> <span style="color:#B44;font-weight:bold">tutorial</span> <span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">Calculator</span>
+<span style="color:#080;font-weight:bold">from</span> <span style="color:#B44;font-weight:bold">tutorial.ttypes</span> <span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">*</span>
+
+<span style="color:#080;font-weight:bold">from</span> <span style="color:#B44;font-weight:bold">thrift</span> <span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">Thrift</span>
+<span style="color:#080;font-weight:bold">from</span> <span style="color:#B44;font-weight:bold">thrift.transport</span> <span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">TSocket</span>
+<span style="color:#080;font-weight:bold">from</span> <span style="color:#B44;font-weight:bold">thrift.transport</span> <span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">TTransport</span>
+<span style="color:#080;font-weight:bold">from</span> <span style="color:#B44;font-weight:bold">thrift.protocol</span> <span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">TBinaryProtocol</span>
+
+<span style="color:#080;font-weight:bold">try</span>:
+
+  <span style="color:#777"># Make socket</span>
+  transport = TSocket.TSocket(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">localhost</span><span style="color:#710">'</span></span>, <span style="color:#00D">9090</span>)
+
+  <span style="color:#777"># Buffering is critical. Raw sockets are very slow</span>
+  transport = TTransport.TBufferedTransport(transport)
+
+  <span style="color:#777"># Wrap in a protocol</span>
+  protocol = TBinaryProtocol.TBinaryProtocol(transport)
+
+  <span style="color:#777"># Create a client to use the protocol encoder</span>
+  client = Calculator.Client(protocol)
+
+  <span style="color:#777"># Connect!</span>
+  transport.open()
+
+  client.ping()
+  <span style="color:#080;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">ping()</span><span style="color:#710">'</span></span>
+
+  sum = client.add(<span style="color:#00D">1</span>,<span style="color:#00D">1</span>)
+  <span style="color:#080;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">1+1=%d</span><span style="color:#710">'</span></span> % (<span style="color:#369;font-weight:bold">sum</span>)
+
+  work = Work()
+
+  work.op = Operation.DIVIDE
+  work.num1 = <span style="color:#00D">1</span>
+  work.num2 = <span style="color:#00D">0</span>
+
+  <span style="color:#080;font-weight:bold">try</span>:
+    quotient = client.calculate(<span style="color:#00D">1</span>, work)
+    <span style="color:#080;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Whoa? You know how to divide by zero?</span><span style="color:#710">'</span></span>
+  <span style="color:#080;font-weight:bold">except</span> InvalidOperation, io:
+    <span style="color:#080;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">InvalidOperation: %r</span><span style="color:#710">'</span></span> % io
+
+  work.op = Operation.SUBTRACT
+  work.num1 = <span style="color:#00D">15</span>
+  work.num2 = <span style="color:#00D">10</span>
+
+  diff = client.calculate(<span style="color:#00D">1</span>, work)
+  <span style="color:#080;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">15-10=%d</span><span style="color:#710">'</span></span> % (diff)
+
+  log = client.getStruct(<span style="color:#00D">1</span>)
+  <span style="color:#080;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Check log: %s</span><span style="color:#710">'</span></span> % (log.value)
+
+  <span style="color:#777"># Close!</span>
+  transport.close()
+
+<span style="color:#080;font-weight:bold">except</span> Thrift.TException, tx:
+  <span style="color:#080;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">%s</span><span style="color:#710">'</span></span> % (tx.message)</code></pre>
 
 <h3>Server</h3>
 
+<pre><code class="language-python"><span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">sys</span>, <span style="color:#B44;font-weight:bold">glob</span>
+sys.path.append(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">gen-py</span><span style="color:#710">'</span></span>)
+sys.path.insert(<span style="color:#00D">0</span>, glob.glob(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">../../lib/py/build/lib.*</span><span style="color:#710">'</span></span>)[<span style="color:#00D">0</span>])
+
+<span style="color:#080;font-weight:bold">from</span> <span style="color:#B44;font-weight:bold">tutorial</span> <span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">Calculator</span>
+<span style="color:#080;font-weight:bold">from</span> <span style="color:#B44;font-weight:bold">tutorial.ttypes</span> <span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">*</span>
+
+<span style="color:#080;font-weight:bold">from</span> <span style="color:#B44;font-weight:bold">shared.ttypes</span> <span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">SharedStruct</span>
+
+<span style="color:#080;font-weight:bold">from</span> <span style="color:#B44;font-weight:bold">thrift.transport</span> <span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">TSocket</span>
+<span style="color:#080;font-weight:bold">from</span> <span style="color:#B44;font-weight:bold">thrift.transport</span> <span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">TTransport</span>
+<span style="color:#080;font-weight:bold">from</span> <span style="color:#B44;font-weight:bold">thrift.protocol</span> <span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">TBinaryProtocol</span>
+<span style="color:#080;font-weight:bold">from</span> <span style="color:#B44;font-weight:bold">thrift.server</span> <span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">TServer</span>
+
+<span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">CalculatorHandler</span>:
+  <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">__init__</span>(<span style="color:#069">self</span>):
+    <span style="color:#069">self</span>.log = {}
+
+  <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">ping</span>(<span style="color:#069">self</span>):
+    <span style="color:#080;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">ping()</span><span style="color:#710">'</span></span>
+
+  <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">add</span>(<span style="color:#069">self</span>, n1, n2):
+    <span style="color:#080;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">add(%d,%d)</span><span style="color:#710">'</span></span> % (n1, n2)
+    <span style="color:#080;font-weight:bold">return</span> n1+n2
+
+  <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">calculate</span>(<span style="color:#069">self</span>, logid, work):
+    <span style="color:#080;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">calculate(%d, %r)</span><span style="color:#710">'</span></span> % (logid, work)
+
+    <span style="color:#080;font-weight:bold">if</span> work.op == Operation.ADD:
+      val = work.num1 + work.num2
+    <span style="color:#080;font-weight:bold">elif</span> work.op == Operation.SUBTRACT:
+      val = work.num1 - work.num2
+    <span style="color:#080;font-weight:bold">elif</span> work.op == Operation.MULTIPLY:
+      val = work.num1 * work.num2
+    <span style="color:#080;font-weight:bold">elif</span> work.op == Operation.DIVIDE:
+      <span style="color:#080;font-weight:bold">if</span> work.num2 == <span style="color:#00D">0</span>:
+        x = InvalidOperation()
+        x.what = work.op
+        x.why = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Cannot divide by 0</span><span style="color:#710">'</span></span>
+        <span style="color:#080;font-weight:bold">raise</span> x
+      val = work.num1 / work.num2
+    <span style="color:#080;font-weight:bold">else</span>:
+      x = InvalidOperation()
+      x.what = work.op
+      x.why = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Invalid operation</span><span style="color:#710">'</span></span>
+      <span style="color:#080;font-weight:bold">raise</span> x
+
+    log = SharedStruct()
+    log.key = logid
+    log.value = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">%d</span><span style="color:#710">'</span></span> % (val)
+    <span style="color:#069">self</span>.log[logid] = log
+
+    <span style="color:#080;font-weight:bold">return</span> val
+
+  <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">getStruct</span>(<span style="color:#069">self</span>, key):
+    <span style="color:#080;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">getStruct(%d)</span><span style="color:#710">'</span></span> % (key)
+    <span style="color:#080;font-weight:bold">return</span> <span style="color:#069">self</span>.log[key]
+
+  <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">zip</span>(<span style="color:#069">self</span>):
+    <span style="color:#080;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">zip()</span><span style="color:#710">'</span></span>
+
+handler = CalculatorHandler()
+processor = Calculator.Processor(handler)
+transport = TSocket.TServerSocket(port=<span style="color:#00D">9090</span>)
+tfactory = TTransport.TBufferedTransportFactory()
+pfactory = TBinaryProtocol.TBinaryProtocolFactory()
+
+server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
+
+<span style="color:#777"># You could do one of these for a multithreaded server</span>
+<span style="color:#777">#server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)</span>
+<span style="color:#777">#server = TServer.TThreadPoolServer(processor, transport, tfactory, pfactory)</span>
+
+<span style="color:#080;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Starting the server...</span><span style="color:#710">'</span></span>
+server.serve()
+<span style="color:#080;font-weight:bold">print</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">done.</span><span style="color:#710">'</span></span></code></pre>
+
 <h2>Additional Information</h2>
+
 	</div>
 	<div class="container">
 	<hr>

Modified: thrift/site/publish/tutorial/rb/index.html
URL: http://svn.apache.org/viewvc/thrift/site/publish/tutorial/rb/index.html?rev=1574384&r1=1574383&r2=1574384&view=diff
==============================================================================
--- thrift/site/publish/tutorial/rb/index.html (original)
+++ thrift/site/publish/tutorial/rb/index.html Wed Mar  5 05:40:00 2014
@@ -68,28 +68,161 @@
   	<div class="container">
 		<h2>Ruby Tutorial</h2>
 
-<hr><h3>Introduction</h3>
+<hr>
+
+<h3>Introduction</h3>
 
 <p>All Apache Thrift tutorials require that you have:</p>
 
 <ol>
-<li>Built and installed the Apache Thrift Compiler and Libraries, see <a href="/docs/BuildingFromSource/">Building from source</a> for more details. </li>
+<li>Built and installed the Apache Thrift Compiler and Libraries, see <a href="/docs/BuildingFromSource/">Building from source</a> for more details.</li>
 <li>
 <p>Generated the <a href="https://git-wip-us.apache.org/repos/asf?p=thrift.git;a=blob_plain;f=tutorial/tutorial.thrift">tutorial.thrift</a> file as <a href="/tutorial/">discussed here</a></p>
 
 <pre><code>thrift -r --gen rb tutorial.thrift
 </code></pre>
 </li>
-<li><p>Followed all prerequesets listed </p></li>
-</ol><h3>Prerequisites</h3>
+<li><p>Followed all prerequesets listed</p></li>
+</ol>
+
+<h3>Prerequisites</h3>
 
 <h3>Client</h3>
 
-<div class="CodeRay"><div class="code"><pre><code class="language-ruby"></code></pre></div></div>
+<pre><code class="language-ruby"><span style="color:#d70">$:</span>.push(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">gen-rb</span><span style="color:#710">'</span></span>)
+<span style="color:#d70">$:</span>.unshift <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">../../lib/rb/lib</span><span style="color:#710">'</span></span>
+
+require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">thrift</span><span style="color:#710">'</span></span>
+
+require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">calculator</span><span style="color:#710">'</span></span>
+
+<span style="color:#080;font-weight:bold">begin</span>
+  port = <span style="color:#069">ARGV</span>[<span style="color:#00D">0</span>] || <span style="color:#00D">9090</span>
+
+  transport = <span style="color:#036;font-weight:bold">Thrift</span>::<span style="color:#036;font-weight:bold">BufferedTransport</span>.new(<span style="color:#036;font-weight:bold">Thrift</span>::<span style="color:#036;font-weight:bold">Socket</span>.new(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">localhost</span><span style="color:#710">'</span></span>, port))
+  protocol = <span style="color:#036;font-weight:bold">Thrift</span>::<span style="color:#036;font-weight:bold">BinaryProtocol</span>.new(transport)
+  client = <span style="color:#036;font-weight:bold">Calculator</span>::<span style="color:#036;font-weight:bold">Client</span>.new(protocol)
+
+  transport.open()
+
+  client.ping()
+  print <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">ping()</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>
+
+  sum = client.add(<span style="color:#00D">1</span>,<span style="color:#00D">1</span>)
+  print <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">1+1=</span><span style="color:#710">"</span></span>, sum, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>
+
+  sum = client.add(<span style="color:#00D">1</span>,<span style="color:#00D">4</span>)
+  print <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">1+4=</span><span style="color:#710">"</span></span>, sum, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>
+
+  work = <span style="color:#036;font-weight:bold">Work</span>.new()
+
+  work.op = <span style="color:#036;font-weight:bold">Operation</span>::<span style="color:#036;font-weight:bold">SUBTRACT</span>
+  work.num1 = <span style="color:#00D">15</span>
+  work.num2 = <span style="color:#00D">10</span>
+  diff = client.calculate(<span style="color:#00D">1</span>, work)
+  print <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">15-10=</span><span style="color:#710">"</span></span>, diff, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>
+
+  log = client.getStruct(<span style="color:#00D">1</span>)
+  print <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Log: </span><span style="color:#710">"</span></span>, log.value, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>
+
+  <span style="color:#080;font-weight:bold">begin</span>
+    work.op = <span style="color:#036;font-weight:bold">Operation</span>::<span style="color:#036;font-weight:bold">DIVIDE</span>
+    work.num1 = <span style="color:#00D">1</span>
+    work.num2 = <span style="color:#00D">0</span>
+    quot = client.calculate(<span style="color:#00D">1</span>, work)
+    puts <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Whoa, we can divide by 0 now?</span><span style="color:#710">"</span></span>
+  <span style="color:#080;font-weight:bold">rescue</span> <span style="color:#036;font-weight:bold">InvalidOperation</span> =&gt; io
+    print <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">InvalidOperation: </span><span style="color:#710">"</span></span>, io.why, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>
+  <span style="color:#080;font-weight:bold">end</span>
+
+  client.zip()
+  print <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">zip</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>
+
+  transport.close()
+
+<span style="color:#080;font-weight:bold">rescue</span> <span style="color:#036;font-weight:bold">Thrift</span>::<span style="color:#036;font-weight:bold">Exception</span> =&gt; tx
+  print <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Thrift::Exception: </span><span style="color:#710">'</span></span>, tx.message, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>
+<span style="color:#080;font-weight:bold">end</span></code></pre>
 
 <h3>Server</h3>
 
+<pre><code class="language-ruby"><span style="color:#d70">$:</span>.push(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">gen-rb</span><span style="color:#710">'</span></span>)
+<span style="color:#d70">$:</span>.unshift <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">../../lib/rb/lib</span><span style="color:#710">'</span></span>
+
+require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">thrift</span><span style="color:#710">'</span></span>
+
+require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">calculator</span><span style="color:#710">'</span></span>
+require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">shared_types</span><span style="color:#710">'</span></span>
+
+<span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">CalculatorHandler</span>
+  <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">initialize</span>()
+    <span style="color:#33B">@log</span> = {}
+  <span style="color:#080;font-weight:bold">end</span>
+
+  <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">ping</span>()
+    puts <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">ping()</span><span style="color:#710">"</span></span>
+  <span style="color:#080;font-weight:bold">end</span>
+
+  <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">add</span>(n1, n2)
+    print <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">add(</span><span style="color:#710">"</span></span>, n1, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">,</span><span style="color:#710">"</span></span>, n2, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">)</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>
+    <span style="color:#080;font-weight:bold">return</span> n1 + n2
+  <span style="color:#080;font-weight:bold">end</span>
+
+  <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">calculate</span>(logid, work)
+    print <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">calculate(</span><span style="color:#710">"</span></span>, logid, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">, {</span><span style="color:#710">"</span></span>, work.op, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">,</span><span style="color:#710">"</span></span>, work.num1, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">,</span><span style="color:#710">"</span></span>, work.num2,<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">})</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>
+    <span style="color:#080;font-weight:bold">if</span> work.op == <span style="color:#036;font-weight:bold">Operation</span>::<span style="color:#036;font-weight:bold">ADD</span>
+      val = work.num1 + work.num2
+    <span style="color:#080;font-weight:bold">elsif</span> work.op == <span style="color:#036;font-weight:bold">Operation</span>::<span style="color:#036;font-weight:bold">SUBTRACT</span>
+      val = work.num1 - work.num2
+    <span style="color:#080;font-weight:bold">elsif</span> work.op == <span style="color:#036;font-weight:bold">Operation</span>::<span style="color:#036;font-weight:bold">MULTIPLY</span>
+      val = work.num1 * work.num2
+    <span style="color:#080;font-weight:bold">elsif</span> work.op == <span style="color:#036;font-weight:bold">Operation</span>::<span style="color:#036;font-weight:bold">DIVIDE</span>
+      <span style="color:#080;font-weight:bold">if</span> work.num2 == <span style="color:#00D">0</span>
+        x = <span style="color:#036;font-weight:bold">InvalidOperation</span>.new()
+        x.what = work.op
+        x.why = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Cannot divide by 0</span><span style="color:#710">"</span></span>
+        raise x
+      <span style="color:#080;font-weight:bold">end</span>
+      val = work.num1 / work.num2
+    <span style="color:#080;font-weight:bold">else</span>
+      x = <span style="color:#036;font-weight:bold">InvalidOperation</span>.new()
+      x.what = work.op
+      x.why = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Invalid operation</span><span style="color:#710">"</span></span>
+      raise x
+    <span style="color:#080;font-weight:bold">end</span>
+
+    entry = <span style="color:#036;font-weight:bold">SharedStruct</span>.new()
+    entry.key = logid
+    entry.value = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="font-weight:bold;color:#666">#{</span>val<span style="font-weight:bold;color:#666">}</span></span><span style="color:#710">"</span></span>
+    <span style="color:#33B">@log</span>[logid] = entry
+
+    <span style="color:#080;font-weight:bold">return</span> val
+
+  <span style="color:#080;font-weight:bold">end</span>
+
+  <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">getStruct</span>(key)
+    print <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">getStruct(</span><span style="color:#710">"</span></span>, key, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">)</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>
+    <span style="color:#080;font-weight:bold">return</span> <span style="color:#33B">@log</span>[key]
+  <span style="color:#080;font-weight:bold">end</span>
+
+  <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">zip</span>()
+    print <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">zip</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>
+  <span style="color:#080;font-weight:bold">end</span>
+
+<span style="color:#080;font-weight:bold">end</span>
+
+handler = <span style="color:#036;font-weight:bold">CalculatorHandler</span>.new()
+processor = <span style="color:#036;font-weight:bold">Calculator</span>::<span style="color:#036;font-weight:bold">Processor</span>.new(handler)
+transport = <span style="color:#036;font-weight:bold">Thrift</span>::<span style="color:#036;font-weight:bold">ServerSocket</span>.new(<span style="color:#00D">9090</span>)
+transportFactory = <span style="color:#036;font-weight:bold">Thrift</span>::<span style="color:#036;font-weight:bold">BufferedTransportFactory</span>.new()
+server = <span style="color:#036;font-weight:bold">Thrift</span>::<span style="color:#036;font-weight:bold">SimpleServer</span>.new(processor, transport, transportFactory)
+
+puts <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Starting the server...</span><span style="color:#710">"</span></span>
+server.serve()
+puts <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">done.</span><span style="color:#710">"</span></span></code></pre>
+
 <h2>Additional Information</h2>
+
 	</div>
 	<div class="container">
 	<hr>

Modified: thrift/site/publish/tutorial/st/index.html
URL: http://svn.apache.org/viewvc/thrift/site/publish/tutorial/st/index.html?rev=1574384&r1=1574383&r2=1574384&view=diff
==============================================================================
--- thrift/site/publish/tutorial/st/index.html (original)
+++ thrift/site/publish/tutorial/st/index.html Wed Mar  5 05:40:00 2014
@@ -68,28 +68,33 @@
   	<div class="container">
 		<h2>Smalltalk Tutorial</h2>
 
-<hr><h3>Introduction</h3>
+<hr>
+
+<h3>Introduction</h3>
 
 <p>All Apache Thrift tutorials require that you have:</p>
 
 <ol>
-<li>Built and installed the Apache Thrift Compiler and Libraries, see <a href="/docs/BuildingFromSource/">Building from source</a> for more details. </li>
+<li>Built and installed the Apache Thrift Compiler and Libraries, see <a href="/docs/BuildingFromSource/">Building from source</a> for more details.</li>
 <li>
 <p>Generated the <a href="https://git-wip-us.apache.org/repos/asf?p=thrift.git;a=blob_plain;f=tutorial/tutorial.thrift">tutorial.thrift</a> file as <a href="/tutorial/">discussed here</a></p>
 
 <pre><code>thrift -r --gen st tutorial.thrift
 </code></pre>
 </li>
-<li><p>Followed all prerequesets listed </p></li>
-</ol><h3>Prerequisites</h3>
+<li><p>Followed all prerequesets listed</p></li>
+</ol>
+
+<h3>Prerequisites</h3>
 
 <h3>Client</h3>
 
-<div class="CodeRay"><div class="code"><pre><code class="language-c"></code></pre></div></div>
+<pre><code class="language-c"></code></pre>
 
 <h3>Server</h3>
 
 <h2>Additional Information</h2>
+
 	</div>
 	<div class="container">
 	<hr>