Friday, September 28, 2007

Understanding GPL - Vote on the two scenerios

I'm sure by now everyone's familiar with the first U.S. GPL lawsuit filed against Monsoon Multimedia by BusyBox and Free Software Foundation.
(If you're not familiar, check out the following links: http://www.linuxdevices.com/news/NS5684746851.html)

Well reading through those made me question the license and how it applies to two different scenarios.

Scenario - A: Say you create a publically accessible website called Fritz.com and this website on the server-side uses a library called abc.jar that's released under the GPL license.

Does that constitute that we release the source code of Fritz.com website to comply with the GPL licensing?

Scenario - B: Say we create a Java framework, called Fritz (Fritz.jar). This is the next upcoming big MVC framework like Struts or WebWork but proprietary. This framework uses a library called abc.jar that's released under the GPL license. And the person or company that developed it wants to sell it. And people can buy it and use it in their development work.

Now since Fritz.jar depends on or uses abc.jar, does that constitute that we release the source code of Fritz.jar to comply with the GPL licensing?

Share your thoughts. Which one of these two cases do we need to release the "fritz" software? Is there a violation in this case? And when you reply, explain why instead of just voting...

Current Votes:

Scenario - A - Yes, release your code as well............................1
Scenario - A - No, you do not need to release your code.........2

Scenario - B - Yes, release your code as well.............................3
Scenario - B - No, you do not need to release your code..........0

Tuesday, July 31, 2007

Java - Closing JDBC Connections - A Common Mistake

Where is the leak? Can someone explain?

Java programmers who have done some JDBC programming by now know that it's important to close the ResultSet, Statements and Connections. And the code looks like the sample below:
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
try
{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
Connection conn = DriverManager.getConnection("jdbc:odbc:issue","x","x");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT * FROM TABLE" );
}
catch (SQLException e)
{
logger.error(e.getMessage(), e);
}
finally
{
try
{
if (rs != null)
rs.close();
}
catch (Exception e)
{
// it's a good idea to log it!
logger.error("Cannot close ResultSet", e);
}
try
{
if (stmt != null)
stmt.close();
}
catch (Exception e)
{
// it's a good idea to log it!
logger.error("Cannot close Statement", e);
}
try
{
if (conn != null)
conn.close();
}
catch (SQLException e)
{
// it's a good idea to log it!
logger.error("Cannot close Connection", e);
}
}



While the above example is accurate, having different methods with a common part "finally" would make one think... why not put the parts of the finally block into a common method to close the resources... So they begin writing a method that looks like this:

public static void closeResources(ResultSet rs, Statement stmt, Connection conn)
{
try
{
if (rs != null)
rs.close();
}
catch (Exception e)
{
// it's a good idea to log it!
logger.error("Cannot close ResultSet", e);
}
try
{
if (stmt != null)
stmt.close();
}
catch (Exception e)
{
// it's a good idea to log it!
logger.error("Cannot close Statement", e);
}
try
{
if (conn != null)
conn.close();
}
catch (SQLException e)
{
// it's a good idea to log it!
logger.error("Cannot close Connection", e);
}
}


and the finally block begins to look like this:

try
{
...
}
catch (Exception e)
{
...
}
finally
{
closeResources(rs, stmt, conn);
}



Is the second approach right or wrong???

Here is my reasoning...

I ran a test where I had a connection-pool and 2nd approach yielded connection leaks... and when I replaced my closeResources(...) method calls with actual try-catch block within my finally blocks to close the connections... the leaks disappeared... So can someone explain why that is the case...

Well, my first thought was this ... from here: http://www.javaworld.com/javaworld/javaqa/2000-05/03-qa-0526-pass.html


A common error made by Java language newcomers. Indeed, even seasoned veterans find it difficult to keep the terms straight.

Java does manipulate objects by reference, and all object variables are references. However, Java doesn't pass method arguments by reference; it passes them by value.

So what you are closing in the closeResources(...) method is a copy of the connection and not the actual connection.

So if you are trying to consolidate common code try to avoid this common mistake. This can cost you a lot of headache when you are trying to find your connection leaks.

But a anonymous friend said the following:


I'm sorry to tell you you're wrong : Java neither passes objects by reference nor value : it passes "references by value". Therefore, the parameter your method gets os actually the value of the reference of the connection, which is properly resolved.

http://www.javaworld.com/javaworld/javaqa/2000-05/03-qa-0526-pass.html ;)


So why am I seeing the behavior that I'm seeing...

Can someone explain???

Friday, July 27, 2007

Spring Tip #1: Application Context

Did you know that if your method needs access to the Application Context then all you need to do is implement a Spring interface "ApplicationContextAware" and override the setApplicationContext(...) method in your bean.



@Override
public void setApplicationContext(ApplicationContext applicationcontext)
throws BeansException {
ctx = applicationcontext;
}


Here is an sample example that shows you how to use it.

Also, if you want to listen to all events... then implement ApplicationListener interface and catch your events like this:


@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof SegmentEvent) {
final SegmentEvent segEvent = (SegmentEvent) event;
processSegment(segEvent.getSegment());
}
}


