<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Of Programming and Architecture</title>
	<link>http://blogs.nagarro.net/kayser</link>
	<description></description>
	<pubDate>Sat, 16 Feb 2008 01:44:30 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3</generator>
	<language>en</language>
			<item>
		<title>OSGi from Here to There, Part II</title>
		<link>http://blogs.nagarro.net/kayser/osgi-from-here-to-there-part-ii/</link>
		<comments>http://blogs.nagarro.net/kayser/osgi-from-here-to-there-part-ii/#comments</comments>
		<pubDate>Thu, 14 Feb 2008 07:27:17 +0000</pubDate>
		<dc:creator>Bill Kayser</dc:creator>
		
		<category><![CDATA[eclipse]]></category>

		<category><![CDATA[equinox]]></category>

		<category><![CDATA[osgi]]></category>

		<guid isPermaLink="false">http://blogs.nagarro.net/kayser/osgi-from-here-to-there-part-ii/</guid>
		<description><![CDATA[So what does it take to migrate a large, multi-tier product to the OSGi Equinox runtime?
We started out with a large, over-frameworked set of applications built with a creaky buildsystem cobbled together from perl scripts and ant build files.  We had all the code crammed into two projects, one for core libraries and the [...]]]></description>
			<content:encoded><![CDATA[<p>So what does it take to migrate a large, multi-tier product to the OSGi Equinox runtime?</p>
<p>We started out with a large, over-frameworked set of applications built with a creaky buildsystem cobbled together from perl scripts and ant build files.  We had all the code crammed into two projects, one for core libraries and the other for application code.   The applications were all part of a stack that had a lot of shared libraries and resources and the only thing that kept parts separated were the build scripts which extracted selected packages from the projects and built jars out of them.  The jars would then be combined into the classpath for the corresponding application.  So there was some attention to keeping components decoupled but nothing that actually enforced dependency management other than the build files.  You couldn&#8217;t see any real structure emerge by browsing the two projects but after you ran the build you could browse the dozen or so different jar files in the targets directory to identify the common components, the application modules, client libraries for server communication, and the shared open source libraries.</p>
<p><img src="http://blogs.nagarro.net/kayser/wp-content/uploads/2008/02/hairball2.thumbnail.jpg" align="left" vspace="12" hspace="16" border="1" alt="Hairball Architecture" title="Software should be Art, not an Art Project!" /></p>
<p>
Don&#8217;t bother reading that last paragraph again.  It&#8217;s not worth it.  It&#8217;s enough to know that things were a mess.  We were a long way from a system based on a component architecture with every functional component of the system assigned to a standalone project with it&#8217;s dependencies and exports plainly elaborated in the IDE.  And even if we did manage to completely reorganize everything, how could it possibly build?  Our buildsystem would be useless, and at that moment there were about 25,000 lines of it to contend with.I spent about three weeks doing nothing but analyzing the situation.  I didn&#8217;t change anything but played around with Equinox.  I hacked our jarfiles to make them look like bundles.  I wrote some PDE builders to see how they worked.  I considered all possible options for breaking apart our two mammoth projects and putting everything back together again in.  I read documentation, wikis, blogs and watched a number of <a href="http://www.eclipsecon.org/2008/" title="EclipseCon Home" target="_blank">EclipseCon</a> presentations.  I was already halfway through my alloted time and I had not made one change.  Finally I decided to take the plunge.  I sent out e-mails to the dev team and told them for the next few weeks (which included the Christmas Holiday) I would be moving code around, breaking the build often, and changing the way they did everything.  Then I went to work on a sort of recursive process to break apart the projects and re-constitute them as OSGi bundles.</p>
<p>Here&#8217;s how it went:</p>
<p>It&#8217;s not hard to make any Java application run in an OSGi runtime.  All you have to do is zip everything up into a single file&#8211;class files, jar files, resources&#8211;and add the appropriate manifest headers.  You need to write a few lines of java that implements a bundle Activator by invoking your main() routine.  Then you start up your OSGi runtime (Equinox) and have the configuration reference your zip file, which is now a bundle.  No application code needs to be changed.</p>
<p>So that was my starting point.  I created four different projects for the different applications that made up our product.  These projects are OSGi Bundles.  I went back to my build output folder from the old ant build and grabbed the jar files needed for each of the applications and copied them into my new bundles.  Then I created an Activator class for each one that just called the main() method for the application.  I was stunned when it actually worked.  It only took a little while but of course I wasn&#8217;t actually compiling code.  It was just a re-packaging of the binaries.</p>
<p>To get to the point of having all the source in OSGi bundles I was going to have to break down the big bundles into smaller ones and move the source over one at a time.  This turned out to be an iterative process that looked something like this:
<ol>
<li>Pick one of the bundle projects I had just created.<img src="http://blogs.nagarro.net/kayser/wp-content/uploads/2008/02/nugeo.gif" align="right" vspace="12" hspace="16" alt="Decomposition" /></li>
<li>Go through the jar files inside of it one at a time.For each one, I would create a new bundle corresponding only to that jar file.  Let me use <code>utilities.jar</code> as an example.  The bundle I created was called <code>com.acme.utilities</code>.
<ol>
<li>I would take all the classes that appeared in <code>utilities.jar, </code>find the java source files in the old projects and move them into my new <code>com.acme.utilities</code> bundle source folder.</li>
<li>Once I had that working, I would go back through all the other bundles I had already created and find any others that were using the <code>utilities.jar</code>.  In those bundles I would delete thejar file and add the dependency on <code>com.acme.utilities</code>.</li>
</ol>
</li>
<li>Now my new bundle project had no more jar libraries in it.  It also had no source code.  I had broken it up into a bunch of bundles like <code>com.acme.utilities</code> so now I could just delete it.</li>
</ol>
<p>
The trick was to work up the food chain starting from the bottom.  Pick out the jar files which did not depend on anything else that wasn&#8217;t already a bundle.  I started with 3rd party libraries and simply converted those jar files into bundles.  It only takes a minute to do this in Eclipse or with the excellent <a href="http://www.aqute.biz/Code/Bnd" target="_blank">BND utility</a> from Peter Kriens.  You add the 3rd party bundles to what&#8217;s known in Eclipse as the target platform for your application.</p>
<p>After this phase, I had gone from two huge projects to a dozen or so smaller ones, each more clearly identified with it&#8217;s function.  Instead of one giant &#8220;libs&#8221; project I had <code>com.acme.utilites.core</code>, <code>com.acme.utilities.swing</code>, and <code>com.acme.utilities.html</code>, etc.</p>
<p>Along the way I discovered problems in our application, like circular dependencies.  These weren&#8217;t necessarily bugs but were isolated cases where someone had specifically broken a rule like accessing some view code from the model.  The IDE was catching problems like this.</p>
<p>One lesson I learned was to let go of our classloaders.  We were using classloaders in a number of places to try to scope visibility of jar files or look up classes dynamically by name.  OSGi now managed all of the issues we were trying to solve with classloaders.  Invariably when I encountered places in the code that were passing classloaders as arguments I could pretty much just remove them completely.  OSGi gives you the proper class visibility no matter where you are.When it was all finished I could look at our code and see real structure.  Bundles represented groups of related classes that often corresponded to some layer in the application, like persistence, ui, domain code, messaging, utilities, etc.  Not only could I see the dependencies but I could make strong assertions about them because they were actually being enforced.  I could find exactly who had visibility into classes down to the package level.  The public module APIs were clearly delineated from the implementation classes.  Not only was there loose coupling but there was also good cohesion.</p>
<p>
Other unanticipated benefits to developers were immediately apparent:
<ul>
<li>It was much easier to understand how things were being used and easier to change them.</li>
<li>We have an environment that supports different Java VMs in different tiers, but we had to write code to the least common denominator.  Now we could move the major parts of the server to Java5 and utilize things like generics without worrying about breaking other tiers because we had separated out the bundles that were not going into the Java 1.3 applications.</li>
<li>We didn&#8217;t have a 20 minute ant build anymore on the developer desktop.  It was part of the headless build only.  Because the same build artifacts were used to launch apps in the IDE and drive the headless build, they were pretty much in sync with each other so developers didn&#8217;t need to do a headless build.  Just edit code, launch application.</li>
<li>We could create extension points for add-ons, rather than implement complicated hooks with classloaders and convoluted configuration files.  This is part of Equinox, not OSGi per se.  It&#8217;s the same kind of benefit you would get with Spring.</li>
<li>Eclipse was much more responsive.  Apparently having lots of small projects instead of one giant one is more efficient for many tasks.  It didn&#8217;t improve Eclipse build times but it did help with other things like auto-complete and refactoring.</li>
</ul>
<p>There were many, many other nice benefits yielded from this exercise, most of them unanticipated.</p>
<p>Would anyone yield these kinds of benefits from converting to OSGi?  I don&#8217;t think so.  We saw such a dramatic improvement because our existing infrastructure was so dilapidated.  Our code was old and the buildsystem brittle.  It&#8217;s a common scenario for many Java developers&#8211;dealing with the legacy of a system that became massively bloated over time.  We all look at systems like that and wistfully imagine rewriting layers with Hibernate, Spring, Struts, JSF&#8211;whatever.  Many times the benefit doesn&#8217;t justify the cost, or the rewrite turns into a classic <a href="http://en.wikipedia.org/wiki/Second_system_effect" title="The Second System Effect">Second System</a>.  From the outset this didn&#8217;t seem much different.  Early on I worried this was going to be a very ambitious undertaking, and I had doubts about whether it would spin out of control.</p>
<p>It didn&#8217;t turn out like that at all.  In fact, this was my first experience giving a facelift to such an old application with relative ease.  I didn&#8217;t have to rewrite any code (other than fixing a few bugs).  I just moved classes around.  I did rewrite the buildsystem, but since the new build artifacts were a tiny fraction of the size of the old buildsystem, this effort paid for itself quickly.   It only took a long time because I was working alone and was being extremely cautious, keeping the system stable continuously throughout the process, rather than just break everything for two weeks and put it all back together again all at once.</p>
<p>Engineers understand the value of this kind of improvement immediately.  You can almost get Product Managers on board with the &#8220;SOA in a JVM&#8221; story.  But Sales and Marketing won&#8217;t bother to stop typing on their Blackberries once you start talking about OSGi.  For me this was mostly about extending the life of a very useful piece of software.  The legacy of older applications isn&#8217;t just the code, but all the energy, innovation and hard work that goes into them, regardless of how you feel about the end result.  We owe it to the original authors to make as much as we can of their work.  We&#8217;d want nothing less for our legacy.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.nagarro.net/kayser/osgi-from-here-to-there-part-ii/feed/</wfw:commentRss>
		</item>
		<item>
		<title>OSGi from Here to There</title>
		<link>http://blogs.nagarro.net/kayser/osgi-from-here-to-there/</link>
		<comments>http://blogs.nagarro.net/kayser/osgi-from-here-to-there/#comments</comments>
		<pubDate>Wed, 02 Jan 2008 05:22:49 +0000</pubDate>
		<dc:creator>Bill Kayser</dc:creator>
		
		<category><![CDATA[eclipse]]></category>

		<category><![CDATA[equinox]]></category>

		<category><![CDATA[osgi]]></category>

		<guid isPermaLink="false">http://blogs.nagarro.net/kayser/osgi-from-here-to-there/</guid>
		<description><![CDATA[In the last installment I talked about programs built on the OSGi runtime, how they consist of discrete bundles of code and resources loosely coupled with each other, using a service registry to communicate, much the way discrete applications work together in an SOA environment. I tried to draw a picture of a Java application [...]]]></description>
			<content:encoded><![CDATA[<p>In the last installment I talked about programs built on the OSGi runtime, how they consist of discrete bundles of code and resources loosely coupled with each other, using a service registry to communicate, much the way discrete applications work together in an SOA environment. I tried to draw a picture of a Java application not as a main class entry point into a soup of jar files and classes all piled onto a single tower known as the class path, but rather as a set of these OSGi bundles, each declaring their own dependencies and exports, with a runtime that wires everything up as a network to satisfy all the dependencies. I tried to describe how applications broken up this way are actually easier to understand and manage. You can look at any individual Java package and make strong assertions about who has access to it and how, and understand what will break if it is modified or removed.</p>
<p>If my picture wasn&#8217;t very clear, or you still don&#8217;t fully grasp the motivation for this, I&#8217;ll describe a specific example that many Java developers should relate to. But before I do, it might be a good idea to make a more detailed presentation of OSGi and Equinox, the implementation used by Eclipse. Rather than take up space here though, I think I&#8217;ll just include some references to articles which I think give the best overview:</p>
<ul>
<li>This <a href="http://www.google.com/url?sa=t&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fwww.eclipsecon.org%2Fsummiteurope2007%2Fpresentations%2FESE2007_EquinoxUpdate.pdf&amp;ei=H89VR568F5aspwTcxLHiCA&amp;usg=AFQjCNEYUic4vuOcsogNX01LIDV6PaCdvQ&amp;sig2=sXE5dQZ8ILjTooxPFJ8mVA" title="Jeff McAffer Presentation">presentation by Jeff McAffer</a> covers some OSGi basics as well as some of the really interesting areas being explored, such as dynamic provisioning of bundles (think of Java Webstart) and <a href="http://wiki.eclipse.org/API_Comparison_demo">API tooling</a>.</li>
<li>50 minute <a href="http://live.eclipse.org/node/387">presentation </a>by some Equinox implementers introducing OSGi and Equinox. Sample Code available for download.</li>
<li><a href="http://www.eclipse.org/equinox/documents/">Equinox Documentation Page</a>, pretty much all you need.</li>
<li>Peter Kriens&#8217; <a href="http://www.osgi.org/blog/">OSGi blog</a> (thanks Abhijat!). This covers OSGi in more detail as well as a lot of the politics going on around competing component models.</li>
</ul>
<p>On a recent project I was working on we ran into a sort of crisis. We had reached a point where development was no longer scaling. Incremental changes to the architecture required a tedious littany of changes to configuration files, build files, test scripts, library paths, IDE configurations, and installer scripts. These changes all had to be carefully coordinated and missed steps often didn&#8217;t show up until further downstream; something as simple as adding a new class could result in a ClassNotFoundError in testing if one of the many dependent configurations had not been updated with the new class. So much effort and diligence was required for even small changes that we could not keep up with the kinds of improvements necessary to remain competitive.</p>
<p>We decided to migrate our application runtime to the OSGi Equinox runtime. As it turned out our motivation had nothing to do with the issues above but with other business issues. What we discovered was that after making the investment in structuring our application into bundles, we were able to breathe new life into it. We could again make big changes to the &#8220;plumbing&#8221; with much less effort and could make stronger assertions about the different parts of the application&#8211;what could be safely refactored and what had fragile dependencies.</p>
<p>The improvements included but were not limited to:</p>
<ul>
<li>Going from 25,000 lines of ant code required for a full build down to about 200 lines of boilerplate configuration, plus about 200 lines of custom callbacks,</li>
<li>We eliminated about seventy class file catalogs used to ensure extra classes were not inadvertently shipped in the wrong jar file or duplicated unnecessarily,</li>
<li>Reducing the size of application distros by eliminating unused dependencies</li>
<li>Surfacing previously unknown bugs based on dangling references to missing classes and libraries,</li>
<li>Eliminating a large body of code devoted to managing extensions with segregated class spaces using custom class loaders.</li>
<li>Going from managing four different runtime configurations for each application&#8211;the IDE classpaths, the IDE launchers, the runtime script classpaths, the build script classpaths&#8211;down to a single feature descriptor listing the OSGi bundles comprised by each application.</li>
</ul>
<p>And probably the biggest improvement was in the introduction of the extension mechanism provided in Equinox to extend applications with a sort of dependency injection. This allowed us a new lease on life as a platform for custom configuration and specialized implementations instead of a product trying to be all things to all customers.</p>
<p>The investment required wasn&#8217;t trivial but it turned out to be much easier and simpler than I expected. I worked on the conversion myself over a period of weeks. We were able to pull the trigger on the new configuration after about two weeks (implemented over a slow holiday period) and have it fully baked with about a four week effort spread over time. Much of this effort consisted on eliminating the old build system, verifying that everything we did before was being done the same way using the new build system. Developers didn&#8217;t really have much downtime but it was very disruptive for them. I had to send out emails every few days or few weeks with instructions on how to do things differently. Most notes were joyous announcements that &#8220;you no longer have to&#8221; do some tedious routine task that you had to do before. For instance, developers no longer had to kick off an ant build before testing an app. They could launch it directly. They no longer had to update build scripts. We no longer had to wait for the CI server to inform us that a build broke because a dependency was missing. Now Eclipse would show us the missing dependencies. In fact, it did this before but because the configuration of the IDE was separate from the build it wouldn&#8217;t really mean anything.</p>
<p>To this day team members still come up to me occasionally to thank me for introducing OSGi, often after being reminded what things were like by having to go back to an old release build. I wish I could take credit but the truth is I never anticipated most of these benefits until I started the conversion.</p>
<p>Now clearly most of the benefit derived had to do with the painfully wrongheaded buildsystem we already had in place by the previous generation of developers. In their defense, it was developed when the only real build tool available was an early version of ant, before they were even using a modern refactoring IDE. And there are a lot of good choices for modern build tools which solve some of these problems (<a href="http://maven.apache.org" title="Maven Buildsystem">Maven</a> and <a href="http://www.eclipse.org/buckminster/">Buckminster</a> are two that I would look at). But OSGi isn&#8217;t really a buildsystem or a configuration management system. It&#8217;s simply a runtime that enables solutions to these problems with a much more coherent, consistent and simplified approach.</p>
<p>Our buildsystem, our unit test runner, the IDE, the extensible platform, the launchers, the branding, dependency management&#8211;all of these mechanisms are now based on the same set of build artifacts, the Equinox configuration files (bundle manifests, feature and product descriptors), files which are managed with a very nice GUI.</p>
<p>I was expecting to start this entry in early December but I&#8217;m learning it&#8217;s hard to get a few hours of quiet time at the computer now with the baby and two year old. I&#8217;m adapting slowly! I hope to continue the OSGi discussion with the actual procedure for converting applications to OSGi and how the PDE headless build works.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.nagarro.net/kayser/osgi-from-here-to-there/feed/</wfw:commentRss>
		</item>
		<item>
		<title>SOA in a JVM</title>
		<link>http://blogs.nagarro.net/kayser/soa-in-a-jvm/</link>
		<comments>http://blogs.nagarro.net/kayser/soa-in-a-jvm/#comments</comments>
		<pubDate>Mon, 26 Nov 2007 00:40:51 +0000</pubDate>
		<dc:creator>Bill Kayser</dc:creator>
		
		<category><![CDATA[eclipse]]></category>

		<category><![CDATA[osgi]]></category>

		<category><![CDATA[soa]]></category>

		<guid isPermaLink="false">http://blogs.nagarro.net/kayser/soa-in-a-jvm/</guid>
		<description><![CDATA[There has never really much debate about whether Service Oriented Architecture is a good idea or not.  Based on principles such as loose coupling, encapsulation, location transparency, and the separation of infrastructure and applications, it has always had broad appeal.  IT executives like the uniformity of a standards based solution that provides management [...]]]></description>
			<content:encoded><![CDATA[<p>There has never really much debate about whether <a href="http://www.developer.com/services/article.php/1010451" title="SOA Definition" target="_blank">Service Oriented Architecture</a> is a good idea or not.  Based on principles such as loose coupling, encapsulation, location transparency, and the separation of infrastructure and applications, it has always had broad appeal.  IT executives like the uniformity of a standards based solution that provides management and visibility across all applications.  Application Owners like that it gives them much needed interoperability with other parts of the business.  And developers especially like the layered architecture and loose coupling achieved with relatively simple plumbing, unlike the component model predecessors of earlier years.</p>
<p><img src="http://blogs.nagarro.net/kayser/wp-content/uploads/2007/11/20050128705-0-large.jpg" alt="Simple Plumbing" align="left" hspace="12" vspace="12" />But this appeal isn&#8217;t limited to distributed enterprise applications.  Wouldn&#8217;t software developers like to see a Service Oriented Architecture for the &#8220;services&#8221; located within a single JVM?</p>
<p>Java Enterprise Software is never written from scratch.  Typically it involves writing components that utilize 3rd party libraries, extensions to application frameworks, communications with different tiers.  Just look at the class path of any Java Enterprise Application and you&#8217;ll see a long list of jar files including JDBC drivers, web application frameworks, validation libraries, Jakarta Commons libraries, and various client libraries.  Also, typically you&#8217;ll see a number of entries developed by other groups in house: proprietary frameworks, common core utilities, i18n libraries, validation frameworks&#8211;on and on.</p>
<p>The end result of the typical class path of a Java application is a giant set of classes from many different libraries all thrown together into a big soup where any class technically can access any other public class, directly or indirectly.  Furthermore, nothing guarantees that all the necessary parts are present.  Just because everything compiles into jar files doesn&#8217;t mean the classes referenced at runtime are actually going to be there, or for that matter be the correct version.<img src="http://blogs.nagarro.net/kayser/wp-content/uploads/2007/11/plumbing.jpg" alt="Poor Plumbing" align="right" border="2" hspace="12" vspace="12" /></p>
<p>In these applications, dependencies are hard to manage.  Tools such as <a href="http://clarkware.com/software/JDepend.html" title="JDepend Open Source Dependency Management Tool">JDepend</a> can be used to identify fragile APIs, problematic dependencies and tight coupling, but nothing really prevents developers from using classes they shouldn&#8217;t be using.  For instance, once someone uses an Oracle specific class in the Oracle JDBC driver they will be unable to use a different vendor&#8217;s driver.  Or some code might inadvertently reference an implementation class that is not part of the public API and break on a subsequent upgrade of the library.</p>
<p>Now imagine that the different libraries and frameworks were actually services.  They had a public API which is accessible to other components and private implementation classes which are not.  The dependencies of any service would be explicit, listing the other services and versions which are required at runtime for them to operate properly. These constraints would be enforced at compilation time as well as at runtime; if a required service in a particular version range is not available in either instance, the system fails fast with an indication of what&#8217;s missing.  If a service tries to access a public class in a service not listed as a dependency, a class not found error occurs (an error also caught at compilation time).  These libraries would still materialize as jar files, but these jar files would be service modules which can be moved in or out of an application even while the application is running.  There would be no separate step of composing the classes of a jar file with globs in an ant file. The definition of a service implies the contents of the jar files&#8211;no need to maintain an ant file, just a manifest file for the service identifying it&#8217;s version and dependencies.</p>
<p align="left"><img src="http://blogs.nagarro.net/kayser/wp-content/uploads/2007/11/sub.jpg" title="If only our software architecture was this neat" align="left" />Some of this may already sound familiar.  <a href="http://en.wikipedia.org/wiki/Inversion_of_control">Inversion of Control</a> (IoC) frameworks such as <a href="http://www.picocontainer.org/">PicoContainer</a> and <a href="http://www.springframework.org/">Spring</a> provide some aspects of the separation of implementation and interface already.  Application servers use class loader hierarchies to enforce separation of class visibility within a single JVM.  And various application architectural patterns such as <a href="http://c2.com/cgi-bin/wiki?AbstractFactory">Abstract Factories</a> and <a href="http://c2.com/cgi-bin/wiki?DependencyInjection">Dependency Injection</a> provide a means for protecting implementation classes and avoiding fragile APIs.</p>
<p>While these frameworks are all helpful they still leave the programmer in charge of introducing and utilizing them.  In most cases, the JVM still loads classes from the big vat of class soup indicated by the class path.  What is needed is something more fundamental, something that would completely &#8220;invert&#8221; the control of the whole application, executing everything as services, not the chosen few components.  Instead of the JVM invoking main() on your main class with a single class loader for all your classes, a small application runtime is invoked that looks at all your services, wires up all the dependencies between the services, blocks any that have unresolved dependencies, then invokes start() on each of the services.</p>
<p>Hold it right there, you are probably saying.  It already sounds complicated. You might be picturing some big API, or massive documentation you have to go out and read.  Sign up for the classes, read the articles, copy the example code, and a week later you&#8217;ve got HelloWorld done.  Stick with me and you&#8217;ll find out it&#8217;s not like that.  The runtime I&#8217;m speaking about is called <a href="http://www.osgi.org/">OSGi</a> and while it is complicated in what it does and how it works, it&#8217;s remarkably simple to utilize with the right tool.  And <a href="http://www.google.com/url?sa=t&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fwww.internetnews.com%2Fdev-news%2Farticle.php%2F3630071&amp;ei=ff9JR8OeIZSWgQOOqKjYDg&amp;usg=AFQjCNHMpXXZF5hLOzRnt0KNN-Ww5poNkw&amp;sig2=sG8yqGEiGbERmBLL4USz_w">more likely than not</a>, you are using that tool already.</p>
<p>OSGi is a standard for a Java component model that has several open source implementations.  The most common implementation is calld <a href="http://www.eclipse.org/equinox/">Equinox</a>.  Equinox is the runtime used by the Eclipse IDE and all Eclipse RCP based applications.  It&#8217;s the lowest level on the Eclipse application runtime stack.  It provides the SOA architecture on which Eclipse runs, as of version 3.0.  If you&#8217;ve programmed RCP applications you&#8217;re already familiar with Equinox, but even if you&#8217;re just an Eclipse user, you might have noticed that Eclipse is composed of plug-ins which all live in the plugins directory in the Eclipse installation.  These plugins are generally jar files or directories that represent the various components of the application.   There can be hundreds of these.  As an Eclipse user, you may appreciate that you can extend Eclipse with new features by simply adding new plugin jars to the plugins directory and restarting the IDE.  If you&#8217;ve looked at how Eclipse starts, you&#8217;ll see it simply invokes a small jar file on the command line&#8211;no reference to any application libraries or classes.  As a plugin developer, you are more keenly aware of how these plugins are built, their lifecycle, and the actual mechanics of extending the IDE.</p>
<p>What you may not be aware of is that the plumbing for all of this is not part of the IDE, or even part of RCP, but is actually part of the Equinox runtime bundled with Eclipse.  The main class invoked when you start up Eclipse is actually an Equinox entry point, and none of the Equinox code knows anything about Eclipse, RCP, SWT or any of that.  This is very important because it means that Equinox can be used as the runtime for any application, including Swing and Web applications.</p>
<p style="text-align: center"><img src="http://blogs.nagarro.net/kayser/wp-content/uploads/2007/11/highlevel.png" alt="Eclipse OSGi Architecture" /></p>
<p style="text-align: center"><em>Eclipse/RCP Architecture built on OSGi</em></p>
<p>What does all of this mean for you?  You have the means and the opportunity to be building your applications with a service oriented architecture, much more easily than you might expect, and I&#8217;ve only scratched the surface of the benefits.</p>
<p>You may have noticed it&#8217;s been a pretty long gap between my last entry and this one.  I&#8217;m currently on a leave of absence while managing a new dependency in my family, in the form of a baby boy born on November 14.   I&#8217;ll pick up this thread in a week or two and show you how we converted our 600,000 line multi-tier swing based application  into a service oriented architecture, replacing over 30,000 lines of ant code with about 200 lines, and vastly improving its maintainability and longevity in the process.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.nagarro.net/kayser/soa-in-a-jvm/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Usability of Programs, Part 2 of 2</title>
		<link>http://blogs.nagarro.net/kayser/the-usability-of-programs-part-2-of-2/</link>
		<comments>http://blogs.nagarro.net/kayser/the-usability-of-programs-part-2-of-2/#comments</comments>
		<pubDate>Mon, 22 Oct 2007 06:32:40 +0000</pubDate>
		<dc:creator>Bill Kayser</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.nagarro.net/kayser/the-usability-of-programs-part-2-of-2/</guid>
		<description><![CDATA[Here are some other principles of UI design that apply to program design:
Reduce Cognitive Load. This guideline in UI design is about minimizing the amount of things a user has to know in order to be able to use a tool effectively. Likewise, a programmer shouldn&#8217;t have to subclass five different classes just to effect [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some other principles of UI design that apply to program design:</p>
<p><strong>Reduce Cognitive Load</strong>. This guideline in UI design is about minimizing the amount of things a user has to know in order to be able to use a tool effectively. Likewise, a programmer shouldn&#8217;t have to subclass five different classes just to effect one small change to an application.  For instance, I often find that in order to add a new behavior interactive application I may have to learn the logging framework, the undo/redo mechanism, the localization framework, and the validation framework&#8211;on top of whatever complicated hierarchies exist in the model and views.  Things usually reach this state when developers anticipating future needs and striving for reusability and generality in their frameworks end up sacrificing simplicity and, ultimately, usability.</p>
<p><a href="http://blogs.nagarro.net/kayser/wp-content/uploads/2007/10/davinci_vman.jpg" title="DaVinci Vman"><img src="http://blogs.nagarro.net/kayser/wp-content/uploads/2007/10/davinci_vman.jpg" alt="DaVinci Vman" align="right" height="250" hspace="16" vspace="12" width="213" /></a><strong>Be consistent</strong>. The brake pedal on one model of car shouldn&#8217;t serve as the accelerator on another. That would be dangerous. It can also be dangerous to mix thread safe classes with classes that aren&#8217;t thread safe, or to have methods accept null String values in some places and throw exceptions in others.  If you adopt an idiom in your public interfaces, like converting exceptions thrown by delegate APIs to local exceptions, or using immutable objects as enumerated types instead of ints, then try to stick with it.  Consistency fosters a perception of predictability and stability.</p>
<p><strong>&#8230;But not too consistent.</strong> Jakob Nielsen, a well known usability expert, suggested that you can take certain principles too far, and the principle of consistency is one of those. He felt that Mac interfaces went to excess in trying to maintain consistency, to the point of defying common sense. A famous example: since the operation of removing things from a desktop consisted of dragging them to the trash can, the operation for ejecting a floppy disk was to drag it from the desktop into the trash can, an operation guaranteed to unnerve a user the first time they try it. In software, programmers often step into the realm of over-engineering in an effort to enforce consistency. An action in a user interface may implement an Undoable interface, but that doesn&#8217;t mean all actions should be undoable. One might take pains to separate UI code from Domain objects, but if it means introducing intermediary classes and interfaces just to keep domain code from importing javax.swing packages then it may be better to diverge from consistency.</p>
<p><strong>Avoid modality.  </strong>In many applications users are confronted with modal dialogs which force them to take action before they can proceed in other parts of the application. While a modal dialog is showing, all other parts of the interface are disabled. On the surface this may seem helpful to the user but oftentimes it&#8217;s just a convenience for the programmer who doesn&#8217;t have the inclination to design the data model so that multiple activities can be conducted concurrently (i.e., changing the properties of an Employee in a dialog while simultaneously deleting that employee in the parent window).</p>
<p>The same thing applies in program design. Sometimes when one object collaborates with another it makes assumptions about the state of that object. Its operation is only guaranteed to be correct under those assumptions. For instance in some data access object there may be operations which result in updating a database object. But these operations might assume that a transaction has been started and fail in the worst possible way if that&#8217;s not the case. Users of this class must be aware these methods can only be called in a transaction and keep track of the state of the transaction. An alternative design might encapsulate individual operations in a full transaction, or offer more support keeping track of the transaction state.</p>
<p>Avoid this kind of modality in your classes. You can&#8217;t drop all preconditions but the fewer opportunities for failure, the more robust the application.</p>
<p><img src="http://blogs.nagarro.net/kayser/wp-content/uploads/2007/10/handle.jpg" alt="Handle" align="left" height="300" hspace="16" vspace="12" width="295" /><strong>Utilize Affordances.  </strong>Affordances are properties of an object that suggest some action can be taken.  A door knob &#8220;affords&#8221; opening a door.  A rectangle on a screen may not afford action, but if it is raised and rounded, resembling a button, it affords being pushed.  For programmers, affordances might be properties of an interface which make it&#8217;s usage more clear.  In a class, abstract methods afford overriding.   If a class requires several instance variables be initialized when the instance is created, then the programmer should afford that action by adding parameters to the constructor to populate those variables, rather than rely on the caller to invoke setters.  Good abstractions and well factored class hierarchies can afford subclass extensions, where flat class structures with duplicate code and concrete classes may not.</p>
<p><strong>Adopt Standards.  </strong>What more is there to say? Standards in User Interface design result in uniformity across user interfaces, giving the user a sense of familiarity when using an application for the first time.  In programming, coding standards provide exactly the same benefit.</p>
<p><strong>Provide Feedback.</strong> Feedback in user interfaces usually means giving some indication that a user action has been detected and interpreted.  If the action was accepted then give an indication to the user of success.  If the action results in an error, make that error known to the user directly.  This could probably be interpreted several ways in the context of programming, but the best one would probably be the principal of &#8220;Fail Fast.&#8221;  This means detecting an erroneous use of a class or method early and communicating the actual offense, preferably in a runtime exception, as opposed to letting it go and waiting until the effects of the error cause secondary exceptions which may not reveal the actual API violation.  An example of this would be not checking for null values in method parameters but passing the null values on to subsequent calls until a NullPointerException appears in a lower level method.  I don&#8217;t think you want to check every pre-condition to an exception since it makes methods very noisy,  but a lot of times there are conditions which are more likely to be violated.  Play the odds and enforce those when you come across them.</p>
<p>You can really go on and on with this idea.  The principles of usability apply to any system that interacts with a user, and that includes a programming model.  The goal of a great programmer should be the same as the great product designers: empower and delight your users.  Programmers should never forget that ultimately their users are not CPUs but other programmers.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.nagarro.net/kayser/the-usability-of-programs-part-2-of-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Usability of Code, Part 1 of 2</title>
		<link>http://blogs.nagarro.net/kayser/the-usability-of-programs-part-1-of-2/</link>
		<comments>http://blogs.nagarro.net/kayser/the-usability-of-programs-part-1-of-2/#comments</comments>
		<pubDate>Fri, 12 Oct 2007 06:54:08 +0000</pubDate>
		<dc:creator>Bill Kayser</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[api design]]></category>

		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://blogs.nagarro.net/kayser/the-usability-of-programs-part-1-of-2/</guid>
		<description><![CDATA[Not long ago Ken Arnold wrote an article for Queue magazine called Programmers are People Too.  In it he talks about applying the principles of User Interface Design to the design of APIs.  It turns out the practices of Human Factors and Usability Engineering have a lot to offer the implementors of public [...]]]></description>
			<content:encoded><![CDATA[<p>Not long ago Ken Arnold wrote an article for Queue magazine called <em><a href="http://www.acmqueue.com/modules.php?name=Content&amp;pa=printer_friendly&amp;pid=317&amp;page=3">Programmers are People Too</a></em>.  In it he talks about applying the principles of User Interface Design to the design of APIs.  It turns out the practices of Human Factors and Usability Engineering have a lot to offer the implementors of public APIs and frameworks.  Think of an API as the &#8220;user interface&#8221; of a larger programming model.   Users are application programmers and the usability of the API is judged not just by it&#8217;s richness, but on the ease of use and learnability of the API.  It&#8217;s not sufficient to address usability with thorough documentation any more than it&#8217;s sufficient to compensate for a bewilderingly difficult user interface to a mobile phone with a five pound user manual.</p>
<p><img src="http://blogs.nagarro.net/kayser/wp-content/uploads/2007/10/explorer-8300-remote-large.jpg" alt="Remote Control Interface" align="left" border="0" height="400" hspace="16" vspace="6" width="120" />The idea of applying Human Factors to API design is not far off the idea of designing programs as works of literature.   In both cases your main focus is your audience, not the computer.  The common principle in both is readability, but the idea of API usability takes it a little further because your audience isn&#8217;t just trying to understand what it&#8217;s looking at but actually use and extend the work.</p>
<p>I believe these principles of usability apply not just to API design, but to programs in general.   Ken Arnold gives a couple of examples of UI principles applied to API design, such as the use of <strong>Progressive Disclosure</strong>.  That&#8217;s the principle that says you shouldn&#8217;t overwhelm a user with more detail than they need for a common task, but rather disclose the additional detail when the need arises as they move further along in some interaction.   Give the user what they need to know when they need it and only when they need it.  That way they won&#8217;t be distracted or confused by superfluous information.</p>
<p>For an API, this might mean segregating the methods of a complicated class into the methods most commonly used by client applications from the less frequently used methods needed in special situations or by advanced users.  For an application designer it might mean using interfaces and abstract classes to hide the distracting implementation details of a class.</p>
<p>Think about other common principles for user interface design, such those described in the <a href="http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuidelines/XHIGIntro/chapter_1_section_1.html">Apple Human Interface Guidelines</a>.  How can these be applied to program design?  I&#8217;ll list some more examples in the next installment of this column.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.nagarro.net/kayser/the-usability-of-programs-part-1-of-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Programmers as Channel Surfers</title>
		<link>http://blogs.nagarro.net/kayser/programmers-as-channel-surfers/</link>
		<comments>http://blogs.nagarro.net/kayser/programmers-as-channel-surfers/#comments</comments>
		<pubDate>Tue, 02 Oct 2007 06:00:41 +0000</pubDate>
		<dc:creator>Bill Kayser</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[literate programming]]></category>

		<category><![CDATA[program documentation standards]]></category>

		<guid isPermaLink="false">http://blogs.nagarro.net/kayser/programmers-as-channel-surfers/</guid>
		<description><![CDATA[If a program is to be a work of literature, then where does that leave object-oriented programs?  In the era of functional decomposition, programs were built around algorithms and data structures. They executed in a single thread as a sequence of steps and subroutine calls, not unlike a story.  Our object-oriented programs, on [...]]]></description>
			<content:encoded><![CDATA[<p>If a program is to be a work of literature, then where does that leave object-oriented programs?  In the era of functional decomposition, programs were built around algorithms and data structures. They executed in a single thread as a sequence of steps and subroutine calls, not unlike a story.  Our object-oriented programs, on the other hand, don’t have such a fixed path of execution.  Whether server or client applications, they start up multiple threads and make heavy use of message passing and asynchronicity.  The essence of a program is not in a sequence of steps and subroutine calls but in the subtle relationships between classes spread across many frameworks and subsystems, relationships such as inheritance, aggregation and collaboration.  So how does one read a Java application like a story?  The whole idea of object oriented programs seems at odds with literate programming.</p>
<p><img src="http://www.windowsusers.org/articles3/convertx/win_tv_surfing.jpg" align="left" border="1" height="151" hspace="14" vspace="6" width="180" />It may help to view your program less as a novel read in a single sitting and more like a TV show that is tuned in once a week by busy people with short attention spans.  The purpose is still to engage and inform, but you need to keep in mind your audience could be jumping in to the story just about anywhere.  Like a viewer flipping through channels, happening upon an interesting show, there’s a good chance that the first time a colleague comes across your code is clicking through the frames in a stack trace.  They will be debugging an application trying to understand some unexpected sequence of events and will stumble upon one of your classes.  Or they might drop in to use some small part of your API.  Maybe they jump into your code to extend some capabilities, add a new feature, or make small changes as part of a global refactoring.  They just want to know enough to get the task done and keep going.  They might watch an episode but then move on.<img src="file:///C:/DOCUME%7E1/Bill/LOCALS%7E1/Temp/moz-screenshot.jpg" /></p>
<p>There are a lot of practical implications to this approach but for this article I’ll just focus on one: give the user the information they need in the context of just “dropping in.”  Think about the questions they might have looking at your code in a debugger: What is this class for?  What elements are in the collection?  Where did this member variable get set?  Don’t make them work to find out something you could have made apparent with very little effort to begin with.  Your goal is to give them enough information about each element so they won’t have to get sidetracked tracking down other references to the element just to see how it’s used .  For example:</p>
<ul>
<li>Don’t make it a precondition for them to read a big design document on your intranet just to be able to understand what your GizmoClass is.  Put the information as close to the artifact as possible.  In the code, or at least in the same directory as the source.</li>
<li>Document all your classes and interfaces.  This may seem like a no-brainer, but it’s not about spending more time writing comments.  Instead, keep it as simple as possible.  Avoid verbosity and forms.  Just a sentence or two to explain what the class is (especially helpful if you couldn’t come up with a really good name).  Maybe say what it’s used for.  That’s usually about as much as someone needs to know.  Refrain from a huge exposition on the overall design or the justification for the class.  Save discussion of the class members for the member comments themselves.  And if you can&#8217;t think of something meaningful to say, don&#8217;t say anything at all.</li>
<li>Don’t duplicate information in an Interface and a Class.  If you have to pick one, document the interface.  Focus on the interface for describing what something is or represents, and in the implementation, anything noteworthy about the implementation.</li>
<li>When declaring variables of collection types, if you say nothing else in the comment you should at least state the actual type of the elements of the collection.</li>
<li>Method javadocs are critical for the casual audience, but not because they will show up in the HTML documentation.  Most IDEs will provide javadoc comments in a tooltip or property sheet, saving the user the step of clicking through to the declaration, or opening up the javadocs in a new window.</li>
<li>Make variable names as descriptive as possible.  Not just your member or local variables.  People tuning in to your code the first time will have a much easier time decrypting your for loops if instead of i or index you use names like row, month, or customerNumber.</li>
<li>Consider “Hungarian Notation” for variable names.  Many developers find this convention ugly and onerous, but you can’t deny the value of immediately recognizing a variables scope without having to jump to its declaration.  There’s a wide spectrum of adherence to this principle; from the old C++ practice of limiting the convention to member variables with a ‘_’ prefix on one hand, to an array of prefixes identifying the scope of every variable.</li>
</ul>
<p>The point of this is not to enumerate a list of documentation standards for your programs, but to get you to think like an author and empathize with your audience.  Use your own experience learning and debugging other people’s code to determine what your audience needs from your documentation.  Give them whatever they need to keep them from changing the channel before your program finishes.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.nagarro.net/kayser/programmers-as-channel-surfers/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Literacy of Programs</title>
		<link>http://blogs.nagarro.net/kayser/the-literacy-of-programs/</link>
		<comments>http://blogs.nagarro.net/kayser/the-literacy-of-programs/#comments</comments>
		<pubDate>Sun, 30 Sep 2007 09:21:36 +0000</pubDate>
		<dc:creator>Bill Kayser</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.nagarro.net/kayser/the-literacy-of-programs/</guid>
		<description><![CDATA[
What is the purpose of a computer program? 
Your colleagues and you all write software.&#xA0; You generate software prose on a daily basis, crafting these artifacts called programs, line by line.&#xA0; You utilize a common language that you all agree upon, a language which bears scant resemblance to a spoken language.&#xA0; So what is it [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blogs.nagarro.net/kayser/wp-content/uploads/2007/09/clip-image001.jpg"><img style="border-right: 0px; border-top: 0px; margin: 0px 10px 10px 0px; border-left: 0px; border-bottom: 0px" height="282" alt="Bill1" src="http://blogs.nagarro.net/kayser/wp-content/uploads/2007/09/clip-image001-thumb.jpg" width="272" align="left" border="0" /></a></p>
<p><strong>What is the purpose of a computer program?</strong> </p>
<p>Your colleagues and you all write software.&#xA0; You generate software prose on a daily basis, crafting these artifacts called programs, line by line.&#xA0; You utilize a common language that you all agree upon, a language which bears scant resemblance to a spoken language.&#xA0; So what is it that you are creating?&#xA0; What is the purpose of these lines of code? </p>
<p>You might say a program elaborates how a computer is to execute an algorithm.&#xA0; It describes what the system should do and how to do it.&#xA0; As programmers, we are the narrators and the computer is our audience.&#xA0; That&#8217;s basically what we were taught in our very first computer class.</p>
<p> <a href="http://blogs.nagarro.net/kayser/the-literacy-of-programs/#more-8" class="more-link">(more&#8230;)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.nagarro.net/kayser/the-literacy-of-programs/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Introducing Bill Kayser</title>
		<link>http://blogs.nagarro.net/kayser/introducing-bill-kayser/</link>
		<comments>http://blogs.nagarro.net/kayser/introducing-bill-kayser/#comments</comments>
		<pubDate>Sun, 30 Sep 2007 08:24:10 +0000</pubDate>
		<dc:creator>Manas Fuloria</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.nagarro.net/kayser/tetet</guid>
		<description><![CDATA[Bill holds a Masters in Computer Science from Stanford University. He has more than 20 years of experience with object technology and languages including C++, Smalltalk and Java (he’s a certified Java programmer and architect). He has served as a member of Sun JCP expert groups on RMI Custom Remote References (JSR78) and EJB Performance [...]]]></description>
			<content:encoded><![CDATA[<p>Bill holds a Masters in Computer Science from Stanford University. He has more than 20 years of experience with object technology and languages including C++, Smalltalk and Java (he’s a certified Java programmer and architect). He has served as a member of Sun JCP expert groups on RMI Custom Remote References (JSR78) and EJB Performance Benchmarking (JSR131). His career spans IBM, Schlumberger (on oilfield applications), WorldStreet Corporation (on financial applications, as Chief Architect) and SupplyChainge (again as Chief Architect) At SupplyChainge, Bill interacted with Nagarro and visited Delhi as well. After SupplyChainge, Bill joined the very successful application performance management company Wily Technology, which was acquired by Computer Associates in early 2006 for a large sum. He currently works on the Wily Introscope™ product. He is also the co-founder of StepZero, LLC, a performance management consulting firm. He collaborates informally with many open source gurus including <a href="http://en.wikipedia.org/wiki/Ward_Cunningham">Ward Cunningham</a>, the father of the Wiki.</p>
<p> <a href="http://blogs.nagarro.net/kayser/introducing-bill-kayser/#more-3" class="more-link">(more&#8230;)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.nagarro.net/kayser/introducing-bill-kayser/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
