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 [4/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/java/index.html
URL: http://svn.apache.org/viewvc/thrift/site/publish/tutorial/java/index.html?rev=1574384&r1=1574383&r2=1574384&view=diff
==============================================================================
--- thrift/site/publish/tutorial/java/index.html (original)
+++ thrift/site/publish/tutorial/java/index.html Wed Mar  5 05:40:00 2014
@@ -68,142 +68,210 @@
   	<div class="container">
 		<h2>Java 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 java 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>
 
-<p>The Java tutorial includes an ant file; running <code>ant build</code> will bring in the libraries required for running the tutorial.</p>
+<h3>Prerequisites</h3>
 
 <h3>Client</h3>
 
-<div class="CodeRay"><div class="code"><pre><code class="language-java">TTransport transport = <span style="color:#080;font-weight:bold">new</span> 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>);
-transport.open();
-
-TProtocol protocol = <span style="color:#080;font-weight:bold">new</span>  TBinaryProtocol(transport);
-Calculator.Client client = <span style="color:#080;font-weight:bold">new</span> Calculator.Client(protocol);
+<pre><code class="language-java"><span style="color:#080;font-weight:bold">import</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">shared</span>.*;
 
-client.ping();
-<span style="color:#0a5;font-weight:bold">System</span>.out.println(<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">import</span> <span style="color:#B44;font-weight:bold">org.apache.thrift.TException</span>;
+<span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">org.apache.thrift.transport.TSSLTransportFactory</span>;
+<span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">org.apache.thrift.transport.TTransport</span>;
+<span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">org.apache.thrift.transport.TSocket</span>;
+<span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">org.apache.thrift.transport.TSSLTransportFactory.TSSLTransportParameters</span>;
+<span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">org.apache.thrift.protocol.TBinaryProtocol</span>;
+<span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">org.apache.thrift.protocol.TProtocol</span>;
+
+<span style="color:#088;font-weight:bold">public</span> <span style="color:#339;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">JavaClient</span> {
+  <span style="color:#088;font-weight:bold">public</span> <span style="color:#088;font-weight:bold">static</span> <span style="color:#339;font-weight:bold">void</span> main(<span style="color:#0a5;font-weight:bold">String</span> <span style="color:#339;font-weight:bold">[]</span> args) {
+
+    <span style="color:#080;font-weight:bold">if</span> (args.length != <span style="color:#00D">1</span>) {
+      <span style="color:#0a5;font-weight:bold">System</span>.out.println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Please enter 'simple' or 'secure'</span><span style="color:#710">"</span></span>);
+      <span style="color:#0a5;font-weight:bold">System</span>.exit(<span style="color:#00D">0</span>);
+    }
 
-<span style="color:#339;font-weight:bold">int</span> sum = client.add(<span style="color:#00D">1</span>,<span style="color:#00D">1</span>);
-<span style="color:#0a5;font-weight:bold">System</span>.out.println(<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);
-
-Work work = <span style="color:#080;font-weight:bold">new</span> Work();
-
-work.op = <span style="color:#0a5;font-weight:bold">Operation</span>.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> {
-    <span style="color:#339;font-weight:bold">int</span> quotient = client.calculate(<span style="color:#00D">1</span>, work);
-    <span style="color:#0a5;font-weight:bold">System</span>.out.println(<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</span><span style="color:#710">"</span></span>);
-} <span style="color:#080;font-weight:bold">catch</span> (InvalidOperation io) {
-    <span style="color:#0a5;font-weight:bold">System</span>.out.println(<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> + io.why);
-}
-
-work.op = <span style="color:#0a5;font-weight:bold">Operation</span>.SUBTRACT;
-work.num1 = <span style="color:#00D">15</span>;
-work.num2 = <span style="color:#00D">10</span>;
-<span style="color:#080;font-weight:bold">try</span> {
-    <span style="color:#339;font-weight:bold">int</span> diff = client.calculate(<span style="color:#00D">1</span>, work);
-    <span style="color:#0a5;font-weight:bold">System</span>.out.println(<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="color:#080;font-weight:bold">catch</span> (InvalidOperation io) {
-    <span style="color:#0a5;font-weight:bold">System</span>.out.println(<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> + io.why);
-}
+    <span style="color:#080;font-weight:bold">try</span> {
+      TTransport transport;
+      <span style="color:#080;font-weight:bold">if</span> (args[<span style="color:#00D">0</span>].contains(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">simple</span><span style="color:#710">"</span></span>)) {
+        transport = <span style="color:#080;font-weight:bold">new</span> 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>);
+        transport.open();
+      }
+      <span style="color:#080;font-weight:bold">else</span> {
+        <span style="color:#777">/*
+         * Similar to the server, you can use the parameters to setup client parameters or
+         * use the default settings. On the client side, you will need a TrustStore which
+         * contains the trusted certificate along with the public key. 
+         * For this example it's a self-signed cert. 
+         */</span>
+        TSSLTransportParameters params = <span style="color:#080;font-weight:bold">new</span> TSSLTransportParameters();
+        params.setTrustStore(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">../../lib/java/test/.truststore</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">thrift</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">SunX509</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">JKS</span><span style="color:#710">"</span></span>);
+        <span style="color:#777">/*
+         * Get a client transport instead of a server transport. The connection is opened on
+         * invocation of the factory method, no need to specifically call open()
+         */</span>
+        transport = TSSLTransportFactory.getClientSocket(<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">9091</span>, <span style="color:#00D">0</span>, params);
+      }
 
-SharedStruct log = client.getStruct(<span style="color:#00D">1</span>);
-<span style="color:#0a5;font-weight:bold">System</span>.out.println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Check log: </span><span style="color:#710">"</span></span> + log.value);
+      TProtocol protocol = <span style="color:#080;font-weight:bold">new</span>  TBinaryProtocol(transport);
+      Calculator.Client client = <span style="color:#080;font-weight:bold">new</span> Calculator.Client(protocol);
 
-transport.close();</code></pre></div></div>
+      perform(client);
 
-<h3>Server</h3>
-
-<div class="CodeRay"><div class="code"><pre><code class="language-java">CalculatorHandler handler = <span style="color:#080;font-weight:bold">new</span> CalculatorHandler();
-Calculator.Processor processor = <span style="color:#080;font-weight:bold">new</span> Calculator.Processor(handler);
-TServerTransport serverTransport = <span style="color:#080;font-weight:bold">new</span> TServerSocket(<span style="color:#00D">9090</span>);
-TServer server = <span style="color:#080;font-weight:bold">new</span> TSimpleServer(<span style="color:#080;font-weight:bold">new</span> Args(serverTransport).processor(processor));
+      transport.close();
+    } <span style="color:#080;font-weight:bold">catch</span> (TException x) {
+      x.printStackTrace();
+    } 
+  }
 
-<span style="color:#0a5;font-weight:bold">System</span>.out.println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Starting the simple server...</span><span style="color:#710">"</span></span>);
-server.serve();</code></pre></div></div>
+  <span style="color:#088;font-weight:bold">private</span> <span style="color:#088;font-weight:bold">static</span> <span style="color:#339;font-weight:bold">void</span> perform(Calculator.Client client) <span style="color:#088;font-weight:bold">throws</span> TException
+  {
+    client.ping();
+    <span style="color:#0a5;font-weight:bold">System</span>.out.println(<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>);
 
-<h3>Server Handler</h3>
+    <span style="color:#339;font-weight:bold">int</span> sum = client.add(<span style="color:#00D">1</span>,<span style="color:#00D">1</span>);
+    <span style="color:#0a5;font-weight:bold">System</span>.out.println(<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);
 
-<div class="CodeRay"><div class="code"><pre><code class="language-java"><span style="color:#088;font-weight:bold">public</span> <span style="color:#339;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">CalculatorHandler</span> <span style="color:#088;font-weight:bold">implements</span> Calculator.Iface {
+    Work work = <span style="color:#080;font-weight:bold">new</span> Work();
 
-  <span style="color:#088;font-weight:bold">private</span> <span style="color:#0a5;font-weight:bold">HashMap</span> log;
+    work.op = <span style="color:#0a5;font-weight:bold">Operation</span>.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> {
+      <span style="color:#339;font-weight:bold">int</span> quotient = client.calculate(<span style="color:#00D">1</span>, work);
+      <span style="color:#0a5;font-weight:bold">System</span>.out.println(<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</span><span style="color:#710">"</span></span>);
+    } <span style="color:#080;font-weight:bold">catch</span> (InvalidOperation io) {
+      <span style="color:#0a5;font-weight:bold">System</span>.out.println(<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> + io.why);
+    }
 
-  <span style="color:#088;font-weight:bold">public</span> CalculatorHandler() {
-    log = <span style="color:#080;font-weight:bold">new</span> <span style="color:#0a5;font-weight:bold">HashMap</span>();
-  }
+    work.op = <span style="color:#0a5;font-weight:bold">Operation</span>.SUBTRACT;
+    work.num1 = <span style="color:#00D">15</span>;
+    work.num2 = <span style="color:#00D">10</span>;
+    <span style="color:#080;font-weight:bold">try</span> {
+      <span style="color:#339;font-weight:bold">int</span> diff = client.calculate(<span style="color:#00D">1</span>, work);
+      <span style="color:#0a5;font-weight:bold">System</span>.out.println(<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="color:#080;font-weight:bold">catch</span> (InvalidOperation io) {
+      <span style="color:#0a5;font-weight:bold">System</span>.out.println(<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> + io.why);
+    }
 
-  <span style="color:#088;font-weight:bold">public</span> <span style="color:#339;font-weight:bold">void</span> ping() {
-    <span style="color:#0a5;font-weight:bold">System</span>.out.println(<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>);
+    SharedStruct log = client.getStruct(<span style="color:#00D">1</span>);
+    <span style="color:#0a5;font-weight:bold">System</span>.out.println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Check log: </span><span style="color:#710">"</span></span> + log.value);
   }
+}</code></pre>
 
-  <span style="color:#088;font-weight:bold">public</span> <span style="color:#339;font-weight:bold">int</span> add(<span style="color:#339;font-weight:bold">int</span> n1, <span style="color:#339;font-weight:bold">int</span> n2) {
-    <span style="color:#0a5;font-weight:bold">System</span>.out.println(<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:#710">"</span></span>);
-    <span style="color:#080;font-weight:bold">return</span> n1 + n2;
-  }
+<h3>Server</h3>
 
-  <span style="color:#088;font-weight:bold">public</span> <span style="color:#339;font-weight:bold">int</span> calculate(<span style="color:#339;font-weight:bold">int</span> logid, Work work) <span style="color:#088;font-weight:bold">throws</span> InvalidOperation {
-    <span style="color:#0a5;font-weight:bold">System</span>.out.println(<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:#710">"</span></span>);
-    <span style="color:#339;font-weight:bold">int</span> val = <span style="color:#00D">0</span>;
-    <span style="color:#080;font-weight:bold">switch</span> (work.op) {
-    <span style="color:#080;font-weight:bold">case</span> ADD:
-      val = work.num1 + work.num2;
-      <span style="color:#080;font-weight:bold">break</span>;
-    <span style="color:#080;font-weight:bold">case</span> SUBTRACT:
-      val = work.num1 - work.num2;
-      <span style="color:#080;font-weight:bold">break</span>;
-    <span style="color:#080;font-weight:bold">case</span> MULTIPLY:
-      val = work.num1 * work.num2;
-      <span style="color:#080;font-weight:bold">break</span>;
-    <span style="color:#080;font-weight:bold">case</span> DIVIDE:
-      <span style="color:#080;font-weight:bold">if</span> (work.num2 == <span style="color:#00D">0</span>) {
-        InvalidOperation io = <span style="color:#080;font-weight:bold">new</span> InvalidOperation();
-        io.what = work.op.getValue();
-        io.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> io;
-      }
-      val = work.num1 / work.num2;
-      <span style="color:#080;font-weight:bold">break</span>;
-    <span style="color:#080;font-weight:bold">default</span>:
-      InvalidOperation io = <span style="color:#080;font-weight:bold">new</span> InvalidOperation();
-      io.what = work.op.getValue();
-      io.why = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Unknown operation</span><span style="color:#710">"</span></span>;
-      <span style="color:#080;font-weight:bold">throw</span> io;
+<pre><code class="language-java"><span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">org.apache.thrift.server.TServer</span>;
+<span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">org.apache.thrift.server.TServer.Args</span>;
+<span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">org.apache.thrift.server.TSimpleServer</span>;
+<span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">org.apache.thrift.server.TThreadPoolServer</span>;
+<span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">org.apache.thrift.transport.TSSLTransportFactory</span>;
+<span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">org.apache.thrift.transport.TServerSocket</span>;
+<span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">org.apache.thrift.transport.TServerTransport</span>;
+<span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">org.apache.thrift.transport.TSSLTransportFactory.TSSLTransportParameters</span>;
+
+<span style="color:#777">// Generated code</span>
+<span style="color:#080;font-weight:bold">import</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">shared</span>.*;
+
+<span style="color:#080;font-weight:bold">import</span> <span style="color:#B44;font-weight:bold">java.util.HashMap</span>;
+
+<span style="color:#088;font-weight:bold">public</span> <span style="color:#339;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">JavaServer</span> {
+
+  <span style="color:#088;font-weight:bold">public</span> <span style="color:#088;font-weight:bold">static</span> CalculatorHandler handler;
+
+  <span style="color:#088;font-weight:bold">public</span> <span style="color:#088;font-weight:bold">static</span> Calculator.Processor processor;
+
+  <span style="color:#088;font-weight:bold">public</span> <span style="color:#088;font-weight:bold">static</span> <span style="color:#339;font-weight:bold">void</span> main(<span style="color:#0a5;font-weight:bold">String</span> <span style="color:#339;font-weight:bold">[]</span> args) {
+    <span style="color:#080;font-weight:bold">try</span> {
+      handler = <span style="color:#080;font-weight:bold">new</span> CalculatorHandler();
+      processor = <span style="color:#080;font-weight:bold">new</span> Calculator.Processor(handler);
+
+      <span style="color:#0a5;font-weight:bold">Runnable</span> simple = <span style="color:#080;font-weight:bold">new</span> <span style="color:#0a5;font-weight:bold">Runnable</span>() {
+        <span style="color:#088;font-weight:bold">public</span> <span style="color:#339;font-weight:bold">void</span> run() {
+          simple(processor);
+        }
+      };      
+      <span style="color:#0a5;font-weight:bold">Runnable</span> secure = <span style="color:#080;font-weight:bold">new</span> <span style="color:#0a5;font-weight:bold">Runnable</span>() {
+        <span style="color:#088;font-weight:bold">public</span> <span style="color:#339;font-weight:bold">void</span> run() {
+          secure(processor);
+        }
+      };
+
+      <span style="color:#080;font-weight:bold">new</span> <span style="color:#0a5;font-weight:bold">Thread</span>(simple).start();
+      <span style="color:#080;font-weight:bold">new</span> <span style="color:#0a5;font-weight:bold">Thread</span>(secure).start();
+    } <span style="color:#080;font-weight:bold">catch</span> (<span style="color:#C00;font-weight:bold">Exception</span> x) {
+      x.printStackTrace();
     }
-
-    SharedStruct entry = <span style="color:#080;font-weight:bold">new</span> SharedStruct();
-    entry.key = logid;
-    entry.value = <span style="color:#0a5;font-weight:bold">Integer</span>.toString(val);
-    log.put(logid, entry);
-
-    <span style="color:#080;font-weight:bold">return</span> val;
   }
 
-  <span style="color:#088;font-weight:bold">public</span> SharedStruct getStruct(<span style="color:#339;font-weight:bold">int</span> key) {
-    <span style="color:#0a5;font-weight:bold">System</span>.out.println(<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:#710">"</span></span>);
-    <span style="color:#080;font-weight:bold">return</span> log.get(key);
+  <span style="color:#088;font-weight:bold">public</span> <span style="color:#088;font-weight:bold">static</span> <span style="color:#339;font-weight:bold">void</span> simple(Calculator.Processor processor) {
+    <span style="color:#080;font-weight:bold">try</span> {
+      TServerTransport serverTransport = <span style="color:#080;font-weight:bold">new</span> TServerSocket(<span style="color:#00D">9090</span>);
+      TServer server = <span style="color:#080;font-weight:bold">new</span> TSimpleServer(<span style="color:#080;font-weight:bold">new</span> Args(serverTransport).processor(processor));
+
+      <span style="color:#777">// Use this for a multithreaded server</span>
+      <span style="color:#777">// TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));</span>
+
+      <span style="color:#0a5;font-weight:bold">System</span>.out.println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Starting the simple server...</span><span style="color:#710">"</span></span>);
+      server.serve();
+    } <span style="color:#080;font-weight:bold">catch</span> (<span style="color:#C00;font-weight:bold">Exception</span> e) {
+      e.printStackTrace();
+    }
   }
 
-  <span style="color:#088;font-weight:bold">public</span> <span style="color:#339;font-weight:bold">void</span> zip() {
-    <span style="color:#0a5;font-weight:bold">System</span>.out.println(<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:#088;font-weight:bold">public</span> <span style="color:#088;font-weight:bold">static</span> <span style="color:#339;font-weight:bold">void</span> secure(Calculator.Processor processor) {
+    <span style="color:#080;font-weight:bold">try</span> {
+      <span style="color:#777">/*
+       * Use TSSLTransportParameters to setup the required SSL parameters. In this example
+       * we are setting the keystore and the keystore password. Other things like algorithms,
+       * cipher suites, client auth etc can be set. 
+       */</span>
+      TSSLTransportParameters params = <span style="color:#080;font-weight:bold">new</span> TSSLTransportParameters();
+      <span style="color:#777">// The Keystore contains the private key</span>
+      params.setKeyStore(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">../../lib/java/test/.keystore</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">thrift</span><span style="color:#710">"</span></span>, <span style="color:#069">null</span>, <span style="color:#069">null</span>);
+
+      <span style="color:#777">/*
+       * Use any of the TSSLTransportFactory to get a server transport with the appropriate
+       * SSL configuration. You can use the default settings if properties are set in the command line.
+       * Ex: -Djavax.net.ssl.keyStore=.keystore and -Djavax.net.ssl.keyStorePassword=thrift
+       * 
+       * Note: You need not explicitly call open(). The underlying server socket is bound on return
+       * from the factory class. 
+       */</span>
+      TServerTransport serverTransport = TSSLTransportFactory.getServerSocket(<span style="color:#00D">9091</span>, <span style="color:#00D">0</span>, <span style="color:#069">null</span>, params);
+      TServer server = <span style="color:#080;font-weight:bold">new</span> TSimpleServer(<span style="color:#080;font-weight:bold">new</span> Args(serverTransport).processor(processor));
+
+      <span style="color:#777">// Use this for a multi threaded server</span>
+      <span style="color:#777">// TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));</span>
+
+      <span style="color:#0a5;font-weight:bold">System</span>.out.println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Starting the secure server...</span><span style="color:#710">"</span></span>);
+      server.serve();
+    } <span style="color:#080;font-weight:bold">catch</span> (<span style="color:#C00;font-weight:bold">Exception</span> e) {
+      e.printStackTrace();
+    }
   }
-
-}</code></pre></div></div>
+}</code></pre>
 
 <h2>Additional Information</h2>
+
 	</div>
 	<div class="container">
 	<hr>

Modified: thrift/site/publish/tutorial/javame/index.html
URL: http://svn.apache.org/viewvc/thrift/site/publish/tutorial/javame/index.html?rev=1574384&r1=1574383&r2=1574384&view=diff
==============================================================================
--- thrift/site/publish/tutorial/javame/index.html (original)
+++ thrift/site/publish/tutorial/javame/index.html Wed Mar  5 05:40:00 2014
@@ -68,28 +68,33 @@
   	<div class="container">
 		<h2>Java Me 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 javame 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-java"></code></pre></div></div>
+<pre><code class="language-java"></code></pre>
 
 <h3>Server</h3>
 
 <h2>Additional Information</h2>
+
 	</div>
 	<div class="container">
 	<hr>

Modified: thrift/site/publish/tutorial/js/index.html
URL: http://svn.apache.org/viewvc/thrift/site/publish/tutorial/js/index.html?rev=1574384&r1=1574383&r2=1574384&view=diff
==============================================================================
--- thrift/site/publish/tutorial/js/index.html (original)
+++ thrift/site/publish/tutorial/js/index.html Wed Mar  5 05:40:00 2014
@@ -68,26 +68,32 @@
   	<div class="container">
 		<h2>Javascript 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 js 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>
 
 <ul>
 <li>This tutorial depends on an existing Thrift server. See either the <a href="/tutorial/java/">Java tutorial</a> or <a href="/tutorial/cpp/">C++ tutorial</a> for how to build and setup one of these servers.</li>
-</ul><h3>Client</h3>
+</ul>
 
-<div class="CodeRay"><div class="code"><pre><code class="language-js"><span style="color:#080;font-weight:bold">function</span> <span style="color:#06B;font-weight:bold">calc</span>() {
+<h3>Client</h3>
+
+<pre><code class="language-js"><span style="color:#080;font-weight:bold">function</span> <span style="color:#06B;font-weight:bold">calc</span>() {
     <span style="color:#080;font-weight:bold">var</span> transport = <span style="color:#080;font-weight:bold">new</span> Thrift.Transport(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">/thrift/service/tutorial/</span><span style="color:#710">"</span></span>);
     <span style="color:#080;font-weight:bold">var</span> protocol  = <span style="color:#080;font-weight:bold">new</span> Thrift.Protocol(transport);
     <span style="color:#080;font-weight:bold">var</span> client    = <span style="color:#080;font-weight:bold">new</span> CalculatorClient(protocol);
@@ -105,7 +111,7 @@
       <span style="color:#369;font-weight:bold">$</span>(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">#result</span><span style="color:#710">'</span></span>).val(ouch.why);
       <span style="color:#369;font-weight:bold">$</span>(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">#result</span><span style="color:#710">'</span></span>).css(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">color</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">red</span><span style="color:#710">'</span></span>);
     }
-}</code></pre></div></div>
+}</code></pre>
 
 <h3>Server</h3>
 
@@ -195,6 +201,7 @@ Once the object is created, we can now p
 <li>The Protocol layer handles the encoding/decoding to JSON format.</li>
 <li>There are also the Thrift object types and call functions defined here as well.</li>
 </ul>
+
 	</div>
 	<div class="container">
 	<hr>

Modified: thrift/site/publish/tutorial/nodejs/index.html
URL: http://svn.apache.org/viewvc/thrift/site/publish/tutorial/nodejs/index.html?rev=1574384&r1=1574383&r2=1574384&view=diff
==============================================================================
--- thrift/site/publish/tutorial/nodejs/index.html (original)
+++ thrift/site/publish/tutorial/nodejs/index.html Wed Mar  5 05:40:00 2014
@@ -68,24 +68,28 @@
   	<div class="container">
 		<h2>Node.js 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 js:node 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-js"><span style="color:#080;font-weight:bold">var</span> thrift = 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>);
+<pre><code class="language-javascript"><span style="color:#080;font-weight:bold">var</span> thrift = 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>);
 <span style="color:#080;font-weight:bold">var</span> ThriftTransports = require(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">thrift/transport</span><span style="color:#710">'</span></span>);
 <span style="color:#080;font-weight:bold">var</span> ThriftProtocols = require(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">thrift/protocol</span><span style="color:#710">'</span></span>);
 <span style="color:#080;font-weight:bold">var</span> Calculator = require(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">./gen-nodejs/Calculator</span><span style="color:#710">'</span></span>);
@@ -136,19 +140,14 @@ work.num1 = <span style="color:#00D">15<
 work.num2 = <span style="color:#00D">10</span>;
 
 client.calculate(<span style="color:#00D">1</span>, work, <span style="color:#080;font-weight:bold">function</span>(err, message) {
-  console.log(<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> + message.value);
+  console.log(<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> + message);
 
   client.getStruct(<span style="color:#00D">1</span>, <span style="color:#080;font-weight:bold">function</span>(err, message){
-    console.log(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Check log: </span><span style="color:#710">'</span></span> + message.value);
-
-    <span style="color:#777">//close the connection once we're done</span>
-    connection.end();
-  });
-});</code></pre></div></div>
+    console.log(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Check log: </span><span style="color:#710">'</span></span> + message.value);</code></pre>
 
 <h3>Server</h3>
 
-<div class="CodeRay"><div class="code"><pre><code class="language-js"><span style="color:#080;font-weight:bold">var</span> thrift = 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>);
+<pre><code class="language-javascript"><span style="color:#080;font-weight:bold">var</span> thrift = 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>);
 <span style="color:#080;font-weight:bold">var</span> Calculator = require(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">./gen-nodejs/Calculator</span><span style="color:#710">"</span></span>);
 <span style="color:#080;font-weight:bold">var</span> ttypes = require(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">./gen-nodejs/tutorial_types</span><span style="color:#710">"</span></span>);
 <span style="color:#080;font-weight:bold">var</span> SharedStruct = require(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">./gen-nodejs/shared_types</span><span style="color:#710">"</span></span>).SharedStruct;
@@ -213,7 +212,10 @@ client.calculate(<span style="color:#00D
 
 });
 
-server.listen(<span style="color:#00D">9090</span>);</code></pre></div></div>
+server.listen(<span style="color:#00D">9090</span>);</code></pre>
+
+<h2>Additional Information</h2>
+
 	</div>
 	<div class="container">
 	<hr>

Modified: thrift/site/publish/tutorial/ocaml/index.html
URL: http://svn.apache.org/viewvc/thrift/site/publish/tutorial/ocaml/index.html?rev=1574384&r1=1574383&r2=1574384&view=diff
==============================================================================
--- thrift/site/publish/tutorial/ocaml/index.html (original)
+++ thrift/site/publish/tutorial/ocaml/index.html Wed Mar  5 05:40:00 2014
@@ -68,28 +68,158 @@
   	<div class="container">
 		<h2>OCaml 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 ocaml 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-java"></code></pre></div></div>
+<pre><code class="language-cpp">open Arg
+open Thrift
+open Tutorial_types
+open Shared_types
+
+exception Die;;
+let sod = function
+    Some v -&gt; v
+  | None -&gt; raise Die;;
+
+type connection = {
+  trans : Transport.t ;
+  proto : Thrift.Protocol.t;
+  calc : Calculator.client ;
+}
+
+let connect ~host port =
+  let tx = <span style="color:#080;font-weight:bold">new</span> TSocket.t host port in
+  let proto = <span style="color:#080;font-weight:bold">new</span> TBinaryProtocol.t tx in
+  let calc = <span style="color:#080;font-weight:bold">new</span> Calculator.client proto proto in
+    tx<span style="color:#579">#opn</span>;
+    { trans = tx ; proto = proto; calc = calc }
+;;
+
+let doclient () =
+  let cli = connect ~host:<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">127.0.0.1</span><span style="color:#710">"</span></span> <span style="color:#00D">9090</span> in
+  <span style="color:#080;font-weight:bold">try</span>
+    cli.calc<span style="color:#579">#ping</span> ;
+    Printf.printf <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> ; flush stdout ;
+    (let sum = cli.calc<span style="color:#579">#add</span> (Int32.of_int <span style="color:#00D">1</span>) (Int32.of_int <span style="color:#00D">1</span>) in
+       Printf.printf <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">1+1=%ld</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span> sum ;
+       flush stdout) ;
+    (let w = <span style="color:#080;font-weight:bold">new</span> work in
+       w<span style="color:#579">#set_op</span> Operation.DIVIDE ;
+       w<span style="color:#579">#set_num1</span> (Int32.of_int <span style="color:#00D">1</span>) ;
+       w<span style="color:#579">#set_num2</span> (Int32.of_int <span style="color:#00D">0</span>) ;
+       <span style="color:#080;font-weight:bold">try</span>
+         let quotient = cli.calc<span style="color:#579">#calculate</span> (Int32.of_int <span style="color:#00D">1</span>) w in
+           Printf.printf <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> ; flush stdout
+       with InvalidOperation io -&gt;
+         Printf.printf <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">InvalidOperation: %s</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span> io<span style="color:#579">#grab_why</span> ; flush stdout) ;
+    (let w = <span style="color:#080;font-weight:bold">new</span> work in
+       w<span style="color:#579">#set_op</span> Operation.SUBTRACT ;
+       w<span style="color:#579">#set_num1</span> (Int32.of_int <span style="color:#00D">15</span>) ;
+       w<span style="color:#579">#set_num2</span> (Int32.of_int <span style="color:#00D">10</span>) ;
+       let diff = cli.calc<span style="color:#579">#calculate</span> (Int32.of_int <span style="color:#00D">1</span>) w in
+         Printf.printf <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">15-10=%ld</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span> diff ; flush stdout) ;
+    (let ss = cli.calc<span style="color:#579">#getStruct</span> (Int32.of_int <span style="color:#00D">1</span>) in
+       Printf.printf <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:#b0b">\n</span><span style="color:#710">"</span></span> ss<span style="color:#579">#grab_value</span> ; flush stdout) ;
+    cli.trans<span style="color:#579">#close</span>
+  with Transport.E (_,what) -&gt;
+    Printf.printf <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">ERROR: %s</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span> what ; flush stdout
+;;
+
+doclient();;</code></pre>
 
 <h3>Server</h3>
 
+<pre><code class="language-cpp">open Arg
+open Thrift
+open Tutorial_types
+open Shared_types
+
+exception Die;;
+let sod = function
+    Some v -&gt; v
+  | None -&gt; raise Die;;
+
+<span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">calc_handler</span> =
+object (self)
+  inherit Calculator.iface
+  val log = Hashtbl.create <span style="color:#00D">23</span>
+  method ping  = Printf.printf <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> ; flush stdout
+  method add a b =
+    Printf.printf<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">add(%ld,%ld)</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span> (sod a) (sod b); flush stdout ;
+    Int32.add (sod a) (sod b)
+  method calculate logid w =
+    let w = sod w in
+      Printf.printf <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">calculate(%ld,{%ld,%ld,%ld})</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span> (sod logid) (Operation.to_i w<span style="color:#579">#grab_op</span>) w<span style="color:#579">#grab_num1</span> w<span style="color:#579">#grab_num2</span>; flush stdout ;
+    let rv =
+      match w<span style="color:#579">#grab_op</span> with
+          Operation.ADD -&gt;
+            Int32.add w<span style="color:#579">#grab_num1</span> w<span style="color:#579">#grab_num2</span>
+        | Operation.SUBTRACT -&gt;
+            Int32.sub w<span style="color:#579">#grab_num1</span> w<span style="color:#579">#grab_num2</span>
+        | Operation.MULTIPLY -&gt;
+            Int32.mul w<span style="color:#579">#grab_num1</span> w<span style="color:#579">#grab_num2</span>
+        | Operation.DIVIDE -&gt;
+            <span style="color:#080;font-weight:bold">if</span> w<span style="color:#579">#grab_num2</span> = Int32.zero then
+              let io = <span style="color:#080;font-weight:bold">new</span> invalidOperation in
+                io<span style="color:#579">#set_what</span> (Operation.to_i w<span style="color:#579">#grab_op</span>) ;
+                io<span style="color:#579">#set_why</span> <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 (InvalidOperation io)
+            <span style="color:#080;font-weight:bold">else</span>
+              Int32.div w<span style="color:#579">#grab_num1</span> w<span style="color:#579">#grab_num2</span> in
+
+    let ss = <span style="color:#080;font-weight:bold">new</span> sharedStruct in
+      ss<span style="color:#579">#set_key</span> (sod logid) ;
+    let buffer = Int32.to_string rv in
+      ss<span style="color:#579">#set_value</span> buffer ;
+      Hashtbl.add log (sod logid) ss ;
+      rv
+
+  method zip =
+    Printf.printf <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>; flush stdout
+
+  method getStruct logid =
+    Printf.printf <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">getStruct(%ld)</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span> (sod logid) ; flush stdout ;
+    Hashtbl.find log (sod logid)
+
+end
+
+let doserver () =
+  let h = <span style="color:#080;font-weight:bold">new</span> calc_handler in
+  let proc = <span style="color:#080;font-weight:bold">new</span> Calculator.processor h in
+  let port = <span style="color:#00D">9090</span> in
+  let pf = <span style="color:#080;font-weight:bold">new</span> TBinaryProtocol.factory in
+  let server = <span style="color:#080;font-weight:bold">new</span> TThreadedServer.t
+                 proc
+                 (<span style="color:#080;font-weight:bold">new</span> TServerSocket.t port)
+                 (<span style="color:#080;font-weight:bold">new</span> Transport.factory)
+                 pf
+                 pf
+  in
+    server<span style="color:#579">#serve</span>
+;;
+
+doserver();;</code></pre>
+
 <h2>Additional Information</h2>
+
 	</div>
 	<div class="container">
 	<hr>

Modified: thrift/site/publish/tutorial/perl/index.html
URL: http://svn.apache.org/viewvc/thrift/site/publish/tutorial/perl/index.html?rev=1574384&r1=1574383&r2=1574384&view=diff
==============================================================================
--- thrift/site/publish/tutorial/perl/index.html (original)
+++ thrift/site/publish/tutorial/perl/index.html Wed Mar  5 05:40:00 2014
@@ -68,28 +68,158 @@
   	<div class="container">
 		<h2>Perl 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 perl 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-ruby"><span style="color:#777">#</span>
+
+use strict;
+use warnings;
+
+use lib <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">../../lib/perl/lib</span><span style="color:#710">'</span></span>;
+use lib <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">../gen-perl</span><span style="color:#710">'</span></span>;
+
+use <span style="color:#036;font-weight:bold">Thrift</span>;
+use <span style="color:#036;font-weight:bold">Thrift</span>::<span style="color:#036;font-weight:bold">BinaryProtocol</span>;
+use <span style="color:#036;font-weight:bold">Thrift</span>::<span style="color:#036;font-weight:bold">Socket</span>;
+use <span style="color:#036;font-weight:bold">Thrift</span>::<span style="color:#036;font-weight:bold">BufferedTransport</span>;
+
+use shared::<span style="color:#036;font-weight:bold">SharedService</span>;
+use tutorial::<span style="color:#036;font-weight:bold">Calculator</span>;
+use shared::<span style="color:#036;font-weight:bold">Types</span>;
+use tutorial::<span style="color:#036;font-weight:bold">Types</span>;
+
+use <span style="color:#036;font-weight:bold">Data</span>::<span style="color:#036;font-weight:bold">Dumper</span>;
+
+my <span style="color:#d70">$socket</span>    = new <span style="color:#036;font-weight:bold">Thrift</span>::Socket(<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>);
+my <span style="color:#d70">$transport</span> = new <span style="color:#036;font-weight:bold">Thrift</span>::BufferedTransport(<span style="color:#d70">$socket</span>,<span style="color:#00D">1024</span>,<span style="color:#00D">1024</span>);
+my <span style="color:#d70">$protocol</span>  = new <span style="color:#036;font-weight:bold">Thrift</span>::BinaryProtocol(<span style="color:#d70">$transport</span>);
+my <span style="color:#d70">$client</span>    = new tutorial::CalculatorClient(<span style="color:#d70">$protocol</span>);
+
+
+eval{
+    <span style="color:#d70">$transport</span>-&gt;open();
+
+    <span style="color:#d70">$client</span>-&gt;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>;
+
+
+    my <span style="color:#d70">$sum</span> = <span style="color:#d70">$client</span>-&gt;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=$sum</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>;
+
+    my <span style="color:#d70">$work</span> = new tutorial::Work();
+
+    <span style="color:#d70">$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:#d70">$work</span>-&gt;num1(<span style="color:#00D">1</span>);
+    <span style="color:#d70">$work</span>-&gt;num2(<span style="color:#00D">0</span>);
+
+    eval {
+        <span style="color:#d70">$client</span>-&gt;calculate(<span style="color:#00D">1</span>, <span style="color:#d70">$work</span>);
+        print <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">if</span>(<span style="color:#d70">$@</span>) {
+        warn <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>.Dumper(<span style="color:#d70">$@</span>);
+    }
+
+    <span style="color:#d70">$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:#d70">$work</span>-&gt;num1(<span style="color:#00D">15</span>);
+    <span style="color:#d70">$work</span>-&gt;num2(<span style="color:#00D">10</span>);
+    my <span style="color:#d70">$diff</span> = <span style="color:#d70">$client</span>-&gt;calculate(<span style="color:#00D">1</span>, <span style="color:#d70">$work</span>);
+    print <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">15-10=$diff</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>;
+
+    my <span style="color:#d70">$log</span> = <span style="color:#d70">$client</span>-&gt;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: $log-&gt;{value}</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>;
+
+    <span style="color:#d70">$transport</span>-&gt;close();</code></pre>
 
 <h3>Server</h3>
 
+<pre><code class="language-ruby"><span style="color:#777">#</span>
+
+use strict;
+use lib <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">../gen-perl</span><span style="color:#710">'</span></span>;
+use <span style="color:#036;font-weight:bold">Thrift</span>::<span style="color:#036;font-weight:bold">Socket</span>;
+use <span style="color:#036;font-weight:bold">Thrift</span>::<span style="color:#036;font-weight:bold">Server</span>;
+use tutorial::<span style="color:#036;font-weight:bold">Calculator</span>;
+
+package <span style="color:#036;font-weight:bold">CalculatorHandler</span>;
+use base qw(tutorial::<span style="color:#036;font-weight:bold">CalculatorIf</span>);
+
+sub new {
+    my <span style="color:#d70">$classname</span> = shift;
+    my <span style="color:#d70">$self</span>      = {};
+
+    <span style="color:#080;font-weight:bold">return</span> bless(<span style="color:#d70">$self</span>,<span style="color:#d70">$classname</span>);
+}
+
+
+sub 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>;
+}
+
+sub add
+{
+  my(<span style="color:#d70">$self</span>, <span style="color:#d70">$n1</span>, <span style="color:#d70">$n2</span>) = <span style="color:#33B">@_</span>;
+  printf(<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:#b0b">\n</span><span style="color:#710">"</span></span>, <span style="color:#d70">$n1</span>, <span style="color:#d70">$n2</span>);
+  <span style="color:#080;font-weight:bold">return</span> <span style="color:#d70">$n1</span> + <span style="color:#d70">$n2</span>;
+}
+
+sub calculate
+{
+  my(<span style="color:#d70">$self</span>, <span style="color:#d70">$logid</span>, <span style="color:#d70">$work</span>) = <span style="color:#33B">@_</span>;
+  my <span style="color:#d70">$op</span>   = <span style="color:#d70">$work</span>-&gt;{op};
+  my <span style="color:#d70">$num1</span> = <span style="color:#d70">$work</span>-&gt;{num1};
+  my <span style="color:#d70">$num2</span> = <span style="color:#d70">$work</span>-&gt;{num2};
+  printf(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">calculate(%d, %d %d %d)</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>, <span style="color:#d70">$logid</span>, <span style="color:#d70">$num1</span>, <span style="color:#d70">$num2</span>, <span style="color:#d70">$op</span>);
+
+  my <span style="color:#d70">$val</span>;
+
+  <span style="color:#080;font-weight:bold">if</span> (<span style="color:#d70">$op</span> == tutorial::<span style="color:#036;font-weight:bold">Operation</span>::<span style="color:#036;font-weight:bold">ADD</span>) {
+    <span style="color:#d70">$val</span> = <span style="color:#d70">$num1</span> + <span style="color:#d70">$num2</span>;
+  } <span style="color:#080;font-weight:bold">elsif</span> (<span style="color:#d70">$op</span> == tutorial::<span style="color:#036;font-weight:bold">Operation</span>::<span style="color:#036;font-weight:bold">SUBTRACT</span>) {
+    <span style="color:#d70">$val</span> = <span style="color:#d70">$num1</span> - <span style="color:#d70">$num2</span>;
+  } <span style="color:#080;font-weight:bold">elsif</span> (<span style="color:#d70">$op</span> == tutorial::<span style="color:#036;font-weight:bold">Operation</span>::<span style="color:#036;font-weight:bold">MULTIPLY</span>) {
+    <span style="color:#d70">$val</span> = <span style="color:#d70">$num1</span> * <span style="color:#d70">$num2</span>;
+  } <span style="color:#080;font-weight:bold">elsif</span> (<span style="color:#d70">$op</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:#d70">$num2</span> == <span style="color:#00D">0</span>)
+    {
+      my <span style="color:#d70">$x</span> = new tutorial::<span style="color:#036;font-weight:bold">InvalidOperation</span>;
+      <span style="color:#d70">$x</span>-&gt;what(<span style="color:#d70">$op</span>);
+      <span style="color:#d70">$x</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>);
+      die <span style="color:#d70">$x</span>;
+    }
+    <span style="color:#d70">$val</span> = <span style="color:#d70">$num1</span> / <span style="color:#d70">$num2</span>;
+  } <span style="color:#080;font-weight:bold">else</span> {
+    my <span style="color:#d70">$x</span> = new tutorial::<span style="color:#036;font-weight:bold">InvalidOperation</span>;
+    <span style="color:#d70">$x</span>-&gt;what(<span style="color:#d70">$op</span>);
+    <span style="color:#d70">$x</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>);
+    die <span style="color:#d70">$x</span>;
+  }
+
+  my <span style="color:#d70">$log</span> = new shared::<span style="color:#036;font-weight:bold">SharedStruct</span>;
+  <span style="color:#d70">$log</span>-&gt;key(<span style="color:#d70">$logid</span>);
+  <span style="color:#d70">$log</span>-&gt;value(int(<span style="color:#d70">$val</span>));</code></pre>
+
 <h2>Additional Information</h2>
+
 	</div>
 	<div class="container">
 	<hr>