And now for some user feedback... :-)

Do you feel that there is not a very good Spring Book or reference that provides you with all the tips-n-tricks on how to harness Spring effectively?

Yes, the knowledge is out there in the Spring reference online and in those various sources but I haven't seen a good source of bite-sized book on Spring Tips...

When I asked around a few of you shared the same comment... Wouldn't it be great if there was a book/blog that gave you a daily Spring Tip with a short example...

If you share my thoughts, drop me a line and be counted...

Friday, June 22, 2007

Open Payment/Commerce Gateway : Is this the right time? Part 1

Open Payment/Commerce Gateway : Is this the right time?


Part 1



We live in such a wonderful period of technological changes in human history that might make our grandfathers jealous. They lived during (or later part of) the industrial revolution, computers were beginning to show up as everyday appliances and human productivity was rising at tremendous rates. Well they were wrong... If they thought that human progress was running like a fast train then today technological progress is running more like a speeding bullet and there is no slowing down in sight. And as humans, we like to classify and mark each era with a name or a tag and so I wonder... What I would call this era that we are currently living in? And as I think about it, what jumps right at me is how "Open Source" has changed the face of earth. It all began with simple and yet powerful ideas from people like Linus Torvalds (creator of Linux), Jimmy Wales (founder of Wikipedia) and others. The seeds they planted have now become trees and they are ready for the harvesting. There was a time when people mocked at Linux and called it a toy in the developers hands, eventually they began laughing. And today people take notice and Linux is gaining prominence and competing with the giants of the operating system businesses. It has driven the idea of open source to every home and is here to stay. Open source has proven that it is a viable and healthy alternative to propriety software.

Similarly, the seeds of open, common, public content began in the minds of a few people such as Jimmy Wales. And today we have the wonderful Wikipedia which changes the way encyclopedia's are created, managed and published. Similarly the idea of internet has created so much synergy that today it has become an integral part of our daily living. Imagine a closed internet where only a few elite can use and participate. This would have created a class system that's equal to the feudal or caste system found in ancient cultures. Well, I think you get the point... The internet and the seeds of open source and open content have broken the chains of knowledge and have liberated us with opportunities beyond measure.

And now I wonder if the time is right for a "Open Payment Gateway" - "an open Visa or Mastercard"... Today, ecommerce is growing and has become a vital part of our existence. Credit-cards have become the defacto standard of currency. But this standard has also built within it a powerful conglomerate where a few elite enjoy the benefits of ecommerce. Today, in order to purchase a product online or at a store - the seller pays a small fee for the transaction. And this fee can be anywhere from 2% to 4% of the purchase price. And the reasoning that banks and credit corporations tell you is that - that's the cost of exchanging data and having systems with checks and balances in place to ensure the security of your money. They say that they take a small fee to build all the back-end communication channels by which they talk to the various financial institutions to take the money from the buyer and move it into the sellers financial institution. But today we live in a day and age where the internet is everywhere and each financial institution has created their own proprietary way of communicating with their bank and so that puts the burden on the credit-card companies to speak not only one language but many languages. And in the past there has been a lot of work put in by open source supporters to create a common infrastructure for paving the way. But what I'm questioning is this - Are we in a point of time where there could be open payment gateways that can help create commerce and at the same time allow the open gateway to be profitable and self sustaining?

In the next few blogs, I will try to gather the users feedback on the above question and try to propose some methods by which we can pave the way for a true "Open Payment/Commerce Gateway" that everyone can benefit.


Link back to this article with this TinyURL: http://tinyurl.com/2dv8f5

Tuesday, June 19, 2007

Java F/OSS (Free/Open Source Software) Tools for Source Code Optimization and Analysis

Java F/OSS (Free/Open Source Software) Tools for Source Code Optimization and Analysis

Below is a list of some tools that can help you examine your Java source code for potential problems:

1. PMD from http://pmd.sourceforge.net/
License: PMD is licensed under a "BSD-style" license

