Monday, December 27, 2010

Dream comes true - a movie directing experience

For random reason, I was assigned for a project of a cheesy 10 minute film, including script writing, film directing and editing. Although all the actors and the producer involved are all nerdy software engineers and managers, one of them does have professional movie acting experience with a best director in the world.

Schedule is tight, actors are not trained, and budget is zero. However the project went well and film went out on time.

Thursday, December 02, 2010

Java closure shows his face - Lambda expression

JSR335, Lambda expression started review ballot stage on November 16th 2010. Java closure finally show the new breath taking expression. Citing from the detail of JSR request:

2.7 Please give a short description of the underlying technology or technologies:

We propose extending the Java Language to support compact lambda expressions (otherwise known as closures or anonymous methods.) Additionally, we will extend the language to support a conversion known as "SAM conversion" to allow lambda expressions to be used where a single-abstract-method interface or class is expected, enabling forward compatibility of existing libraries.

We propose extending the semantics of interfaces in the Java Language to support virtual extension methods, whereby an interface can nominate a static default method to stand in for the implementation of an interface method in the event that an implementation class does not provide an implementation of the extension method. This enables interfaces to be augmented with new methods "after the fact" without breaking existing implementation classes.

Time permitting, we will use these features to augment the core Java SE libraries to support a more lambda-friendly style of programming, such as:
Collection collection = ... ;
collection.sortBy(#{ Foo f -> f.getLastName() });

collection.remove(#{ Foo f -> f.isBlue() });
This will likely be accompanied by a set of standardized "SAM" types such as Predicate, Filter, Mapper, Reducer, etc.

Saturday, October 23, 2010

My day

  • 8:00 Time to get up. First thing first, before Yilin wakes up, I have a few minutes to prepare her breakfast. Fortunately, this is done with my mom's help.
  • 8:10 Yilin usually starts her day at this point, which leads to diaper changing, cloth changing, running and chasing, etc.
  • 8:20 - 9:20 A full hour can slip so quickly, when it's time to feed Yilin. Again, my life would be much more painful if my mom weren't here. Sometimes I take chance to have my breakfast, sometimes I miss.
  • 9:20 It's time to take Yilin to day care. It's already late since the morning activity time is from 9AM to 10 AM. If lucky Yilin can enjoy the sunshine for 30 minutes.
  • 9:50 - 10:30 After good bye with Yilin, finally it's time to take a bus and go to work. This 40 minutes is one of my most relaxing time in a day. Sometimes I pick a book to read. But more and more often, I play little games on iphone.
  • 10:30 It's an awkward time to come to office and start work this late. However I'm used to it, and colleagues seem to be used to me as well.
  • 10:30 - 12:00 My job isn't easy. Other than things I sign up to do or others expect me to do, the meetings, emails, emergencies, random discussions pop up and takes 80% of my office time. Usually I can't really start working before 12:00.
  • 12:00 Time for lunch, but things are still piling up in front of me. Fortunately, the cafeteria downstairs allows customer to order online. It only takes 30 seconds to order a lunch, then I can continue work.
  • 12:40 Here's a little excise in the middle of the day. Running to the cafeteria, locating my order and taking it back to office, only takes 5 minutes for a fit person like me.
  • 12:45 Lunch is done with typing and discussion at the same time, usually.
  • 13:00 My lunch is officially finished. This experience occasionally becomes much better, or more like normal lunch, if my friends invite me to go out.
  • 13:00 - 18:00 This part of me is the working me. Again, 80% is taken away by unplanned meetings, discussions and accidents. But the good thing is, 20% times 5 hours, is still a lot of time for me to actually work and make progress. Aside from that, I have a little dark secret why I don't fall behind the schedule. Again, if my mom weren't here, I'd worry who's gonna take Yilin back home now.
  • 18:00 - 18:40 Another wonderful 40 minutes bus time. However this 40 minutes is less enjoyable than the one in the morning, since it's right in the rush hour, and bus looks pretty much like a can full of salmon slices.
  • 18:40 - 19:40 Another round of diaper changing, chasing and feeding. If I'm lucky I can have a dinner meanwhile, otherwise I'll have cold dinner after Yilin sleeps.
  • 19:40 Every night I bath Yilin. It's a important step to make her sleepy. If this step is done incorrectly, she could be an excited little girl for hours.
  • 19:50 - 20:30 Yilin is born an energetic child. It's like a battle to calm her down and help her sleep. I've done it for hundreds of times but I still don't know a shortcut.
  • 20:40 Finally it's time for my blood pressure to back to normal. At this point the apartment often looks like a ruin. Food is everywhere on carpet and wall, and a hundred dishes are waiting for wash. Luckily, I can take all the time it needs to clean everything up patiently.
  • 9:30 - 11:30 Sitting on the couch, this part is the best part of my day. I often wonder, what would I do if I have two hours for my own. However answer is usually the same, catch up the work, reply the 200 emails that got missed in the day, and do not get fired. The two hours here is my little dark secret. It's my secret why I only do 1 hour for real work at office and still can catch up projects and keep my job.
  • 11:30 - 12:00 If I sleep right after work, I always get insomnia. 30 minutes relax time, meaning music or video game, is very necessary for me to have a normal sleep like a sane person.
  • 2:00 Yilin still can't sleep through night. It's the time to feed her. It's not a horrible thing to come up at 2 AM, as it might sound to be, since I've done so many times, and I can wake up and go back to sleep like nothing happened.
  • 5:00 Another feeding.

This is my day, my standard weekday that I've been living for many months. It's occasionally better when my wife comes and help. But more often than not, it's a nightmare when she can't and mom has to leave, or something worse than a nightmare when Yilin is sick at the same time.

My day isn't an easy one. Once a while I think about it, likely on a bus by the way, I'm surprised that I managed to deal with it and keep myself entertained.

Monday, August 23, 2010

11 reasons to be a fulltime dad

11. Escape from paid job
10. Lose weight
9. Appreciate wife and parents more
8. Speak a new language, baby talk
7. Change a lot of diaper, clean a lot of mess and do a lot of cooking
6. Survive without sleeping
5. Understand why day care is expensive
4. Live with priorities
3. Learn to do everything with plan
2. Learn to do anything without plan
1. Become a patient person

Tuesday, May 04, 2010

This blog has moved

This blog is now located at
You will be automatically redirected in 30 seconds, or you may click here.

For feed subscribers, please update your feed subscriptions to

Tuesday, January 05, 2010

RESTful service with JAX-RS is so easy, a caveman could do it

A recent project requires me to build a RESTful service that supports supports stream input, output and JAXB binding. After a quick research, I was amazed when I found how easy it is to build RESTful service using JAX-WS(JSR-311) and Apache CXF. Cut the chase, let the code talk.
@Path( "/hello" )
public interface Greeter {
@Path( "/{user}")
@Produces( "text/plain" )
public String sayHelloTo( @PathParam( "user" )String userName );
It seems the annotations in the interface above provides everything client needs to know, and that's exactly right. Following CXF class returns an implementation of Greeter that knows to send HTTP request to and return the HTML response as a String. There's zero coding work involved to create fully functional client.
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
Greeter greeter = JAXRSClientFactory.create( "",
Greeter.class );
String result = greeter.sayHelloTo( "jiaqi" );
The server side code is even more amazing. Once interface is implemented, CXF provides library that seamlessly integrates arbitrary implementation with Servlet using Springframework. All you need to do is:

  • Making sure cxf-rt-frontend-jaxrs jar file and dependencies are in classpath. Which is simple in Maven:


  • CXF servlet and spring context listener is in web.xml

  • And tell Servlet to call my implementation in spring configuration

<beans xmlns:jaxrs="" ... >
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxrs:server id="restfulService" address="/">
<ref bean="greeter" />
<bean name="greeter"
class="sample.GreeterImpl" ... >
CXF project has a document with super detailed examples, which talked about more flexible use cases such as arbitrary MIME type, HTTP headers, cookies and stream based API. RESTful Java with JAX-RS is a book that worth reading for JAX-RS loving people. Anyway, now it's time for me to rewrite all my services.

A caveman could do it