<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Do, or do not - Rafael Steil</title>
	
	<link>http://rafaelsteil.com</link>
	<description />
	<lastBuildDate>Mon, 30 Apr 2012 20:09:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/rafaelsteil" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="rafaelsteil" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Acessing a local machine from the outside using a reverse proxy</title>
		<link>http://rafaelsteil.com/2012/04/30/acessing-a-local-machine-from-the-outside-using-a-reverse-proxy/</link>
		<comments>http://rafaelsteil.com/2012/04/30/acessing-a-local-machine-from-the-outside-using-a-reverse-proxy/#comments</comments>
		<pubDate>Mon, 30 Apr 2012 20:09:25 +0000</pubDate>
		<dc:creator>Rafael Steil</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[tunnel]]></category>

		<guid isPermaLink="false">http://rafaelsteil.com/?p=174</guid>
		<description><![CDATA[This is really neat: have you ever wanted to access your local machine or any other computer that it&#8217;s located in the local network from the outside world? I did, many times. The first and most common approach is to &#8230; <a href="http://rafaelsteil.com/2012/04/30/acessing-a-local-machine-from-the-outside-using-a-reverse-proxy/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is really neat: have you ever wanted to access your local machine or any other computer that it&#8217;s located in the local network from the outside world? I did, many times. The first and most common approach is to enable a DMZ in the router so all traffic that comes through the public IP address (for example, your modem&#8217;s IP) goes to a specific local computer. This works faily well, but you have to have access to the router&#8217;s configuration, and it is limited to a single destination machine.</p>
<p>If you are in an environment you don&#8217;t control, like your company, to change the router configuration is not an option, so how to we solve this problem? Using reverse tunneling through SSH.</p>
<p>For those new to the concept of tunneling, it is a trick that you can do with virtually any ssh client so all traffic from a local port goes to a remote server and port. It is also extremely useful to bypass corporate firewall rules and to use your remote server as a SOCKS proxy (so you can access Hulu from a blocked country). You can find more details at <a href="http://www.revsys.com/writings/quicktips/ssh-tunnel.html" target="_blank">http://www.revsys.com/writings/quicktips/ssh-tunnel.html</a>, <a href="http://ocaoimh.ie/2008/02/13/how-to-use-ssh-as-a-proxy-server/" target="_blank">http://ocaoimh.ie/2008/02/13/how-to-use-ssh-as-a-proxy-server/</a> and Google.</p>
<p>But the main question here is the opposite: how to we allow anyone to access our local machines? The answer is a reverse runnel. It is very simple to get it up and running, but it took me some good hours to find the correct approch, even because I didn&#8217;t know what to search for in the beginning. The steps are:</p>
<ul>
<li>Change a setting in your server&#8217;s sshd_config</li>
<li>Choose a remote port to connect to</li>
<li>Choose the local (destination) port to route the traffic</li>
<li>Open the revere tunnel</li>
</ul>
<p>So I have a webserver running on my localhost at port 8080, and I want that when someone calls &#8220;example.com&#8221; at port 15000, it sees my local webserver. In order to do that, first go to your remove server and add the following line to sshd_config (probably /etc/ssh/sshd_config)</p>
<pre>GatewayPorts yes</pre>
<p>This is strickly necessary, otherwise the tunnel will only work from the server to your machine (and not from any address to your machine). You can close the ssh session if you want.</p>
<p>Now, from your local machine, open the tunnel:</p>
<pre>ssh -N -R "*:15000:localhost:8080" username@example.com</pre>
<p>type the ssh password, and that&#8217;s all. The &#8220;-N&#8221; argument just hangs the ssh client, instead of opening a remote shell, &#8220;-R&#8221; is for the reverse tunnel itself, &#8220;*:&#8221; is to listen on all interfaces (strickly necessary, otherwise it will only listen in the loopback interface), &#8220;15000&#8243; is the port at example.com that users will connect to, &#8220;localhost&#8221; is your own local machine, and &#8220;8080&#8243; is the port in your local machine that will get the traffic.</p>
<p>This is very useful for development purposes, like when I had to test Amazon SNS using an HTTP endpoint.</p>
]]></content:encoded>
			<wfw:commentRss>http://rafaelsteil.com/2012/04/30/acessing-a-local-machine-from-the-outside-using-a-reverse-proxy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A thought about Know-how</title>
		<link>http://rafaelsteil.com/2012/03/14/a-thought-about-know-how/</link>
		<comments>http://rafaelsteil.com/2012/03/14/a-thought-about-know-how/#comments</comments>
		<pubDate>Wed, 14 Mar 2012 15:05:24 +0000</pubDate>
		<dc:creator>Rafael Steil</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://rafaelsteil.com/?p=170</guid>
		<description><![CDATA[When a company says that they have dozens of thousands of experience doing &#60;add something here&#62;, but they let their valuable employees leave just like if they didn&#8217;t mean anything, the company is actually lying.]]></description>
			<content:encoded><![CDATA[<p>When a company says that they have dozens of thousands of experience doing <em>&lt;add something here&gt;, </em>but they let their valuable employees leave just like if they didn&#8217;t mean anything, the company is actually lying.</p>
]]></content:encoded>
			<wfw:commentRss>http://rafaelsteil.com/2012/03/14/a-thought-about-know-how/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get the public / local IP of your EC2 instance via command line</title>
		<link>http://rafaelsteil.com/2012/02/15/get-the-public-local-ip-of-your-ec2-instance-via-command-line/</link>
		<comments>http://rafaelsteil.com/2012/02/15/get-the-public-local-ip-of-your-ec2-instance-via-command-line/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 20:03:07 +0000</pubDate>
		<dc:creator>Rafael Steil</dc:creator>
				<category><![CDATA[aws]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[ec2]]></category>

		<guid isPermaLink="false">http://rafaelsteil.com/?p=167</guid>
		<description><![CDATA[While you can get the public and private IP address of your Amazon EC2 instance via the AWS Console, it may be extremely useful to query it from anywhere you can make an HTTP request, such a shell script. The &#8230; <a href="http://rafaelsteil.com/2012/02/15/get-the-public-local-ip-of-your-ec2-instance-via-command-line/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While you can get the public and private IP address of your Amazon EC2 instance via the AWS Console, it may be extremely useful to query it from anywhere you can make an HTTP request, such a shell script. The operation is really simple, just make a GET request to the following URL <strong><em>from within your EC2 instance:</em></strong></p>
<p><strong>Local IP:</strong></p>
<pre>curl http://169.254.169.254/latest/meta-data/local-ipv4</pre>
<p><strong>Public IP:</strong></p>
<pre>curl http://169.254.169.254/latest/meta-data/public-ipv4</pre>
<p>I often use this feature to pre-configure services and update configuration files, as in EC2 you get a new IP Address each time you reboot.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://rafaelsteil.com/2012/02/15/get-the-public-local-ip-of-your-ec2-instance-via-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing java.lang.OutOfMemoryError: PermGen space in Tomcat</title>
		<link>http://rafaelsteil.com/2012/02/12/fixing-java-lang-outofmemoryerror-permgen-space-in-tomcat/</link>
		<comments>http://rafaelsteil.com/2012/02/12/fixing-java-lang-outofmemoryerror-permgen-space-in-tomcat/#comments</comments>
		<pubDate>Sun, 12 Feb 2012 14:01:02 +0000</pubDate>
		<dc:creator>Rafael Steil</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[oom]]></category>
		<category><![CDATA[outofmemory]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://rafaelsteil.com/?p=163</guid>
		<description><![CDATA[If you have ever used Tomcat for development purposes for more than 10 minutes (especially within Eclipse), you certainly have encountered the infamous messag &#8220;OutOfMemoryError: PermGen space&#8221;, and the only solution was to restart Tomcat. Despite the fact that you should be &#8230; <a href="http://rafaelsteil.com/2012/02/12/fixing-java-lang-outofmemoryerror-permgen-space-in-tomcat/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you have ever used Tomcat for development purposes for more than 10 minutes (especially within Eclipse), you certainly have encountered the infamous messag <em>&#8220;OutOfMemoryError: PermGen space&#8221;, </em>and the only solution was to restart Tomcat.</p>
<p>Despite the fact that you should be aware that such message<em> may </em>indicate a deeper problem, there is an <em>easy&#8217;n dirty</em> solution via JVM options. I have come to the fix after browsing the Interwebs for a while, and your luck may vary. The solution consists in setting up the following set of JVM arguments:</p>
<pre>-server
-XX:+DisableExplicitGC
-XX:MaxPermSize=256m
-XX:PermSize=256m
-XX:MaxNewSize=256m
-XX:NewSize=256m
-XX:+UseConcMarkSweepGC
-XX:+CMSClassUnloadingEnabled
-XX:+CMSPermGenSweepingEnabled</pre>
<p>I have added them all for the sake of laziness, although the last three are said to be used with caution (especially the last one)</p>
<p><strong>Setting up within Eclipse</strong></p>
<p>Even in 2012 I still use the <a href="http://www.eclipsetotale.com/tomcatPlugin.html" target="_blank">Sysdeo Tomcat Plugin</a> because of its simpliciy over Eclipse&#8217;s WTP Servers. Open Window -&gt; Preferences (<em>Command + ,</em> if you are using a Mac) and go to <em>Tomcat -&gt; JVM Settings -&gt; Append to JVM parameters</em>.</p>
<p><strong>Setting up Tomcat standalone</strong></p>
<p>Another approach is to add the arguments directly to <em>Catalina.sh. </em>Locate it in Tomcat&#8217;s <em>bin </em>directory and set the <em>JAVA_OPTS </em>variable, like this:</p>
<pre>JAVA_OPTS="-XX:+DisableExplicitGC -XX:MaxPermSize=256m -XX:PermSize=256m
-XX:MaxNewSize=256m -XX:NewSize=256m -XX:+UseConcMarkSweepGC
-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled"</pre>
<p>Just restart Tomcat and you should be good to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://rafaelsteil.com/2012/02/12/fixing-java-lang-outofmemoryerror-permgen-space-in-tomcat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why SELECT * is bad (or could be)</title>
		<link>http://rafaelsteil.com/2012/01/31/why-select-is-bad-or-could-be/</link>
		<comments>http://rafaelsteil.com/2012/01/31/why-select-is-bad-or-could-be/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 13:32:54 +0000</pubDate>
		<dc:creator>Rafael Steil</dc:creator>
				<category><![CDATA[sql]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://rafaelsteil.com/?p=157</guid>
		<description><![CDATA[I have always been told that SELECT * FROM some_table is a bad thing, but as a lazy developer that I am, it was just easier to select everything than to care about such thing. I also think that a &#8230; <a href="http://rafaelsteil.com/2012/01/31/why-select-is-bad-or-could-be/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have always been told that <em>SELECT * FROM some_table</em> is a bad thing, but as a lazy developer that I am, it was just <em>easier </em>to select everything than to care about such thing. I also think that a lot of people face this statement as some kind of heresy, but I have my doubts that they <em>really </em>understand what it means. One of the worst examples one can provide to defend against star selects is this:</p>
<pre>SELECT field1, field2, fieldN FROM some_table</pre>
<p>where <em>field1, field2 </em>and <em>fieldN </em>are ALL fields from <em>some_table. </em>Sure it is declarative programming, but you can&#8217;t get much more than that.</p>
<p>It is <a href="http://www.google.com.br/search?q=why+select+*+is+bad" target="_blank">not hard to find</a> a lot of reasons and explanations against SELECT *, but one does not simply understands the impact of something before having problems with it. It is the same thing for everything, from Design Patterns to fire and children: a developer can&#8217;t just read <a href="http://en.wikipedia.org/wiki/Design_Patterns" target="_blank">GoF</a> and try to apply it &#8220;everywhere&#8221; without <em>facing</em> the hard way the effects of bad software design. It does not work that way. Also, a child will not understand what his parents truly mean when they say &#8220;<em>don&#8217;t put your hand in the fire, it will burn and hurt a lot</em>&#8221; without <em>doing </em>it.</p>
<p>So, when can SELECT * be bad? As I see it, it could have huge impacts in either disk and network I/O, and memory. The explanation is simple: the more data you ask for, the more the server has to read from the disk and transfer the data over the network to your application, and you could end using much more memory than you need for any given operation.</p>
<p>See the following graph from a DB server, showing I/O usage:</p>
<p><img class="alignnone size-full wp-image-158" title="vdm_db_io" src="http://rafaelsteil.com/wp-content/uploads/2012/01/vdm_db_io-e1328015872483.png" alt="" width="490" height="210" /></p>
<p>See the two big gaps? The disk I/O dropped when some queries were optimized to return only what the application <em>really </em>needed for each operation. Before that, the server I/O was hitting around 80.000 ~ 100.000 blocks per second, which for this setup is a lot. Not surprisingly, the web server was wasting a lot of memory as well.</p>
<p>In the end, you will have to list the pros and cons about each strategy, and remember that the application size matters &#8211; one may not see big improvements in small services.</p>
<p>And always remember that <a href="http://www.theregister.co.uk/2007/06/22/premature_optimisation/" target="_blank">premature optimization</a> is the <a href="http://en.wikiquote.org/wiki/Donald_Knuth" target="_blank">root of all evil.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://rafaelsteil.com/2012/01/31/why-select-is-bad-or-could-be/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up JMX for JConsole / VisualVM on EC2, plus Jetty Configuration</title>
		<link>http://rafaelsteil.com/2012/01/27/setting-up-jmx-for-jconsole-visualvm-on-ec2-plus-jetty-configuration/</link>
		<comments>http://rafaelsteil.com/2012/01/27/setting-up-jmx-for-jconsole-visualvm-on-ec2-plus-jetty-configuration/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 18:46:22 +0000</pubDate>
		<dc:creator>Rafael Steil</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[jconsole]]></category>
		<category><![CDATA[jetty]]></category>
		<category><![CDATA[jmx]]></category>
		<category><![CDATA[rmi]]></category>
		<category><![CDATA[visualvm]]></category>

		<guid isPermaLink="false">http://rafaelsteil.com/?p=142</guid>
		<description><![CDATA[Inspecting applications via JMX can be a very valuable tool in order to keep track of Memory, CPU and any other kind of information that are provided by the MBeans of the remote Java application. However, to get it working &#8230; <a href="http://rafaelsteil.com/2012/01/27/setting-up-jmx-for-jconsole-visualvm-on-ec2-plus-jetty-configuration/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Inspecting applications via JMX can be a very valuable tool in order to keep track of Memory, CPU and any other kind of information that are provided by the MBeans of the remote Java application. However, to get it working correctly can be tricky, specially if you haven&#8217;t play with it before, as the documentation is a little sparse.</p>
<p>Before going into the details, here are some very valuable links:</p>
<ul>
<li><a href="http://docs.oracle.com/javase/1.5.0/docs/guide/management/agent.html" target="_blank">Monitoring and Management Using JMX</a>, contains all property keys you may need to use, with detailed information about each one.</li>
<li><a href="http://java.sun.com/developer/technicalArticles/J2SE/jmx.html" target="_blank">Getting Started with Java Management Extensions (JMX)</a> has a good overview of JMX in general, plus some example codes to help you get started.</li>
<li><a href="http://visualvm.java.net/" target="_blank">VisualVM</a> is a graphical tool to connect to the machines and inspect the Java Virtual Machine.</li>
<li><a href="http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html" target="_blank">JConsole</a> is the predecessor of VisualVM, but it still remains a good tool nowadays.</li>
</ul>
<p>In order to get VisualVM or JConsole working with remote applications you will need to set some JVM properties on the application you want to track. In the list below are the ones that worked for me, but keep in mind that you may have different results depending on the application and the Java version (yes, it happens). In a nutshell, you&#8217;ll need to pass these properties to the JVM:</p>
<pre>-Dcom.sun.management.jmxremote
 -Dcom.sun.management.jmxremote.port=&lt;port&gt;
 -Dcom.sun.management.jmxremote.authenticate=false
 -Dcom.sun.management.jmxremote.ssl=false
 -Djava.security.policy=&lt;policy file&gt;
 -Dcom.sun.management.jmxremote.local.only=false
 -Djava.rmi.server.hostname=&lt;your public hostname&gt;
 -Dcom.sun.management.jmxremote.password.file=&lt;password_file&gt;</pre>
<p><em>&#8220;com.sun.management.jmxremote.port<em>&#8220;</em></em> requires the port number to listen for remote RMI connections. Make sure you specify an unused one.<em> </em></p>
<p><em><em>&#8220;</em>java.rmi.server.hostname&#8221;</em> is the public hostname (like example.com) of your server, without HTTP or anything else. You cannot use an internal address, otherwise you won&#8217;t be able to remotely access the service.</p>
<p>&#8220;<em>com.sun.management.jmxremote.authenticate&#8221;</em> will require an username and password if set to true, otherwise anyone that knows (or discovers) the addres will be able to connect to your JMX registry.</p>
<p>&#8220;<em>com.sun.management.jmxremote.password.file&#8221;</em> is only necessary if you set <em>authenticate=true</em>, and you should specify the full path of a text file with the username and passwords (in plain text) that are allowed to connect to your instance. More information about the sintaxt at <a href="http://docs.oracle.com/javase/1.5.0/docs/guide/management/agent.html#auth" target="_blank">http://docs.oracle.com/javase/1.5.0/docs/guide/management/agent.html#auth</a>.</p>
<p>&#8220;<em>java.security.policy&#8221;</em> is the path of a <a href="http://docs.oracle.com/javase/1.3/docs/guide/security/PolicyFiles.html" target="_blank">Java Policy File</a> with the rules you need. For the sake of simplicity, you can create one with the following contents:</p>
<pre>grant {
 permission java.security.AllPermission;
 };</pre>
<p>You may or may not need to set the policy file (I didn&#8217;t).</p>
<p>You don&#8217;t need <em>all</em> of these properties in order to the remote JMX working. As I said before, it will depend of your luck. In my very own case, I used only these:</p>
<pre>-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.local.only=false
-Djava.rmi.server.hostname=example.com</pre>
<p>You should pass these values when starting your java application, like</p>
<pre>java -Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=9001 [.....] -jar myapp.jar</pre>
<p><strong>Setting up EC2</strong><br />
The most important thing to set when running JMX on Amazon&#8217;s EC2 is to open the TCP ports to the IPs you will connect from, otherwise the client application won&#8217;t be able to reach the Agent. For the sake of simplicity, open all TCP ports from 0 to 65535, get it working and then keep open only the necessary ports. This approach is easier because the RMI registry that JMX uses (may?) create random ports of its communication, so you&#8217;ll have to inspect it (I am no expert on the subject, in other words).</p>
<p>On EC2 you configure the ports in the &#8220;Security Groups&#8221; section of the AWS Management Console.</p>
<p><img class="alignnone size-full wp-image-144" title="ec2-security-group" src="http://rafaelsteil.com/wp-content/uploads/2012/01/ec2-security-group.png" alt="" width="281" height="149" /></p>
<p><strong>Setting up Jetty</strong><strong><br />
</strong> As a bonus, here&#8217;s how to get JMX working with Jetty. The process is fairly simple, it&#8217;s just a matter of adding the configuration keys to the right files.</p>
<p>First of all, you need to edit the file &#8220;<em>start.ini&#8221;</em> (located in Jetty&#8217;s root directory) and uncomment the line that has &#8220;<em>etc/jetty-jmx.xml</em>&#8220;, which is probably located at the end of the file, as shown in below:</p>
<p><img class="size-full wp-image-146 alignnone" title="start-ini-jmx" src="http://rafaelsteil.com/wp-content/uploads/2012/01/start-ini-jmx.png" alt="" width="444" height="141" /></p>
<p>Then, add each of the JVM properties in a different line in the same file (it doesn&#8217;t matter where). It should look like this:</p>
<p><img class="alignnone size-full wp-image-149" title="start-ini-jvm-options" src="http://rafaelsteil.com/wp-content/uploads/2012/01/start-ini-jvm-options1.png" alt="" width="554" height="121" /></p>
<p>Please note that &#8220;<em>&#8211;exec</em>&#8221; is a property specific to Jetty, and necessary to make it understand the other VM properties. &#8220;<em>-Xshare:off</em>&#8221; disables class data sharing, which is necessary to make VisualVM work correctly. The other settings are the ones described earlier.</p>
<p>The last step is to configure the file &#8220;<em>etc/jetty-jmx.xml&#8221;</em> to instruct it to automatically create a RMI registry and set the RMI connection properties, which are essential to remotely connect to it. My configuration file (based on Jetty <img src='http://rafaelsteil.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> is below:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;http://www.eclipse.org/jetty/configure.dtd&quot;&gt;
&lt;Configure id=&quot;Server&quot; class=&quot;org.eclipse.jetty.server.Server&quot;&gt;
  &lt;Call id=&quot;MBeanServer&quot; class=&quot;java.lang.management.ManagementFactory&quot; name=&quot;getPlatformMBeanServer&quot;/&gt;
  &lt;New id=&quot;MBeanContainer&quot; class=&quot;org.eclipse.jetty.jmx.MBeanContainer&quot;&gt;
    &lt;Arg&gt;
      &lt;Ref id=&quot;MBeanServer&quot;/&gt;
    &lt;/Arg&gt;
  &lt;/New&gt;
  &lt;Get id=&quot;Container&quot; name=&quot;container&quot;&gt;
    &lt;Call name=&quot;addEventListener&quot;&gt;
      &lt;Arg&gt;
        &lt;Ref id=&quot;MBeanContainer&quot;/&gt;
      &lt;/Arg&gt;
    &lt;/Call&gt;
  &lt;/Get&gt;
  &lt;Call name=&quot;addBean&quot;&gt;
    &lt;Arg&gt;
      &lt;Ref id=&quot;MBeanContainer&quot;/&gt;
    &lt;/Arg&gt;
  &lt;/Call&gt;
  &lt;Get id=&quot;Logger&quot; class=&quot;org.eclipse.jetty.util.log.Log&quot; name=&quot;log&quot;/&gt;
  &lt;Ref id=&quot;MBeanContainer&quot;&gt;
    &lt;Call name=&quot;addBean&quot;&gt;
      &lt;Arg&gt;
        &lt;Ref id=&quot;Logger&quot;/&gt;
      &lt;/Arg&gt;
    &lt;/Call&gt;
  &lt;/Ref&gt;
  &lt;Call name=&quot;createRegistry&quot; class=&quot;java.rmi.registry.LocateRegistry&quot;&gt;
    &lt;Arg type=&quot;java.lang.Integer&quot;&gt;1099&lt;/Arg&gt;
    &lt;Call name=&quot;sleep&quot; class=&quot;java.lang.Thread&quot;&gt;
      &lt;Arg type=&quot;java.lang.Integer&quot;&gt;1000&lt;/Arg&gt;
    &lt;/Call&gt;
  &lt;/Call&gt;
  &lt;New id=&quot;ConnectorServer&quot; class=&quot;org.eclipse.jetty.jmx.ConnectorServer&quot;&gt;
    &lt;Arg&gt;
      &lt;New class=&quot;javax.management.remote.JMXServiceURL&quot;&gt;
        &lt;Arg type=&quot;java.lang.String&quot;&gt;rmi&lt;/Arg&gt;
        &lt;Arg type=&quot;java.lang.String&quot;&gt;ec2-177-71-143-137.sa-east-1.compute.amazonaws.com&lt;/Arg&gt;
        &lt;Arg type=&quot;java.lang.Integer&quot;&gt;0&lt;/Arg&gt;
        &lt;Arg type=&quot;java.lang.String&quot;&gt;/jndi/rmi://ec2-177-71-143-137.sa-east-1.compute.amazonaws.com:1099/jettyjmx&lt;/Arg&gt;
      &lt;/New&gt;
    &lt;/Arg&gt;
    &lt;Arg&gt;org.eclipse.jetty:name=rmiconnectorserver&lt;/Arg&gt;
    &lt;Call name=&quot;start&quot;/&gt;
  &lt;/New&gt;
&lt;/Configure&gt;
</pre>
<p>That&#8217;s all. When you start Jetty, it will log (to the console or file, depending of how you configured it) the JMX address you will need to use in order to connect to it from your local machine. Please see the following image:</p>
<p><img class="alignnone size-full wp-image-150" title="jetty-start-jmx" src="http://rafaelsteil.com/wp-content/uploads/2012/01/jetty-start-jmx.png" alt="" width="500" height="240" /></p>
<pre><em>service:jmx:rmi://ec2-177-71-143-137.sa-east-1.compute.amazonaws.com/jndi/rmi://ec2-177-71-143-137.sa-east-1.compute.amazonaws.com:1099/jettyjmx</em></pre>
<p>In my case, the address that I should use in VisualVM is the address of my EC2 instance (<em>ec2-177-71-143-137.sa-east-1.compute.amazonaws.com</em>):</p>
<p><img class="alignnone size-full wp-image-151" title="visualvm-step1" src="http://rafaelsteil.com/wp-content/uploads/2012/01/visualvm-step1.png" alt="" width="459" height="385" /></p>
<p>If the connection is successful, then you can right click on the remote host name and insert the address of the RMI registry, like shown below:</p>
<p><img class="alignnone size-full wp-image-152" title="visualvm-step2" src="http://rafaelsteil.com/wp-content/uploads/2012/01/visualvm-step2.png" alt="" width="470" height="304" /></p>
<p>If you were lucky enough, you should be able to instrument Jetty remotely:</p>
<p><img class="alignnone size-full wp-image-154" title="visualvm-final" src="http://rafaelsteil.com/wp-content/uploads/2012/01/visualvm-final1.png" alt="" width="490" height="517" /></p>
]]></content:encoded>
			<wfw:commentRss>http://rafaelsteil.com/2012/01/27/setting-up-jmx-for-jconsole-visualvm-on-ec2-plus-jetty-configuration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up SQL logs in Rails 2 and 3 console</title>
		<link>http://rafaelsteil.com/2012/01/25/setting-up-sql-logs-in-rails-2-and-3-console/</link>
		<comments>http://rafaelsteil.com/2012/01/25/setting-up-sql-logs-in-rails-2-and-3-console/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 13:23:33 +0000</pubDate>
		<dc:creator>Rafael Steil</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://rafaelsteil.com/?p=138</guid>
		<description><![CDATA[When developing Rails applications, it is often desirable to see what ActiveRecord is doing behind the scenes when using the console. By default, log messages in script/console (Rails 2) or rails c (Rails 3) are only sent to log/development.log, which &#8230; <a href="http://rafaelsteil.com/2012/01/25/setting-up-sql-logs-in-rails-2-and-3-console/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When developing Rails applications, it is often desirable to see what ActiveRecord is doing behind the scenes when using the console. By default, log messages in <em>script/console</em> (Rails 2) or <em>rails c</em> (Rails 3) are only sent to <em>log/development.log</em>, which I find quite annoying to keep an eye on. Much better would be if it the messages were sent directly to the console itself.</p>
<p>It turns out that it is very simple to achieve that. Add the following code to your <em>~/.irbrc</em> file:</p>
<pre class="brush: ruby; title: ; notranslate">
# File ~/.irbrc
require 'logger'

# For Rails 2
RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)

# For Rails 3
ActiveRecord::Base.logger = Logger.new(STDOUT)
</pre>
<p>Simple as that. Restart the console and load any AR model, and the SQL statement should appear right before the data. For the same of simplicity, I set woth <em>RAILS_DEFAULT_LOGGER</em> and <em>ActiveRecord::Base.logger</em>, even because I had sittuations where only having one of the configurations didn&#8217;t work so well (for an unknown reason to me)</p>
]]></content:encoded>
			<wfw:commentRss>http://rafaelsteil.com/2012/01/25/setting-up-sql-logs-in-rails-2-and-3-console/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing the mouse cursor in Swing for the entire application</title>
		<link>http://rafaelsteil.com/2012/01/23/changing-the-mouse-cursor-in-swing-for-the-entire-application/</link>
		<comments>http://rafaelsteil.com/2012/01/23/changing-the-mouse-cursor-in-swing-for-the-entire-application/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 15:00:25 +0000</pubDate>
		<dc:creator>Rafael Steil</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[cursor]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mouse]]></category>
		<category><![CDATA[swing]]></category>

		<guid isPermaLink="false">http://rafaelsteil.com/?p=125</guid>
		<description><![CDATA[It is quite easy to change the mouse cursor in a Java Swing application, but most documentation and examples available only demonstrate how to change the cursor for a specific component. However, in an application I am developing &#8211; which &#8230; <a href="http://rafaelsteil.com/2012/01/23/changing-the-mouse-cursor-in-swing-for-the-entire-application/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It is quite easy to change the mouse cursor in a Java Swing application, but most documentation and examples available only demonstrate how to change the cursor for a specific component. However, in an application I am developing &#8211; which has a fairly complex component hierarchy &#8211; I needed to ensure that the cursor would remain the one I set no matter where the mouse were (the most common example is the &#8220;busy / waiting&#8221; cursor, although that was not my case).</p>
<p>To change the cursor in a application wide fashion, you have to access the Glass Pane and set its cursor, and then make the glass pane visible &#8211; otherwise, it has no effect at all.</p>
<p>Take the following code as example:</p>
<pre class="brush: java; title: ; notranslate">
int cursorType = Cursor.S_RESIZE_CURSOR;
Component glassPane = ((RootPaneContainer)someComponent.getTopLevelAncestor()).getGlassPane();
glassPane.setCursor(Cursor.getPredefinedCursor(cursorType));
glassPane.setVisible(cursorType != Cursor.DEFAULT_CURSOR);
</pre>
<p>In the previous code, &#8220;<em>someComponent&#8221;</em> is any <em>JComponent</em> you have, it doesn&#8217;t matter which one (can be a JLabel, JButton, JPanel.. just take one). The trick is to access the RootPaneContainer, and then get the glass pane from it.</p>
<p>The last part is to make the glass pane visible only when the cursor <em>is not</em> the default one. That&#8217;s all.</p>
]]></content:encoded>
			<wfw:commentRss>http://rafaelsteil.com/2012/01/23/changing-the-mouse-cursor-in-swing-for-the-entire-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Complete XCode 4 keyboard shortcuts reference</title>
		<link>http://rafaelsteil.com/2011/12/14/complete-xcode-4-keyboard-shortcuts-reference/</link>
		<comments>http://rafaelsteil.com/2011/12/14/complete-xcode-4-keyboard-shortcuts-reference/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 16:22:27 +0000</pubDate>
		<dc:creator>Rafael Steil</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://rafaelsteil.com/?p=130</guid>
		<description><![CDATA[XCode has had a major redesign starting in version 4. Not only the UI and Compiler have changed, but many keyboard shortcuts did too, and for those used to develop using XCode 3 the transition is a bit hairy. While &#8230; <a href="http://rafaelsteil.com/2011/12/14/complete-xcode-4-keyboard-shortcuts-reference/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>XCode has had a major redesign starting in version 4. Not only the UI and Compiler have changed, but many keyboard shortcuts did too, and for those used to develop using XCode 3 the transition is a bit hairy. While Apple does not provide a complete reference guide for all the shortcuts (none that I know), some handy developers out there do.</p>
<p>The <a href="http://cocoasamurai.blogspot.com/2011/03/xcode-4-keyboard-shortcuts-now.html" target="_blank">XCode 4 Keyboard Shortcut Reference Guide</a> has a very complete and extremely useful list of all shortcuts, organized in a pretty PDF file. The download links are:</p>
<ul>
<li><a href="https://github.com/Machx/Xcode-Keyboard-Shortcuts" target="_blank">Project repository at Github</a></li>
<li><a href="https://github.com/downloads/Machx/Xcode-Keyboard-Shortcuts/Xcode_Shortcuts.pdf" target="_blank">Reference guide as PDF with blue background and white font</a></li>
<li><a href="https://github.com/downloads/Machx/Xcode-Keyboard-Shortcuts/Xcode_Shortcuts_bw.pdf.zip" target="_blank">Reference guide as PDF with white background and black font</a></li>
</ul>
<div><a href="http://rafaelsteil.com/wp-content/uploads/2011/12/xc4_kbsc.png"><img class="alignnone size-full wp-image-132" title="xc4_kbsc" src="http://rafaelsteil.com/wp-content/uploads/2011/12/xc4_kbsc.png" alt="" width="318" height="297" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://rafaelsteil.com/2011/12/14/complete-xcode-4-keyboard-shortcuts-reference/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The status of Swing in 2011</title>
		<link>http://rafaelsteil.com/2011/12/05/the-status-of-swing-in-2011/</link>
		<comments>http://rafaelsteil.com/2011/12/05/the-status-of-swing-in-2011/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 13:58:54 +0000</pubDate>
		<dc:creator>Rafael Steil</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[swing]]></category>

		<guid isPermaLink="false">http://rafaelsteil.com/?p=103</guid>
		<description><![CDATA[I always have been a Web developer in my career &#8211; well, most of the time, as since the iPad was released I have been doing some heavy development on iOS, specially in the field of digital readers. Nevertheless, is &#8230; <a href="http://rafaelsteil.com/2011/12/05/the-status-of-swing-in-2011/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I always have been a Web developer in my career &#8211; well, most of the time, as since the iPad was released I have been doing some heavy development on iOS, specially in the field of digital readers. Nevertheless, is the Web platform that I am most familiar with. Being a solution centric professional, it was not surprise that last month I was requested to develop a new tool that could run on Mac and Windows desktops, in order to allow newspaper and magazine publishers to create rich content issues for mobile devices and possible web readers.</p>
<p>The company I work for was a long time user of Microsoft solutions (only because that when they started over 11 years ago, it was easier to find Action Script developers that could do some ASP coding, thus the migration to the .NET platform was some kind of natural for them), but for the past couple of years the transition to Rails and now Java is taking place over .NET (which is something to be discussed another time), and using Java for the new tool seemed the best way to go through, as Java is a very mature platform, with plenty of developers and documentation available, and not to have to maintain totally different base codes of Mac and Windows was a very good argument.</p>
<p>However, I didn&#8217;t have so many good opinions about Swing (the Java GUI Toolkit), even though it is the standard approach to do desktop programming with Java. Sure that there are other toolkits out there, like SWT and QT, but I had to consider that other people would be working on the software later, doing bug fixing and general improvements, thus if it required extra training it could be a problem.</p>
<p>All my experience with Swing was limited to some small programs or books I read, but it was enough to let me know that:<br />
- I&#8217;d need to deal with layout managers<br />
- That layout managers can get quite complex or verbose very easily (or both)<br />
- That Swing didn&#8217;t have any major upgrade for years (if any)<br />
- I had a clue that there weren&#8217;t so many third party components<br />
- And definitely that I wasn&#8217;t willing to do hand coding of the GUIs. A GUI designer was vital.</p>
<p>I have mixed feelings about layout managers. I understand why they were created, but you had to know them all in order to make a fairly complex program, as each one of them accomplish a very specific task. Also, any documentation (including books) date back to 2004 or 2005 at most, which leads one to think that it was abandoned, but this feeling goes away after some time, as Swing has almost all (if not all) major components one may need to create any program, and it is possible to create your own components if needed. Swing is mature as well, and the fact it does not get a major upgrade in years may only means that there isn&#8217;t that many stuff to have.</p>
<p>Ok, I may being a little too optimistic here, as certainly the API could be improved a lot and more components could be available by default, but Sun was never good at designing easy to use APIs, far from that, and the failed Java FX thing only proves that the guys over there had no clue at all of what to do.</p>
<p>When searching for documentation, you often will find articles dated back to &#8217;98, &#8217;02. This frequently helps to keep alive that feeling that you are dealing with a dinosaur and using something that will die soon &#8211; even it will not (I hope). Sure that any example code that it&#8217;s not for Java 1.1 is very welcome when you know nothing.</p>
<p>The complexity of doing even simple things is something you will face constantly. The Java API was never known for its friendliness &#8211; it appears that very different teams at Sun, that did not talk to each other, were developing the base class library, thus creating a lot of inconsistency across the API -, but Swing goes a step further to make your life harder. Maybe it&#8217;s because I am more confortable with web programming, but I have done a lot of WinForms and Silverlight (.NET) coding, and by far Swing is harder. Take for example Drag and Drop over a JList or (worst) a JTree: it is insanely hard to make it work, even after reading hundreds of source code lines from open source projects and discussion forums. The event dispatching system is another thing that the more I read the less I understand, and many times I found myself doing some sort of implementation of the observer pattern instead of sticking with Swing&#8217;s own classes (I ended with a somewhat simple but very effective &#8216;EventCentral&#8217; class).</p>
<p>As for third party components, there are some, but not many, not to mention those that does not work very well. Conversely, the WinForms API of .NET (here I go again, sorry) still get plenty of stuff today, although not as many as it did once, and you can&#8217;t stop thinking about it occasionally.</p>
<p>In conclusion, at the end of the day Swing it&#8217;s the only choice you have if you are going to use Java for desktop development, and albeit it has a lot of bugs and a weak, non-active community, it gets the job done. I have looked at SWT and JavaFX, but the former it still even more restricted, and the latter&#8217;s first release was a fiasco, but apparently Oracle is trying to respawn it with a 2.0 version.</p>
]]></content:encoded>
			<wfw:commentRss>http://rafaelsteil.com/2011/12/05/the-status-of-swing-in-2011/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss><!-- Dynamic Page Served (once) in 0.437 seconds --><!-- Cached page served by WP-Cache -->