PMD scans Java source code and looks for potential problems like:

* Possible bugs - empty try/catch/finally/switch statements
* Dead code - unused local variables, parameters and private methods
* Suboptimal code - wasteful String/StringBuffer usage
* Overcomplicated expressions - unnecessary if statements, for loops that could be while loops
* Duplicate code - copied/pasted code means copied/pasted bugs

You can download everything from here, and you can get an overview of all the rules at the rulesets index page.

PMD is integrated with JDeveloper, Eclipse, JEdit, JBuilder, BlueJ, CodeGuide, NetBeans/Sun Java Studio Enterprise/Creator, IntelliJ IDEA, TextPad, Maven, Ant, Gel, JCreator, and Emacs.

2. FindBug from http://findbugs.sourceforge.net
License: L-GPL

FindBugs, a program which uses static analysis to look for bugs in Java code. And since this is a project from my alumni university (IEEE - University of Maryland, College Park - Bill Pugh) , I have to definitely add this contribution to this list.

3. Clover from http://www.cenqua.com/clover/
License: Free for Open Source (more like a GPL)

Measures statement, method, and branch coverage and has XML, HTML, and GUI reporting. and comprehensive plug-ins for major IDEs.

* Improve Test Quality
* Increase Testing Productivity
* Keep Team on Track

  • Fully integrated plugins for NetBeans, Eclipse , IntelliJ IDEA, JBuilder and JDeveloper. These plugins allow you to measure and inspect coverage results without leaving the IDE.
  • Seamless Integration with projects using Apache Ant and Maven. * Easy integration into legacy build systems with command line interface and API.
  • Fast, accurate, configurable, detailed coverage reporting of Method, Statement, and Branch coverage.
  • Rich reporting in HTML, PDF, XML or a Swing GUI
  • Precise control over the coverage gathering with source-level filtering.
  • Historical charting of code coverage and other metrics.
  • Fully compatible with JUnit 3.x & 4.x, TestNG, JTiger and other testing frameworks. Can also be used with manual, functional or integration testing.
4. Macker from http://innig.net/macker/
License: GPL

Macker is a build-time architectural rule checking utility for Java developers. It's meant to model the architectural ideals programmers always dream up for their projects, and then break -- it helps keep code clean and consistent. You can tailor a rules file to suit a specific project's structure, or write some general "good practice" rules for your code. Macker doesn't try to shove anybody else's rules down your throat; it's flexible, and writing a rules file is part of the development process for each unique project.

5 EMMA from http://emma.sourceforge.net/
License: EMMA is distributed under the terms of Common Public License v1.0 and is thus free for both open-source and commercial development.

Reports on class, method, basic block, and line coverage (text, HTML, and XML).

  • EMMA can instrument classes for coverage either offline (before they are loaded) or on the fly (using an instrumenting application classloader).

  • Supported coverage types: class, method, line, basic block. EMMA can detect when a single source code line is covered only partially.

  • Coverage stats are aggregated at method, class, package, and "all classes" levels.

  • Output report types: plain text, HTML, XML. All report types support drill-down, to a user-controlled detail depth. The HTML report supports source code linking.

  • Output reports can highlight items with coverage levels below user-provided thresholds.

  • Coverage data obtained in different instrumentation or test runs can be merged together.

  • EMMA does not require access to the source code and degrades gracefully with decreasing amount of debug information available in the input classes.

  • EMMA can instrument individial .class files or entire .jars (in place, if desired). Efficient coverage subset filtering is possible, too.

  • Makefile and ANT build integration are supported on equal footing.

  • EMMA is quite fast: the runtime overhead of added instrumentation is small (5-20%) and the bytecode instrumentor itself is very fast (mostly limited by file I/O speed). Memory overhead is a few hundred bytes per Java class.

  • EMMA is 100% pure Java, has no external library dependencies, and works in any Java 2 JVM (even 1.2.x).

6. XRadar from http://xradar.sourceforge.net/
License: BSD (me thinks)

The XRadar is an open extensible code report tool currently supporting all Java based systems. The batch-processing framework produces HTML/SVG reports of the systems current state and the development over time - all presented in sexy tables and graphs.

The XRadar gives measurements on standard software metrics such as package metrics and dependencies, code size and complexity, code duplications, coding violations and code-style violations.

7. Hammurapi from Hammurapi Group
License: (if anyone knows the license for this email me Venkatt.Guhesan at Y! dot com)

