Sunny Chan blogs

Can you see the Logic in my Madness?

Tuesday Dec 13, 2011

Java SE Embedded and Synology Diskstation

I have got a Synology DS209 at home, which is an ARM based NAS. Oracle has released Java SE Embedded 7 and it has got ARMv5 support, so naturally I would want to see whether my NAS is up to it:



disk> uname -a
Linux disk 2.6.32.12 #1955 Sat Nov 26 14:50:54 CST 2011 armv5tel GNU/Linux synology_88f6281_209
disk> java -version
java version "1.7.0_02"
Java(TM) SE Runtime Environment for Embedded (build 1.7.0_02-b13, headless)
Java HotSpot(TM) Client VM (build 22.0-b10, mixed mode)


So "Hello World" is working. Let's try something more fun - like running jetty:


disk> java -jar start.jar
2011-12-14 03:33:21.810:INFO:oejs.Server:jetty-8.0.4.v20111024
2011-12-14 03:33:22.039:INFO:oejdp.ScanningAppProvider:Deployment monitor /volume1/homes/schan/jetty-distribution-8.0.4.v20111024/webapps at interval 1
2011-12-14 03:33:22.075:INFO:oejdp.ScanningAppProvider:Deployment monitor /volume1/homes/schan/jetty-distribution-8.0.4.v20111024/contexts at interval 1
2011-12-14 03:33:22.096:INFO:oejd.DeploymentManager:Deployable added: /volume1/homes/schan/jetty-distribution-8.0.4.v20111024/contexts/javadoc.xml
2011-12-14 03:33:22.413:INFO:oejd.DeploymentManager:Deployable added: /volume1/homes/schan/jetty-distribution-8.0.4.v20111024/contexts/test.xml
2011-12-14 03:33:22.845:INFO:oejw.WebInfConfiguration:Extract jar:file:/volume1/homes/schan/jetty-distribution-8.0.4.v20111024/webapps/test.war!/ to /tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp
2011-12-14 03:33:30.509:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp/},/volume1/homes/schan/jetty-distribution-8.0.4.v20111024/webapps/test.war
2011-12-14 03:33:30.510:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp/},/volume1/homes/schan/jetty-distribution-8.0.4.v20111024/webapps/test.war
2011-12-14 03:33:30.510:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp/},/volume1/homes/schan/jetty-distribution-8.0.4.v20111024/webapps/test.war
2011-12-14 03:33:30.518:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp/},/volume1/homes/schan/jetty-distribution-8.0.4.v20111024/webapps/test.war
2011-12-14 03:33:30.518:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp/},/volume1/homes/schan/jetty-distribution-8.0.4.v20111024/webapps/test.war
2011-12-14 03:33:31.338:INFO:oejhs.SslContextFactory:No keystore or trust store configured.  ACCEPTING UNTRUSTED CERTIFICATES!!!!!
2011-12-14 03:33:32.929:INFO:oejs.TransparentProxy:TransparentProxy @ /javadoc-proxy to http://download.eclipse.org/jetty/stable-8/apidocs
2011-12-14 03:33:33.047:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8080 STARTING

I am very impressed - They also have the server VM for ARMv7 too - maybe it's time to get a new Diskstation!



Blog upgraded

I have upgraded this website to:



  • Apache Roller 5.0

  • Apache TOmcat 6.0.35

  • Java 7 Update 2


Let's see how this goes!

Saturday Nov 12, 2011

More OpenJDK compile notes for Fedora 16

Just to save people from scratching their heads - if you try and compile OpenJDK from vanilla source bundle (not IcedTea) on Fedora 16, you migth see libjvm.so fails to link with a message:


libstdc++ not found


If you look at OpeJDK build readme:


This is caused by a missing libstdc++.a library. This is installed as part of a specific package (e.g. libstdc++.so.devel.386). By default some 64-bit Linux versions (e.g. Fedora) only install the 64-bit version of the libstdc++ package. Various parts of the JDK build require a static link of the C++ runtime libraries to allow for maximum portability of the built images.


 DOH! So what you will need on Fedora 16 is libstdc++-static package

Friday Oct 28, 2011

OpenJDK compile problem on Ubuntu 11.10, and the fix

If you have following the OpenJDK build Readme and try to compile OpenJDK on Ubuntu 11.10, you may see this error: 


