Old overengineered project :)

I was looking through some old backups (~2003), and found a Java program I wrote to create thumbnails of photos for the website I was running at home. What a stupid idea that was, especially since I was running Linux at the time. There were plenty of programs that could do that conversion for me, not to mention running my own photo gallery wasn’t the brightest idea either. The worst part of the code is how over engineered it was for such a simple task. I was going to delete it, but I went ahead and put the project, PhotoResizer, up on github with all my other projects. Want to see how not cool it is? Sure you do, you need a good laugh right about now don’t you? :)

So let’s take a look at some of the over-engineering. First off, I wonder where I was in my coding when I did this. It was 2003, and I was a Java weanie. I lived and breathed Java and thought it was the greatest language ever. Six years later, I know for a fact that’s just plain WRONG. As a Java weanie I used to think we always needed interfaces for everything “just in case” I needed to add another implementation.

So here’s the Configuration interface :) now why the hell would I want another configuration implementation? What are the odds that I’d need more than one type of config file?

public interface Configuration {
 
    String getProperty(String key);
 
    int getPropertyAsInt(String key) throws NumberFormatException;
}

If you have an interface that means you probably have a concrete implementation, yep I did:

package net.zeusville.core.config;
 
import java.util.Properties;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
 
/**
* @author jmrodri
*
* To change the template for this generated type comment go to Window -
* Preferences - Java - Code Generation - Code and Comments
*/
public class PropertyConfigImpl implements Configuration {
 
    private Properties properties;
 
    public PropertyConfigImpl(String filename)
        throws InvalidConfigurationException {
        try {
            properties = new Properties();
            FileInputStream fis = new FileInputStream(filename);
            properties.load(fis);
        }
        catch (FileNotFoundException e) {
            throw new InvalidConfigurationException("Could not find ["
                    + filename + "]", e);
        }
        catch (IOException e) {
            throw new InvalidConfigurationException("Could not read ["
                    + filename + "]", e);
        }
    }
 
    /*
* (non-Javadoc)
*
* @see net.zeusville.util.Configuration#getProperty(java.lang.String)
*/
    public String getProperty(String key) {
        return properties.getProperty(key);
    }
 
    public int getPropertyAsInt(String key) throws NumberFormatException {
        return Integer.parseInt(getProperty(key));
    }
}

LOL! That is certainly a lot of code to read in a .properties file. It gets better :) Because we all know that every interface and concrete implementation needs a factory or in my case a Manager.

public class ConfigurationManager {
 
    private static Configuration configuration;
 
    public static Configuration getConfiguration() {
        if (configuration == null)
            configuration = new PropertyConfigImpl(
                    "config/PhotoResizer.properties");
 
        return configuration;
    }
 
}

Wow, that’s just sad. I can’t believe I actually wrote this stuff. I’m not done yet :) Like Billy Mays would say ‘… but that’s not all, there’s MORE!’

How much more could I have done to over-engineer this solution? I mean I’m just wanting to create thumbnails of a directory of pictures. Just read the list of files, and for each one convert to a configurable thumbnail size, write it out. Done right? no way José I went all out. No Java program is acceptable without THREADS! Don’t bother getting off the floor, because what I’m about to show you next will make you laugh your @$$ off.

Simple threads weren’t good enough for this high powered solution :) I went all out and created a queue of work items with a pool of worker threads doing the conversion. No really, that’s what I did. Check out the InterThreadQueue.

Here’s the run() method from the ImageTransformer which looks to be the guts of PhotoResizer.

    public void run() {
Object item = null;
try {
while (keepRunning() && (item = queue.get()) != null) {
PhotoInfo pi = (PhotoInfo) item;
System.out.println(“ImageTransformer [" + pi.toString() + "]“);
transform(pi);
}
}
catch (InterThreadQueueTimeoutException itqe) {
itqe.printStackTrace();
}

}

public void transform(PhotoInfo pi) {
createThumbNail(pi);
createMain(pi);
}

Not sure if I should even bother to go and clean this code up and make it simpler. Probably not, best thing to do is just scrap it, and use python or a bash script for this.

Hey you can get off the floor now. What would’ve caused me to write stuff like this? Simply because I was a Java weanie and that’s what Java causes you to do. Try to write code that is flexible and over-engineered. Think about it, if it’s a Java project and there’s a database involved the team says ‘Oh we need an ORM, let’s use Hibernate’ without first asking do we really NEED a database in the first place.

Or when writing a web ui, ‘we need a web framework: Struts (yes I’m dating myself), or Seam (that’s the new hotness isn’t it?)’ The question should probably be ‘should I really use Java for my webui at all?’ Answer is an obvious ‘No! use Ruby or Python for it’ You’ll thank me later.

The next time you’re about to choose a framework or any tool, ask yourself ‘is this really the right tool to solve the problem?’

Evil Robot Conference (no robots allowed)

On Saturday, I attended the Evil Robot Conference held at Red Hat HQ.

I got there a bit late, but I caught the tail end of Clinton Ebadi’s talk on “UnCommon Web: A Common Lisp Tale of Continuations, Multimethods,
Metaclasses, and Web Applications”. While Lisp can be hard to understand, what you can do with it from a web programming perspective made Java webapps look quite lame considering the amount of code you have to write to make them do anything.

