Monday, October 18, 2010

Overhauled MySQL plugin for RHQ

I have just pushed a contribution by Steve Millidge to RHQ master. He overhauled the existing MySQL plugin big time, so that it now auto discovers the MySQL server with its databases and users.

Also the number of gathered metrics is vastly improved. The new code is currently only in master (in git), but will also show up in the next RHQ build.

Here is a small screen shot (with the current state of the RHQ 4 UI) that shows what has been discovered on my local MySQL 5.1.51 instance.



Bildschirmfoto 2010-10-18 um 11.58.06.png


As always, try it out and please give us and Steve feedback ( I am sure he also accepts pints as feedback :-)


Saturday, October 16, 2010

Android and the title bar progress indicator


I just spent quite some time trying to figure out how to get a tiny little spinning progress thingy in the title bar of my application. And to be honest, while there is a lot of documentation out there, it is far from trivial to finally implement it.

The best "how to" is just  few weeks old and the author also wanted to have such a thing.

Basically steps are: define a custom layout for the title bar, ask the system to allow replacing the title bar, set the content layout, only then set the custom title bar layout and then obtain a reference to the ProgressBar object.

As the post above is quite extensive, I just want to emphasis on the latter points:


protected void onCreate(Bundle savedInstanceState) {
   requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // 1
   setContentView(R.layout.single_tweet);        // 2
                              R.layout.window_title); // 3
   pg = (ProgressBar) findViewById(; // 4


Comments for the lines above:

  1. Ask the system to allow for a custom window title
  2. Set the content view of the whole window
  3. set the layout for the custom title
  4. Obtain the reference to the progress bar

If this order is not honored, pg, the reference to the ProgressBar will be null.

The layout for the title is shown in above post, so I'll not repeat it here.

The second important aspect is the usage of the ProgressBar. The main thread of execution in Android is the UI thread. And when a callback is running, the UI is not updating while such a callback is running. So, the following is not starting the progress indicator:

   public void myButtonPressedCallback(View v) {

The state of the progress indicator will only be set after myButton..() has returned. In oder to correclty handle this, you need to e.g. use an AsyncTask:


    private class DownloadImageTask extends AsyncTask<User, Void,Bitmap> {
        protected void onPreExecute() {
        protected Bitmap doInBackground(User... users) {
        protected void onPostExecute(Bitmap result) {



In this case, the ProgressBar is made visible in onPreExecute() (which runs in the UI thread. Then the background thread is started to do the long running computation and after this has finished, onPostExecute() runs again in the UI thread, where you can 'switch off' the ProgressBar again.


Friday, October 15, 2010

Android app lifecycle or "why do I sometimes get an empty screen?"


Many examples on the net for Android programs use something like this:

  public class MyActivity extends Activity {
    protected void onCreate(Bundle savedState) {
         doSomeSetup(); // e.g. login to a remote site

This is usually fine, but in some situations you end up with an application that just shows an empty screen. You may wonder what happens here.

Actually if you have a look the Android Application Lifecycle , you will see that onCreate() will only be called when the application is 'cold started'.

If the application is just resumed, onCreate() is not called again and and thus the dispatch to the next activity never happens. The application just sits on the empty screen.

There is an easy solution: onResume() is always called when the application comes to foreground again no matter if the app was cold started or just came to foreground again. So the above code could also read:

public class MyActivity extends Activity {
   protected void onCreate(Bundle savedState) {
         doSomeSetup(); // e.g. login to a remote site
protected void onResume() {
         if (!loggedIn()) 

Now on cold start, the login is done in onCreate() and then control goes to onResume() that dispatches to the next activity. On warm start, onResume() is directly called, that can check if the login is still valid.


Monday, October 11, 2010

JUDCon Berlin review (with pictures)


I've been at JUDCon Berlin for the last two days and this has been a very good experience. The conference venue (Radialsystem V) was just perfect, my hotel was next door to the venue, and we had a lot of good presentations.


Radialsystem V
(Radialsystem V from outside)


Ok, this was a little sparse.

After last JUDCon in Boston was well received, the JBoss team decided to do another JUDCon outside of the US to meet more of the community. The choice was made to go to Berlin (probably because JBossWorld Berlin was huge too :-)

I've submitted a talk on plugin development for RHQ and the JBossAS admin-console, which was accepted, so I had the luck to go to JUDCon.

I arrived already on Wednesday evening, went to the hotel and later to a cocktail bar (Sanatorium 23) together with Tobias Hartwig, Mark Little, Bruno Georges, Marek Goldmann, Bela Ban and some others.

On Thursday JUDCon started with a "keynote" by Mark Little and then continued in two parallel tracks. I first went to the BlackTie talk by Tom Jenkinson - and after the talk it became apparent that the next presenter, Bill Burke, was not able to make it to the conference in time (he still was in Krakow at the JDD). So I took over and presented an overview over RHQ. The room was still full, nearly no one left even as Galder was advertising his Infinispan talk :-) As I did not prepare slides for the talk, I took the ones I used the week before at OneDayTalk (they are linked there). The biggest time of the talk I did a live demo of RHQ 3 including installing RHQ from scratch, taking my computer into inventory and showing the UI. As time was running out (45 mins aren't that much :-), I could not show provisioning. After the talk I got a lot of questions - directly at the end of the session and also throughout the day.

Next, there was lunch in the big room with a speech given by a representative from Ingres, the sponsor of JUDCon. After lunch, sessions continued and I attended the two talks by Jesper Pedersen (IronJacamar and Tattletale - the latter is definitively something I need to look into) and then one by Steve Ross-Talbot about Savara before I gave my talk about writing plugins for RHQ.

This talk went quite well until the point where I tried to load my generated plugin into the IDE and the IDE just hang. And then when trying to compile, mvn gave me an error about some git problem. This something I need to look into. Nevertheless, I guess my audience got the idea on what is needed to do.

After dinner, where an iPad was given away by Ingres (Red Hat employees were not eligible :-( ) Hackfest started with some lightning talks were Jesper was quickly presenting about JBoss AS 7 (now on GitHub). Hackfest went until 1am when were thrown out of the venue.

Friday started with another series of talks. targeted around jBPM and Rules and other relevant themes like Errai and CDi or performance. I sneaked in many talks for a bit.

JUDCon has finished at 5:30pm with most of the participants staying 'til then end. I went to the airport and back to Stuttgart.

JUDCon was a great experience with lots of good talks and conversations. Participants were happy to get information from the source, from the people who know the stuff best as they have written it in the first place.

And for me it was a great pleasure too to meet my colleagues, who I normally only read in emails, blog posts or on Irc.

Slides to all talks are supposed to show up on the JUDCon page very soon.


(Tom Jenkinson)
(Jesper Pedersen on JBossAS 7)
(Heiko Braun on Errai)


Tuesday, October 05, 2010

Re-write Excel files with POI 3.6


Apache POI is a well known (java) project to handle reading and writing MS-Office documents. Another project in that area is jexcel (Lars Vogel has written a tutorial on its usage).

I was using POI in the past to just write new documents. Now I needed to read a worksheet and update it. POI has a nice "busy developers guide" on this, which did not directly work for me, so I've updated it to work for me:




import org.apache.poi.hssf.usermodel.HSSFWorkbook;




public void run() {


Workbook wb;

// Check if Workbook is present - otherwise create it

try {

InputStream inp = new FileInputStream(WB_NAME);

wb = new HSSFWorkbook(inp);

} catch (Exception e) {

wb = new HSSFWorkbook();


// Now write to it

try {

// Check if we have our sheet

if (wb.getNumberOfSheets()==0) {



Sheet sheet = wb.getSheetAt(0);


// Write row=2, cell=3 ==> D3

Row row = sheet.getRow(2);

if (row==null) // empty sheet

row = sheet.createRow(2);

Cell cell = row.getCell(3);

if (cell == null)

cell = row.createCell(3);


cell.setCellValue("a test");


// Write the output to a file

FileOutputStream fileOut = new FileOutputStream(WB_NAME);




catch (Exception e) {






Of course your mileage may wary :-)


Monday, October 04, 2010

RHQ 4 UI preview video

I've put a video on Youtube, that shows a quick preview of the RHQ 4 UI work. As you know the UI is being rewritten in GWT and we have posted a developer preview some time ago.

If you did not install this preview, here is a chance to get a glance at what we're working on.

As always: please give us feedback!

Saturday, October 02, 2010

Small review of OneDayTalk (with pictures)

Yesterday I was in Munich at the JBoss One Day Talk conference, talking about RHQ. The conference was organized by the Munich JBoss User Group.

Conference was very nice - like a big family event. Met some (JBoss) colleagues like Emmanuel Bernard, Manik and Navin Surtani, Thomas Diesler and Heiko Braun, as well as others like Andreas and the organizing Serge Pagop (who also works for Red Hat now). Also met Java Rockstar Adam Bien.

My talk about RHQ went mostly well - had around 40-50 listeners and got some good questions after the talk. The downside was that I spending a little too much time on the slides and general aspects so that I was not able to fully show the new RHQ 4 UI or even the provisioning subsystem.

If you want to new about the new UI, you can download the developer preview we released some time ago or checkout this video on YouTube. And come to JUDCon in Berlin next week to see it in action as well, as learn about plugin development.

My slides from the talk are also available as PDF.

Here are some impressions from the OneDayTalk:

Adam Bien on stage
(Adam Bien, hacking live on stage)
Manik Surtani
(Manik Surtani, talking about Infinispan)
Volker Bergmann
(Volker Bergman on performance testing)
Navin Surtani and Emanuel
(Navin Surtani and Emanuel Bernard)
(After-talk-Party at Löwenbräukeller)