/home/schan/openjdk7/build/linux-amd64/tmp/sun/javax.sound/jsoundalsa/obj64/PLATFORM_API_LinuxOS_ALSA_PCM.o: In function `DAUDIO_GetFormats':
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x1fd): undefined reference to `snd_pcm_format_mask_malloc'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x20a): undefined reference to `snd_pcm_close'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x225): undefined reference to `snd_pcm_hw_params_malloc'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x236): undefined reference to `snd_pcm_hw_params_get_format_mask'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x246): undefined reference to `snd_pcm_format_mask_free'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x259): undefined reference to `snd_pcm_hw_params_any'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x26a): undefined reference to `snd_pcm_hw_params_get_format_mask'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x277): undefined reference to `snd_pcm_hw_params_get_channels_min'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x288): undefined reference to `snd_pcm_hw_params_get_channels_max'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x2cf): undefined reference to `snd_pcm_format_mask_test'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x45d): undefined reference to `snd_pcm_hw_params_free'
/home/schan/openjdk7/build/linux-amd64/tmp/sun/javax.sound/jsoundalsa/obj64/PLATFORM_API_LinuxOS_ALSA_PCM.o: In function `setStartThresholdNoCommit':
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x48c): undefined reference to `snd_pcm_sw_params_set_start_threshold'
/home/schan/openjdk7/build/linux-amd64/tmp/sun/javax.sound/jsoundalsa/obj64/PLATFORM_API_LinuxOS_ALSA_PCM.o: In function `setStartThreshold':
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x4bf): undefined reference to `snd_pcm_sw_params'
/home/schan/openjdk7/build/linux-amd64/tmp/sun/javax.sound/jsoundalsa/obj64/PLATFORM_API_LinuxOS_ALSA_PCM.o: In function `setHWParams':
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x518): undefined reference to `snd_pcm_hw_params_any'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x531): undefined reference to `snd_pcm_hw_params_set_access'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x544): undefined reference to `snd_pcm_hw_params_set_format'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x557): undefined reference to `snd_pcm_hw_params_set_channels'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x58a): undefined reference to `snd_pcm_hw_params_set_rate_near'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x5dc): undefined reference to `snd_pcm_hw_params_set_buffer_size_near'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x60b): undefined reference to `snd_pcm_hw_params_set_period_time_near'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x61b): undefined reference to `snd_pcm_hw_params'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x647): undefined reference to `snd_pcm_hw_params_set_periods_near'
/home/schan/openjdk7/build/linux-amd64/tmp/sun/javax.sound/jsoundalsa/obj64/PLATFORM_API_LinuxOS_ALSA_PCM.o: In function `setSWParams':
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x67e): undefined reference to `snd_pcm_sw_params_current'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x6b4): undefined reference to `snd_pcm_sw_params_set_avail_min'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x6c4): undefined reference to `snd_pcm_sw_params'


Don't panic - it looks like the Java's linking sequence for ALSA sound library is wrong. Just use this patch:


--- old/make/javax/sound/jsoundalsa/Makefile    2011-10-28 02:28:00.000000000 -0400
+++ new/make/javax/sound/jsoundalsa/Makefile    2011-10-28 02:28:00.000000000 -0400
@@ -65,7 +65,7 @@
        $(MIDIFILES_export) \
        $(PORTFILES_export)
 
-LDFLAGS += -lasound
+EXTRA_LIBS += -lasound
 
 CPPFLAGS += \
        -DUSE_DAUDIO=TRUE \


You should be good to go!

Sunday Jul 24, 2011

How to compile OpenJDK on Windows

These are the steps that I have made OpenJDK to compile on Windows platform:




  1. Install Visual C++ 2010 Express (or if you are rich, get Visual Studio 2010 Professional) 

  2. Install Windows 7 Platform SDK

  3. Install Cygwin, install the packages suggested on OpenJDK Readme. Also install gcc for step 5

  4. Install DirectX 9.0 SDK

  5. The gnu make package in the current cygwin does not support Windows directory convention and you should compile your own version of the make 3.82 which has the correct support.

  6. Download latest Freetype


    • Compile it using Visual C++ - you can find the Visual C++ project file under <freetype src>/builds/win32/vc2010. 

    • Make sure you have change the type of DLL it generates by going to Project->Properties, then Configuration Manager... button, set it to Release and Win32

    • Make sure you have set it so that it builds a DLL - you can find that under Project->Properties, Configuration Properties, General and there should be a Configuration Type drop down box

    • You can then build freetype. The DLL generated will have a version number attached to it (e.g. freetype245.dll) and you will need to make sure you rename it to freetype.dll.


  7. Get latest Apache ANT

  8. Make sure you have a Java 6 JDK installed

  9. Download the openjdk source code, either using hg or source bundle (I will assume you put it in c:\openjdk)

  10. Open a command prompt for Windows SDK by going to Start -> Windows SDK 7.1 -> Windows SDK 7.1 command prompt

  11. For 32bit ONLY, you should run the Visual Studio compiler settings batch file: c:\program files\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat

  12. Make sure you have override the standard cygwin bin path so that make.exe you have compiled in step 5 take precedent of the default cygwin.

  13. Also check that the link.exe you run in the path is the actual Microsoft linker and not the cygwin's link command - you will need to fiddle with the path.

  14. Setup a number of environment variables:


    1. ALT_BOOTDIR should point to the Java 6 JDK (Step 8)

    2. ALT_DXSDK_PATH is the DirectX SDK PATH (Step 4)

    3. ALT_FREETYPE_LIB_PATH and ALT_FREETYPE_HEADERS_PATH.

    4. ANT_HOME

    5. HOTSPOT_BUILD_JOBS if you want to parallelize your build - you can't use -j options in the make command

    6. ALLOW_DOWNLOADS=true so that it can download JAXP and JAXS jar

    7. Make sure the path is setup correctly (Step 12/13)


  15. You are ready to give it a go. First, run "make sanity" and see whether there is anything you setup incorrectly. If something is wrong, fix it.

  16. If you have passed make sanity, you can run make to build the JDK! Go and make a cuppa, it will take a while. On my i7-2600 and hard drive it took 2 hours.


