<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss'><id>tag:blogger.com,1999:blog-19517292</id><updated>2009-10-14T15:49:53.666+02:00</updated><title type='text'>Alex Soto</title><subtitle type='html'>Hello, my name is Alex. I studied Computer Science and Engineering. I am focus in Artificial Intelligence, and now I am working in Rule Induction using Emergent Intelligence.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://alexsotob.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default'/><link rel='alternate' type='text/html' href='http://alexsotob.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Alex Soto</name><uri>http://www.blogger.com/profile/11632964711752480304</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>10</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-19517292.post-8523720631477943861</id><published>2008-04-29T18:26:00.005+02:00</published><updated>2008-04-29T18:48:39.426+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Spring Integration Java XMPP Smack Jabber SourceAdapter'/><title type='text'>... and all he captures is endless rain.</title><content type='html'>&lt;style type="text/css"&gt;--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;At last entry i wrote about developing a Taget Adapter for &lt;span style="font-style: italic;"&gt;SpringIntegration&lt;/span&gt; Module. In thi sentry i will talk about developing a &lt;span style="font-style: italic;"&gt;SourceAdapter.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;As my last entry, &lt;span style="font-style: italic;"&gt;Jabber&lt;/span&gt; server will be used, and &lt;span style="font-style: italic;"&gt;Smack&lt;/span&gt; API for connecting and receiving messages.&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;From previous entry server configuration, and some classes will be used, so strictly, only &lt;span style="font-style: italic;"&gt;SourceAdapter&lt;/span&gt; and its configuration are going to be explain.&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;Firstly, but, a little explanation about two possible kind of communication for source adapters:&lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;      &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;Poll: which means that every period of time the program are checking if new content is available. For example FTP Source Adapter is an example because ftp server doesn't throw an interruption when another user upload a file.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;    &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;Driven-Event: which means that an asynchronous event is thrown and can be captured. Our IM Adapter is an example.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;     &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;Each &lt;span style="font-style: italic;"&gt;SourceAdapter&lt;/span&gt; must implements &lt;span style="font-style: italic;"&gt;SourceAdapter&lt;/span&gt; interface. But as &lt;span style="font-style: italic;"&gt;TargetAdapter,&lt;/span&gt; there are some classes that help developers in writting an Adapter. At least two classes are provided for developing a &lt;span style="font-style: italic;"&gt;SourceAdapter&lt;/span&gt; that, of course, implements &lt;span style="font-style: italic;"&gt;SourceAdapter&lt;/span&gt; interface:&lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;    &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-style: italic;"&gt;AbstractSourceAdapter:&lt;/span&gt; A base class providing common behavior for source adapters. It has some methods for sending messages to a channel, set message mappers, ...&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;    &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-style: italic;"&gt;PollingSourceAdapter:&lt;/span&gt; A base class for polling if new message is available to be sent. It has some methods like period between polls, initial delay, ...&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;        &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;Our case requires extending &lt;span style="font-style: italic;"&gt;AbstractSourceAdapter.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;IMSourceAdapter extends AbstractSourceAdapter&lt;immessage&gt; implements&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;        &lt;span style="font-size:85%;"&gt;InitializingBean&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;IMMessage is a class that represents a message sent through channel. IMMessage is a self developed class and its explanation can be found on previous post.&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;Because of event communication, &lt;span style="font-style: italic;"&gt;Smack&lt;/span&gt; API requires that you subscribe to an event implementing an interface, so each time an event occurs, that interface is executed. This initialization is developed in initialize() Spring method and next piece of code is the business logic.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;final XMPPConnection connection = new XMPPConnection(this.server); (1)&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;  try {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;   connection.connect();&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;   connection.login(this.user, this.password);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;  } catch (final XMPPException e) {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;   throw new MessageHandlingException("Error starting", e);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;  }&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;  final PacketFilter packetFilter = new MessageTypeFilter(&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;          Message.Type.chat);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;  connection.createPacketCollector(packetFilter); (2)&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;  final PacketListener packetListener = new PacketListener() { (3)&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;   @Override&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;   public void processPacket(Packet arg0) {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;    String msn = ((Message) arg0).getBody(); (4)&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;    SimpleIMMessage simpleIMMessage = new SimpleIMMessage();&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;    simpleIMMessage.setText(msn); (5)&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;    IMSourceAdapter.this.sendToChannel(simpleIMMessage); (6)&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;   }&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;blockquote&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;  };&lt;br /&gt;connection.addPacketListener(packetListener, packetFilter); (7)&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;          &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;(1) Uses Smack XMPPConnection for connecting to server.&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;(2) Creats a filter for throwing only events when a new chat message is received.&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;(3) Creats the business logic that must be executed each time a message is received.&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;(4) Gets the body of the message. (What the other user has written).&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;(5) Creats an IMMessage for sending through channel.&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;(6) Send the message through MessageChannel.&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;(7) Register the event.&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;As can be seen, the only important call is &lt;span style="font-style: italic;"&gt;sendToChannel&lt;/span&gt; that sends the message to spring integration structure, the other logic may vary depending on source adapter that are going to be developed.&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;XML configuration file is so easy:&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#60;?xml version="1.0" encoding="UTF-8"?&amp;#62;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;  &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#60;&lt;br /&gt;beans:beans xmlns="http://www.springframework.org/schema/integration"&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt; xmlns:beans="http://www.springframework.org/schema/beans"&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt; xmlns:context="http://www.springframework.org/schema/context"&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt; xmlns:jee="http://www.springframework.org/schema/jee"&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt; xsi:schemaLocation="http://www.springframework.org/schema/beans&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;        &lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;http://www.springframework.org/schema/beans/spring-beans-2.5.xsd&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;        &lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;http://www.springframework.org/schema/integration&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;        &lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;http://www.springframework.org/schema/integration/spring-integration-1.0.xsd&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;        &lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;http://www.springframework.org/schema/context&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;        &lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;http://www.springframework.org/schema/context/spring-context-2.5.xsd&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;        &lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;http://www.springframework.org/schema/jee &lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;        &lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;http://www.springframework.org/schema/jee/spring-jee-2.5.xsd"&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0in;"&gt;  &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#60;message-bus /&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;  &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#60;annotation-driven /&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;  &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#60;channel id="inMessage"&gt;&amp;#60;/channel&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;  &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;  &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#60;beans:bean id="sourceIM" class="test.spring.integration.im.IMSourceAdapter"&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;  &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#60;beans:property name="user" value="logger"&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;  &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#60;/beans:property&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;  &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#60;beans:property name="password" value="logger"&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;  &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#60;/beans:property&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;  &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#60;beans:property name="server" value="localhost"&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#60;/beans:property&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;  &amp;#60;beans:property name="channel" ref="inMessage"&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;  &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#60;/beans:property&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;  &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#60;beans:property name="messageMapper"&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;  &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#60;beans:bean class="test.spring.integration.im.TextIMMessageMapper"&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;  &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#60;/beans:bean&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;  &amp;#60;/beans:property&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt; &amp;#60;/beans:bean&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt; &amp;#60;file-target directory="/temp" channel="inMessage"/&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#60;/beans:beans&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&amp;#62;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;         &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;For running the example, start the Jabber Server (OpenFire), start a client Spark, and talk to logger user. Each message will be saved one file.&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;SpringIntegration 1.0M3 has been used for developing the TargetAdapter.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19517292-8523720631477943861?l=alexsotob.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://alexsotob.blogspot.com/feeds/8523720631477943861/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=19517292&amp;postID=8523720631477943861' title='1 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/8523720631477943861'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/8523720631477943861'/><link rel='alternate' type='text/html' href='http://alexsotob.blogspot.com/2008/04/and-all-he-captures-is-endless-rain.html' title='... and all he captures is endless rain.'/><author><name>Alex Soto</name><uri>http://www.blogger.com/profile/11632964711752480304</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07751811022503259661'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19517292.post-1984735706875142491</id><published>2008-04-15T21:40:00.009+02:00</published><updated>2008-04-19T11:41:06.869+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='springframework spring integration java TargetAdapter XMPP smack'/><title type='text'>There are four new colours on the rainbow, an old man takes polaroids ...</title><content type='html'>&lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt;Spring Integration is a new project from &lt;a href="http://www.springframework.org/"&gt;Spring Framework&lt;/a&gt; developers. As it says on its website: &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;"&lt;span style="font-style: italic;"&gt;Provides a programming model to support the well-known Enterprise Integration Patterns (...) and enables simple messaging within Spring-based applications and integrates with external systems via simple adapters.&lt;/span&gt;" &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;Its homepage is &lt;a href="http://www.springframework.org/spring-integration"&gt;http://www.springframework.org/spring-integration&lt;/a&gt;. &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;In this entry, but is supposed that some basic concepts about Spring Integration are known. What we are going to explain is the development of a new adapter. &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;But what is an Adapter? In Spring Integration, an adapter is a component that interacts with external systems (servers, other components ...). As its name suggests, an adapter adapts the input of an external component and it transforms to something that can be sent through spring-integration pipe, and also adapts what is received from the pipe for sending to external component. &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;That pipe is &lt;span style="font-style: italic;"&gt;MessageChannel&lt;/span&gt; class. Spring Integration is built with different adapters, JMS, RMI, Files, Mail, ... That's good while you are working with systems that required adapters are already implemented, but, what's happens if your application requires communication with an external system which an adapter has not already developed? The solution is easy, implement yourself the adapter. &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;That's what I am going to explain, how to implements a &lt;span style="font-style: italic;"&gt;TargetAdapter&lt;/span&gt; (adapter for output messaging). In next entry would be explain how to implement a SourceAdapter (adapter for incoming messages). &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;Only two classes are really important org.springframework.integration.handler.MessageHandler that is used for handle the messages, and org.springframework.integration.message.AbstractMessageMapper that transform:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;          &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt;From specific input to Spring Integration Message. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;         &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt;From Spring Integration Message to specific output.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;     &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt;In this example, integration to instant messaging system will be used. The basic idea is develop a system that sent a message from Spring Integration to a XMPP server (a.k.a Jabber) user account.&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;       &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;Full schema of application is:&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_mu60LWPmw0A/SAm7-gFH9II/AAAAAAAABB0/yumw6Y1kRbA/s1600-h/schema.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_mu60LWPmw0A/SAm7-gFH9II/AAAAAAAABB0/yumw6Y1kRbA/s400/schema.jpg" alt="" id="BLOGGER_PHOTO_ID_5190886727958918274" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0in;"&gt;For running, apart from Spring/Spring Integration jars, JDK ..., two programs and an API are required:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;         &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt;OpenFire, that's a XMPP server. XMPP is an open, XML-inspired protocol for near real time, extensible instant messaging (IM) and presence information. &lt;a href="http://www.igniterealtime.org/projects/openfire/index.jsp"&gt;http://www.igniterealtime.org/projects/openfire/index.jsp &lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;         &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt; Spark, a client for communicating with XMPP server. &lt;a href="http://www.igniterealtime.org/projects/spark/index.jsp"&gt;http://www.igniterealtime.org/projects/spark/index.jsp&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;       &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt;Smack, an API for communicating with XMPP server. &lt;a href="http://www.igniterealtime.org/projects/smack/index.jsp"&gt;http://www.igniterealtime.org/projects/smack/index.jsp &lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;       &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt;First install OpenFire server and add two users:  &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; - login)&lt;span style="font-style: italic;"&gt; logger&lt;/span&gt; password) &lt;span style="font-style: italic;"&gt;logger&lt;/span&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; - login) &lt;span style="font-style: italic;"&gt;incidence&lt;/span&gt; password) &lt;span style="font-style: italic;"&gt;incidence&lt;/span&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;Second, install Spark, and then login with logger account and add incidence user as buddy and logout, after that login with incidence and add logger user as buddy, and don't logout. &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;Third, put smack jar and its dependencies into class path (Spring dependencies are there too). &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;Now, start the development of two most important classes:&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;       &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;blockquote&gt;class IMTargetAdapter implements MessageHandler, InitializingBean&lt;/blockquote&gt;&lt;br /&gt;      &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt;Acts as an adapter through internal messages to external messages. The most important method is handle. &lt;/p&gt;&lt;br /&gt;      &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p style="margin-bottom: 0in;"&gt;public Message handle(final Message msn{ &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;  final IMMessage iMessage = this.textMessage &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;          .fromMessage((Message&lt;string&gt;) msn); (1) &lt;/string&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;  iMessage.setTo(this.getReceiver()); &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;  try { &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;   this.xmppSender.send((SimpleIMMessage) iMessage); (2) &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;  } catch (final IMException e) { &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;   throw new MessageHandlingException("Error while sending message.", &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;           e); (3) &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;  } &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;  return null; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; } &lt;/p&gt;&lt;/blockquote&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;/p&gt; &lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;         &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;(1) using a MessageMapper the spring integration message class (msn variable) is transformed to specific external system messages. &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;(2) using xmppSender (Facade for accessing Smack Library [out of scope of this entry]), the message is sent. &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;(3) case that an error occurs, MessageHandlingException must be thrown. &lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;         &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;And finally class TextIMMessageMapper extends &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;        AbstractMessageMapper&lt;string,&gt; &lt;/string,&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;That has two important methods:&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;         &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p style="margin-bottom: 0in;"&gt;public IMMessage fromMessage(final Message&lt;string&gt; msn) { (1) &lt;/string&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;  final SimpleIMMessage simpleIMMessage = new SimpleIMMessage(); &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;  simpleIMMessage.setText(msn.getPayload()); &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;  return simpleIMMessage; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; } &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; public Message&lt;string&gt; toMessage(final IMMessage msn) { (2) &lt;/string&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;  return new StringMessage(((SimpleIMMessage) msn).getText()); &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; } &lt;/p&gt;&lt;/blockquote&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;      &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;(1) transforms spring integration message to external message. SimpleIMMessage is a class that wraps messages that are sent using Smack API. &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;(2) transforms an external message to spring integration message (used in SourceAdapters). &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;Then it is time to configure the Spring XML file for configure channels and TargetAdapters so messages can be delivered to Instant Message Service.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;         &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt;&amp;lt;channel id="output"&amp;gt;&amp;lt;/channel&amp;gt; (1) &lt;/p&gt;          &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt;&amp;lt;beans:bean id="defaultMessageEndpoint" class="org.springframework.integration.endpoint.DefaultMessageEndpoint"&amp;gt;(2) &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;  &amp;lt;beans:property name="handler"&amp;gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;   &amp;lt;beans:bean class="test.spring.integration.im.IMTargetAdapter"&amp;gt;(3) &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;    &amp;lt;beans:property name="xmppSender" ref="xmppIM"&amp;gt;&amp;lt;/beans:property&amp;gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;    &amp;lt;beans:property name="receiver" value="incidence@grumpy"&amp;gt;&amp;lt;/beans:property&amp;gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;   &amp;lt;/beans:bean&amp;gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;  &amp;lt;/beans:property&amp;gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;  &amp;lt;beans:property name="subscription"&amp;gt;(4) &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;   &amp;lt;beans:bean class="org.springframework.integration.scheduling.Subscription"&amp;gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;    &amp;lt;beans:constructor-arg type="java.lang.String" value="output"&amp;gt;&amp;lt;/beans:constructor-arg&amp;gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;   &amp;lt;/beans:bean&amp;gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;  &amp;lt;/beans:property&amp;gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &amp;lt;/beans:bean&amp;gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0in;"&gt;      &lt;style type="text/css"&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;(1) Defines the output channel. &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;(2) Each component that is connected into MessageChannel must be a MessageEndpoint. DefaultMessageEndpoint is a helper class for this porpoise. Because TargetAdapter is not an Endpoint, it must be wrapped into one. &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;(3) Handler method is method that will be invoked by MessageEndpoint when a message is received. In this case, a MessageHandler (IMTargetAdapter) is provided, with required information (Facade for communicating with Smack API, and the receiver of messages (incidence@&lt;server_host&gt;). &lt;/server_host&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;(4) MessageEndpoint must be subscribed into a channel. &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;Using Namehandler is out of scope of this document; of course it would be cleaner using Ext. XML authoring. &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;And that's all; you can download source code for trying, but remember to change receiver value.  &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;a href="http://www.uploading.com/files/W9ASWJBI/TargetAdapterIM.zip.html"&gt;Download&lt;/a&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;The example has been developed using:&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;JDK 6.0&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;Eclipse 3.3&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;P.S. This entry was written using spring integration 1.0.0 M3&lt;/p&gt; &lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19517292-1984735706875142491?l=alexsotob.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://alexsotob.blogspot.com/feeds/1984735706875142491/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=19517292&amp;postID=1984735706875142491' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/1984735706875142491'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/1984735706875142491'/><link rel='alternate' type='text/html' href='http://alexsotob.blogspot.com/2008/04/there-are-four-new-colours-on-rainbow.html' title='There are four new colours on the rainbow, an old man takes polaroids ...'/><author><name>Alex Soto</name><uri>http://www.blogger.com/profile/11632964711752480304</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07751811022503259661'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_mu60LWPmw0A/SAm7-gFH9II/AAAAAAAABB0/yumw6Y1kRbA/s72-c/schema.jpg' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19517292.post-2992983342984374438</id><published>2007-08-25T20:58:00.000+02:00</published><updated>2007-08-25T21:23:37.995+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='fishing'/><title type='text'>Fishing (none technical entry :P)</title><content type='html'>Well after all my work mates laught at me with my last (and unsuccessful) fishing experience, (too long to explain in a blog sorry), the other day i went to fish again, and this time of course "who doubt it", the experience was successful. Five &lt;span onclick="dr4sdgryt2(event)" style="cursor: pointer;"&gt;gilthead bream.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span onclick="dr4sdgryt2(event)" style="cursor: pointer;"&gt;Of course, i won't tell where we go cause this is like mushroom fields, nobody tells the secret place. But the view is beautiful.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_mu60LWPmw0A/RtB_r5MFe7I/AAAAAAAAAAM/5esaRWKIyKg/s1600-h/beach.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_mu60LWPmw0A/RtB_r5MFe7I/AAAAAAAAAAM/5esaRWKIyKg/s400/beach.jpg" alt="" id="BLOGGER_PHOTO_ID_5102718769873386418" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Well as i told, i went to fish with Jessi and two friends, with two fishing rods and ten worms from 22:00 to 02:00.&lt;br /&gt;&lt;br /&gt;Cause im sure my work mates won't believe me, i upload some photos.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_mu60LWPmw0A/RtCA3pMFe9I/AAAAAAAAAAc/Sb1r-yBOpV4/s1600-h/fish2.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_mu60LWPmw0A/RtCA3pMFe9I/AAAAAAAAAAc/Sb1r-yBOpV4/s400/fish2.jpg" alt="" id="BLOGGER_PHOTO_ID_5102720071248477138" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_mu60LWPmw0A/RtCAjZMFe8I/AAAAAAAAAAU/yBkDYI_wWC4/s1600-h/fish1.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_mu60LWPmw0A/RtCAjZMFe8I/AAAAAAAAAAU/yBkDYI_wWC4/s400/fish1.jpg" alt="" id="BLOGGER_PHOTO_ID_5102719723356126146" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;And of course next day we got a great launch with our treasures.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_mu60LWPmw0A/RtCBP5MFe-I/AAAAAAAAAAk/i7Rew7cXpJ8/s1600-h/launch.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_mu60LWPmw0A/RtCBP5MFe-I/AAAAAAAAAAk/i7Rew7cXpJ8/s400/launch.jpg" alt="" id="BLOGGER_PHOTO_ID_5102720487860304866" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span onclick="dr4sdgryt2(event)" style="cursor: pointer;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19517292-2992983342984374438?l=alexsotob.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://alexsotob.blogspot.com/feeds/2992983342984374438/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=19517292&amp;postID=2992983342984374438' title='2 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/2992983342984374438'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/2992983342984374438'/><link rel='alternate' type='text/html' href='http://alexsotob.blogspot.com/2007/08/fishing-none-technical-entry-p.html' title='Fishing (none technical entry :P)'/><author><name>Alex Soto</name><uri>http://www.blogger.com/profile/11632964711752480304</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07751811022503259661'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_mu60LWPmw0A/RtB_r5MFe7I/AAAAAAAAAAM/5esaRWKIyKg/s72-c/beach.jpg' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19517292.post-116254092323476072</id><published>2006-11-03T08:59:00.000+01:00</published><updated>2006-11-08T19:50:21.093+01:00</updated><title type='text'>After Spring, the Summer Comes</title><content type='html'>&lt;p align="center"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.springframework.org/files/xdev-spring_logo.jpg"&gt;&lt;img style="width: 388px; height: 54px;" alt="" src="http://www.springframework.org/files/xdev-spring_logo.jpg" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="justify"&gt;Hello, in blog "After Spring, the Summer Comes", I will summarize interfaces of Spring Core Framework for extending its funcionalities. I'm an active member in Spring Forum, so I have seen some questions about extending funcionalities in Spring or how to modify some behavior of Framework, for this reason I have decided to write down some extension points of Core.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;div align="justify"&gt;First interface is (application/Bean)&lt;em&gt;FactoryAware&lt;/em&gt; if your class implements previous interface, and also have an attribute of (application/BeanFactory) and a setter method, &lt;strong&gt;Spring&lt;/strong&gt; will inject the current loaded class. (See 3.3.8 for more information). Moreover it is explained how to avoid the intrusion of &lt;strong&gt;Spring&lt;/strong&gt; into our code.&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;Next interface &lt;em&gt;MethodReplacer&lt;/em&gt; is used for changing implementation of a method. &lt;strong&gt;Spring&lt;/strong&gt; will inject new implementation to existing class method. (See 3.3.8.2 for an example).&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;Another interesting interface is &lt;em&gt;org.springframework.beans.factory.config.Scope&lt;/em&gt;. &lt;strong&gt;Spring&lt;/strong&gt; 2.0, implements five different scopes, prototype, singleton, request, session, global session. Of course, &lt;strong&gt;Spring&lt;/strong&gt; offers the possibility of creating our scope by implementing &lt;em&gt;Scope&lt;/em&gt; interface. In chapter 3.4.4, an example can be found.&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;Two interfaces are provided to control lifecycle of bean. These two interfaces are &lt;em&gt;org.springframework.beans.factory.InitializingBean&lt;/em&gt; that are executed after properties of bean are setted, and &lt;em&gt;org.springframework.beans.factory.DisposableBean&lt;/em&gt; that is called when container containing the bean is being destroyed. Of course it is better to use next approach, that is using init-method and destroy-method from &lt;strong&gt;Spring&lt;/strong&gt; file, so no &lt;strong&gt;Spring&lt;/strong&gt; dependencies are inserted into our code. This last option is preferred but these two exceptions also exists. (See Chapter 3.5.1). &lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;Another interface is &lt;em&gt;org.springframework.beans.factory.BeanNameAware&lt;/em&gt;. The BeanFactory will call the bean through this interface to inform the bean of the id it was deployed under. (See 3.5.2.2 for a little description). &lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;Next interface &lt;em&gt;BeanPostProcessor&lt;/em&gt; is used if you want to do some custom logic after the Spring container has finished instantiating, configuring and otherwise initializing a bean, you can plug in one or more &lt;em&gt;BeanPostProcessor&lt;/em&gt; implementations. (See Chapter 3.7.1). &lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;The next extension point that we will look at is the &lt;em&gt;org.springframework.beans.factory.config.BeanFactoryPostProcessor&lt;/em&gt;. &lt;em&gt;BeanFactoryPostProcessors&lt;/em&gt; reads the configuration metadata and potentially change it before the container has actually instantied any other beans. Typical example is &lt;em&gt;PropertyPlaceholderConfigurer&lt;/em&gt;, where values injected into a bean are changed for .properties file. (See Chapter 3.7.2 for full information). &lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;Next very important interface is &lt;em&gt;org.springframework.beans.factory.FactoryBean&lt;/em&gt;. This interface must be implemented by objects that are themselves factories, and you want to use &lt;strong&gt;Spring&lt;/strong&gt; IoC. If you have some complex initialization code that is better expressed in Java as opposed to a (potentially) verbose amount of XML, you can create your own &lt;em&gt;FactoryBean&lt;/em&gt;, write the complex initialization inside that class, and then plug your custom &lt;em&gt;FactoryBean&lt;/em&gt; into the container. (See Chapter 3.7.3). &lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;&lt;strong&gt;Spring&lt;/strong&gt; has events, two interfaces must be implemented &lt;em&gt;ApplicationContext&lt;/em&gt; and &lt;em&gt;ApplicationEvent&lt;/em&gt;. Every time an &lt;em&gt;ApplicationEvent&lt;/em&gt; gets published to the &lt;strong&gt;ApplicationContext&lt;/strong&gt;, that bean will be notified.&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;&lt;strong&gt;Spring's&lt;/strong&gt; Resource interface is meant to be a more capable interface for abstracting access to low-level resources. It is used in Spring and by Spring.&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;&lt;strong&gt;Spring's&lt;/strong&gt; features a&lt;i&gt; Validator&lt;/i&gt; interface that you can use to validate objects. The&lt;i&gt; Validator&lt;/i&gt; interface works using an &lt;em&gt;Errors&lt;/em&gt; object so that while validating, validators can report validation failures to the &lt;em&gt;Errors&lt;/em&gt; object. &lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;&lt;em&gt;PropertyEditorSupport&lt;/em&gt; is a class not interface, but also it is used for extending Spring. PropertyEditors are used for converting String format to the complex type of a property. For example &lt;strong&gt;Spring&lt;/strong&gt; provides&lt;i&gt; &lt;/i&gt;LocaleEditor that converts an String value to a Locale class. (In chapter 5.4.2.1 an example is provided). &lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;The last class I explain for extending &lt;strong&gt;Spring&lt;/strong&gt; is &lt;em&gt;NamespaceHandler&lt;/em&gt; and interface &lt;em&gt;BeanDefinitionParser&lt;/em&gt;. Both classes are used for extending basic XML &lt;strong&gt;Spring&lt;/strong&gt; file. You can write your own custom XML bean definition parsers and integrating such parsers into the &lt;strong&gt;Spring&lt;/strong&gt; IoC container. This approach is used by &lt;strong&gt;Spring&lt;/strong&gt; 2.0 for transactions, utils, ... You can create your own definition as is explainde in &lt;myns:dateformat id="dateFormat"&gt;&lt;myns:dateformat id="dateFormat" lenient="true" pattern="yyyy-MM-dd HH:mm"&gt;&lt;myns:dateformat id="dateFormat" lenient="true" pattern="yyyy-MM-dd HH:mm"&gt;Appendix B.&lt;/myns:dateformat&gt;&lt;/myns:dateformat&gt;&lt;/myns:dateformat&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;myns:dateformat&gt;&lt;myns:dateformat lenient="true" pattern="yyyy-MM-dd HH:mm"&gt;&lt;myns:dateformat lenient="true" pattern="yyyy-MM-dd HH:mm"&gt;Now &lt;em&gt;&lt;strong&gt;Summer&lt;/strong&gt;&lt;/em&gt; has become. You have some interfaces to extend &lt;strong&gt;Spring Framework&lt;/strong&gt; so it &lt;/myns:dateformat&gt;&lt;/myns:dateformat&gt;&lt;/myns:dateformat&gt;can adapt to your necessities.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19517292-116254092323476072?l=alexsotob.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://alexsotob.blogspot.com/feeds/116254092323476072/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=19517292&amp;postID=116254092323476072' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/116254092323476072'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/116254092323476072'/><link rel='alternate' type='text/html' href='http://alexsotob.blogspot.com/2006/11/after-spring-summer-comes.html' title='After Spring, the Summer Comes'/><author><name>Alex Soto</name><uri>http://www.blogger.com/profile/11632964711752480304</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07751811022503259661'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19517292.post-115313191212511159</id><published>2006-07-17T12:23:00.000+02:00</published><updated>2006-07-18T10:08:50.730+02:00</updated><title type='text'>Offspring matters ....</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://xmlbeans.apache.org/images/project-logo.gif"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 200px;" src="http://xmlbeans.apache.org/images/project-logo.gif" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;As you know, in &lt;span style="font-weight: bold;"&gt;XSD&lt;/span&gt; files, there is an attribute to mark an element as abstract. This means that other element will extend it. Typical example of Figure, with Circle, Square, ... as children.&lt;br /&gt;&lt;br /&gt;Ok, that's perfect. Imagine you are using &lt;span style="font-weight: bold;"&gt;XmlBeans&lt;/span&gt; (XML binding). You have a list of FigureType, and want to iterate over all figures, and depending its type, make one thing or another (for example drawing the figure). In this case an instanceof approach won't work because in XML Beans we are working with interfaces, not with implementations object, so for example SquareType interface doesn't extends from FigureType interface. So how can we implements the previous example?&lt;br /&gt;&lt;br /&gt;Using two thing, one working wiht &lt;span style="font-weight: bold;"&gt;DOM&lt;/span&gt; repesentation instead of object representation, and next using type attribute that all extentended tags require. An example:&lt;br /&gt;&lt;br /&gt;&amp;#60;figure type="SquareType" area="c*c" sides="4"&amp;#62;&lt;br /&gt;&lt;br /&gt;Take a look that the tag is figure but square information is present.&lt;br /&gt;&lt;br /&gt;Now let's see the java code to treat this example:&lt;br /&gt;&lt;br /&gt;It is as simple as we can imagine:&lt;br /&gt;&lt;br /&gt;First we return the DOM representation&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;final Node node = figureType.getDomNode();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Next we gets the type attribute using DOM library.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;final NamedNodeMap nodeAttMap = node.getAttributes();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;final String type = nodeAttMap.getNamedItemNS("http://www.w3.org/2001/XMLSchema-instance", "type").getNodeValue();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Remember to change the first parameter of getNameItemNS if namespace of type attribute is changed.&lt;br /&gt;&lt;br /&gt;and finally simply a hell if-then-else sequence:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;if("SquareType".equals(type)) {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;    (SquareType) figureType.changeType(SquareType.type));&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;} else {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;    ...&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Take a look at line inside if; we must cast from &lt;span style="font-weight: bold;"&gt;FigureType to SquareType using changeType&lt;/span&gt; method.&lt;br /&gt;&lt;br /&gt;And that's all, simple and easy, only tedious because of if-then-else chain.&lt;/figure&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19517292-115313191212511159?l=alexsotob.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://alexsotob.blogspot.com/feeds/115313191212511159/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=19517292&amp;postID=115313191212511159' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/115313191212511159'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/115313191212511159'/><link rel='alternate' type='text/html' href='http://alexsotob.blogspot.com/2006/07/offspring-matters.html' title='Offspring matters ....'/><author><name>Alex Soto</name><uri>http://www.blogger.com/profile/11632964711752480304</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07751811022503259661'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19517292.post-115260561940869075</id><published>2006-07-11T10:08:00.000+02:00</published><updated>2006-07-11T10:13:39.430+02:00</updated><title type='text'>Debianizing Java</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.ubuntu.com/include/xubuntulogo2.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 166px; height: 43px;" src="http://www.ubuntu.com/include/xubuntulogo2.png" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;When you go to java.sun.com to download JDK, you find a disagreeable surprise, only a &lt;span style="font-style: italic;"&gt;RPM&lt;/span&gt; or a &lt;span style="font-style: italic;"&gt;BIN&lt;/span&gt; file is found. What's happening if you have a &lt;span style="font-weight: bold;"&gt;Debin/Ubuntu&lt;/span&gt; distribution? Probably you would like to work with a DEB file, but it is not available in java sun site. A simple solution can be done.&lt;br /&gt;&lt;br /&gt;First you download the &lt;span style="font-style: italic;"&gt;BIN JDK&lt;/span&gt; file you want to install. Then using &lt;span style="font-style: italic;"&gt;synaptic,&lt;/span&gt; you download &lt;span style="font-style: italic;"&gt;fakeroot&lt;/span&gt; aplication and &lt;span style="font-style: italic;"&gt;make-jpkg&lt;/span&gt; application. And finally, you apply the next command, &lt;span style="font-style: italic;"&gt;fakeroot make-jpkg &lt;jdkfilename&gt;.bin&lt;/jdkfilename&gt;&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;After a few moments you will have a &lt;jdkfilename&gt;.deb file, so you can install using &lt;span style="font-weight: bold;"&gt;dpkg&lt;/span&gt; tool. After that, because we want to execute by default this new java virtual machine/compiler, execute &lt;span style="font-style: italic;"&gt;update-alternatives --config java&lt;/span&gt;, and choose the new jdk installed.&lt;br /&gt;&lt;br /&gt;And thats all, as simple as you can imagine.&lt;br /&gt;&lt;/jdkfilename&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19517292-115260561940869075?l=alexsotob.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://alexsotob.blogspot.com/feeds/115260561940869075/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=19517292&amp;postID=115260561940869075' title='1 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/115260561940869075'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/115260561940869075'/><link rel='alternate' type='text/html' href='http://alexsotob.blogspot.com/2006/07/debianizing-java.html' title='Debianizing Java'/><author><name>Alex Soto</name><uri>http://www.blogger.com/profile/11632964711752480304</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07751811022503259661'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19517292.post-114258022575311978</id><published>2006-03-17T08:11:00.000+01:00</published><updated>2006-10-21T12:59:52.620+02:00</updated><title type='text'>Cramer Versus Cramer</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;span style="font-weight: bold;"&gt;Cramer vs Cramer&lt;/span&gt;, Java Virtual Machine vs Java Virtual Machine. This article try to give information of what is the best java virtual machine for a given problem. To do this we have choosen two benchmarks so we can give an objective opinion of which are the best virtual machine. There is a lot of benchmarks and a lot of java virtual machines, but we have focused into two virtual machines, &lt;span style="font-style: italic;"&gt;Java HotSpot(TM) Client VM (build 1.5.0_05-b05)&lt;/span&gt; and &lt;span style="font-style: italic;"&gt;IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 Linux x86-32 j9vmxi3223-20051103 (JIT enabled)&lt;/span&gt;, and two benchmarks, &lt;span style="font-weight: bold;"&gt;JGF Benchmark&lt;/span&gt; &lt;a href="http://www.epcc.ed.ac.uk/javagrande/javag.html"&gt;http://www.epcc.ed.ac.uk/javagrande/javag.html&lt;/a&gt; and &lt;span style="font-weight: bold;"&gt;Richards and DeltaBlue Benchmark&lt;/span&gt; &lt;a href="http://research.sun.com/people/mario/java_benchmarking/download2.html"&gt;http://research.sun.com/people/mario/java_benchmarking/download2.html&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I would try to explain both benchmarks, but for more information please visit its site.&lt;br /&gt;&lt;br /&gt;JGF is composed by three big groups of benchmarks, Sequential Benchmark, Multi-Threaded Benchmark and MPJ Benchmark.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="text-align: justify;"&gt;&lt;li&gt;The sequential benchmarks, suitable for single processor execution.&lt;/li&gt;&lt;li&gt;The multi-threaded benchmarks, suitable for parallel execution on shared memory multiprocessors.&lt;/li&gt;&lt;li&gt;The MPJ benchmarks, suitable for parallel execution on distributed memory multiprocessors. &lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;For our porpouse only the first and second benchmarks would be executed.&lt;br /&gt;&lt;br /&gt;Sequential Benchmark also have the next subsections:&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="text-align: justify;"&gt;&lt;li&gt;Arith: execution of arithmetic operations&lt;/li&gt;&lt;li&gt;Assign: variable assignment&lt;/li&gt;&lt;li&gt;Cast: casting&lt;/li&gt;&lt;li&gt;Create: creating objects and arrays&lt;/li&gt;&lt;li&gt;Loop: Loop overheads&lt;/li&gt;&lt;li&gt;Math: execution of maths library operations&lt;/li&gt;&lt;li&gt;Method: method invocation&lt;/li&gt;&lt;li&gt;Serial: Serialisation&lt;/li&gt;&lt;li&gt;Exception Exception handling&lt;/li&gt;&lt;li&gt;Serial: Read/Write Lists&lt;/li&gt;&lt;li&gt; Method: executing methods in same object or foreign object&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="text-align: justify;"&gt;&lt;li&gt;Series: Fourier coefficient analysis&lt;/li&gt;&lt;li&gt;LUFact: LU Factorisation&lt;/li&gt;&lt;li&gt;SOR: Successive over-relaxation&lt;/li&gt;&lt;li&gt;HeapSort: Integer sorting&lt;/li&gt;&lt;li&gt;Crypt: IDEA encryption&lt;/li&gt;&lt;li&gt; FFT: FFT&lt;/li&gt;&lt;li&gt;Sparse: Sparse Matrix multiplication&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="text-align: justify;"&gt;&lt;li&gt;Search: Alpha-beta pruned search&lt;/li&gt;&lt;li&gt;Euler: Computational Fluid Dynamics&lt;/li&gt;&lt;li&gt;MD: Molecular Dynamics simulation&lt;/li&gt;&lt;li&gt;MC: Monte Carlo simulation&lt;/li&gt;&lt;li&gt;Ray Tracer: 3D Ray Tracer&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;Multi-Thread Benchmark also have the next subsection:&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="text-align: justify;"&gt;&lt;li&gt;ForkJoin: forking and joining threads&lt;/li&gt;&lt;li&gt;Barrier: barrier synchronisation&lt;/li&gt;&lt;li&gt;Sync: synchronized blocks and methods&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;ul style="text-align: justify;"&gt;&lt;li&gt;Series: Fourier coefficient analysis&lt;/li&gt;&lt;li&gt;LUFact: LU Factorisation&lt;/li&gt;&lt;li&gt;SOR: Successive over-relaxation&lt;/li&gt;&lt;li&gt;Crypt: IDEA encryption&lt;/li&gt;&lt;li&gt;Sparse: Sparse Matrix multiplication&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="text-align: justify;"&gt;&lt;li&gt;MolDyn: Molecular Dynamics simulation&lt;/li&gt;&lt;li&gt;MonteCarlo: Monte Carlo simulation&lt;/li&gt;&lt;li&gt;RayTracer: 3D Ray Tracer&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;br /&gt;At the heart of Richards is a task dispatcher (Richards.schedule). Tasks come in 4 different flavors, each represented by a class (DeviceTask, HandlerTask, IdleTask, WorkTask, all subclasses of Task). Each kind of task has an associated work function (fn). At startup (Richards.run), a particular task mix is created, and then the tasks are scheduled, each having its work function invoked. The work functions manipulate work packets and packet queues. At the end of the benchmark (in Richards.run) the number of queued and held packets is checked against the correct value to assist in verifying that the benchmark ran correctly.&lt;br /&gt;&lt;br /&gt;For our pourpouse we have executed all sequential benchmark. And only the first group of multi-thread becnhmark. Also, we have runned Richards Benchmark.&lt;br /&gt;&lt;br /&gt;All this benchmarks has been runned on a Pentium IV 3 GHz and 512 MB RAM, on Ubuntu Linux 5.10. The optional arguments for java command has been  -Xms256m -Xmx512m because there is some tests that needs as memory as possible or a RuntimeException would be thrown.&lt;br /&gt;&lt;br /&gt;Lets see the results of the first section of sequencial benchmark.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/3347/1933/1600/jfg1.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/3347/1933/400/jfg1.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;In this graph we can see that for mathematical operations is faster Java HotSpot than IBM. IBM Java Virtual Machine only wins in creations of objects and rounding numbers, in all other operations, like managing lists, arrays or casting is better Java HotSpot.&lt;br /&gt;&lt;br /&gt;About section 2 in sequencial benchmark, we can see that we have the same tests but with three different results, that is because the size of data increases in every test. See JGF homepage to see how the values increases because there is no standard growth between the tests.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/3347/1933/1600/jfg2a.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/3347/1933/320/jfg2a.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/3347/1933/1600/jfg2atime.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/3347/1933/320/jfg2atime.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;We can say that in all tests Java HotSpot is much faster that IBM JVM, this is because HotSpot is better in numerical problems than IBM Java Virtual Machine.&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/3347/1933/1600/jfg2b.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/3347/1933/320/jfg2b.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: justify;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/3347/1933/1600/jfg2btime.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/3347/1933/320/jfg2btime.jpg" alt="" border="0" /&gt;&lt;/a&gt;Although the differences has been minimized, Java HotSpot is faster than IBM JVM.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/3347/1933/1600/jfg2c.0.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/3347/1933/320/jfg2c.0.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;div style="text-align: left;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/3347/1933/1600/jfg2ctime.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/3347/1933/320/jfg2ctime.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;div style="text-align: justify;"&gt;When the load is heavy, IBM JVM in some tests are faster than Java HotSpot, surely we can say that IBM JVM manages memory data better than Java HotSpot.&lt;br /&gt;&lt;br /&gt;Now, let's do the same, but with the second group of benchmarks, remember that only the first group, because we are not interested in knowing how fast is a JVM executing mathematical operations in parallel, because we have already executed when I was executing sequential, what we really wants to know is which Java Virtual Machine manages the threads faster.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/3347/1933/1600/jfg11t.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://photos1.blogger.com/blogger/3347/1933/320/jfg11t.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As we can see, with only one thread, in this case (and all future cases), IBM Virtual Machine is faster than Sun Java HotSpot. See that synchronizers in IBM is spectacular in comparision to Java HotSpot.&lt;br /&gt;&lt;br /&gt;Note that in &lt;span style="font-style: italic;"&gt;forkjoin &lt;/span&gt;a negative value is calculated. I have tried three times the same test and with one thread, always the result has been negative. I think that an overfload has been produced. Of course it is impossible a negative count of forkjoins.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: right;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/3347/1933/1600/jfg12t.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://photos1.blogger.com/blogger/3347/1933/320/jfg12t.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;With two threads, the difference between both JVM has been reduced in three first tests, but in synchronizations, IBM still be the best ione in difference.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;With 5 , 10 and 20  threads happens the same as 2 threads. IBM still being faster than Java HotSpot.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/3347/1933/1600/jfg15t.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://photos1.blogger.com/blogger/3347/1933/320/jfg15t.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/3347/1933/1600/jfg110t.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://photos1.blogger.com/blogger/3347/1933/320/jfg110t.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/3347/1933/1600/jfg120t.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://photos1.blogger.com/blogger/3347/1933/320/jfg120t.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Finally, although first tests sun VM is faster than IBM, we can say but that with a lot of threads synchronizating, IBM VM is faster than sun VM.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/3347/1933/1600/jfg1160t.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://photos1.blogger.com/blogger/3347/1933/320/jfg1160t.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/3347/1933/1600/jfg140t.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://photos1.blogger.com/blogger/3347/1933/320/jfg140t.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/3347/1933/1600/jfg180t.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://photos1.blogger.com/blogger/3347/1933/320/jfg180t.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In summary, in &lt;span style="font-style: italic;"&gt;thread &lt;/span&gt;environment like &lt;span style="font-style: italic;"&gt;web servers, IBM JVM &lt;/span&gt;seems to be better than&lt;span style="font-style: italic;"&gt; SUN VM. &lt;/span&gt;On the other hand,  SUN VM in standard applications offer a better throughput.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19517292-114258022575311978?l=alexsotob.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://alexsotob.blogspot.com/feeds/114258022575311978/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=19517292&amp;postID=114258022575311978' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/114258022575311978'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/114258022575311978'/><link rel='alternate' type='text/html' href='http://alexsotob.blogspot.com/2006/03/cramer-versus-cramer.html' title='Cramer Versus Cramer'/><author><name>Alex Soto</name><uri>http://www.blogger.com/profile/11632964711752480304</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07751811022503259661'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19517292.post-113464361015921975</id><published>2005-12-15T11:46:00.000+01:00</published><updated>2006-02-05T13:31:29.840+01:00</updated><title type='text'>... and winter arrives to woodchuck.</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.hibernate.org/tpl/jboss/img/01_oben_logo.gif"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 167px; height: 52px;" src="http://www.hibernate.org/tpl/jboss/img/01_oben_logo.gif" alt="" border="0" /&gt;&lt;/a&gt;In this blog, I would try to justify why use Hibernate instead of plain JDBC.&lt;br /&gt;&lt;br /&gt;What is Hibernate? Hibernate is a powerful, high performance object/relational persistence and query service. What offer Hibernate? What makes better from other solutions?&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;First of all, Hibernate is considerated a professional open-source project.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;It implements all Object Oriented Programming features like, associations, inheritance, polymorphism, composition and collections.&lt;/li&gt;&lt;li&gt;It is transparent to JDBC connections, but doesn't hide.&lt;/li&gt;&lt;li&gt;It has its query engine, HQL, Criteria and Query by Example, as well as native SQL.&lt;/li&gt;&lt;li&gt;Hibernate decouples  business objects from RDMS, thanks of dialects. You can change your RDMS without changing business database process.&lt;/li&gt;&lt;li&gt;Hibernate lets you implements quality code, because it takes you to use good practices in patterns world. So easy to develop a Generic DAO pattern.&lt;/li&gt;&lt;li&gt;Easy to use. It is so easy to implements typical operations of the data layer. For example to insert a tuple into database it is as easy as call &lt;span style="font-style: italic;"&gt;session.save(Object obj)&lt;/span&gt;.&lt;/li&gt;&lt;li&gt;The model objects (Value Objects or Tranfer Objects), haven't any dependency to hibernate, you musn't extend them from any hibernate class. Hibernate would use reflection and configuration files to know which classes and fields must be supported by database operations.&lt;/li&gt;&lt;li&gt;Hibernate can work with cache services and transactional services. Typically JTA and JBossCache, but you can use any other.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Model objects have to be configured into Hibernate Engine. For this configuration, you have three possible strategies, XML Files, JDK5.0 (EJB3) Annotations or Hibernate XDoclet, so developer has variability at his point.&lt;/li&gt;&lt;li&gt;Hibernate Validator is an annotated solution for validating model objects, you can validate fields of your object model without implementing any conditional, only using field annotations.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19517292-113464361015921975?l=alexsotob.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://alexsotob.blogspot.com/feeds/113464361015921975/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=19517292&amp;postID=113464361015921975' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/113464361015921975'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/113464361015921975'/><link rel='alternate' type='text/html' href='http://alexsotob.blogspot.com/2005/12/and-winter-arrives-to-woodchuck.html' title='... and winter arrives to woodchuck.'/><author><name>Alex Soto</name><uri>http://www.blogger.com/profile/11632964711752480304</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07751811022503259661'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19517292.post-113388260008708763</id><published>2005-12-06T16:03:00.000+01:00</published><updated>2005-12-07T11:47:33.066+01:00</updated><title type='text'>Cross-Validation VS Bootstrap</title><content type='html'>When you develop a &lt;span style="font-style: italic;"&gt;Machine Learning &lt;/span&gt;Technique, you need to know how better is your solution compared with other solutions.&lt;br /&gt;There are a lot of methods, but the most used are Fold-Cross Validation and Bootstrap. Both are commonly used in classifiers system. In my thesis "&lt;span style="font-weight: bold;"&gt;Rule Induction Using Ants&lt;/span&gt;", we find not knowing with of  two techniques we would use.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;In paper "&lt;span style="font-weight: bold;"&gt;A study of Cross-Validation and Bootstrap dor Accuracy Estimation and Model Selection&lt;/span&gt;" written by &lt;span style="font-style: italic;"&gt;Ron Kohavi &lt;/span&gt;are some experiments in C4.5 and Naive-Bayesian Classifiers. The results with that algorithms and six datasets are:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;   &lt;li&gt;Bootstrap has low variance, but large bias in some problems.&lt;/li&gt;   &lt;li&gt;&lt;span style="font-style: italic;"&gt;K &lt;/span&gt;-Fold Cross Validation with moderate values (10-20), reduce the variance but increase bias.&lt;/li&gt;   &lt;li&gt;Using &lt;span style="font-weight: bold;"&gt;Stratified &lt;/span&gt;strategy is better in terms of variance and bias, comparated with Regular Cross Validation.&lt;/li&gt; &lt;/ul&gt; So it seems that 10-Fold-Cross Validation is the best strategy tu use, but, are any better technique rather than Cross Validation and Bootstrap? And more important, that study has used only six datasets, has anybody know any study that say in which cases are better Bootstrap and which cases are K-Fold-Cross Validation?&lt;br /&gt;&lt;br /&gt;That's all folks, I wish this Post could help someone.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19517292-113388260008708763?l=alexsotob.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://alexsotob.blogspot.com/feeds/113388260008708763/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=19517292&amp;postID=113388260008708763' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/113388260008708763'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/113388260008708763'/><link rel='alternate' type='text/html' href='http://alexsotob.blogspot.com/2005/12/cross-validation-vs-bootstrap.html' title='Cross-Validation VS Bootstrap'/><author><name>Alex Soto</name><uri>http://www.blogger.com/profile/11632964711752480304</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07751811022503259661'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19517292.post-113386818958369013</id><published>2005-12-06T12:17:00.000+01:00</published><updated>2005-12-06T12:23:16.560+01:00</updated><title type='text'>Hello Everyone</title><content type='html'>Hello, this is my first Blog. I just don't know when I could write off another, but I promise writing new entries every time I can.&lt;br /&gt;&lt;br /&gt;This blog try to be a discussion blog of Artificial Intelligence and Computer in General, but of course I am open to talk about any theme it could be interesting.&lt;br /&gt;&lt;br /&gt;Also I would try to publish my research results in Artificial Intelligence and concretaly Emergent Intelligence.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;I wish everyone could post comments and different points of view.&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19517292-113386818958369013?l=alexsotob.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://alexsotob.blogspot.com/feeds/113386818958369013/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=19517292&amp;postID=113386818958369013' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/113386818958369013'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19517292/posts/default/113386818958369013'/><link rel='alternate' type='text/html' href='http://alexsotob.blogspot.com/2005/12/hello-everyone.html' title='Hello Everyone'/><author><name>Alex Soto</name><uri>http://www.blogger.com/profile/11632964711752480304</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07751811022503259661'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry></feed>