Skip to main content

Posts

Remember to put a timeout on your heartbeat pings

I'm working a distributed piece of software which needs to be disabled when a tier is not reachable. To do that, I developed a Spring bean (a java service class) and I scheduled a method on it (with a @scheduled annotation). This method makes some heartbeat pings on each tier. The java service class contains a flag which indicates if all is OK. If an heartbeat fails, this boolean status is set to false. Of course, thanks to Spring, I easily injected this class into my web pages. If a user tries to access to the application and the health status is set to false, he is automatically redirected to a page which indicates that the service is closed. But, let's go back to pings.

I scheduled my pings to be executed each minute. That was for me a good value. But, a problem appeared during my first real tests. I realized that pings durations could be longer than one minute because the network connect() method blocked my thread. Of course, I forgot to manage short timeouts!

After a few go…

Use Spring 3 Expression Language (spEL) to get an Integer from an environment variable

Today, I played with Spring Batch. As you probably know, in a classic XML Spring config file, you can use ${my.property} to inject a system property in a bean attribute. That's quite simple.

But, in a JPA item reader (Spring Batch users should understand that), you cannot use this old syntax to inject values in your HQL query (using a parameterValues property). So, I decided to test the fabulously complicated spEL. A wonderful idea...

So, my problem is to get an Integer value from an argument passed to my JVM with something -Dmy.prop=value. Of course, if I don't have any JVM param, I want to have a default value.

Here is the solution :

#{(T(java.lang.Integer).parseInt(systemProperties['process.past.days']?:0))}

So, let's explain it :
#{(systemProperties['process.past.days'])} is required to retrieve a system property called process.past.days#{(systemProperties['process.past.days']?:0)} is required if you want to set 0 as default value... but... it's …

Colorify your Eclipse

Yesterday, while I was watching a video about the Play! framework, I realized that I was contemplating TextMate's colors. So, after some googlings, I discovered a "color plugin" which changes the text theme (it doesn't concern the overall look and feel but just the text apparence here). It is so nice so I put here the update-site url :
http://eclipse-color-theme.github.com/update

Spring saved my day on an UTF-8 encoding problem