Important: In order to build a 32bit JDK you must use a 32bit System - ie. you cannot cross compile (ie. 64bit Windows and compile a 32bit JDK)



Let me know whether it works for you. if it doesn't tell me what's wrong and I will fix the instructions!



Friday Jul 15, 2011

COSCUP talk

This is the abstract for my COSCUP talk on August 18th, 2011:


OpenJDK 7: The universal language runtime


Sunny Chan
Hong Kong Java User Group Leader


OpenJDK 7 is the latest release of the Java Platform. In this release, there are a number of major innovations in the OpenJDK's Java Virtual Machine to enable other scripting languages like Ruby, Python and PHP to run on the platform efficiently.


In this talk, I will give you 5 reasons why you should run your applications written in alternative languages like Ruby on the OpenJDK Runtime. I will also explore some of the common myths about running your application with the Java Runtime.

Tuesday Feb 16, 2010

Three Weeks In


Here is my status / thought three weeks into Plan A (formerly known as Plan B)




  1. I am still jet lagged. I feel sleepy during the morning but otherwise I am fine

  2. I have been eating out almost 85% of the days I have been in Hong Kong. I have also joined Fitness First and definitely need to make use of it

  3. The amount of alcohol I have consumed in the last three weeks is the sum of all alcohol I have consumed 3 months before I leave UK.

  4. Where the f**k did all the people come from?! The whole town is packed

  5. My mom is better at investigating my life than FBI / MI5 / KGB

  6. I still feel like I am on holiday here in Hong Kong. I think that would change when my boxes arrive.

  7. My box is currently somewhere near the Gulf at the moment. I just hope that the pirates in Somali won't find it

  8. Work is fine, except a lot of midnight calls. 

  9. Lunch is much better around here. Plenty of nice food and company!

  10. My salary is pretty good over here. Why didn't I do it earlier?

  11. I missed MINI. Didn't help when they have big poster showing Mini near Time Square.


I do miss you guys in UK. Honest.

Wednesday Dec 23, 2009

Looking back

The cat is now out of the bag, and I am slowly shutting down my life over here. I think it's time to do a review and take stock of what I have achieved and looking ahead


Most people have thought that my mom and dad made the decision for me to come over here, on the contrary it is actually me initiated the whole studying in UK. I was not happy at the school I was studying in Hong Kong and I see this as a way out to the terrible time I had in Hong Kong - I considered myself being bullied by my teacher and I thought certainly this "mother" country could not be worse. (The colonial government did a good job of brain-washing me :-).


When I first set foot in this country it feels strange yet farmiliar. The car drive on the correct side of the road, except that everything is in English. I certainly can feel the chill but I do find the people are very welcoming and have a strange sense of humour. But I certainly didn't forsee my experience in Felsted - it changed my life completely.


I definitely remember the first night in Follies. I was sobbing like a little baby in the little desk that we have for the NIPs (stands for Not Important Person). I think most of my housemate is puzzled - I think it is the thought of having to fence for myself from that point onwards. But soon after I get into the strive of studying and living in the boarding school, and I definitely make good use of my time there. Initially I am pretty sceptical of the gwai chais there. My parents have told me a few things about what they are like and I have found out that it is completely different - once we have worked out our cultrual differences I think my friends Felsted are warm and welcoming, and much more down to earth then I first thought. I have certainly made a lot of really good friends and we are still in touch 20 years later.


I am a pretty open minded person and after my "training" in Felsted I can really apperciate the way of life here and the culture. What I really love about this country is that people are humble and they are able to laugh about themselves and being selfless in a lot of ways. They like to engage with people and encouraged to look outwards and dream. I feel free to be myself here - as long as you don't go and kill people, you can do whatever you want. There are certainly a lot more social norm and convention out there in Asia, which would be very interesting to deal with.


I will definitely feel sad to leave behind all my good friends I made over the years, as well as the piece of London that I own (okay, the little piece of London that have been leased to me for another 70 years :-). I would definitely missed the days that I can go to the football games or take a spin in the winding road down in countryside.