Had lunch at El Cerro with Kevin Smith, from Hypothetical Labs, and a few other folks attending the conference. A good time was had by all, and the salsa was quite spicy but oh so good today :)

After lunch, I sat through Dan DeMaggio’s “Anti-databases (NoSQL): Where they came from and where they’re going”. I learned a lot of alternatives to the old school single database setup. There’s a lot of cool stuff out there for this such as redis, Cassandra, couchdb, BigTable.

Dan’s talk was followed by Kevin’s “Intro to Erlang” which was most excellent as well. Kevin seemed very comfortable talking and definitely knows his stuff. Great job!

Last but not least, I got to hear what BRTFS was from Josef Bacik. Very cool stuff, most of the time I forget how much cool stuff goes into OS development compared to the webapps I do for a living.

All in all, it was a great day long conference. I hope we can make it at least a yearly event.

PS. Sorry I missed your talk Max :) and thanks for the donuts.

Java why doth I loathe thee

I’m working on a new project that will be written in Java and have a JSON REST-like api. For the project we’re investigating RESTEasy. I proceed to download the zip file (ugh) and look inside. That’s when I remember why I loathe Java so much.


[jesusr@... ]$ unzip -v ~/Download/resteasy-jaxrs-1.1.GA-all.zip | awk '{print $8}' | grep "\.jar$"


resteasy-jaxrs-1.1.GA/lib/activation-1.1.jar
resteasy-jaxrs-1.1.GA/lib/apache-mime4j-0.6.jar
resteasy-jaxrs-1.1.GA/lib/async-http-jbossweb-1.1.GA.jar
resteasy-jaxrs-1.1.GA/lib/async-http-servlet-3.0-1.1.GA.jar
resteasy-jaxrs-1.1.GA/lib/async-http-tomcat6-1.1.GA.jar
resteasy-jaxrs-1.1.GA/lib/commons-codec-1.2.jar
resteasy-jaxrs-1.1.GA/lib/commons-httpclient-3.1.jar
resteasy-jaxrs-1.1.GA/lib/commons-logging-1.1.1.jar
resteasy-jaxrs-1.1.GA/lib/FastInfoset-1.2.7.jar
resteasy-jaxrs-1.1.GA/lib/guice-1.0.jar
resteasy-jaxrs-1.1.GA/lib/jackson-core-asl-1.0.1.jar
resteasy-jaxrs-1.1.GA/lib/jackson-jaxrs-1.0.1.jar
resteasy-jaxrs-1.1.GA/lib/jackson-mapper-asl-1.0.1.jar
resteasy-jaxrs-1.1.GA/lib/javassist-3.6.0.GA.jar
resteasy-jaxrs-1.1.GA/lib/jaxb-api-2.1.jar
resteasy-jaxrs-1.1.GA/lib/jaxb-impl-2.1.10.jar
resteasy-jaxrs-1.1.GA/lib/jaxrs-api-1.1.GA.jar
resteasy-jaxrs-1.1.GA/lib/jboss-common-core-2.2.10.GA.jar
resteasy-jaxrs-1.1.GA/lib/jboss-logging-spi-2.0.5.GA.jar
resteasy-jaxrs-1.1.GA/lib/jbosscache-core-3.0.3.GA.jar
resteasy-jaxrs-1.1.GA/lib/jcl-over-slf4j-1.5.8.jar
resteasy-jaxrs-1.1.GA/lib/jettison-1.1.jar
resteasy-jaxrs-1.1.GA/lib/jgroups-2.6.7.GA.jar
resteasy-jaxrs-1.1.GA/lib/jsr250-api-1.0.jar
resteasy-jaxrs-1.1.GA/lib/jta-1.1.jar
resteasy-jaxrs-1.1.GA/lib/jyaml-1.3.jar
resteasy-jaxrs-1.1.GA/lib/mail-1.4.jar
resteasy-jaxrs-1.1.GA/lib/resteasy-atom-provider-1.1.GA.jar
resteasy-jaxrs-1.1.GA/lib/resteasy-cache-core-1.1.GA.jar
resteasy-jaxrs-1.1.GA/lib/resteasy-guice-1.1.GA.jar
resteasy-jaxrs-1.1.GA/lib/resteasy-jackson-provider-1.1.GA.jar
resteasy-jaxrs-1.1.GA/lib/resteasy-jaxb-provider-1.1.GA.jar
resteasy-jaxrs-1.1.GA/lib/resteasy-jaxrs-1.1.GA.jar
resteasy-jaxrs-1.1.GA/lib/resteasy-multipart-provider-1.1.GA.jar
resteasy-jaxrs-1.1.GA/lib/resteasy-spring-1.1.GA.jar
resteasy-jaxrs-1.1.GA/lib/resteasy-yaml-provider-1.1.GA.jar
resteasy-jaxrs-1.1.GA/lib/scannotation-1.0.2.jar
resteasy-jaxrs-1.1.GA/lib/sjsxp-1.0.1.jar
resteasy-jaxrs-1.1.GA/lib/slf4j-api-1.5.8.jar
resteasy-jaxrs-1.1.GA/lib/slf4j-simple-1.5.8.jar
resteasy-jaxrs-1.1.GA/lib/stax-api-1.0.jar

