Improve font rendering under Linux for your favorite (java) IDE

I recently decided to go back to linux (currently Fedora 17 and KDE) at home but I’m under Windows Seven at work (not my choice but not so bad after all) and I have been shocked the first time I launched my favorite Java IDE (nobody is perfect :D ) that is currently Intellij Idea.

Here is a screenshot of what I get (even with Adobe’s new Source Code Pro font if you hadn’t already guess):

Click to enlarge

Yes, this looks really ugly.

I whined on twitter about it (because my wife really doesn’t care about my ugly fonts problems) and Mark Derricutt directed me towards a search on an anti-aliasing problem (OK, I should have find it myself if I hadn’t be so lazy on this sunday morning). And I found this article that saved my day.

I first changed the Look & Feel under Intellij Idea from the default Idea one to GTK+:

Change Intellij Idea look & feel

Then I exported the _JAVA_OPTIONS with the proposed values:
export _JAVA_OPTIONS="-Dawt.useSystemAAFontSettings=on -Dswing.aatext=true"

(I did it in my /etc/profile.d/java.sh file but put it where you think is the more appropriate according to your own preferences).

And tada! Now my favourite IDE looks awesome!

So thanks again Mark and Gordon!

jsr107 javax.cache annotations with Google Guice

I’m using Google Guice as my Dependency Injection framework. I wanted to use the javax.cache api aka JSR107 (with EHcache as implementation). If you want to learn more about this famous JSR107, it could be a good idea to go to Greg Luck blog to get some more infos about it.

In my case, I wanted to use the annotations part of the JSR107 because I find them to be more elegant than a pure code solution (understand, you can put cache in your app without changing the logic, you just annotate your business methods, and woosh, you have cache set up).

But the JSR107 annotations implementations are DI framework dependant. And untill some days ago, only Spring and CDI implementation were provided.

I twitted to search any volunteers that might be interested in contributing (with or without me) to a Guice implementation.

Some hours laters, some commits from Michael Stachel were pushed by Alex Snaps to the github repo and here they are, the JSR 107 annotations for Guice were available.

I’d like to show you how you can use them.

The full source code is available here as a Mercurial repository on Bitbucket.

I’m using Maven, so here is the dependency part of the pom

        
            com.google.inject
            guice
            ${guice.version}
        
        
        
            net.sf.ehcache
            ehcache-jcache
            1.4.0-beta1
        
        
            javax.cache.implementation
            cache-annotations-ri-guice
            0.5-SNAPSHOT
        

You can see here that I’m using the latest snapshot of the cache-annotations-ri-guice artifact (0.5-SNAPSHOT as I’m writing this post). I don’t know if the snapshots are available somewhere, so I just cloned the corresponding git repositories and installed the snapshots locally. To be more precise, you will need to clone the jsr107-spec repo to build and install locally the jsr107 api artifacts that are needed by the jsr107 Reference Implementation artifacts, among which you’ll find the cache-annotations-ri-guice artifact.

Now, let’s write a basic UserService interface (ok, you don’t need an interface actually):

package net.awl.ismp.guice.jsr107;
import java.util.List;
/**
 *
 * @author looztra
 */
public interface UserService {
    public User getUserById(int id, int callId);
    public List<User> getUserByLastName(String name, int callId);
    public boolean calledBy(int callId);
}

The UserService makes reference to a User class:

package net.awl.ismp.guice.jsr107;
import java.io.Serializable;
import lombok.Data;
/**
 *
 * @author looztra
 */
@Data
public class User implements Serializable {
    private int id;
    private String firstName;
    private String lastName;
    private int age;
}

People that follow may have spotted that I was too lazy to write the accessors and that I chose to use the Lombok @Data annotation instead.

Here is the main part of a simple implementation of the basic UserService:

package net.awl.ismp.guice.jsr107;
import java.util.*;
import javax.cache.annotation.CacheKeyParam;
import javax.cache.annotation.CacheResult;
import lombok.extern.slf4j.Slf4j;
/**
 *
 * @author looztra
 */
@Slf4j
public class SimpleUserService implements UserService {
    private Map<Integer, User> users = new HashMap<Integer, User>();
    private List<Integer> callers = new ArrayList<Integer>();
    public SimpleUserService() {
        initContent();
    }
    @Override
    @CacheResult(cacheName = "getUserById")
    public User getUserById(@CacheKeyParam int id, int callId) {
        log.info("getUserById(): business method called for id (" + id + ") and callId (" + callId + ")");
        registerCaller(callId);
        if (id >= 0 && id < 100) {
            return users.get(id);
        } else {
            return null;
        }
    }
    @Override
    @CacheResult(cacheName = "getUserByLastName")
    public List<User> getUserByLastName(@CacheKeyParam String name, int callId) {
        log.info("getUserByLastName(): business method called for name <" + name + "> and callId <" + callId + ">");
        registerCaller(callId);
        List<User> matches = new ArrayList<User>();
        for (Map.Entry<Integer, User> entry : users.entrySet()) {
            User potentialMatch = entry.getValue();
            if (potentialMatch.getLastName().contains(name)) {
                matches.add(potentialMatch);
            }
        }
        return matches;
    }
...
}

