Saturday, May 10, 2008

Java One 2008, day two

Gosh it is friday and I have only written up my notes for tuesday. Time certainly flies here. I resolved to take it a little bit easier, and say eat or something, on tuesday.

So the day started with the Oracle keynote, quite a good one as generally I don't find much of interest in there for an Oracle developer. Lots of good stuff using web center and bea stuff we so recently aquired. Indeed the crowd around me seem suitable impressed with this enterprise 2.0 demo.

The first session of the day was TS-5579 Closures Cookbook presented by Neal Gafter of the BGGA proposal. So we were looking a one possible solution; but one that was strangly compelling.

So the presentation was focused around the languages changes required to support the following time general call:

public void timeWithNoReturn()
  throws MyException
   time(“opName”, {=>
      // some statements that can throw MyException

public int timeWithReturn()
  throws MyException
   time(“opName”, {=>
     // Note the return is from the "timeWithReturn" and will bypass anything
     // except finally blocks

     return ...compute result...;

Looks simple enough? Well when you follow the presentation though you come accross several issues. For example in the return case you will end up with a compile error because there is not guarenteed return from the second method. Also with the current type system it would be hard to define multiple throws types in the API. Take a look at the API, with some annotations added to show new language features.

// Note "throws X" this generic type can have multiple Exceptions defined for it
// R is type "Void" in the non-return case and
// R is type "Nothing" which is a special type which signal the tool that the 
// operation never really returns, think of System.exit(...) which should never 
// return

interface Block {
  R execute() throws X;

public  R time(
  String opName, Block block) throws X {
    long startTime = System.nanoTime();
    boolean success = true;
    try {
      R ret = block.execute();
      // In the return case you never get to this statement; but the 
      // finaly statement is run
      return ret;
    } catch (final Throwable ex) {
      // Notice the "final" in the catch clause, this allows us to rethrow
      // Throwable without having to delcare that in the operation definition.

      success = false;
      throw ex;
    } finally {
        "opName", System.nanoTime() - startTime, success);

Another example is a closure for making sure streams are closed out, a very common issue, here a function type is used rather than an interface:

// Note function type takes as parameter C that returns X and throws X.

R withStream(C c, { C ==> R throws X } block)
  throws X, IOException {

  try {
    return block.invoke(c);
  } finally {

// So code might look like, note the simplified syntax

withStream (InputStream s = getInputStream())
   // Do somethign

There are other examples particularly with the "for" loop modifier so that the closure can properly use break and continue. But you will need to look into the proposals for more information.

Still not suggestion that a choice has been made as to which of the closure proposals is the best though.... hopefully in time for JDK 7.

Next up was TS-5286 which focused on Web Beans which is very similar to the functionality seen in Spring 2.5. Use of Meta or Annotation on Annotations in order to guide how things are put together. Not entirely sure whether this is more valuable as a component, or just something that is a retreat of other work. Intereesting design all the same.

I then popped into TS-5535 which was about tying java service together in a restfull way. Unfortunately it appear to cover much of the TS and BOF I have talked about before so I decided to take a walk over to the Alumin lounge to take my mind off the upcoming presentation. Just down the road as the crow flies in the intercontinental, there was also the promise of the gift but apparently that doesn't work if you are also a presenter. Oh well.

Then it was back to the session for my presentation with Manoj. (TS-5318) This appeared to go okay, and indeed appeared to go over okay based on feedback from people in the audience. I apparently did talk a little bit to fast so my "jokes" might have been lost as the audience was used to proper English. Still 3-400 people and not a large number of people left which I take to be a good sign

[Interestingly Manoj went to a Metro presentation on Friday and one of the questions was whether they were going to do an async annotation like we had been talked about. Luckily Manoj was on hand to give his card to the sun folks and re-inforce the point. Nice to know we had some effect and were presenting something that they people were going to be interested in]

Left the room with a real buzz, met a nice chap from Venzuila, I think, he is going to get in touch next week. Stupid me for not taking any business cards.

I tried to go to "TS-6213 Boldly going where java..." which started with Terracotta but I kinda lost focus and decided to crawl the Pavillion a little bit. I am not saying that the ability to automatically sync data between VMs is interesting, I just wasn't in the mood. But more on my adventures in the pavillion in another post.

The last session of the day was BOF-5661 which gave a nice introduction to Comet and a mind blowing technology called "Reverse-Ajax". So Comet is a style of programming where the server pushed events to the client asynchronously. The name comet has been picked to be a generic term withouth out any clever agenda. In general though the web page has the normal socket open along with a second that provide a channel for the server to update the client.

The astute amoung you will know that a particlar server can only deal with so many threads and therefore open connections at a time. There are ways to work around this that are dealt with in Servlet 3.0 and NIO.2; but there are servers you can use for this that know how to keep up connections without loading up the number of threads. In particular cometd was metioned.

Now once you have a connection you can update the client, this generally involves lot of script in the browser a whole bunch of clients were presented that allow the java on the server to update the HTML page either with partial updates or just blocks of java script to be run on all of the clients. Really very cool stuff, blew my mind for the evening.

With that I was off to the pub with a few friends from NJ. Though it was best to eat properly for a change!

No comments: