jueves, 20 de febrero de 2014

Solving problems when installing Jasperserver in Centos 6.x

When you try to install jasperserver in Centos 6.x you can face errors like:

Warning: Problem running post-install step. Installation may not complete
correctly
 Error running
/usr/jasperserver/jasperreports-server-cp-5.5.0/apache-ant/bin/ant
import-minimal-ce :
BUILD FAILED
/usr/jasperserver/jasperreports-server-cp-5.5.0/buildomatic/bin/import-export.xml
:275: The following error occurred while executing this line:
/usr/jasperserver/jasperreports-server-cp-5.5.0/buildomatic/bin/import-export.xml
:158: Java returned: 255



At least in our installation the problem was that the "myservername.localdomain" wasn't included in the file /etc/hosts.

It should look like this:

127.0.0.1       localhost myservername.localdomain

I hope this can help someone.

lunes, 18 de febrero de 2013

Deploying JasperServer on Glassfish V2 final

After following the JasperServer installation guide step by step in order to deploy the JasperServer.war in an existing Glassfish V2 installation I got this exception when trying to start the app server:

java.lang.IllegalAccessException: Class com.sun.jersey.core.spi.component.ComponentConstructor can not access a member of class com.sun.jersey.json.impl.provider.entity.JSONArrayProvider with modifiers ""


It looks like there's a a conflicting jakson-jersey libs by default in glassfish V2 final. To correct the problem you must download Jerseys libs and replace the ones in [glassfish-folder]/lib. Specifically the bad libs are: 
 
jackson-asl-0.9.4.jar
jersey-bundle-1.0.3.1.jar
jettison-1.0.1.jar


You can find the non conflicting libs here:

http://maven.java.net/service/local/artifact/maven/redirect?r=releases&g=com.sun.jersey&a=jersey-archive&v=1.12&e=zip

viernes, 11 de mayo de 2012

Warning!!!! Thread.sleep called in loop

Wow serveral months since last post!

Well returning to the topic, when you write a code block like this:
 while(timeout()){  
  try{  
   Thread.sleep(1);  
  }catch(Exception e){}  
 }  
Some IDEs as Netbeans or some software quality tools popup a warning informing that this kind of code usually is a design flaw or a bad practice, in other words a code smell. If you search in google you will get quick answers like "if you put a Thread.sleep inside a loop you are writting inneficient code, you should use notify and wait" but at the end of the day I have never found a clear example of how this code conversion from a "while" loop to a monitored code should be done. So.... here's the example, lets think an hipotetical problem where one thread is pooling a message bus. If you send a message trough the message bus you must wait an amount of time for another message that is a response for the sent message. The amateur way of implementing this would look like:
 Message lastMessage = null;  
 void sendMessage(Message messageToSend){  
   messageToSend.send();  
   while(!timeout()){  
    if(lastMessage != null){  
     reponseReceived(lastMessage);  
     lastMessage = null;  
    }  
    try{Thread.sleep(sleepTime);}catch(Exception e){}  
   }   
 }  
 //The message bus listener code, this is not that relevant  
 //We can just assume that this method is called from other thread.  
 void messageFoundInBus(Message responseMessage){  
  lastMessage = responseMessage;  
 }  
This code works but have two main problems. First, this is not efficient because sleepTime will put the Thread to sleep for a fixed amount of time. E.g. If you have 10 seconds in this constant the worst scenario is receiving the Message just after start sleeping making the Thread wait 9.x seconds to be aware of the response even if the message arrived long time ago. You could say, just use a smaller value but that could cause a different problem because if the sleep time is to short or you even decide to not put the Thread.sleep you could face starvation. The second problem is that while you are sleeping you could get a second message and override your response. There's no locking code. You could just include some synchronized sentences but you could forget it just because you are not forced to synchronize anything. If you use notify and wait you will be forced to synchronize this code avoiding this kind of problems from the beggining. Here's a second aproach using notify and synchronize:
 Message lastMessage = null;  
 final Object responseMonitor = new Object();  
 void sendMessage(Message messageToSend){  
   try{  
    messageToSend.send();    
    if(lastMessage != null){  
     synchronized (responseMonitor) {  
       responseMonitor.wait(timeout);
     }     
    }  
    if(lastMessage != null){  
     reponseReceived(lastMessage);  
     lastMessage = null;  
    }  
   }catch(Exception e){}  
 }  
 //The message bus listener code, this is not that relevant  
 //We can just assume that this method is called from other thread.  
 Message lastMessage = null;  
 void messageFoundInBus(Message responseMessage){  
  synchronized (responseMonitor) {  
   lastMessage = responseMessage;  
   responseMonitor.notify()  
  }  
 }  
The solution that I present is not an absolute rule, there are a lot of reasons not related to wait for a resource that could bring you to need a loop with a sleep inside, but almost every time you should be able to find a better way in order to avoid this kind of code.

domingo, 31 de julio de 2011

Moving files to honeycomp tablet internall memory using linux (without pain)

Long time since my last post but I have been a little busy! I got really frustrated trying to send some files to my asus transformer this weekend (using ubuntu). I tried to mount it as a file system via mtp but it was a complete failure, slow transfer rate, corrupted transfers, tablet frezzes, etc, etc, are some of the main problems that I faced.

I was almost done when I decided to try another aproach, I decided to install a SSH server in my laptop and a FTPs client in the tablet. The result? Flawless victory. Yes the transfer rate will never be as USB but is really convenient downloading my movies directly from my bed. :)

To install the SSH server in linux (at least if you are using any debian based distribution) just type:

sudo apt-get install ssh

And the scp client of my choise was AndFTP that can be found in the android market.

domingo, 30 de enero de 2011

Fix TV overscan using ubuntu nvidia privative drivers

I have an old LG HD-TV and I have been struggling trying to make it work fine with my ASUS laptop. The problem is that when I start "twin view" using the HDMI output of the laptop I get overscan in the TV, this means that I can't see my full desktop because 200 pixels in X axis and Y axis are lost. I have read in a lot of forums that modifing the device ID using a binary file or modifying directly the xorg.conf are the only workarounds to solve this problem but after spending almost an hour I discovered that nvidia-settings have its own tool to fix overscan.

I'm using 260.19.06 version installed using the official ubuntu repositories. To change the overscan simply launch nvidia-settings and go to Xserver Display Configuration. Detect your tv and enable it in twin view or as main screen. Now in the nvidia-settings main menu select your GPU tab and search your TV, in my case it says DFP-1 (LG Electronics 32LCD2D-MD). Select it and if you don't see a scroll-bar with title "Oversan Compensation" then click "ResetDefaults" button. After that operation you should see the "Oversan Compensation" scrollbar and you can scale the output to fit your TV size.



This driver have a lot of glitches and bugs, for example when I change any configuration I can't see the "accept configuration dialog" so I need to guees where is the accept button. In a similar way every time I change any configuration I lost my system theme and get reverted to gnome default theme. Those problems didn't presented when I was using the official drivers downloaded directly from Nvidia but after the last kernel update I just can't figure out how to make them work again. :(

viernes, 21 de enero de 2011

Mantain more than one music library in Rhythmbox

This is a really strange requirement but there are sometimes that you may want to mantain two separate libraries using the same linux user. In my case, I have one library in /home/myUser/Music and other one in /home/myUser/MusicLowQuality. This is usefull because I mantain a second version of all my music in a lower quality for syncing my mp3 player. The problem starts when you import this two folders to Rhythmbox because you will have a duplicate of every single song.

The Rhythmbox Library Database is stored in ~/.local/share/ryhtmbox/rythmdb.xml by default but you can invoke rythmbox this way to take any file you want:


rhythmbox --rhythmdb-file=/home/myuser/.local/share/rhythmbox/mynewdb.xml