The initContent() an the registerCaller() method are only utilities methods (full source code available here).

The interesting parts are the two annotations @CacheResult and @CacheKeyParam.

Straight from the javadoc: When a method annotated with @CacheResult is invoked a CacheKey will be generated and javax.cache.Cache#get(Object) is called before the invoked method actually executes. If a value is found in the cache it is returned and the annotated method is never actually executed. If no value is found the annotated method is invoked and the returned value is stored in the cache with the generated key.

The @CacheResult is then a very simple way to set up a Read-Through cache.

The @CacheKeyParam is used to specify which subset of the method params are to be used as part of the CacheKey (by default, all the method params are used).

Those 2 annotations are not the only one existing of course. You could use @CachePut to implement a Write-Through cache for instance.

Before it can work as expected, don’t forget to register the CacheAnnotationsModule so that Guice injector can use the jsr107 annotations.

...
@BeforeClass
    public void setUp() {
        Injector injector = Guice.createInjector(new MyModule(),new CacheAnnotationsModule());
        service = injector.getInstance(UserService.class);
    }
...

MyModule being a very simple Guice module matching my simple needs:

package net.awl.ismp.guice.jsr107;
import com.google.inject.AbstractModule;
/**
 *
 * @author looztra
 */
public class MyModule extends AbstractModule {
    @Override
    protected void configure() {
        bind(UserService.class).to(SimpleUserService.class);
    }
}

A simple unit test to see it in action

    @Test
    public void testGetIdTwice() {
        Assert.assertNotNull(service);
        int callId = getCallerId();
        log.info("testGetIdTwice(): calling the service the first time with callerId <" + callId + ">");
        User found = service.getUserById(testGetIdTwice_SEARCHED_ID, callId);
        Assert.assertNotNull(found);
        log.info("testGetIdTwice(): found user <" + found + ">");
        // check that we went through the business method the time
        Assert.assertTrue(service.calledBy(callId));
        //
        int callId2 = getCallerId();
        log.info("testGetIdTwice(): calling the service the second time with callerId <" + callId2 + ">");
        User found2 = service.getUserById(testGetIdTwice_SEARCHED_ID, callId2);
        Assert.assertNotNull(found2);
        // check that we did not go through the business method this time
        Assert.assertFalse(service.calledBy(callId2));
    }

Feel free to get the full source code that is available here as a Mercurial repository on Bitbucket.

Mercurial : track changes to a repository with RSS

If you are used to CVS or SVN notifications, you may want to reproduce the emails that you received each time a commit is made by a developper.

You can do that using Hooks with mercurial but the built-in mercurial web server provides RSS feeds of changes in every repository. Simply subscribe to the rss feed provided at your repository url + /rss-log/ and that's it.

Enjoy

WTF? my keyboard layout changed while I was working under Eclipse!

Just happened again to me. Once again. And I had to search once again how to fix it.
Actually, I was playing with Eclipse shortcuts…and I fired Alt+Shift several times…which seems to be the default shortcut under windows to switch between registred keyboard layouts. I don’t remember why but I registred a QWERTY layout (but can’t remember when I could have use it), but I always work with an AZERTY layout.
2 solutions:

  • change the windows shortcut (that is global to windows, i.e. that will surcharge any application shortcut)
  • unregister the layout that you never use

In both cases, go to Control Pannel > Regionnal Settings > Languages > Details.

Some jRRD news

Some (old) news about jRRD, a pure java library that allows you to read Round Robin Database files created by rrdtool.

The project has been “mavenized” and moved to SVN (ok, maybe we should have switched directly to Git, please don’t tell Linus we are still using SVN).

A version 0.3 has been released, a full changelog can be found here. The main changes are:

  • a patch to fix the case of multiple datasources has been applied (initialy provided by Juraj Sucik).
  • supports version 3 rrd files (jRRD v0.1 only had support for version 1 rrd files)
  • x86_64 files (only tested on linux 64bits plateform, if you have access to other 64bits plateform, please contact us)



The project is not really active because in its current state, it fits our needs, so fill free to wake it up and send us your feature requests.

Cygwin rxvt under windows Seven

Ok, you’ve not been blessed by the MacOS Spirit so you don’t have a MBP but you’d like to have a decent *nix term under windows Seven. You tried the same shortcut that worked previously under XP:

