<?xml version="1.0" encoding="UTF-8"?>
<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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nagarro Blog &#187; Java</title>
	<atom:link href="http://www.nagarro.com/blog/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nagarro.com/blog</link>
	<description>Nagarro blog: software development, design, architecture and usability</description>
	<lastBuildDate>Wed, 30 Jun 2010 19:17:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Cloud Computing Series: Exploring the Google App Engine Java Runtime Environment</title>
		<link>http://www.nagarro.com/blog/cloud-computing-series-exploring-the-google-app-engine-java-runtime-environment/</link>
		<comments>http://www.nagarro.com/blog/cloud-computing-series-exploring-the-google-app-engine-java-runtime-environment/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 17:42:59 +0000</pubDate>
		<dc:creator>Ram Kripal Prasad</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Cloud computing]]></category>
		<category><![CDATA[GAE]]></category>
		<category><![CDATA[Google App Engine]]></category>
		<category><![CDATA[Runtime Environment]]></category>

		<guid isPermaLink="false">http://www.nagarro.com/blog/?p=418</guid>
		<description><![CDATA[Google recently released a Java runtime environment for their App Engine platform. As a software development organization, this offering is of special interest to Nagarro, as it offers several advantages over competing cloud hosting environments. Hosting a Java application on Google’s infrastructure provides automatic scaling and load balancing, a feature that is of interest to [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-thumbnail wp-image-424" title="Various Cloud Formations" src="http://www.nagarro.com/blog/wp-content/uploads/2009/09/photo_13459_20090818-150x150.jpg" alt="Various Cloud Formations" width="78" height="78" />Google recently released a Java runtime environment for their App Engine platform. As a software development organization, this offering is of special interest to Nagarro, as it offers several advantages over competing cloud hosting environments. Hosting a Java application on Google’s infrastructure provides automatic scaling and load balancing, a feature that is of interest to a number of our software product development ISV customers. To better understand the issues and risks, we conducted an internal exercise to assess the technical effort required to port an existing application to the Google App Engine for Java (GAE-J).<span id="more-418"></span><br/><br/><strong>A Bit of Background</strong><br/><br/>GAE-J is a complete development stack that uses familiar Java technologies like JSPs, servlets and JavaScript to build and host web applications. With GAE-J we would write the application code, test it on the local machine and upload it to Google with a simple click of a button or a command line script. Once the application is uploaded to the Google infrastructure, it would host and scale the application for us. We would then, no longer need to worry about system administration, bringing up new instances of the application, clustering the database or buying new machines.<br/><br/>GAE-J provides access to many popular services from the enterprise applications world, including a scheduler, logging that can be reported from the Google Application console, mail, caching and URL fetch. It also provides elegant integration with technologies like Spring, Sitemesh, Struts etc.<br/><br/>GAE-J also makes it easy to serve static files like Images, CSS style sheets, JavaScript code, movies and Flash animations can served directly to the browser from separate servers that those that invoke servlets.<br/><br/>As you would expect from initiatives by Google, GAE-J comes with extensive online documentation &#8211; including quick start guides which I found invaluable. Also, Google provides many tools that make coding and developer testing simple and quick. GAE-J provides a local sandbox (based on Jetty) that should be used for testing before deploying into the cloud. The development web server simulates the App Engine Java runtime environment and all of its services, including the datastore. The <span style="color: blue;">Google Plugin for Eclipse </span>can run the server in the Eclipse debugger. You can also run the development server from the command line.<br/><br/><strong>Our Experience</strong><br/><br/>We found that using Google App Engine has great advantages, but it also has serious limitations. Google has implemented a tight security model on GAE-J, and you can&#8217;t write to the file system, it is read-only. You can only store data using the Google Datastore API. On first look, this seemed like a big restriction, but given the fact that the servers are clustered, it made sense in the long run.<br/><br/>In the GAE-J sandbox, the application code only runs in response to a web request or a <em>cron</em> job, and must return response data within 30 seconds in any case. A request handler cannot spawn a sub-process or execute code after the response has been sent.<br/><br/>Uploading the initial data is another challenge; however, that may be solved by providing the capability to upload data into the data store of the application itself.<br/><br/>It is also evident that GAE-J is still in its infancy and has glaring restrictions (for example: GAE-J sets a hard limit to the number of application and static files in the application; refer to <a href="http://code.google.com/appengine/docs/java/runtime.html#Quotas_and_Limits"><span style="color:blue;">The Java Servlet Environment &#8211; Quotas and Limits</span></a>.) IMO that needs to be addressed ASAP; to continue its evolution into a serious contender in the Cloud Services industry.<br/><br/>In conclusion, we found that moving an existing project to GAE-J’s infrastructure is not a trivial job, but it can be done. There are a big number of areas that differ between traditional web applications and Google’s app engine. I agree with Abhijat’s post on <a title="Cloud Computing Demystified: Part-I" href="../cloud-computing-demystified-part-i/"><span style="color:blue;">Cloud Computing Demystified: Part-I</span></a> <strong><em>#<span style="font-family:"> the real cost of using these services </span></em></strong>that identifying and reconciling all these differences would require significant work; esp. in view of the fact that in many cases it may be imperative that the changes (refactoring / re-organizations) made MUST work nicely with the traditional deployment as well. Specifically, certain areas such as the constraints from traditional relational database methodology, restrictions on the number of URLMap entries etc. may induce a re-design of the application and add to the challenges of migrating to the GAE-J cloud.<br/><br/>It would be much easier to develop a new project on GAE-J where innovative architectures for an application could be explored, rather than trying to port an existing application.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nagarro.com/blog/cloud-computing-series-exploring-the-google-app-engine-java-runtime-environment/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using ActiveRecord for Database Setup and Migration: A How-to</title>
		<link>http://www.nagarro.com/blog/using-activerecord-for-database-setup-and-migration/</link>
		<comments>http://www.nagarro.com/blog/using-activerecord-for-database-setup-and-migration/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 15:20:08 +0000</pubDate>
		<dc:creator>Ram Kripal Prasad</dc:creator>
				<category><![CDATA[Concepts]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[LAMP]]></category>

		<guid isPermaLink="false">http://www.nagarro.com/blog/?p=305</guid>
		<description><![CDATA[One of the first places where the ActiveRecord pattern first appeared, was in the book Patterns of Enterprise Architecture by Martin Fowler. The ActiveRecord pattern embeds the knowledge of how to interact with the database directly into the class performing the interaction.
Per Wikipedia  
With ActiveRecord, a database table or view is wrapped into a class, thus [...]]]></description>
			<content:encoded><![CDATA[<p>One of the first places where the ActiveRecord pattern first appeared, was in the book <em>Patterns of Enterprise Architecture</em> by <em>Martin Fowler</em>. The ActiveRecord pattern embeds the knowledge of how to interact with the database directly into the class performing the interaction.<span id="more-305"></span></p>
<p>Per <em><a href="http://en.wikipedia.org/wiki/Active_record_pattern">Wikipedia</a></em>  </p>
<blockquote><p>With ActiveRecord, a database table or view is wrapped into a class, thus an object instance is tied to a single row in the table. After creation of an object, a new row is added to the table upon save. Any object loaded gets its information from the database; when an object is updated, the corresponding row in the table is also updated. The wrapper class implements accessor methods or properties for each column in the table or view.</p></blockquote>
<p>This pattern is often implemented by ORM and Object Persistence Tools like Hibernate (Java) and ActiveRecord (ruby). The implementation framework handles generating the necessary SQL appropriate for the database being used and executing them over a database connection.</p>
<p>Recently, in a couple of projects I used ActiveRecord Migrations to manage database setup and migrations.<br />
Below, I shall present a walk though the steps that I followed to get a set of ActiveRecord migrations working on my Ubuntu-9.0.4 desktop.</p>
<p>1. Check if you have ruby installed:</p>
<p>     <em>ruby -v</em></p>
<p>You&#8217;d see something like the following: <em>ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]</em></p>
<p>If not, then install ruby by executing the following from a terminal window:</p>
<p>     <em>sudo aptitude install <strong>ruby</strong></em></p>
<p>Also, install <a href="http://rake.rubyforge.org/">rake, – ruby&#8217;s build program with capabilities similar to make</a> using:</p>
<p>    <em>sudo aptitude install <strong>rake</strong></em></p>
<p>2. Install <a href="http://rubygems.org/read/book/1">rubygems</a>:</p>
<p>    <em>sudo aptitude install <strong>rubygems1.9</strong></em></p>
<p>3. Install the following ruby-gems</p>
<ul>
<li>ActiveRecord: <em>sudo gem install <strong>activerecord</strong></em></li>
<li>Database adapter: I used the MySQL database; so I needed to install the mysql gem  <em>sudo gem install <strong>mysql</strong></em><br/><br/>The above command results in the following error:<br/><br/>&nbsp;&nbsp;<em>extconf.rb:8:in `require’: no such file to load — mkmf (LoadError)</em></li>
</ul>
<p><strong>Fix:</strong> Being a Debian or Ubuntu user you’ll find that the Ruby standard distribution is split into lots of little packages in order to comply with <a href="http://www.debian.org/doc/debian-policy/">Debian packaging Guidelines</a>. Installing ruby only gives you the ruby binary and a subset of the libraries for Ruby. You’ll need to add more packages if you want to utilize more of Ruby’s standard library.</p>
<p>Hence, we need to install the ruby-dev package prior to installing the mysql gem.</p>
<p>  <em>sudo aptitude install ruby-dev</em></p>
<p>4. Create directories to hold the migration definitions:</p>
<p>  <em>mkdir ~/workspace/db_setup<br />
  mkdir ~/workspace/db_setup/migrations</em></p>
<p>That&#8217;s all on the installation side. Now it&#8217;s time to write the migrations.</p>
<p>With ActiveRecord, each change to the database is termed as a <strong>migration</strong>. Migrations derive from <em>ActiveRecord::Migration</em> and enable a developer to generate a database structure using a series of Ruby script files (each of which is an individual migration) to define database operations. It&#8217;s a <em>database-agnostic representation</em> of the database. It uses generic data types for columns, like :binary, :string, :text, :boolean, etc. to define the kind of data to be stored in a column. A sample migration would look like the following:</p>
<p><b>File:</b> <em>migrations/001_create_institutions.rb</em><br />
class CreateInstitutions &lt; ActiveRecord::Migration<br />
def self.up<br />
create_table :institutions, {:id =&gt; true} do |inst|<br />
inst.column :name, :string, :limit =&gt; 100, :null =&gt; false<br />
inst.column :url, :string, :null =&gt; false<br />
end</p>
<p>execute(&#8217;ALTER TABLE institutions ADD UNIQUE (name) &#8216;);</p>
<p>end</p>
<p>def self.down<br />
drop_table : institutions<br />
end<br />
end</p>
<ul>
<li>The file-naming convention is important here:
<ul>
<li>ActiveRecord uses the numeric prefix to determine which migrations it needs to apply. To do this, it creates a table called as <strong>SCHEMA_MIGRATIONS</strong> in the database in which the VERSION column holds the number from the last migration added. When the migrations are run without a target version specified, it will only execute the migrations that have number greater than that stored in the database, lowest numbered first.</li>
<li>The class name should correspond to a camel case representation of the migration&#8217;s file name.</li>
<li>Typically your project would have a collection of these migrations, in files with prefixes as 001_xx, 002_xx&#8230;. and so on, each defining a change desired on the database.</li>
</ul>
</li>
<li>The two methods <strong>up</strong> and <strong>down</strong> should be functional complements of each other. The <strong>up</strong> method is executed when upgrading the database while <strong>down</strong> method is executed while reverting to an earlier version.</li>
<li>You can do many things in a migration – create and delete tables, add and remove columns, set column constraints (such as nullability and column length) and also run code to initialize the data in a table.</li>
<li>As a convenience, you also have the <strong>execute</strong> method available (shown as the last statement in the <strong>up</strong> method) to run SQL / commands directly. This has many implications: it lets you execute commands that use specific database dialects, like adding database constraints. The following script allows you to execute SQL commands from an external file, say <em>create_db.sql</em>:<br/><br/>&nbsp;&nbsp;sqlCode = File.open(File.dirname(__FILE__) + &#8220;/create_db.sql&#8221;).read<br/>&nbsp;&nbsp;sqlCode.split(&#8221;;\n&#8221;).each do |stmt|<br/>&nbsp;&nbsp;&nbsp;<b>execute</b> stmt if stmt =~ /\S/<br/>&nbsp;&nbsp;end</li>
</ul>
<p>ActiveRecord can read the database configuration from a YAML config file called as database.yml (place it under ~/workspace/db_setup) that looks like:</p>
<p><em># The # character signifies a comment.<br />
#<br />
# Define db config per environment here.<br />
# yml files are formatted in a very strict way; you cannot insert spaces and tabs randomly.<br />
# Typically they use two (2) spaces to indent options.<br />
#<br />
# The space between the &#8216;:&#8217; and the configuration values is required.<br />
dev:</p>
<p>  adapter: mysql<br />
  database: devdb<br />
  username: dev_user<br />
  password: dev_pass<br />
  host:     127.0.0.1</p>
<p>qa:</p>
<p>  adapter: mysql<br />
  database: $DB_NAME<br />
  username: $USER<br />
  password: $PASSWORD<br />
  host:     $HOST<br />
</em></p>
<p>A set of ActiveRecord migrations can be executed as<br />
1. A part of a Rails application by invoking</p>
<p>  rake db:migrate RAILS_ENV=xx VERSION=yy</p>
<p>2. A standalone Ruby application: If it is not a part of a Rails application, there is no default Rakefile to use. So we&#8217;d need to create one (under ~/workspace/db_setup) with the following content:</p>
<p><em>require &#8216;rubygems&#8217;<br />
require &#8216;active_record&#8217;<br />
require &#8216;yaml&#8217;<br />
task :default => :migrate</p>
<p>desc &#8220;Migrate the database through scripts in &#8216;migrations&#8217;. Target specific version with VERSION=x&#8221;<br />
task :migrate =&gt; :environment do<br />
ActiveRecord::Migrator.migrate(&#8217;migrations&#8217;, ENV["VERSION"] ? ENV["VERSION"].to_i : nil )<br />
end</p>
<p>task :environment do<br />
RAILS_ENV = (ENV['RAILS_ENV'] ||= &#8216;dev&#8217;)<br />
dbconfig = YAML::load(File.open(&#8217;database.yml&#8217;))[RAILS_ENV]<br />
ActiveRecord::Base.establish_connection(dbconfig)</p>
<p># Enable diagnostic logging to help debugging.<br />
# Note that ActiveRecord colorizes output for viewing in a terminal.<br />
# But when viewed as a normal file, it isn&#8217;t readable. So we disable it.<br />
ActiveRecord::Base.colorize_logging = false<br />
logFile = File.open(&#8217;database.log&#8217;, &#8216;w&#8217;) # set it to &#8216;STDERR&#8217; to enable logging to Std. ERROR console<br />
ActiveRecord::Base.logger = Logger.new(logFile)<br />
end</em></p>
<p>To execute the migrations, run the following command from the directory containing the RakeFile:</p>
<p>  rake RAILS_ENV=xx VERSION=yy</p>
<p>Both the above mentioned ways lend themselves to be easily invoked from a multitude of build and CI tools, like ANT, CruiseControl, python scripts etc.</p>
<p>Thus we, saw how to configure ActiveRecord as a database agnostic mechanism of managing database setup and incremental migrations. It is relatively simple to use and highly extensible.</p>
<p>Although, some may argue that ActiveRecord leads to a high degree of coupling between application code and database structure; in many cases the issues due to this coupling is much easier to manage than to adopt an alternate complex solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nagarro.com/blog/using-activerecord-for-database-setup-and-migration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Web Toolkit for Rich Internet Applications –A Java Programmer’s Experience</title>
		<link>http://www.nagarro.com/blog/google-web-toolkit-internet-applications/</link>
		<comments>http://www.nagarro.com/blog/google-web-toolkit-internet-applications/#comments</comments>
		<pubDate>Thu, 14 May 2009 17:52:42 +0000</pubDate>
		<dc:creator>Nitin Sood</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.nagarro.com/blog/?p=285</guid>
		<description><![CDATA[Recently, I have been working on porting a Struts and uPortal based legacy application to GWT. This work was initiated a year ago to replace an unappealing, non-responsive and slow user interface of the legacy application. Another key requirement was to make the client side technology stack lighter. Use of multiple client side technologies (Struts, [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I have been working on porting a Struts and uPortal based legacy application to GWT. This work was initiated a year ago to replace an unappealing, non-responsive and slow user interface of the legacy application. Another key requirement was to make the client side technology stack lighter. Use of multiple client side technologies (Struts, uPortal, JSP, Tag libraries, Java Script, configuration files, CSS, XSLT) made it difficult to make even simple UI changes.<span id="more-285"></span></p>
<p>After initial analysis, it was clear that we needed to incorporate AJAX in multiple areas across the application. It was further decided to use one of the existing AJAX frameworks rather than writing AJAX &#8220;by hand&#8221;. After evaluating several AJAX frameworks, we selected GWT. Other AJAX frameworks like DOJO and YUI library are also good but they did not solve the above mentioned problems arising from a fat architecture and a complicated technology stack.</p>
<p>One of the primary reasons for selecting GWT was its unique approach to developing the complete application: both the client side and the server side components using Java. GUI development with GWT APIs is similar to Swing development and it is refreshing to forget JSP, JavaScript, and Struts and write everything using Java. I am very happy with experience so far and we have vastly improved presentation layer while retaining most of the service layer code.</p>
<p>With GWT, the AJAX front-end is written in Java that gets compiled into highly optimized Java Script. Developers do not need to write Java Script while end users are provided with dynamic and standards-compliant AJAX experience. JavaScript gets downloaded by the client browser at runtime where most of the client side processing is performed thus releasing the server side from handling presentation tasks.</p>
<p>I am impressed by the developer friendly features of GWT. Using Java in the presentation layer facilitates the use of design patterns and creation of reusable widget libraries. GWT’s approach to history management, internationalization, and service layer interaction is easy to understand and implement. I felt spoilt by the choice of available tools, default support for multiple browsers and ability to debug AJAX in hosted mode. I also noticed ancillary benefits like elimination of training on multiple technologies, reduced dependence on technology experts, and the overall speed of development.</p>
<p>I have heard arguments about Flex being a better RIA choice than GWT. I think this may be because some people may not be aware of other GWT widget libraries (like GWT-EXT) available today. Although GWT comes with a very good collection of useful and cool widgets but you can always use third party widget libraries which provide additional AJAX components like a special Tree or Grid component. We used <a href="http://code.google.com/p/gwt-ext/">GWT-EXT</a>, a very rich widget library to achieve the desired functionality.</p>
<p>I found a few features missing &#8211; for example, there is no inbuilt support to load client side libraries on demand. Actually GWT loads all client-side libraries in client’s browser when the end-user accesses any module of the web application for the first time. So I think GWT may be a misfit for large enterprise applications. Also I faced problems due to lack of emulators for some of the Java classes like Calendar and our application POJOs contain Calendar objects. The good thing is that there are workarounds available to solve these problems.</p>
<p>I strongly recommend GWT if you are developing a mid size web application that needs enhanced usability and a desktop like look and feel.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nagarro.com/blog/google-web-toolkit-internet-applications/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Application programming in the era of multicore processors</title>
		<link>http://www.nagarro.com/blog/application-programming-in-the-era-of-multicore-processors/</link>
		<comments>http://www.nagarro.com/blog/application-programming-in-the-era-of-multicore-processors/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 20:44:55 +0000</pubDate>
		<dc:creator>Abhijat Vatsyayan</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tools and Utilities]]></category>
		<category><![CDATA[Concurrent programming]]></category>

		<guid isPermaLink="false">http://www.nagarro.com/blog/?p=142</guid>
		<description><![CDATA[Computer chip manufacturers cannot keep on increasing the clock speed indefinitely to make their processors faster. They seem to have already reached the limit (on clock speed) and have started putting multiple independent processing cores on a single chip to increase the computational capacity. As most systems start running on processors with tens of cores (if [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><span style="color: #000000;">Computer chip manufacturers cannot keep on increasing the clock speed indefinitely to make their processors faster. They seem to have already reached the limit (on clock speed) and have started putting multiple<span id="more-142"></span> independent processing cores on a single chip to increase the computational capacity. As most systems start running on processors with tens of cores (if not hundreds right away) application programmers will need to start relying on concurrent programming to make their applications faster and responsive. This will lead to significant changes in the way we design, develop, debug and test programs. We will have new tools, APIs, compilers, languages and frameworks for supporting highly concurrent programs written by application programmers.</span></p>
<p><span style="color: #000000;">The first and most obvious change will be that programmers will start using many more threads and use current lock based approaches to synchronize access to shared data. Now detecting bugs in multithreaded programs is extremely difficult and as we write more concurrent programs, it will become increasingly important to have tools which can check our programs for correctness. Two such tools are <span style="text-decoration: underline;"><a href="http://research.microsoft.com/en-us/projects/chess/" target="_blank">CHESS</a></span> from Microsoft research and <span style="text-decoration: underline;"><a href="http://fsl.cs.uiuc.edu/index.php/JPredictor" target="_blank">jPredictor</a></span> from UIUC. Both are still research projects but are definitely worth taking a look at and playing around with.</span></p>
<p style="text-align: justify;"><span style="color: #000000;">The transactional memory research community advocates getting rid of lock based approach for managing access to shared data. The idea comes from the database world where transactions have been around for a long time. Hardware transactional memory, hybrid transactional memory and software transactional memory, the three broad categories in which implementations are often split, are all under active research but there already are quite a few implementations out there for you to play around with. One of the core ideas behind using transactional memory for accessing shared data is to allow users to specify &#8220;what&#8221; needs to be synchronized and then let the machine take care of the &#8220;how&#8221; part (compare this to how you use locks today). This is supposed to greatly simplify the concurrent programming model but it is too early to say if it really does make the programming model simpler.</span></p>
<p style="text-align: justify;"><span style="color: #000000;">While  I cannot cover or summarize the work being done on transactional memory without making it into a small project, I can provide a few starting points that you may find interesting. Microsoft is doing very interesting work in this area and while a lot of it uses Haskel, there is a <span style="text-decoration: underline;"><a href="http://research.microsoft.com/en-us/downloads/6cfc842d-1c16-4739-afaf-edb35f544384/default.aspx" target="_blank">C-sharp API for software transactional memory</a></span> that you should look at. If you are a Java programmer, you should take a look at <span style="text-decoration: underline;"><a href="http://www.sun.com/download/products.xml?id=453fb28e" target="_blank">DSTM2</a></span>. And irrespective of what technology you use for building systems, I will recommend reading publications on transactional memory by Maurice Herlihy, Simon Peyton-Jones, Victor Luchangco and Mark Moir (there are others, I just picked up the four I see often in the literature).</span></p>
<p style="text-align: justify;"><span style="color: #000000;">Finally, we should not ignore the world of message passing. <span style="text-decoration: underline;"><a href="http://www.openmp.org/" target="_blank">OpenMP</a></span> and <span style="text-decoration: underline;"><a href="http://erlang.org/" target="_blank">Erlang</a></span> have been around for a long time and are designed for concurrent programming. OpenMP is an API you can use from C/C++ and FORTRAN to write parallel programs to take advantage of shared-memory architectures.  Erlang is a programming language in which you write processes that communicate exclusively using messages and if you write your Erlang programs correctly, you get the ability to scale to hundreds of processors for free.</span></p>
<p style="text-align: justify;"><span style="color: #000000;"><br />
</span></p>
<p style="text-align: justify;"><span style="color: #000000;"><br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nagarro.com/blog/application-programming-in-the-era-of-multicore-processors/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby vs. Java</title>
		<link>http://www.nagarro.com/blog/ruby-vs-java/</link>
		<comments>http://www.nagarro.com/blog/ruby-vs-java/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 17:44:34 +0000</pubDate>
		<dc:creator>Bill Kayser</dc:creator>
				<category><![CDATA[Guest Blog: Kayser]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[radrails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blogs.nagarro.net/kayser/ruby_vs_java/</guid>
		<description><![CDATA[It&#8217;s not that we don&#8217;t have enough people offering opinions on what is a better language.  It&#8217;s just that some of us never tire of discussing it.  There are so many perspectives, so many arguments, and so many people willing to   spend time blogging about it you&#8217;d think we&#8217;d all be pretty sick of it [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s not that we don&#8217;t have enough people offering opinions on what is a better language.  It&#8217;s just that some of us never tire of discussing it.  There are so many perspectives, so many arguments, and so many people willing to  <span id="more-29"></span> spend time blogging about it you&#8217;d think we&#8217;d all be pretty sick of it by now, and I might move on to some more interesting less traveled topic, like <em>Semicolons: friend or foil to good programming?</em> or <em>Extreme Programming, Acceptance Testing, and ISO 9001: Putting it All Together</em>.</p>
<p>Yet I just can&#8217;t stay away, and neither can you if you are still reading this.  So let me jump right in with my take&#8230;</p>
<p><strong><em>Ruby Doesn&#8217;t Scale</em></strong>.  It can&#8217;t take you to the same places Java can.</p>
<p>I don&#8217;t mean performance-wise.  And I don&#8217;t necessarily believe it can&#8217;t scale complexity-wise.  I just think it won&#8217;t scale with the size of a team.  I can&#8217;t see an application equivalent to 2 million lines of Java code with 80 developers written in Ruby.  Here are some reasons why:</p>
<ul>
<li>the language and tools don&#8217;t facilitate writing APIs<img src="http://www.nagarro.com/blog/wp-content/uploads/2009/02/java_vs_ruby1.jpg" alt="Java Books vs Ruby Books" hspace="16" vspace="16" width="243" height="200" align="right" /></li>
<li>it&#8217;s too hard to protect code from the side effects of other unrelated subsystems</li>
<li>the language and tools do not support for components or version management (see my posts on OSGi)</li>
<li>one bad Ruby developer can do a lot more damage than one bad Java developer</li>
<li>there are a lot of bad Ruby developers (I am one!)</li>
<li>the tests don&#8217;t scale&#8211;no Ruby app can survive inadequate tests, and the while the amount of tests grows linearly with the size of the application, the cost of maintaining them grows exponentially.  This may be true of any tests but&#8230;</li>
<li>you need more tests with Ruby&#8211;a Java app can survive without a complete unit test suite.  In fact, some large Java app can survive without tests at all.  Call me crazy but I&#8217;ve seen it.  What did we do before JUnit, after all?  I don&#8217;t think I&#8217;d want to work on one of those apps, but the point is, test code for Ruby is as essential as an interpreter to make a decent sized Ruby app work.</li>
<li>there&#8217;s no meta-programming in Java; that&#8217;s kind of a bummer, but it also means no massive indecipherable frameworks collapsing under the weight of the author&#8217;s cleverness, frameworks which are so unfathomable they are as brittle as COBOL.</li>
</ul>
<p>There, I said it.  Now that I did, I&#8217;ll make a couple of other observations about why I love Ruby anyway:</p>
<ul>
<li>A two million line Java program probably translates to 100K lines of Ruby code</li>
<li>80 Java developers are probably as productive as 20 equivalently skilled Ruby developers</li>
<li>With only a couple of developers, I think there&#8217;s no limit to how big the application can be.  In fact, the language is much better suited for a very small team than Java because you can be so much more efficient if you know what you&#8217;re doing.</li>
<li>The tools for Ruby are way behind Java, and there&#8217;s no reason to think they won&#8217;t catch up.  When they do, it&#8217;s entirely possible the gulf between the scalability of the languages will close substantially.  I certainly hope they will.  As far as the tools for writing Ruby go, I feel like I stepped back into 2002 when I went from Java/Eclipse to Ruby/{NetBeans/RadRails/TextMate}.  rake ~ make: when was the last time I typed in make when writing Java apps?</li>
<li>The tools may be behind, but the available libraries, plugins and gems are already very rich.</li>
<li>Ruby helped me remember why I love to write programs</li>
</ul>
<p>The last point I threw in there apropos of nothing, other than to point out that while I do miss some things about writing Java apps, I&#8217;m happy to be writing in Ruby now, and hope to keep working on it for the indefinite future, or until our app gets over 100,000 lines of Ruby which should be&#8230; never.</p>
<p>P.S. Here&#8217;s my <a href="http://www.youtube.com/watch?v=PQbuyKUaKFo">favorite entry</a> in the Ruby vs. Java debate, brought to you courtesty of RailsEnvy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nagarro.com/blog/ruby-vs-java/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>OSGi from Here to There, Part II</title>
		<link>http://www.nagarro.com/blog/osgi-from-here-to-there-part-ii/</link>
		<comments>http://www.nagarro.com/blog/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[Guest Blog: Kayser]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Eclipse]]></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 other [...]]]></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 <span id="more-24"></span>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 title="Software should be Art, not an Art Project!" src="http://www.nagarro.com/blog/wp-content/uploads/2008/02/hairball2_thumbnail1.jpg" border="1" alt="Hairball Architecture" hspace="16" vspace="12" align="left" /></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 title="EclipseCon Home" href="http://www.eclipsecon.org/2008/" 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:</p>
<ol>
<li>Pick one of the bundle projects I had just created.<img src="http://www.nagarro.com/blog/wp-content/uploads/2008/02/nugeo.gif" alt="Decomposition" hspace="16" vspace="12" align="right" /></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:</p>
<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 title="The Second System Effect" href="http://en.wikipedia.org/wiki/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://www.nagarro.com/blog/osgi-from-here-to-there-part-ii/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>OSGi from Here to There</title>
		<link>http://www.nagarro.com/blog/osgi-from-here-to-there/</link>
		<comments>http://www.nagarro.com/blog/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[Guest Blog: Kayser]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Eclipse]]></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 <span id="more-23"></span>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>
<p>This <a title="Jeff McAffer Presentation" 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">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>.</p>
<ul>
<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 title="Maven Buildsystem" href="http://maven.apache.org">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://www.nagarro.com/blog/osgi-from-here-to-there/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>SOA in a JVM</title>
		<link>http://www.nagarro.com/blog/soa-in-a-jvm/</link>
		<comments>http://www.nagarro.com/blog/soa-in-a-jvm/#comments</comments>
		<pubDate>Mon, 26 Nov 2007 00:40:51 +0000</pubDate>
		<dc:creator>Bill Kayser</dc:creator>
				<category><![CDATA[Guest Blog: Kayser]]></category>
		<category><![CDATA[Java]]></category>
		<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 and visibility [...]]]></description>
			<content:encoded><![CDATA[<p>There has never really much debate about whether <a title="SOA Definition" href="http://www.developer.com/services/article.php/1010451" 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 <span id="more-17"></span>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://www.nagarro.com/blog/wp-content/uploads/2007/11/20050128705-0-large.jpg" alt="Simple Plumbing" hspace="12" vspace="12" align="left" />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" border="2" alt="Poor Plumbing" hspace="12" vspace="12" align="right" /></p>
<p>In these applications, dependencies are hard to manage. Tools such as <a title="JDepend Open Source Dependency Management Tool" href="http://clarkware.com/software/JDepend.html">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 title="If only our software architecture was this neat" src="http://blogs.nagarro.net/kayser/wp-content/uploads/2007/11/sub.jpg" alt="" 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://www.nagarro.com/blog/soa-in-a-jvm/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Programmers as Channel Surfers</title>
		<link>http://www.nagarro.com/blog/programmers-as-channel-surfers/</link>
		<comments>http://www.nagarro.com/blog/programmers-as-channel-surfers/#comments</comments>
		<pubDate>Tue, 02 Oct 2007 06:00:41 +0000</pubDate>
		<dc:creator>Bill Kayser</dc:creator>
				<category><![CDATA[Guest Blog: Kayser]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></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 the other [...]]]></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><span id="more-10"></span></p>
<p><img src="http://www.windowsusers.org/articles3/convertx/win_tv_surfing.jpg" border="1" alt="" hspace="14" vspace="6" width="180" height="151" align="left" />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.</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://www.nagarro.com/blog/programmers-as-channel-surfers/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>
