Saturday, May 31, 2008

Firefox wants to achieve the Download World Record

It's a fact Firefox has become the most used web browser nowadays. I'm using it right now and there is 79% chances you are using it too, according to my blog statistics. I don't have expressive numbers to show (that's the reason I'm not using Google Advertising yet), but at least 237 visits came from users using Firefox in the last 15 days.



Now Firefow 3 is coming with dramatic improvements, but it is still in beta version, which allows you to navigate comfortably, but not to use all its plug-ins, since they are incompatible with the current implementation.

These days, the Firefox community started a promotion to achieve the greatest number of downloads within 24 hours. The idea is to break the world record and be part of the next edition of the Guinness Book.

Read more about it at http://www.spreadfirefox.com.

Tuesday, May 27, 2008

SpringOne Menu



Here is my table of chosen talks for SpringOne 2008:

June, 11
  • Enterprise Application Management - Jennifer Hickey (12:00 - 13:00)
  • Enterprise Development Tools for Spring - Christian Dupuis (14:00 - 15:00)
  • Using Spring Security 2 - Mike Wiesner (15:10 - 16:10)
  • Enterprise Integration with Spring Batch - Dave Syer (16:40 - 17:40)
  • Enterprise Integration Patterns with Spring - Mark Fisher (17:50 - 18:50)
June, 12
  • Inside SpringSource Application Platform - Rob Harrop (10:30 - 11:30)
  • Applying the Spring Framework for Model-Driven Architecture - Jan Ypma (12:00 - 01:00)
  • Java Server Faces - The Biggest Loser of Java Web Frameworks? - Jeremy Grelle (15:00 - 16:10)
  • Spring Web Flow 2.0 Deep Dive - Keith Donald (16:40 - 17:40)
  • RESTful Web Services in Spring - Arjen Poutsma (17:50 - 18:50)
All CEJUG members have the right to request changes in the list above according to the conference schedule. Just comment this post with your suggestions.

Sunday, May 25, 2008

Java Univesity Prize

CEJUG is promoting the PUJ '08. This is a prize created by Felipe Gaúcho in 2007. Now, we are organizing the second edition and the winner will attend Javoxx '08, the Java community conference, with all expenses paid by the PUJ Sponsors. Many thanks to Fortes Informática, Ivia, Sun Microsystems, Usix Technology and Java Magazine.

I made the video below to promote the prize. If you are a geek you will like it:



This is my forth original production about CEJUG initiatives. You can see more at: http://www.youtube.com/htmfilho. If you invite me to attend your conference as a CEJUG representative, certainly I will promote it through an official CEJUG video. The next video will be about Jazoon, an European Java conference hosted in Zurich from June 23 to 27. Se you there!!

Hibernate and Jersey Conflict on Glassfish

Last weekend I tried to use Jersey in an enterprise application to make some RESTful web services available. The idea was to generate data to be plot by flash charts. So, I created a new web module in addition to the already existent one. I thought it was better to keep it in a separate module to avoid changing the original web application, since it still uses Struts as web framework. Before adding any RESTful web service, I just created the web application and deployed it successfully as an additional enterprise module. I'm happy about that because I will use the same strategy to migrate the web module from Struts to JSF, keeping the Struts version working in parallel to the JSF version, both sharing the same business logic.

I use Netbeans because it makes my life easier. The Jersey module is available in the 6.1 version and for download in the update center for previous versions. Since installed, you may click with the right button on a web project to see the context menu and select “New ... / RESTful Web Services from Patterns” or “New ... / RESTful Web Services from Entity classes”. Since I'm not implementing entity classes in this module, I selected the one from patterns. It will start a wizard to prepare the application for REST and generate the initial class skeleton to start working.

I followed those steps and the RESTful web service was created successfully. However, when I start to deploy the whole application again, an obscure error appears in the Glassfish output log insistently. In such situation I tried everything: clean, build, clean and build, remove the module and deploy it separately, but nothing was enough to solve the problem below:

LifecycleException: java.lang.NoSuchMethodError: org.objectweb.asm.ClassReader.accept(Lorg/objectweb/asm/ClassVisitor;I)
(...)
Caused by: java.lang.IllegalStateException:
ContainerBase.addChild:
start: LifecycleException:
java.lang.NoSuchMethodError: org.objectweb.asm.ClassReader.accept(Lorg/objectweb/asm/ClassVisitor;I)

I checked if I was using the libraries appropriately, if they were correctly wrapped and if there was any library conflict. Yes, there is a library conflict with Hibernate, the persistence framework I am using as a JPA implementation. Jersey uses the ASM library, which is also used by Hibernate, but on different versions. Hibernate uses version 1.5.3 and Jersey uses 3.5.1. A big difference! We can not just delete the old version and put the new one there because they are architecturally different. Version 1.5.3 has an "attrs" package while 3.5.1 doesn't have it but a "signatures" package. Changing the version can cause other problems and I'm not expecting them afterwards. So, how do I solve it consistently?

The ASM package is needed by the cglib package, which is part of the Hibernate libraries. If we remove that package, Jersey will work correctly, but Hibernate will stop working. To solve this conflict use cglib-nodep.jar instead of cglib.jar and keep ASM version 3.x with Jersey. cglib-nodep.jar includes some ASM classes demanded by cglib.jar, changing the package name to avoid any class conflict.