C:\Cygwin\bin\rxvt.exe -g 120×70+75+-1  -sl 1500 -fn courier -bg black -fg grey -sr -e bash –login -i

but all you get is big window with strange spacing between chars:

.
Ok, it’s time to customize some stuff. Open a cygwin shell (or an ugly uncustomized rxvt), go to your home directory, and create/edit your .Xdefaults file to fit this one:

#Rxvt.reverseVideo:      true
Rxvt.scrollBar_right:   false
Rxvt.saveLines:         2048
Rxvt.font:              "Lucida Console-12"

Then edit your shortcut to something similar to this one:

C:\cygwin\bin\rxvt.exe -display :0 -bg black -fg grey -tn rxvt -sr -sl 1500 -g "140x60+1+-1" -e /usr/bin/bash --login -i

If you need to adjust the size of the window, you can change the -g “140×60+1+-1″ values.

You should now get something much more like that:



Enjoy!

Piwik Analytics plugin for Hudson

Piwik is an open source (GPL licensed) web analytics software program (similar to Google Analytics). Hudson is a continuous integration server. If you want to track visits on your Hudson server using piwik, you need a Piwik Analytics plugin for Hudson. None exists officialy. I had a look at the Google Analytics plugin and adapted it to Piwik.

All you’ll need is a piwik siteId, the piwik server name and path of your piwik installation. And the Piwik Analytics plugin for Hudson that you can download here (save as…) till there is an official version available (maybe some more tests needed, any feedback will be appreciated!)

Update 2009-11-03: I fixed the mime type for hpi files so no more Save as should be needed.
Update 2009-11-04: some minor changes: french translations and the possibility to add download extensions (see

http://piwik.org/docs/javascript-tracking/

Update 2009-11-06: fixed the package to be compatible with jdk 1.5
Update 2009-11-07: the plugin has been officially released and should be available in you admin plugin list.

Hudson Piwik Analytics plugin

Fedora Core 11 & VMware Player 2.5.2

Si vous venez comme moi de mettre à jour votre fedora vers la version 11 et que vous utilisez VMware player (par choix ou sous la contrainte, alors que VirtualBox fonctionne très bien), vous allez vous confronter à un petit problème: les modules supplémentaires compilés par l’installeur de vmware ne compilent pas justement.

La raison est simple, le kernel livré avec la fc11 est un 2.6.29, qui n’était pas encore sorti lorsque le player 2.5.2 est sorti.

Toutes les infos et le patch a appliquer se trouvent par là.

Après application du patch, ça devrait donner:

Starting VMware services:
Virtual machine monitor                                 [  OK  ]
Virtual machine communication interface                 [  OK  ]
Blocking file system                                    [  OK  ]
Virtual ethernet                                        [  OK  ]
Shared Memory Available                                 [  OK  ]

et zou.

vmware-6.5.2-modules-2.6.29-fix.sh
vmware-6.5.2-modules-2.6.29-fix.patch

If you’ve just upgraded your fedora install to version 11 and that you (have to) use VMware player (despite VirtualBox works very well), you will encounter a small problem: additionnal kernel modules needed by the vmware install won’t compile.

Indeed, the kernel bundled with fc11 is a 2.6.29, that wasn’t out when vmware player 2.5.2 was released.

All informations and a patch to apply are provided here.

Let’s apply the patch and enjoy:

Starting VMware services:
 Virtual machine monitor                                 [  OK  ]
 Virtual machine communication interface                 [  OK  ]
 Blocking file system                                    [  OK  ]
 Virtual ethernet                                        [  OK  ]
 Shared Memory Available                                 [  OK  ]
that's all folks!

vmware-6.5.2-modules-2.6.29-fix.sh
vmware-6.5.2-modules-2.6.29-fix.patch

jrrd TODO List

  • update website :)
  • release 0.2
  • use maven and SVN
  • explain the differences with other java rrd tools (jrobin, rrd4j, see https://wiki.man.poznan.pl/perfsonar-mdm/index.php/RRD_Java_libraries)

Java: auto-initialisation des variables d’instance…ou pas

A chaque fois que je crée une nouvelle classe, je me demande si je dois forcer la valeur par défaut des variables d’instance. La plupart du temps je me dis “je ne veux pas dépendre d’un comportement par défaut, je vais forcer explicitement la valeur par défaut de la variable d’instance, ce sera plus lisible”. C’est peut-être discutable mais je n’ai jamais eu l’occasion d’en discuter avec des java-gurus, ni d’ailleurs de réellement me poser des questions sur le bien-fondé et la justesse de ce choix.

Jusqu’à ce jour. Je viens de découvrir (shame on me?) qu’il est parfois nécessaire de ne pas explicitement forcer la valeur par défaut.

Read more »

Page optimized by WP Minify WordPress Plugin