However, I feel that it is the right opportunity to make a change in direction for my life. It would be a big culture shock when I am back in Hong Kong but I don't want to regard it not doing this while I still can. Who knows where life would take me but I certainly would be quite happy to come back and call UK home.



Sunday Oct 04, 2009

Sunny's 5 Year Itch

According the this website, The phase "The Seven Years Itch" means the inclination to become unfaithful after seven years of marriage. Ladies, don't worry, I am still single and available. However I wonder whether I do have a five years itch.

So far in my life I never really stayed at one location / school /  job for more then 5 years. The worst period is during my Primary School years, where one reason or another I have moved to 3 primary schools - nearly once every 2 years. By the way, I do not recommend anyone to subject their son and daughter to this as for me it was pretty traumatic, and it has turned my life upside down. Without the bad experiences during my late Primary / early Secondary School years, I would probably have not pluck up the courage to take the big step to study in UK. The period I spent in Felsted is the best time in my life, where I made friends and won respect - people still remember me out there after 10 years! If I haven't studied to Felsted, I probably won't get into Imperial, and would probably got the job that I am doing now.

Sometimes I am wondering whether Plan B is my 5 Year Itch, but I don't think it is such a bad thing.

For those who wonder what happen with Plan B I am still waiting for Human Resource in the bank I am working for to sort things out. It may take 2-3 months. I have already started to throw away old books and stop buying items that I cannot take with me. However, until I have the offer no one should assume that Plan B is happening. So please do not discuss this with my parents yet!

 

Saturday Oct 03, 2009

Donation sought (at the request of my mom)

Dear Children,
 
            Please note :
 

         相信你們都常常聽我提及有關我參與不同的義工服務。其中一個團體是"無界限 - 精神健康社區融合會" (簡稱無界限 )。

 

                 很高興在這裏,隆重宣佈: 本會的第一份宣傳小冊子已經出世了 (見附件)。身為司庫的我,親眼見證這群babies(小冊子),在這個貧窮但充滿愛、理想和團結的大家庭裏面,只用了650元便做出了2,000個值得我們自豪的寶貝.......它們身負重任 :

 

(一) 將 "無界限" 的成立、宗旨、目標、服務對象/內容等等介紹給尚未認識我們的朋友。 希望朋友們知道,在社區上有一群人正在努力默默地為精神病康復者提供服務,幫助他們融入社區和重拾自信。朋友們! 你地能放下對他們的歧視和誤解; 以愛,包容去接納他們,一個共融的社區,對他們重投社會有莫大的幫助。

 

(二) 朋友們如果你身邊在這方面有需要協助的人,可以聯絡我們,可能我們未必可直接幫到手,但我們可以儘量為你們提供相關的渠道,獲得合適的協助。有問題,不要怕,只要勇敢面對,一定OK。

 

(三) 歡迎認同我們理念的社會各界人士,加入我們的行列。

 

(四) 籌募經費 : 希望大家能慷慨解囊,樂善好施。

 

           Please help to spread the news to your friends, colleagues (in HK for Sunny) so that someone may like to donate money to our community.  I will bring a few handouts to Sharon's home today.

 

            Forwarded two words files for follow-up action.

 

Mother

Sunday Sep 13, 2009

The Italian Job - preliminary plan



View The Italian Job in a larger map


I am planning to switch on Google Latitude during the trip so that people can track where I am. More details to follow 

Friday Aug 07, 2009

Autofs hints

Just to save other people out there who have try to use autofs:

All automount map file must be non executable (eg rw-r-r-)

If not automounter will refuse to load it. I was scratching my head for a whole night trying to figure out my new ubuntu installation refuse to mount my NFS home directory. I am just about to blame ubuntu for this :-)

Friday Jul 17, 2009

T-Mobile G1 - The Google Phone

Well, as most people who read this knows that I am pretty keen on Palm Pre. However my Nokia N95 is falling apart and I need a phone now to replace my Nokia. So I decided to take a look and I have decided to get a T-Mobile G1 for now, and then when Palm Pre is out here at the end of the year I would go and get

For those who doesn't know, T-Mobile G1 is the first phone that is based upon Google Android, the Linux based mobile OS that uses a subset/special implementation of Java as the main program interface.

I have been using the G1 for about a week now, and so far so good. It's pretty slick and the interface are pretty good compare to the iPhone. All the apps I wanted to use are there, including a fairly decent Live Messenger client. Althought the AppStore is not as good as Apple, it is growing and there are a few useful one up there. Hopefully once the Chinese Manufacturer making cheaper Android phone more developers will move onto the platform. Though it should be fairly easy to move J2ME application onto the Android platform (quite similar but not exactly the same - however a good developer can easily develop Facade to support both).

Anyway, I should download the SDK and have a play around soon.