I'm working on Jasig CAS (an SSO server) and I had an issue with special chars. For example, it was impossible to log in with a password like &é"'(-.
I checked my jsp file :it was encoded in UTF-8I checked the encoding directive (<%@ page contentType="text/html; charset=UTF-8" %>) : OKThe idea was to force the request encoding with something like :

request.setCharacterEncoding("UTF-8");

But I was in Spring MVC and I didn't want an ugly hack. Fortunately, Spring saved my day with a builtin servlet filter to declare in the web.xml.

<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<par…

Kill Oracle session after a JVM was killed

For the moment, I'm playing with Spring Batch. In development, it appends that I need to kill my JVM. The problem is that C3P0 is not allowed to acquire another connection on Oracle on next restart. It's just because the previous one is still there. If you have an Oracle account with the required privileges, the you can see your old session in v$session and destroy it :
select * from v$sessionalter system kill session 'sid,serial#'

Ubuntu 11.10 and ATI radeon problem : fan always on

Since I migrated my laptop (HP 4720s) to Ubuntu 11.10 with gnome-shell, I have the following issue :
the open source ATI drivers works well but my fan is always spinningthe additional drivers proposed by Ubuntu don't work and make gnome-shell unusablethe drivers (11.9) from AMD is very slow

So, for the moment, the best deal for me is to keep the open source drivers. DON'T INSTALL ANY OTHER DRIVER THAN THE ONCE INSTALLED BY DEFAULT. What we will do is to underclock the GPU to keep the temperature acceptable and avoid any problems with the fan. Let's open a terminal :echo -e '#!/bin/sh\necho low > /sys/class/drm/card0/device/power_profile' | sudo tee /etc/init.d/ati-power-savesudo chmod +x /etc/init.d/ati-power-savesudo update-rc.d ati-power-save defaults 99By the way, we will increase FPS by disabling vertical sync.

echo 'export vblank_mode=0' | sudo tee -a /etc/environment
Reboot and enjoy the silence!

Ubuntu 11.10 : you should try gnome-shell

Ubuntu 11.10 is provided with Unity, the graphical user interface from Canonical. Compared to the previous release (Ubuntu 11.04), you can now swith to Gnome Shell. But, why should you swith from Unity to Gnome Shell that you could consider as very similar? My opinion is that Gnome Shell is more pragmatic and beautiful than Unity.
So, how to activate Gnome Shell ? Go to the software center and activate the patner repositories in the software sourcesIn a terminal, run sudo apt-get install gnome-shellActivate it by default with sudo /usr/lib/lightdm/lightdm-set-defaults -s gnome-shellReboot and enjoy!Now that you have almost a prefect shell, you should install some addons : sudo apt-get install ubuntu-restricted-extras (for flash, java and dvd features)enable dvd decryption with sudo sh /usr/share/doc/libdvdread4/install-css.shsudo apt-get updatesudo apt-get install chromium-browsersudo apt-get remove firefoxsudo apt-get install smplayerA good thing is also to enable numlock on lightdm : …

A Java VNC Server implementation

I found this code today and I really have to test it.

Sources are here : http://ramshacking.blogspot.com/2009/07/server-class-for-vnc.html



import java.awt.AWTException;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import java.awt.event.*;

public class JVNCserver{

private final int WIDTH = Toolkit.getDefaultToolkit().getScreenSize().width;
private final int HEIGHT = Toolkit.getDefaultToolkit().getScreenSize().height;
private final Rectangle screenRect = new Rectangle(0, 0, WIDTH, HEIGHT);
public Socket socket;
public ServerSocket s;
private CaptureThread capturethread;
private CaptureEvents captureevents;
private Robot robot;
private O…

VMWare is not the only one to virtualize desktops

Today, as I was looking for some information about Ubuntu 11.04, I discovered Edubuntu weblive. This solution allows to open a real linux session over internet. Just go here and enjoy this revolution : http://www.edubuntu.org/weblive

By the way, I had to understand what kind of technology there is under weblive. I first found Stephane Graber's blog : http://www.stgraber.org. Then, I understood that it's a Linux terminal server with a FreeNX java agent. I realized how it is a real concurrent of the vmware solution.

If (like me), you want to "virtualize" desktops in your company, you have to :
understand how LTSP Cluster works (https://www.ltsp-cluster.org)understand what is LTSP of course (http://ltsp.org/)know things about the open source freenx implementation (http://code.google.com/p/neatx/)have a look to this lauchpad link : https://launchpad.net/~weblive-devunderstand what is LXC (http://lxc.sourceforge.net/)If you have legacy Microsoft applications such as Outlook,…

Maven war overlay and debugging

I'm currently working on a project which uses the maven war overlay feature. In such condition, I didn't succeed to start my a Tomcat instance from Eclipse WTP. That's because the war is built to late in the maven process and the Maven integration with WTP never calls the appropriate building step. Thus, I decided to start my server from the command line. With 'war overlay', I need to do :
mvn tomcat:run-war
But, what about debugging? Here I found two solutions.
Solution 1 : the standard mode
Just use :
mvnDebug tomcat:run-war
But it's a pre-configured solution and you should want to precise some specific options according to your environment.
Solution 2 : customize your debugging options
This is very simple. Ensure that you correctly declared your JAVA_HOMESet the debugging options which will be used by the JVM
For example : export MAVEN_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"
Then, just start y…

High-Performance Oracle JDBC Programming

IMPORTANT NOTE : I'm not the author of this post. Ths original location is here : http://blog.csdn.net/hakunamatata2008/archive/2009/05/13/4175764.aspx

High-Performance Oracle JDBC Programming

Learn how to improve performance of Oracle-driven JDBC programs by leveraging connection and statement pooling features.

By Yuli Vasiliev

Published April 2009

Using pooling techniques such as connection pooling and statement pooling can significantly improve performance of database-intensive applications, because it enables the reuse of objects that would otherwise need to be created from scratch, at the expense of time and resources.

Reusing database connection objects representing physical database connections utilized by an application can result in significant performance gains, provided that the application interacts with the database intensively, frequently re-establishing connections with the same parameters. On the other hand, you won’t benefit from using a connection pool if your applicat…