The ASM library is a Java bytecode manipulation and analysis framework. According to its website "(...) it can be used to modify existing classes or dynamically generate classes, directly in binary form. Provides common transformation and analysis algorithms to easily assemble custom complex transformations and code analysis tools". ASM is used by many products like AspectJ, Oracle TopLink, JRuby, and many others. It can not be simply ignored by frameworks because it is a matter of flexibility. The best alternative is always to investigate the unexpected problem and claim for a better error presentation on the JVM.

Thursday, May 1, 2008

The Importance of Software Modeling

During my free time I made a very big refactoring of the Planexstrategy business layer. I transformed static business methods to EJB3 (Enterprise Java Beans version 3). All business classes are now stateless session beans and my entity classes are now mapped using JPA (Java Persistence API) to an Oracle database. Putting it in numbers, I converted 73 business classes to EJBs and I mapped 81 entity classes using JPA. I also had to update 270 references to business components in the control layer, fix a lot of bad code and retest the whole application. I spent at least two months to do everything.

Why did I make such madness? If I have to give a reason, just one is enough to justify: Business layer as static methods. Yes, It is pretty ugly for an object-oriented implementation! Anyway, it worked very well with a very good performance for, at least, 2 years. Other good reasons push me out to continue insistently:
  1. EJB is finally easy to implement, maintain and test. Some people disagree about the "easy" adjective, but I assure it after 73 conversions. I had just to add the necessary annotations and make some changes in my business classes because they already look like EJBs, since I tried to simulate the stateless property using static methods. Now, any business method can be exposed as web services, the business layer can be accessed by different types of clients (web or desktop, locally or remotely) and a set of integration possibilities is now available to interchange data with systems of the organization or even outside it.
  2. I hate to create a bizarre package .har to pack entity classes in JBoss. If you want to use Hibernate in an optimal way under JBoss, it's necessary to put all your entity classes in a .har file, which is deployed within the .ear package. I definitely decided for JPA because I can still use Hibernate but in a standard way, without any explicit reference to the Hibernate library, which gives more portability to the application.
  3. I love to think about the future and when I assume the risk of changing entire layers of an application it's because I visualize it as part of a big scenario, where workflows will be even more automated, companies will not survive without a minimal level of integration with other companies, there is no programming language generic enough to address all technical issues and such languages should be integrated anyway, and many other things.
This was not my first experience with a big refactoring, but it was the most important in terms of knowledge and convictions. In other moments I will share this knowledge. Now I will talk about an important conviction that I had in the past and now it was weakened in my culture by agile methodologies: the importance of software modeling as a requirement to implement software. I will start the subject citing a Martin Fowler's text:
"The only checking we can do of UML-like diagrams is peer review. While this is helpful it leads to errors in the design that are often only uncovered during coding and testing. Even skilled designers, such as I consider myself to be, are often surprised when we turn such a design into software."

Martin is an important agile guru. Anyone who wants to follow an agile methodology should read his ideas about the subject. I did that and I still believe in most of them, but during the Planexstrategy refactoring I learned how important is to see a global view of the implementation before implementing a new functionality. I will illustrate it using UML component models, however, I tried to simplify them in order to save time. When you see a direct link between components, actually you are seeing a link to an interface of the component, as illustrated by the figure below:


The text in the figure is in Portuguese, but it will not confuse your understanding about the problem. It isn't necessary to explain what each element means. The component CotacaoProdutoBsn uses the component ProdutoBsn through its interface ProdutoLocal. This interface is used by the EJB container to make components available for clients running in the same application server. Because this interface should be defined for all components, I will assume it is present in all links between components and hide it from the component diagram.

After an extensive work to convert all business classes to EJB, I finally went to test the EJBs on the application server. I had to solve a lot of annotation mistakes and finally all error messages disappeared. However, just a subset of EJBs were started. No reasonable message was listed in the log to justify why many others EJBs just didn't start as expected. I spent some days until I realized that there is no limitation on the number of EJBs, no memory leaks and no additional annotation mistakes, but a serious and dangerous high coupling between EJBs. The figure below illustrates the situation:



As you can see on the highlighted links, AtividadeBsn and TarefaBsn are interdependent and AtividadeBsn and UsoRecursoBsn are also interdependent. These were only two cases in a list of 20. Well, how something terrible like this can happen in a Java application developed by an expert programmer with years of experience? ;-)

I should be humble and honest with myself to assume my mistake and publish it in my blog. At the same time, I can list some reasons for that:
  • I received a lot of pressure from costumers to implement new features in a short period of time
  • The runtime infrastructure is not robust enough to validate the application before a deployment process
  • I don't have a complete overview of the software components and it isn't easy to detect a high coupling without a complete source code reading of other components.
Then, I realized that, if I had a component diagram like the figure below before starting to implement, that kind of mistake might have been avoided. Don't you think?



In my opinion: yes. We can visualize if it's necessary to add new components or just increment an existent one, reuse existent implementations from other components and remember that AtividadeBsn should not invoke a TarefaBsn method and neither should UsoRecursoBsn be aware of the existence of AtividadeBsn.

Finally, contrary to some agile practices, UML diagrams should be strongly considered and it should be drawn using a software instead of sketches in a piece of paper, since we have to update such diagrams all the time. If you disagree with my position, please tell me if I can avoid high coupling mistakes without UML diagrams.