Why oh why do Java projects have to include every library they use? I already have a version of commons-codec on my machine. Why do I need yet another? As a Linux user, I’m used to downloading software that requires the libraries it needs to be installed, either by manually building the required libraries or using RPM to install the software and its dependencies. Java is in desperate need of an RPM like dependency manager for deploying software because having to include a copy of every single library and version you need is down right ridiculous.

I know many will argue that ‘we certify the project against version X of library Y, any other version might break’. That’s a bigger problem in the Java community where they commonly break ABI/API compatibility even in point releases. For example, a library called jfreechart once removed an entire package in a point release: 0.9.20 to 0.9.21. This required our code to be recompiled against the newest one. That is just silly and shouldn’t be allowed. In the C world that would get you banned from writing C libraries.

</rant>

Happy Birthday, Spacewalk!

It’s amazing how fast time flies. A year ago today, we announced project Spacewalk.

Spacewalk

In that year, we’ve had five releases on three Linux versions: RHEL 5, CentOS 5, and Fedora 10. Currently we’re working on getting Spacewalk 0.6 ready for Fedora 11. Want to help? Check us out on #spacewalk and #spacewalk-devel on freenode or contact us on spacewalk mailing list.

We also added quite a few features to the project:

If you would like to try it check out the HowToInstall wiki page.

Spacewalk 0.4 RELEASED!

Today we released Spacewalk 0.4! It was an amazing release, I’m proud of the teams accomplishments with this release. We continue to move towards integrating open source projects as well as trying to get ourselves working on Fedora. Here are a few of what you will find in Spacewalk 0.4.

Features & Enhancements

  • integration with Cobbler and Koan
  • introduction Organization Trusts and Channel sharing, known internally as Multi-Org II: The Sequel.
  • multi-arch enhancement to better work with multi-arch packages on 64-bit systems.
  • a new set of APIs, including the following namespaces:
    • channel.access.*
    • channel.org.*
    • package.*
  • SELinux support added
  • added the ability to search documentation, in Spacewalk we include a search index of the online docs.
  • updated the help page to include api docs and docs search
  • more perl to java migrations
  • satellite-httpd was removed in favor of using the standard httpd
  • upgrades from 0.3 -> 0.4 available as well: https://fedorahosted.org/spacewalk/wiki/HowToUpgrade

Bugs fixed

An outstanding 118! total bugs fixed since 0.3 – http://tinyurl.com/7oytud

Known issues

  • in order to take full advantage of the multi-arch feature, you’ll need:
    • updated client packages
    • recreate the stored profiles
  • bad news is that Spacewalk running on Fedora is not yet available. The good news is that we have started building packages to work with Fedora 10. :)
  • 480233 – deleting stored profiles causes ISE
  • 479640 – do not conflict with specspo. Work around is to rpm -e specspo.

Community

A special thanks goes out to Colin Coe for his continued contributions to the apis. Also, thanks to Todd Sanders for his Telemetry contribution. See contributors from past releases: https://hosted.fedoraproject.org/spacewalk/wiki/ContributorList

Installation Help
https://hosted.fedoraproject.org/spacewalk/wiki/HowToInstall#Installation

Busy weekend

It was a busy weekend, Liz went away for the weekend while I watched the 3 kids. They were actually very well behaved and gave me little to no trouble. I was expecting quite a bit :D We went to their Friday playgroup, afterwards had the kid’s favorite: McDonald’s for dinner. On Saturday, we went to Border’s to get the kid’s some books, I went with the intention to buy Doctor Who Season 2, but didn’t want to pay the $68 for it. I ended up getting a Doctor Who book instead, yeah I’m as surprised as you that I ended up with a book.

In the evenings I spent the time catching up on my sci-fi shows: finished watching Doctor Who Season 4, saw all of Season 1 (I started with Season 2), and I started watching Firefly (thanks robin). I also managed to get 2 patches submitted and accepted to redstone-xmlrpc, and I submitted the package to jpackage for review. Another library I use all the time is jdbcLogDriver written by a former colleague of mine, I got commit access to it this weekend as well. Today I started to shake the dust off zmugfs. I still haven’t been able to add write access to the file system, and the read mode is extremely slow at startup. I need a better algorithm for downloading the photos and caching them.

buzzwords

The tech industry is overflowing with buzzwords. I’m not sure if other industries are the same, but I know I am inundated with buzzwords on a daily basis, sometimes to the point of exhaustion.

George Carlin, one of my favorite comedians, has his “Seven dirty words” so I figured I’d list the seven dirty buzzwords I can do without for quite some time.

  1. platform
  2. pluggable (plugins)
  3. enterprise
  4. scalability (scalable)
  5. high availability
  6. extensibility
  7. architecture

If I never hear the above words again it wouldn’t bother me in the least. And you may notice I avoided the acronym hell that JEE (yes I’m using one of them) puts you through, that’s a much longer list.