Wednesday, April 22, 2009

The difference between a jar and a bundle

I spoke with someone yesterday about a jar file dependency problem. In the middle of the conversation it became clear that the other person did not know anything about OSGi bundles (also known as plug-ins.) I forget that most Java programmers don't dwell in OSGi. As a way of informing my colleague, here's a high-level enumeration of the features of OSGi bundles and plug-ins:
  • They are the same thing. Plug-ins are bundles, and bundles are plug-ins: they mean the same thing.

  • They are jars, and more than jars: OSGi bundles are jar files with yummy metadata inside. Much of this metadata is in the jar's manifest, found at META-INF/MANIFEST.MF. This metadata, when read by an OSGi runtime container, is what gives the bundle its power.

  • They limit visibility: With OSGi, just because a class is public doesn't mean you can get to it. All bundles include an export list of package names, and if a package isn't in the export list, it doesn't exist to the outside world. This allows developers to build an extensive internal class hierarchy and minimize the surface area of the bundle's API without abusing the notion of package-private visibility. A common pattern, for instance, is to put interfaces in one package and implementations in another, and only export the interface package.

  • They have versions: All OSGi bundles are given a version number, so it's possible for an application to simultaneously access different versions of the same bundle (e.g. junit 3.8.1 and junit 4.0.) Since each bundle has its own classloader, both bundles' classes can coexist in the same JVM.

  • They express their dependencies on other bundles: OSGi bundles declare which other bundles they depend upon. This allows them to ensure that any dependencies are met before the bundle is resolved. Only resolved bundles can be activated. Because bundles have versions, versioning can be included in the dependency specification, so one bundle can depend on version junit version 3.8.1 and another bundle can depend on junit version 4.0.

  • They have lifecycle events: Bundles can contain code that is run when the bundle is activated, and again when the bundle is deactivated. You can read more information in the documentation for the BundleActivator interface.

  • They collaborate with each other through an extension mechanism: Bundles may define a contract for extension, and in kind they can extend other bundles' extensions. This is how bundles configure each other. If bundles are black boxes, this would be the wires and junctures connecting them.

    Most of these configurations can expressed through code, but by using XML the configurations can be read and processed without instantiating the associated bundles or classes. Sometimes I find the use of a plugin.xml file to be more of a pain than just writing code, but it delays helps delay unnecessary performance penalties for as long as possible.

  • They are meant to be run in an OSGi runtime container: Sure, these are jar files, and you can put them on the classpath just like any other plain-ol' jar file. If you do that, though, you lose all the benefits of the bundle architecture like limited package visibility, verioning, et cetera. It's the OSGi runtime container that provides the power behind bundles. Well-known implementations include Eclipse's Equinox, Knopflerfish, Apache Felix and Concierge.

    Some bundles are often used as plain-ol' jars due to their structure and power: SWT and JFace (combined they are Eclipse's answer to Swing) and JDT (a powerful Java parsing library) are well-known examples.
OSGi also supports package versions (in addition to bundle versions, listed above) and declarative services, but I know almost nothing about those features.

If you want to get started with OSGi, try this introductory tutorial, read the OSGi specifications, or look at the soon-to-be released book Equinox and OSGi: The Power Behind Eclipse (currently available on Safari Rough Cuts.)

Parenthetically: I realize there is a battle between Sun camp and OSGi camp over the future of the Java module specification. This post isn't about that, but if you want some details, you can start by looking at JSR 294.

Thanks to Jeff McCaffer and Chris Lopez for their valuable feedback on the draft.

Tuesday, April 21, 2009

Will the real Mark Jackman please have a happy birthday?

Mushy sappy ahead.

Today is Mark Jackman's birthday. Mark and I have been good friends for a long time. I once referred to him as the Gigantigest Brain of All Time.

It's pretty well known that Mark hates blogs. He thinks they're insipid. When I first learned this in 2005, the first thing I did was create a blog in his name. It has stories like A VERY interesting cloud:

I looked at the sky. I saw a cloud that looked like this:

.....-
//-#--0-//
///-------//-
//....----++=///
\\----++##---//

I can't tell yet if this is the top of Peppermint Patty's head, or a tank. Don't you like that link for Peppermint Patty? That is so n33t.
In other words, content that represents the very thing that Mark hates about blogs. I'm grateful that he loved it.

