<?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>My IT-blog &#187; programming</title>
	<atom:link href="http://dev.eek.be/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://dev.eek.be</link>
	<description>IT knowledge exchange</description>
	<lastBuildDate>Sun, 18 Dec 2011 10:37:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Create a Message Driven Bean with Netbeans</title>
		<link>http://dev.eek.be/2011/01/create-a-message-driven-bean-with-netbeans/</link>
		<comments>http://dev.eek.be/2011/01/create-a-message-driven-bean-with-netbeans/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 16:55:09 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[JMS]]></category>
		<category><![CDATA[MDB]]></category>
		<category><![CDATA[message driven beans]]></category>
		<category><![CDATA[messaging]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[queue]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=530</guid>
		<description><![CDATA[I was looking how Message Driven Beans in JEE 6 works and I was surprised that it isn&#8217;t that difficult. I was especially surprised about the support for MDB&#8217;s (and the other beans) in Netbeans. Creating a working example with a MDB is just a matter of minutes. In this post I&#8217;ll try to teach ]]></description>
			<content:encoded><![CDATA[<p>I was looking how Message Driven Beans in JEE 6 works and I was surprised that it isn&#8217;t that difficult. I was especially surprised about the support for MDB&#8217;s (and the other beans) in Netbeans. Creating a working example with a MDB is just a matter of minutes.</p>
<p>In this post I&#8217;ll try to teach you how to create a message driven bean which can communicate with an application client.<br />
In order to follow this tutorial, I&#8217;ll assume you have Netbeans (6.9) and Glassfish available on your system.</p>
<h2>Creating the Message driven bean</h2>
<p>Create a new project in Netbeans and choose for a Java EE &#8211; EJB Module.</p>
<div id="attachment_532" class="wp-caption aligncenter" style="width: 565px"><a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB1.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB1.png" alt="" title="MDB1" width="555" height="314" class="size-full wp-image-532" /></a>
<p class="wp-caption-text">Create a new project</p>
</div>
<p>Next, give your project a name and make sure you select Glassfish 3 as your server and Java EE 6 as your Java EE version.</p>
<div id="attachment_533" class="wp-caption aligncenter" style="width: 590px"><a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB2.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB2.png" alt="Server and settings" title="MDB2" width="580" height="207" class="size-full wp-image-533" /></a>
<p class="wp-caption-text">Server and settings</p>
</div>
<p>Than you can add a new Message Driven Bean to your project</p>
<div id="attachment_534" class="wp-caption aligncenter" style="width: 535px"><a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB3.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB3.png" alt="" title="MDB3" width="525" height="388" class="size-full wp-image-534" /></a>
<p class="wp-caption-text">Add a Message Driven Bean</p>
</div>
<p>Give the Bean a name and a package.<br />
Click next to destinations on the Add button to add a destination.<br />
Choose a name for your destination.<br />
Choose between Queue or Topic. In this example it isn&#8217;t important which one you choose. The difference between Topic and Queue is if you want <a href="http://en.wikipedia.org/wiki/Point-to-point_communication_(telecommunications)" target="_new">Point-to-point</a> or <a href="http://en.wikipedia.org/wiki/Publish/subscribe" target="_new">Publish/subscribe</a> communication for your beans.</p>
<div id="attachment_536" class="wp-caption aligncenter" style="width: 635px"><a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB4.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB4.png" alt="" title="MDB4" width="625" height="510" class="size-full wp-image-536" /></a>
<p class="wp-caption-text">Name your bean</p>
</div>
<p>Netbeans creates code for you and, except for the actual businesscode, your bean is ready.</p>
<p>In this simple example, I just want to pass a name from my applicationclient to my bean and my bean has to echo &#8220;Helllo name&#8221;</p>
<p>The full code looks like this:</p>
<pre class="prettyprint">
package hello;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;

@MessageDriven(mappedName = "jms/hello", activationConfig =  {
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
    })
public class HelloBean implements MessageListener {

    public HelloBean() {
    }

    public void onMessage(Message message) {
        try {
            System.out.println("Hello " + message.getStringProperty("name"));
        } catch (JMSException ex) {
            Logger.getLogger(HelloBean.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
</pre>
<p>Almost all the configuration is mapped into 1 annotation.<br />
- The annotation @MessageDriven transforms your normal class into an actual Message Driven Bean.<br />
- The @ActivationConfigProperty annotation is to be used for defining properties to your bean such as the acknowledge mode, message selector, subscription durability and destination type.<br />
In previous versions of JEE, you had to create an XML-file to define all these properties.</p>
<p>Our bean is finished and can be deployed.<br />
Start your Glassfish server and simply click on the deploy button to deploy your bean into Glassfish.</p>
<p>If you open your Glassfish admin console (by default located at http://localhost:4848/ ),  you should see that your application is successfully deployed and activated into Glassfish.<br />
<a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB5.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB5.png" alt="" title="MDB5" width="781" height="234" class="aligncenter size-full wp-image-538" /></a></p>
<p>Also verify that the JMS resources for your MDB are succesfully created</p>
<p><a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB6.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB6.png" alt="" title="MDB6" width="598" height="259" class="aligncenter size-full wp-image-539" /></a></p>
<h2>Creating the Application client</h2>
<p>The MDB is created and is waiting for messages. Now it&#8217;s time to create the Application client.<br />
Just create a new project and choose for an Enterprise Applicaton Client from the list</p>
<p><a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB7.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB7.png" alt="" title="MDB7" width="545" height="435" class="aligncenter size-full wp-image-540" /></a></p>
<p>The code for the applicaton client looks like this:</p>
<pre class="prettyprint">
package mdbclient;

import javax.annotation.Resource;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;

public class Main {

    @Resource(mappedName = "jms/helloFactory")
    private static ConnectionFactory connectionFactory;

    @Resource(mappedName = "jms/hello")
    private static Queue queue;

    public static void main(String[] args) throws JMSException {
        Connection connection = connectionFactory.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(queue);
        Message message = session.createTextMessage();
        message.setStringProperty("name", "World!!");
        producer.send(message);
        System.exit(0);
    }
}
</pre>
<p>If you deploy and run this application you should see in the server output the string &#8220;Hello World!!<br />
<a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB8.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB8.png" alt="" title="MDB8" width="810" height="198" class="aligncenter size-full wp-image-542" /></a></p>
<p>What&#8217;s going on?<br />
First we have to create 2 resources to inject the parameters into the Queue and ConnectionFactory . This can be done easily with the @resource annotation.<br />
Next, we just have to create the actual jms-message. I think the code is pretty clear so it shouldn&#8217;t be to difficult to understand what&#8217;s going on.</p>
<h2>Remote invocation</h2>
<p>It would be cool if we can run the client from a remote computer.<br />
This is also very easy with webstart.</p>
<p>Go to your Glassfish admin and simply enable Java Web Start.<br />
<a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB9.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB9.png" alt="" title="MDB9" width="759" height="252" class="aligncenter size-full wp-image-543" /></a></p>
<p>If you launch this jnpl file from a remote compter, you should again see the message &#8220;Hello World!!&#8221; in your Glassfish Server output.</p>
<p>When you get an error, it&#8217;s possible that you have to change the IP address of the orb-listener-1 to the IP address of the computer where your Glassfish is running on.<br />
<a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB10.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB10.png" alt="" title="MDB10" width="659" height="691" class="aligncenter size-full wp-image-544" /></a></p>
<p>Happy Messaging!!</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2011/01/create-a-message-driven-bean-with-netbeans/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>PHP quirks: passing an array by reference</title>
		<link>http://dev.eek.be/2010/10/php-quirks-passing-an-array-by-reference/</link>
		<comments>http://dev.eek.be/2010/10/php-quirks-passing-an-array-by-reference/#comments</comments>
		<pubDate>Sat, 16 Oct 2010 12:39:12 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[quirks]]></category>
		<category><![CDATA[references]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=375</guid>
		<description><![CDATA[Passing an array in php to a foreach which loops over the elements by reference can have strange behaviour. Look at the following code: //Create an array $array=array('a','b','c','d','e','f','g'); //Loop over the array by reference foreach($array as &#038;$a){ } //Loop again over the array foreach($array as $a){ } //Print the array print_r($array); What do you think ]]></description>
			<content:encoded><![CDATA[<p>Passing an array in php to a foreach which loops over the elements by reference can have strange behaviour.<br />
<span id="more-375"></span></p>
<p>Look at the following code:</p>
<pre class="prettyprint">

//Create an array
$array=array('a','b','c','d','e','f','g');

//Loop over the array by reference
foreach($array as &#038;$a){
}

//Loop again over the array
foreach($array as $a){
}

//Print the array
print_r($array);
</pre>
<p>What do you think the output would be if you run this piece of code?<br />
Because the array is never changed, the expected result would be:</p>
<pre class="prettyprint">
Array
(
    [0] => a
    [1] => b
    [2] => c
    [3] => d
    [4] => e
    [5] => f
    [6] => g
)
</pre>
<p>If that was the case, I obviously wouldn&#8217;t made this blogpost <img src='http://dev.eek.be/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> <br />
The result of the code is:</p>
<pre class="prettyprint">
Array
(
    [0] => a
    [1] => b
    [2] => c
    [3] => d
    [4] => e
    [5] => f
    [6] => f
)
</pre>
<p><strong>What&#8217;s going on??</strong><br />
Well&#8230;<br />
When you loop the first time over the array, the variable $a will be referenced to the array $array.<br />
This means that with every iteration $a points to the specified element in the array.<br />
After every element passed the foreach, $a still points to the last element in the array. In this case &#8216;g&#8217;.</p>
<p>Now you have to loop again over the array.<br />
When the first element &#8216;a&#8217; is passed to the foreach. $a will be set to &#8216;a&#8217; but there is still a reference to $a from the previous foreach, which holds the value &#8216;g&#8217;. Because it&#8217;s a reference, the value of &#8216;g&#8217; in the array changes to &#8216;a&#8217;.<br />
When the second element &#8216;b&#8217; is passed to the foreach. $a will be set to &#8216;b&#8217; but the reference to $a still exists so the value of the referenced $a changes from &#8216;a&#8217; to &#8216;b&#8217;<br />
And so on.</p>
<p>If you print the value of the array at every iteration, you will have the following output:</p>
<pre class="prettyprint">
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f [6] => a )
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f [6] => b )
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f [6] => c )
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f [6] => d )
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f [6] => e )
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f [6] => f )
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f [6] => f )
</pre>
<p><strong>What to do??</strong><br />
1. Don&#8217;t use references in a foreach. Really. If you have to do it, you propably are doing something wrong.<br />
2. If you do need them, delete them after they are used:</p>
<pre class="prettyprint">
$array=array('a','b','c','d','e','f','g');

//Loop over the array
foreach($array as &#038;$a){
}
//remove the reference
unset($a);
//loop again over the array. The output looks like expected
foreach($array as $a){
        print_r($array);
}
</pre>
<p>3. If you do need them and you can&#8217;t delete it because you need the variable elsewhere. Document your code!!!<br />
This little piece of code is very hard to debug when there&#8217;s something wrong. Good documented code can save you a lot of headache.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2010/10/php-quirks-passing-an-array-by-reference/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Backing up Mysql with Java and PHP</title>
		<link>http://dev.eek.be/2010/04/backing-up-mysql-with-java-and-php/</link>
		<comments>http://dev.eek.be/2010/04/backing-up-mysql-with-java-and-php/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 09:35:26 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[dump]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=310</guid>
		<description><![CDATA[mysqldump is an effective tool to backup MySQL databases. In normal cases, it&#8217;s done trough a command line commando but it can be used programmatically. It&#8217;s a very easy script and it could be useful. (don&#8217;t have to log in into console to take a backup, create an auto backup on deployment, &#8230;) It will ]]></description>
			<content:encoded><![CDATA[<p>mysqldump is an effective tool to backup MySQL databases. In normal cases, it&#8217;s done trough a command line commando but it can be used programmatically.<br />
It&#8217;s a very easy script and it could be useful. (don&#8217;t have to log in into console to take a backup, create an auto backup on deployment, &#8230;)<br />
It will work on Windows and Linux as long as mysql is in your PATH.</p>
<pre class="prettyprint">
package be.eek.test.mysql;

import java.io.IOException;
import java.io.InputStream;

public class MysqlBackup {

    /**
    main method is just to create a working example
    **/
    public static void main(String[] args) throws IOException {
        new MysqlBackup().MakeBackup();
    }

    public void MakeBackup() throws IOException {
        String dump = "mysqldump "      //Path to mysql
                + "--host=localhost "       //Mysql hostname
                + "--port=3306 "            //Mysql portnumber
                + "--user=root "            //Mysql username
                + "--password=test "        //Mysql password
                + "--add-drop-table "       //Add a DROP TABLE statement before each CREATE TABLE statement
                + "--add-drop-database "    //Add a DROP DATABASE statement before each CREATE DATABASE statement
                + "--complete-insert "      //Use complete INSERT statements that include column names.
                + "--extended-insert "      //Use multiple-row INSERT syntax that include several VALUES lists
                + "test";                   //Mysql databasename

        Process run = Runtime.getRuntime().exec(dump);

        InputStream in = run.getInputStream();

        int nextChar;
        StringBuffer sb = new StringBuffer();

        while ((nextChar = in.read()) != -1) {
            sb.append((char) nextChar);
        }

        //Here, you can for example write it to a file and save it
        System.out.println(sb);
    }
}
</pre>
<p>The same thing is also possible in php:</p>
<pre class="prettyprint lang-php">
$dump = "mysqldump "
        . "--host=localhost "       //Mysql hostname
        . "--port=3306 "            //Mysql portnumber
        . "--user=root "            //Mysql username
        . "--password=test "        //Mysql password
        . "--add-drop-table "       //Add a DROP TABLE statement before each CREATE TABLE statement
        . "--add-drop-database "    //Add a DROP DATABASE statement before each CREATE DATABASE statement
        . "--complete-insert "      //Use complete INSERT statements that include column names.
        . "--extended-insert "      //Use multiple-row INSERT syntax that include several VALUES lists
        . "test";                   //databasename

$backup = system($dump);
echo $backup;
die();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2010/04/backing-up-mysql-with-java-and-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Go language</title>
		<link>http://dev.eek.be/2009/11/go-language/</link>
		<comments>http://dev.eek.be/2009/11/go-language/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 20:27:13 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[Go]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=237</guid>
		<description><![CDATA[Google released a new programming language. I&#8217;m not pretty sure if it will become popular but here are two videos to give you an impression]]></description>
			<content:encoded><![CDATA[<p>Google released a new programming language.<br />
I&#8217;m not pretty sure if it will become popular but here are two videos to give you an impression.</p>
<p><object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/wwoWei-GAPo&#038;hl=en&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/wwoWei-GAPo&#038;hl=en&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object><br />
<object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/rKnDgT73v8s&#038;hl=en&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/rKnDgT73v8s&#038;hl=en&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2009/11/go-language/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