Hammurapi is a tool for execution of automated inspection of Java program code. Following the example of 282 rules of Hammurabi's code, we are offered over 120 Java classes, the so-called inspectors, which can, at three levels (source code, packages, repository of Java files), state whether the analysed source code contains violations of commonly accepted standards of coding.

Relevant Links:
http://en.sdjournal.org/products/articleInfo/93
http://wiki.hammurapi.biz/index.php?title=Hammurapi_4_Quick_Start

8. Relief from http://www.workingfrog.org/
License: GPL

Relief is a design tool providing a new look on Java projects. Relying on our ability to deal with real objects by examining their shape, size or relative place in space it gives a "physical" view on java packages, types and fields and their relationships, making them easier to handle.




If anyone has other tools that they would like to add to this list or would like to add additional comments to the list above, please feel free to send me an email at Venkatt.Guhesan at y! dot com

I hope you find this list useful...

Venkatt Guhesan

Saturday, June 16, 2007

HOW-TO: Raaga.com and Real Player in Linux Ubuntu 7.04 Feisty Fawn

Hello All:

I have seen a lot of posts in the past that have complained that after upgrade to Ubuntu 7.04 Feisty Fawn, some of the popular music sites for Indians such as Raaga.com are no longer working when it comes to using Real Player 10.

Here is a fix that worked for me...

My Specifications:
Ubuntu 7.04 Feisty Fawn
Fire Fox 2.0.0.4
Real Player 10 (what came with the regular Synaptic sources...)
Date: Saturday, June 16, 2007

Issue:
From my limited understanding and research, it seems that the current production release of Real Player has some incompatibility with some sites... and some solutions propose that you revert to an older release of Real Player 10.0.3-1... This solution is sound but I have found that instead of going backward, I tried using a build from the nightly release of Real Player and this also fixes the problem so I usually prefer using a newer release than a older release... So if you would like to use a newer release, then read on...

Solution:
1. Go here: (Helix Community Nightly Stable Builds of Real Player NOT Helix Player)
http://forms.helixcommunity.org/helix/builds/?category=realplay-current

2. Download: Real Player (package) - linux-2.2-libc6-gcc32-i586@rhel4
(The one I have is built on 06/15/07. And at this present time Helix Community DOES NOT distribute packages for Ubuntu/Debian releases. Hopefully that will change in the future. So what we'll need to do is install and run another program called 'alien' which re-packages the RPM file into a DEB install package.)
Save the file to ~/Desktop because my directions below are assuming that you have it downloaded to your 'Desktop'. File name downloaded will be something like this:

3. Open a terminal prompt and run the following commands: (need to have administrator password for this)
sudo apt-get update
sudo apt-get install alien


Now you have alien installed. If you have some problem go here and read about it:
http://ubuntu.wordpress.com/2005/09/23/installing-using-an-rpm-file/

4. Converting RPMs to DEB installer. Type the following in the terminal prompt
cd ~/Desktop
sudo alien -k name-of-rpm-file.rpm

[in my case the file name is RealPlayer-10.1.0.3239-20070615.i586.rpm]
After completeion you should now have a ".deb" file on your desktop.

5. Installing the debian package (DEB): Run the following in the terminal:
sudo dpkg -i name-of-deb-file.deb

[in my case it's RealPlayer-10.1.0.3239-20070615.i586.deb]
This brings up a dialog asking you to install the package... go ahead and install and when completed this copies the files and the executables under /opt/real/RealPlayer directory.

6. Now you need to add the realplay executabel to the System Path. Here's how:
sudo ln -s /opt/real/RealPlayer/realplay /usr/bin/realplay


7. Now you need to make sure you have copied the needed plugin's to FireFox profile under your user home directory:
- Open a Nautilus Explorer (equivalent to Windows Explorer) and choose under in the top menu,
- Navigate to "/opt/real/RealPlayer/mozilla" directory. And here you should see a couple of files: nphelix.so nphelix.xpt. Copy those two files to this location: "~/.mozilla/plugins", here the tilde(~) represents your Home Directory. Once you copy the two files there and you restart FireFox (ff), ff will be able to find the plugins when it needs RealPlayer...

8. Now you can goto, Raaga.com - choose your favorite songs and listen to them...

I hope you have found this link useful. If you have any questions or comments to share send them to Venkatt.Guhesan @ yahoo dot com

Enjoy!!!

To share this link to others use the following TinyURL:
http://tinyurl.com/2rg7hd

(If you have other friends and family who listens to Raaga.com and are using Ubuntu - then send them the TinyURL to them so that they can benefit from this as well.)

Venkatt Guhesan