Two years later, I was talking with our mutual friend Jeremy and we decided to create yet another blog. One where Mark Jackman -- the real Mark Jackman -- would post his outrage about being misrepresented. We decided to call it The Real Mark Jackman, even though it was fake, all fake. The blog was defined by its fourth post titled "Restoring My Integrity":

Integrity is important to me. My integrity, other peoples’ integrities, you name it. One thing I learned is this: integrity is the basis of relationship, and when your integrity is out, there’s no relationship. The discussion of integrity is more important on the Internet, where it can be so easily discarded for convenience. With this I realize that if I’m going to start a blog, my integrity is going to be of utmost importance. That’s why I think it’s critical that I come clean before our relationship goes on any further.
This is my fourth blog post. My first post introduced the blog and my second one pointed out my very recent discovery of an imposter blog. My friend Jeremy correctly caught that I started the blog, by calling it “The Real Mark Jackman’s Weblog” and only later did I make a second comment: “Hey! There’s this fake me!”

I wouldn’t normally make a big deal about it but Jeremy called me out, and so I must confess: I didn’t start this blog to keep friends in touch, but to combat the fraud perpetuated by this fake Mark Jackman. Interesting Cloud? Indeed! I intentionally wrote my blog posts in that specific order because I wanted to shroud my real intent - to combat a blatant lie, one where we’re all victims of someone else’s lack of character. And yet, my own lack of character defied my true intentions, and Jeremy, a good and loyal friend, caught me in my lie.

Some of you might think this is not such a big deal, but it is. If I don’t come clean about my real intentions, I’m just as much a phoney as “The Fake Mark Jackman”. The last thing the world needs is another blog with pick-and-choose honesty. The last thing the world needs is another fraudulent genius.

I promise that I will never lie to you again.
Afterwards we went back to writing bogus crap about things like Polly-o String Cheese or republishing our not-for-kids email blather, only occasionally touching on the purpose of the blog: Mark Jackman's online identity.

We had higher aspirations for this blog. Really, we did. We tried taking it in a different direction, but could not give it the greatness that Mark genuinely deserves. It was our plan to keep it a secret from him and reveal it on his birthday. Four months ago, he called me and said "Have you seen this site called 'The Real Mark Jackman'? What is that?" What it is, Mark, is a not-so-successful attempt at creating something worthy of honoring you.

And so, on Mark's big birthday, we have retired the blog with a farewell post titled "Who is real? Not me.":

It has finally come clear to me that the great social experiment of an Internet of ideas is doomed to fail, if anything because it’s impossible to tell what is real. Let me give you a concrete example.

...

the whole point of my blog was to identify these other people in the world who claim to be Mark Jackman. My attempts to contact them or their online webmasters yielded no fruit. I wish I spent more time focusing on this noble goal instead of talking about things unrelated to anything because resolution of this issue has become critical: someone is claiming I am not real. With that, I see that the experiment this blog is serving has failed, and it’s sign of where the Internet is bound to take us: a place where identity is meaningless and can be casually exchanged for nothing. If Oprah can purchase her identity on Twitter, why can’t someone buy mine with nothing more than sheer will?

But here’s the truth. I’m real. This is really my blog. I really work for deckArta (our website is down right now, but it’ll come back, you’ll see!) And so now my very existence is at question. Though it’s true, it is my birthday, and I appreciate there is one final acknowledgment that I am who I am, because before too long my coworkers will ask me to show my driver’s license, my girlfriend is going to say that she has no idea who she slept next to all these years, and further down the road when the Internet is the sole gateway to our consciousnesses, I will disappear in a puff of inconsequential smoke.

It may be that truth is fiction, and I am dead, but not without taking someone with me. Happy Birthday.
Mark deserves better for his birthday than our failed ego trip, so let me end with this: Mark is the most loyal of friends, brilliant and funny, compassionate and direct. He is great to have during your hard times, but even better during your best times.

Mark used to say that he won a contest before he was born and the prize was to be whomever he wanted. He picked himself. I won a similar contest: my prize was selecting a friend with all the qualities I would want. I picked him.

Happy Birthday, Mark.

Monday, April 20, 2009

How to deal with Oracle fear



By now you've all heard news about Oracle's intention to purchase Sun Microsystems for $7.4B. Almost every person I've spoken with today is not happy about this. Not happy because Oracle is not a research organization. Not happy because IBM would have been the best place for Java to land. Not happy because of what it might mean for MySQL. Not happy because Oracle is generally not regarded for their hardware platform (I speak without a solid understanding of Oracle's business model.)

