Catwalk Model Processor

Jun 8th, 2010

I have just released the code for Catwalk a Java Annotation Processor for automatically generating derived domain model classes.

Supposing you have a JPA Entity which you want to pass to a servlet stripped of certain private / internal properties, adding a few annotations to the getters you want to expose allows Catwalk to generate a new class with only those properties and convenience methods for converting between the two types of objects.

The project is still missing a few essentials before being useful, such as documentation, proper examples and being uploaded to a Maven repo.

In the following example, a TestModel class is converted to a WebTestModel class:

TestModel.java

package net.dataforte.test.model;

@Model(pattern = "Web#", classPackage = "net.dataforte.test.webmodel")
public class TestModel {
	String s;
	int i;

	@ModelAttribute
	public String getS() {
		return s;
	}

	public void setS(String s) {
		this.s = s;
	}

	public int getI() {
		return i;
	}

	public void setI(int i) {
		this.i = i;
	}
}

WebTestModel.java

package net.dataforte.test.webmodel;

public class WebTestModel {

	private java.lang.String s;

	public WebTestModel() {}

	public WebTestModel(net.dataforte.test.model.TestModel src) {
		this.fromTestModel(src);
	}

	java.lang.String getS() {
		return s;
	}

	void setS(java.lang.String s) {
		this.s = s;
	}

	public WebTestModel fromTestModel(net.dataforte.test.model.TestModel src) {
		this.s = src.getS();
		return this;
	}

	public net.dataforte.test.model.TestModel toTestModel() {
		net.dataforte.test.model.TestModel that = new net.dataforte.test.model.TestModel();
		that.setS(this.s);
		return that;
	}

}
Tags:

Java and Large Memory Pages on Linux

Mar 12th, 2010

Recently I helped configure a system for an application running under Tomcat on Linux with very large memory requirements: a minimum heap of 6GB with a maximum of 11GB. The JVM was initially configured to use the Parallel garbage collector. With this configuration garbage collection of the “Young Generation” was fine, but the “Old Generation” GC was taking over 30 seconds (and blocking all other threads while doing this). We looked into enabling Large Memory Pages, a feature of modern CPUs which allow memory-hungry applications to allocate memory in 2MB chunks instead of the standard 4KB. Documentation on the web on how to do this exactly is sparse and missing some details we ran into. Here’s the sequence of steps we had to take:

  1. configure the kernel’s maximum shared memory to span the whole address space (via the kernel.shmmax and kernel.shmall parameters)
  2. configure the kernel’s allocated large memory pages (via the vm.nr_hugepages parameter)
  3. configure the user limits to ensure that the user running Tomcat can allocate the necessary memory (via the maxlock parameter)
  4. ensure that PAM applies the security limits to users who “login” via su and sudo
  5. configure the JVM for Large Memory Pages

Add the following lines to /etc/sysctl.conf and use sysctl -p to reload the changes into the running kernel although I recommend rebooting the system so that the Large Memory pages can be properly allocated (they have to be contiguous).

# Maximum size of a shared memory segment (in bytes)
kernel.shmmax=17179869184
# Maximum total size of all shared memory segments (in pages of 4KB)
kernel.shmall=3145728
# Number of allocated Large Memory Pages (each one takes up 2MB)
vm.nr_hugepages=6144

Edit /etc/security/limits.conf so that the user running the Java application can lock the correct amount of memory.

tomcat soft memlock 12884901888
tomcat hard memlock 12884901888

Edit /etc/pam.d/su and /etc/pam.d/sudo and ensure that they contain the following line so that the above memory limits are applied:

session    required   pam_limits.so

Next add the relevant options to the JVM’s command-line:

-XX:+UseLargePages -Xmx11g -Xms6g

Eclipse crashes with Lucid

Mar 3rd, 2010

Update: it seems like a lot of people find this useful. With the final release of Ubuntu 10.04 Lucid Lynx, xulrunner-1.9.2 is in the main repository. Because of this, just uninstall xulrunner-1.9.1 and you’re done.

I like living on the edge: I use Ubuntu Lucid and Eclipse 3.6M5 on my x86-64 notebook. Since the 25th of February, Eclipse started crashing when closing the content assist popup window. I narrowed it down to the upgrade to libcairo2-1.8.10-2ubuntu1. This causes a RenderBadPicture X Error when the documentation popup that appears on the right of the possible completions is closed. Downgrading to libcairo2-1.8.8 solved the problem, but it seems that the real problem lies within xulrunner 1.9.1 which SWT uses to render the docs. The Mozilla bug is https://bugzilla.mozilla.org/show_bug.cgi?id=522635. A quick workaround is to set the GRE_HOME environment variable to some meaningless path (e.g. /tmp) before launching Eclipse. Another possible solution is to install xulrunner-1.9.2 (only available from the mozilla-daily-ppa). I have filed a bug report un Launchpad asking for an official upgrade to xulrunner 1.9.2.

XBMC+NVIDIA+DynamicTwinView = Wrong refresh rate

Feb 2nd, 2010

I was wondering why I got tearing with XBMC even though I had enabled vsync and why XBMC was reporting a refresh rate of 50Hz for my screen instead of 75Hz as it should have been. It turns out that NVIDIA’s DynamicTwinView feature reports a fake refresh rate (that of the MetaMode which encompasses all of the screens involved in the TwinView) which may not be the one for the physical device. As I am not using TwinView I added the following Option to my xorg.conf Device section:

Option "DynamicTwinView" "False"
Tags: , ,

HTPC photos

Jan 28th, 2010

I promised over a month ago some photos of my custom HTPC, so here they are:

The front of the box showing the 20x2 LCD, the slimline Optiarc BC-5600S Blu-Ray/DVDRW and two of the USB ports

The front of the box showing the 20x2 LCD, the slimline Optiarc BC-5600S Blu-Ray/DVDRW and two of the USB ports

The untidy guts of the box showing the Zotac ION ITX motherboard on the right, the 700GB Western Digital HDD and the Slimline BD/DVDRW Drive. There are two 1GB sticks of DDR2 RAM under the optical drive. Notice the unused horizontal slots in the case at the rear of the box

The untidy guts of the box showing the Zotac ION ITX motherboard on the right, the 700GB Western Digital HDD and the Slimline BD/DVDRW Drive. There are two 1GB sticks of DDR2 RAM under the optical drive. Notice the unused horizontal slots in the case at the rear of the box

The back of the case showing the multitude of connections: PS/2 mouse, USB Wi-Fi Siemens stick, optical S/PDIF output, HDMI, VGA, analog audio out and the DC power cable (the brick is out of view)

The back of the case showing the multitude of connections: PS/2 mouse, USB Wi-Fi Siemens stick, optical S/PDIF output, HDMI, VGA, analog audio out and the DC power cable (the brick is out of view)

The box is running Ubuntu 9.10 (aka Karmic Koala) and XBMC which takes advantage of the ION’s PureVideo capabilities via VDPAU.

Tags: , , ,

Static resources versioning in web applications

Jan 28th, 2010

I recently had trouble with a Javascript-heavy application which was deployed to the end users quite frequently in its initial stages. The problem was that users were seeing bugs which had been fixed with the latest release and that was because their browsers were caching the static resources of the web application for too long. A forced refresh (Ctrl+F5 or Ctrl+R) solved the problem but I wanted a better, automatic way.

The solution was to add a version to the path of each static resource and then use url rewriting to get the real file. In practice in my HTML I refer to resources like this:

<link rel='stylesheet' type='text/css' href='1.0.6/css/styles.css' />
<script src='1.0.6/js/script.js'></script>

In my case the 1.0.6 is the pom.version which I get using Maven resource filtering. I then use the wonderful URL Rewrite Filter (but I could also have used Apache’s mod_rewrite ) to rewrite URLs matching

^/[0-9]+[a-zA-Z0-9\.\-]+/(js|css|img)/(.*)$

to

/$1/$2

I think I’ll go back and apply this fix to all my apps :)

Zotac ION C

Dec 10th, 2009

Yesterday I received a new motherboard for my HTPC: it’s a Zotac ION C which has a passively cooled Atom N230 CPU and a NVIDIA 9400 GPU which supports hardware-accelerated H.264/VC-1 1080p video with very little CPU usage. It’s so quiet now :) I will take pictures and post them eventually.

Jira LDAP integration

Dec 4th, 2009

As part of work I’ve been doing for a customer who was quite disappointed with Jira’s LDAP shortcomings, I’ve implemented an alternative OSUser LDAP CredentialsProvider. Because of serious limitations, proper integration is not possible (although planned for Jira 4.1), but my implementation covers most problems.

Tags: , ,

Too-OneBee

Nov 18th, 2009

I have started yet another open-source project: Too-OneBee. It’s both an embeddable and standalone web console for monitoring a J2EE application. It lives at Google Code: http://code.google.com/p/too-onebee/
It embeds a javax.scripting console for running scripts within the webapp, a JMX browser, a session/request/application/server context viewer, a JNDI browser.
I would like to add pluggable handlers so that, for example, one could add Spring integration, a JDBC tool (a la phpMyAdmin), etc.

Too-One Bee - Scripting

Too-One Bee - Scripting

Firefox 3.6 and Thunderbird 3.0 on Karmic

Nov 10th, 2009

I regularly use Thunderbird 3.0 betas on my Karmic via the Ubuntu Daily Mozilla PPA. Unfortunately the PPA also contains snapshot builds of Firefox 3.5 and XulRunner 1.9.1, which I want to keep at their standard Ubuntu versions. To make apt-get upgradeing as painless as possible I am using package pinning to stop unwanted packages from other repositories to override the defaults.

I have added this to my /etc/apt/preferences file:
Dirty Code

Package: *
Pin: release o=Ubuntu,a=karmic
Pin-Priority: 900

Package: firefox-3.5
Pin: release o=LP-PPA-ubuntu-mozilla-daily,a=karmic
Pin-Priority: -10

Package: firefox-3.5-branding
Pin: release o=LP-PPA-ubuntu-mozilla-daily,a=karmic
Pin-Priority: -10

Package: firefox-3.5-gnome-support
Pin: release o=LP-PPA-ubuntu-mozilla-daily,a=karmic
Pin-Priority: -10

Package: firefox
Pin: release o=LP-PPA-ubuntu-mozilla-daily,a=karmic
Pin-Priority: -10

Package: firefox-gnome-support
Pin: release o=LP-PPA-ubuntu-mozilla-daily,a=karmic
Pin-Priority: -10

Package: xulrunner-1.9.1
Pin: release o=LP-PPA-ubuntu-mozilla-daily,a=karmic
Pin-Priority: -10

Package: xulrunner-1.9.1-gnome-support
Pin: release o=LP-PPA-ubuntu-mozilla-daily,a=karmic
Pin-Priority: -10