This way you can create two diferent launchers that target to two different music libs. This is terrific but I found just one annoying behaivior. If you have the auto-inspect option enabled pointing to /home/myUser/Music and invoke the launcher that use the LowQuality folder when you include new music files to /Music they will be included in the wrong lib. This is a little difficult to explain :3

The easiest solution that I found was changing the path to the inpection folder before calling the launcher.

you can invoke rythmbox this way to take any file you want:


gconftool -s /apps/rhythmbox/library_locations -t list --list-type string [file:///home/myUser/MusicLowQuality] && rhythmbox --rhythmdb-file=/home/myuser/.local/share/rhythmbox/lowqualitydb.xml

gconftool -s /apps/rhythmbox/library_locations -t list --list-type string [file:///home/myUser/Music] && rhythmbox --rhythmdb-file=/home/myuser/.local/share/rhythmbox/normaldb.xml


I hope this can be useful for someone :)

martes, 11 de enero de 2011

Integrating liquibase in your java code

In modern software developing, versioning your source code is a most do and you can easilly find robust opensource and privative solutions to mantain a healthy versioned code. In the other hand, most developers agreed that versioning the changes made in your data model is as important than versioning your source code, but the tools available to do this task are not as extended and documented as the first ones.

In most projects that I have had the opportunity to participate the usual way to version the database is creating SQL scripts and run them in a progresive way. This does the job but have some drawbacks, for example:

1 If you use an ORM for the persistence of your project then you must write the versioning scripts for all the different database providers that you want to support.
2 If you need rollback functionallity then you must mantain two scripts.
3 If you have different branches in your projects merging changes can be a tiring process.
4. You must write plumbing code for versioning in your project. The old reinventing the wheel problem.

We decided to try Liquibase, an interesting database versioning tool that solves most the problems presented, mantaining the changes of your database in an "engine independent" way and supports rollbacks, diffs and tagging. We are not explaining how to use this tool here because the official documentation that you can find in liquibase.com is really good, what we will be explaining here is something that we couldn't find in the official documentation and this is including the liquibase library directly in you java code and use this as an API.

Liquibase was intended to be used via command line, ANT scripts and maven. In our case this wasn't enough and we wanted to be able the call and use the liquibase services directly in our java code to have the flexibility to do runtime updates in our own project. We tried to access directly the Liquibase object with no luck, we experimented many exceptions and hard times because the source code of liquibase is not documented as we would like, so the final desition was using the command line integration class.

First you need to download liquibase 2.0 and the jdbc connector for your database and include them in your project libraries. Next you need to extend from the class liquibase.integration.commandLine.Main (yes this is really ugly, we will still searching a better way).



public class DatabaseVersioningService extends liquibase.integration.commandline.Main implements DatabaseVersioningServiceLocal {
private static final String DATABASENAME_CHANGELOG_PARAM = "DATABASENAME";
private static final String CHANGELOG_PATH = "changeLogs/changelog_master.xml";
private static final String MYSQL_CLASS_DRIVER = "com.mysql.jdbc.Driver";
private static final String UPDATE_COMMAND = "update";

public void updateToHEAD(String dbUser, String dbPassword) {
try {
setMigrationParameters(dbUser, dbPassword);
applyDefaults();
configureClassLoader();
doMigration();
} catch (Throwable ex) {
ex.printStackTrace();
}
}

private void setMigrationParameters(String dbUser, String dbPassword, String command) throws URISyntaxException, SQLException {
changeLogFile = getClass().getResource(CHANGELOG_PATH).getPath();
username = dbUser;
password = dbPassword;
driver = MYSQL_CLASS_DRIVER;
url = new URI(padposDataSource.getConnection().getMetaData().getURL());
command = command;
}
}



Like you can see in the sample code is really simple but figure out this from the liquibase source code wasn't that easy, so we hope this can help someone else that wants to integrate liquibase directly in code. We will be studying liquibase code and maybe we will be writting a service tier to make this in a cleaner and elgant way.