<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog4Java &#187; Asynchronous I/O</title>
	<atom:link href="http://malsolo.com/blog4java/?feed=rss2&#038;tag=asynchronous-io" rel="self" type="application/rss+xml" />
	<link>http://malsolo.com/blog4java</link>
	<description>A personal and Java blog, likely only for me</description>
	<lastBuildDate>Tue, 31 Mar 2015 15:52:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<item>
		<title>Getting started with Vert.x</title>
		<link>http://malsolo.com/blog4java/?p=35</link>
		<comments>http://malsolo.com/blog4java/?p=35#comments</comments>
		<pubDate>Tue, 08 Jul 2014 13:29:29 +0000</pubDate>
		<dc:creator><![CDATA[Javier (@jbbarquero)]]></dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Asynchronous I/O]]></category>
		<category><![CDATA[Vert.x]]></category>

		<guid isPermaLink="false">http://malsolo.com/blog4java/?p=35</guid>
		<description><![CDATA[What is Vert.x? In my humble opinion, Vert.x is a poorly documented platform for creating server applications intended to be scalable by using an event-driven, non-blocking I/O in the JVM. The first definition for Vert.x I heard was &#8220;it&#8217;s like &#8230; <a href="http://malsolo.com/blog4java/?p=35">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h4>What is Vert.x?</h4>
<p>In my humble opinion, Vert.x is a poorly documented platform for creating server applications intended to be scalable by using an event-driven, non-blocking I/O in the JVM.</p>
<p>The first definition for Vert.x I heard was <em>&#8220;it&#8217;s like Node.js but in the JVM&#8221;</em>. (Yeah!,  part of my first definition has been copied from the description that can be found at <a href="http://nodejs.org/" title="Node.js" target="_blank">Node.js</a>)</p>
<p>OK! Let&#8217;s take a look to the <a title="Vert.x" href="http://vertx.io/" target="_blank">Vert.x site</a>:</p>
<blockquote><p>&#8220;Vert.x is a lightweight, high performance application platform for the JVM that&#8217;s designed for modern mobile, web, and enterprise applications.&#8221;</p></blockquote>
<p>Terrific! Furthermore:</p>
<ul>
<li>It&#8217;s <strong>polyglot</strong>: you can write your application components in Java, JavaScript, CoffeeScript, Ruby, Python or Groovy. And you can even mix all these languages. Sincerely, I don&#8217;t find this feature exciting.</li>
<li>It has a <strong>simple</strong> APIs for writing non-blocking network enabled applications.</li>
<li>It&#8217;s <strong>scalable</strong> because it uses non blocking I/O to serve many connections with minimal threads plus passing messages to handle the logic of the application.</li>
<li>It provides a simple actor-like <strong>concurrency</strong> model, so that you don&#8217;t have to worry about multi-threaded programming anymore.</li>
</ul>
<p>Well! I still miss something here.</p>
<p>Taking a look to the <strong><em>Key Features</em></strong> you&#8217;ll learn that Vert.x has an <strong>Event Bus</strong>, a kind of Queue that will use the Vert.x components, called <strong>Verticles</strong>, to communicate between them regardless their programming language. It uses WebSockets and SockJS to achieve the JavaScript penetration that they claim.</p>
<p>Vert.x is a platform that you invoke from the command line, <code>vert.x run</code> for single Verticles or <code>vert.x runmod</code> for the encapsulation system that Vert.x provides: the <strong>module system</strong> (that can be shared via <a title="Maven Central Repository" href="http://mvnrepository.com/" target="_blank">Maven repository</a> or <a title="Bintray" href="https://bintray.com/" target="_blank">Bintray</a> and can be registered in the <a title="Vert.x Module Registry" href="http://modulereg.vertx.io/" target="_blank">module registry</a>). But it also can be embedded in a Java application.</p>
<h4>Install Vert.x</h4>
<p>Installing Vert.x is very easy:</p>
<ol>
<li>You need a Linux, OS X or Windows with JDK 1.7.0 or later installed (try <code>javac -version</code> in order to ensure that you have the JDK bin directory on your <code>PATH</code>).</li>
<li>Download the latest release of Vert.x, <a title="Vert.x Downloads" href="http://vertx.io/downloads.html" target="_blank">2.1.1 at the time of this writing</a>.</li>
<li>Decompress the download file. I like to have an Applications directory in my home directory, so: <code>tar -zxf ~/Applications/vert.x-2.1.1.tar.gz</code> will work right.</li>
<li>Add the Vert.x bin directory to your PATH environment variable.</li>
</ol>
<p>Now you can check the version:</p><pre class="crayon-plain-tag">$ vertx version
2.1.1 (built 2014-06-18 14:11:03)</pre><p></p>
<h4>The first example</h4>
<p>Testing the install is as easy as write a simple web server. This example will show the main features of Vert.x: simplicity, scalability, concurrency. With a few more examples, the polyglot would be showed as well.</p>
<p>Copy the following into a text editor and save it as <strong>Server.java</strong></p><pre class="crayon-plain-tag">public class Main {
import org.vertx.java.core.Handler;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.platform.Verticle;

public class Server extends Verticle {

  public void start() {
    vertx.createHttpServer().requestHandler(new Handler&lt;HttpServerRequest&gt;() {
      public void handle(HttpServerRequest req) {
        //String file = req.path().equals(&quot;/&quot;) ? &quot;index.html&quot; : req.path();
        //req.response().sendFile(&quot;webroot/&quot; + file);
        req.response().end(&quot;Hello World!&quot;);
      }
    }).listen(8080);
  }
}</pre><p>Now run this Verticle (more on the Vert.x concepts later) by opening a console in the directory where you saved the file, and typing:</p><pre class="crayon-plain-tag">~/Documents/vert.x$ vertx run Server.java
Succeeded in deploying verticle</pre><p>To ensure that you have really succeeded with this verticle, open a web browser and go to http://localhost:8080 (see above the highlighted line 15, if you want to change the port number)</p>
<p>You have to see &#8220;Hello World!&#8221; (without the quotes)</p>
<div id="attachment_68" style="width: 310px" class="wp-caption alignnone"><a href="http://malsolo.com/blog4java/wp-content/uploads/2014/07/vertxhello.png"><img class="size-medium wp-image-68" src="http://malsolo.com/blog4java/wp-content/uploads/2014/07/vertxhello-300x141.png" alt="Hello world from Vert.x" width="300" height="141" /></a><p class="wp-caption-text">Hello vert.x</p></div>
<p>Now you can stop the server by using Ctrl+C (Command-C in OS X)</p><pre class="crayon-plain-tag">^C
~/Documents/vert.x$</pre><p></p>
<p>Regarding polyglot, you can find more or less the same sample at <a href="http://vertx.io/" title="Vert.x site" target="_blank"></a> in <a href="http://vertx.io/#ws_js" title="JavaScript" target="_blank">JavaScript</a>, <a href="http://vertx.io/#ws_ruby" title="Ruby" target="_blank">Ruby</a>, <a href="http://vertx.io/#ws_groovy" title="Groovy" target="_blank">Groovy</a>, <a href="http://vertx.io/#ws_python" title="Python" target="_blank">Python</a> and <a href="http://vertx.io/#ws_clojure" title="Clojure" target="_blank">Clojure</a></p>
<p>You can see with this example another feature of Vert.x: you don’t need to compile Java code. I suppose that the authors wanted to give the same facilities that the other languages have, but they are script languages. I don’t find interesting this option, and it’s totally useless for big projects, that is better to be distributed as modules.</p>
<h4>Next steps</h4>
<p>We have seen almost nothing of Vert.x but the installation and a dumb test. In later posts, I will explain the Core Concepts and I will develop a Java Vert.x application using maven.</p>
]]></content:encoded>
			<wfw:commentRss>http://malsolo.com/blog4java/?feed=rss2&#038;p=35</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