The joke today is "I better brush up on my {C++,. NET, Python}" "Thank goodness for Sqlite." And after that, there's generally a lot of worry about how this is all going to play out.

I say, take that angst and learn something with it. You think Java's future has just been cut short? Go learn Python. Or Ruby. Or even Scala or .NET. Hell, it doesn't have to be something related to the Sun/Oracle merger. If you're worried that something as relatively insignificant as one company purchasing another renders you stagnant, then go prove to yourself that you can still learn something new.

Do it. Because even if the dire predictions are wrong, you'll have gained a new perspective.

Tuesday, April 14, 2009

Limerick of the day

Just a small something to maintain the "blather-" part of this blog.
A fine young purveyor of eats
Called bacon the "chocolate" of meats
But a confectionarian
And utter contrarian
Called chocolate the "bacon" of sweets
Thanks, Jeff McCaffer.

Friday, April 10, 2009

All About The Cult of Tom

"The first thing to understand is that the story of the Cult of Tom is at heart the story of a booth.  A video confessional booth. A video confessional booth for our office. A video confessional booth for our office with unwavering devotion to our director as its fundamental theme."

Between 2007 and 2008, a handful of my colleagues from Google Santa Monica built our own video booth. It was a labor of love, as was the public site I built to commemorate it. The shrine's shrine, you may say.

It is my sincere hope that by sharing this with you it will motivate you to go do your own crazy stuff. So please, read it and enjoy it.

http://www.cultoftom.com

Sunday, April 05, 2009

John Pizzarelli at the Bronx High School of Science

We found out that John Pizzarelli was performing at the Bronx High School of Science today. Since both my wife and I really enjoy his music we decide to go. The tickets were fairly inexpensive, only $25 apiece. Unfortunately we were twenty minutes late. Who knew that driving 30 block on Jerome Avenue would be do difficult?

John led a four-piece band today, with his brother Martin on bass, and two people I did not know playing piano and drums. I've seen John Pizzarelli play three other times, and typically it was John, Martin and Ray Kennedy on piano. Fortunately, the pianist and drummer cooly showed their stuff. He also had an occasionaly guest violinist whose name I cannot recall, but was clearly talented (and apparently very young, only two years out of college.)

Every set I've seen John and his band play has been significantly different from the others. I finally realize that I can't expect to go back and hear the songs I liked from the shows before. He seems to have an encyclopedic knowledge of American standards (a la Jonathan Schwartz, whom John seems to be able to imitate to comedic effect) and now I hope his next show is entirely different, though I hope he doesn't take I Like Jersey Best out of rotation.

An unexpected surprise was a 3 or 4 piece set with the Bronx Science High School Band. High school bands are high school bands, that's for sure, but this band could definitely beat up my old high school band. That segment was fun and a little sweet.

After the show, John sat in the lobby, signed CDs and chatted with guests. He's friendly and warm, and was very happy to pose for a quick photo. I didn't have high hopes of my G1's camera quality, but this time it came out pretty good.

Why were they performing at the Bronx High School of Science? It seems as though John's son is a student there, and if the program is any guide, John has been playing fundraising concerts for his son's school for many years.

Finally, we were told that tomorrow is John's birthday, so, hey, Happy Birthday, John.

Thursday, April 02, 2009

Sometimes it's just plain difficult to contribute to Eclipse

Case in point: today's irritation.

John Atherton taught me about some fantastic Eclipse core developer tools during his talk at EclipseCon. After downloading then and trying them out, I found that the Resource Delta Spy was exactly what I needed to debug a particularly gnarly problem. Yet, for a reason which I will not describe in detail, the plug-in doesn't do exactly what I want it to: I decided to check out the code and make a change.

If I download the source at dev.eclipse.org/cvsroot/eclipse / HEAD / org.eclipse.core.tools, I get compiler errors because the code at head has constraints in its manifest that require Eclipse 3.5. So I looked for an earlier version in the Versions subtree, and found a version v20050225. This version doesn't have any version constraints in MANIFEST.MF, but it also doesn't compiler with a 3.4.2 instance, because some classes moved from org.eclipse.osgi.framework.stats to org.eclipse.core.runtime.internal.stats.

This isn't the first time I've had a problem trying to find the right piece of source at Eclipse.

Is it just me or does trying to contribute to Eclipse seem like a sisyphean effort? What's the magic incantation?

(Update: Really I just want the view to show more than 2048 characters of data. That's a useful amount of data for a toy resource delta, but doesn't help when I have to test a substantive change.)