Tuesday, October 14, 2008

Servlet 3.0

Today's java.net article An Introduction To Servlet 3.0 has a pretty good overview of some of the things we might expect in the upcoming Servlet 3.0 API. 1)I'm not sure I like the use of annotations for servlets, perhaps I'm just getting old and cranky. Class hierarchies provide clarity. I've been using annotations in Spring MVC with mixed feelings. 2)I really like the idea of WebFragments for frameworks can automatically add their own stuff. I hope there's a way to disable it though. I can see some problems using a jar file that contains a web fragment and not really knowing it's even there. It could be filtering some other requests. Ouch! 3) Programmatic login/logout. It's about time we have reasonable flexibility for authentication. There are those that will says it's too little/too late because of Spring Security/Acegi. I like these too, but as much as you like to pretend, its not a standard, its not even a de facto standard. This is likely to be the best thing to come out of the new spec. I hope they get it right the first time. 4) The asynchronous support intrigues me. I'd like to get my hands on this and try some scalability testing. 5) HTTP Only cookies to prevent some cross-site scripting sounds promising. I'll have to look into some hacks to find out if this is of any practical use. 6) I agree with one of the commenters. Where are the generics? Generics provide consistency. If they can be introduced into the API without breaking backwards compatibility then just do it. They were fitted into the Collections API, so I think getParameterMap etc could slip it in no problem. By the way how about some new methods to get around those methods that return Enumeration. The Enumeration class needs to go. How about an Iterator or an Iterable so getHeaders() can be used in an enhanced for loop.

Wednesday, September 24, 2008

Are all stateful Web applications broken?

Brian Goetz opens our eyes again to the world of concurrency fallacies in basic everyday code. In his latest article Brian reintroduces us to something every Java web developer either know or should know but sometimes forget. You must code cautiously when using ServletContext and HttpSession to hold state. It makes the code ugly as sin, but it will bite you in the ass later if you don't. I know he was focusing on the thread-safety of the matter, but he did elude to problems with replication of data across a cluster. Too often we design with the intent that an app will remain small and a single server will suffice. Sometimes we'll stick some data for performance reasons in the ServletContext and expect it to always be present and current. However, the ServletContext is not replicated across a cluster like HttpSession objects. In this case you must resort to more involved solutions like: 1) Always hit the database: It becomes a performance drag, but will work. 2) In some cases a local non-distributed cache will work. In this case each node has its own cache of data it is utilizing, but the cache need not be replicated as the data will be retrieved from persistent storage. However, cache flushes must be distributed so that common items in all node's caches will be flushed when needed. OSCache does this very well. 3) Use the HTTP Session instead of the ServletContext. This one always feels wrong to me, but I guess in some limited circumstances is simple and useful. The problem is that mostly static data will exist in many HTTPSession objects instead of a more centralized location. You'll be using lots more memory, serialization and replication will take longer, and its a bloated solution. Use very sparingly. 4) I've never tried these but they seem interesting. Look into EHCache to see if it supports cache replication, or the Terracotta "network attached memory". While I'm certain these can scale, but what's the performance tradeoff to achieve the scalability.

Wednesday, August 27, 2008

Swing Explorer IDE Plugins

Swing Explorer now has IDE plug-ins for NetBeans and Eclipse. Swing Explorer is a cool utility for visually inspecting Swing applications at runtime. Here's a screenshot that mostly describes the type of functionality available. Using the plug-in allows you to easily link back to source code.

Thursday, August 07, 2008

Know the java.util.Collections class

Here's a good blog entry which is best summed up by Effective Java(2nd edition) Item 47: Know and use the libraries. Know the java.util.Collections class In case you'd like to discover some more gems, here's the JavaDoc for java.util.Collections.

Friday, July 25, 2008

Pushbutton documentation

Here's a cool article from IBM DeveloperWorks about various tools used for autogenerating documentation (UML, DB Schema, Ant). Automation for the people: Pushbutton documentation Other tools I would add on top of these would include SpringViz or BeanDoc and JDepend.

Tuesday, July 08, 2008

JDK 6 Update 7 Release Include VisualVM!

The Java SE 6 Update 7 Release Notes show that VisualVM is now included in the JDK. VisualVM is a sweet monitoring/debugging tool that brings together jconsole, jhat, jstack, gchisto, the NetBeans profiler, and other tools into a single pluggable interface utilizing the NetBeans platform.

Thursday, June 19, 2008

NetBeans Decompiler plugin

I've been using NBJAD for an interface in NetBeans to decompile code, and it works great. The trick on my ubuntu system is to make sure I get the statically linked version of jad from here.

Tuesday, January 29, 2008

SPOT Hudson Video

I managed to make a crude video recording of my extreme feedback from Continuous Integration using Hudson and Sun SPOTS. The video is kinda bad mostly because I'm not good at this kind of stuff, but it shows my computer screen on the Hudson dashboard showing a good build. All the Sun SPOTs sitting in front of the monitor are shining bright blue to match the build. As Hudson is building the project there is a lot of dead time, but towards the end of the video, you will see the build break and all the SPOTs give an indication by blinking red 5 times, then stabilizing on red. In the video, its kinda hard to distinguish what color the SPOT LEDs are because they are so bright, and the video camera can't decide what to focus on. However, believe me when I say the LEDs are very blue followed later by very red :). As I mentioned before each of our developers has one in a cube, and the SPOTS talk wireless. I put all the SPOTS in front of the same monitor for dramatic effect. I hope you enjoy. I'll be posting the code somewhere soon, so if you're interested stay tuned.

Thursday, January 24, 2008

Hudson Extreme Feedback Device

Some of you may have heard of creating ambient ORBs for extreme feedback devices. Some of my team members and myself contemplated buying the parts and trying to build one like Kohsuke, then we had a different idea. One of our co-workers had a stack of Sun SPOTs that were not currently being used, so I developed a distributed extreme feedback device for hudson using Sun SPOTs. The idea is simple. Each developer has a SPOT on their desk, and the color of the LEDS on the SPOT changes to match the status of the build. First, I wrote code to be deployed on each SunSPOT which waits for radiograms to tell it what color to change to. Next, I wrote a web application with a ServletContextListener, which polls /hudson/api/xml for the "color" of a project. Based on the color hudson returns for the configured job (red, blue, yellow, grey), this app broadcasts a radiogram message to the configured port to all Sun SPOTs in the PAN and they change color. I'm probably going to cleanup and post the code somewhere in the near future in case you're interested.

Saturday, January 19, 2008

Syntax Hightlighter

I just discovered SyntaxHighlighter . It's a javascript library to do syntax highlighting for lots of languages. It seems to work very well, I've changed all the code examples in this blog to use it. I've only found one minor annoyance that I have to use < and > in java code that uses generics, but a bug report has been filed on the issue.
import java.util.List;
import java.util.ArrayList;

public class MyClass {
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        list.add("SyntaxHightlighter is nice!");

New domain brantb.com

For any of you following, brantb.com will now get you to this blog.