<?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>A Day At The Races &#187; osgi</title>
	<atom:link href="http://blog.jetztgrad.net/category/osgi/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jetztgrad.net</link>
	<description>Programming was my first love, and it will be my last.</description>
	<lastBuildDate>Thu, 05 May 2011 08:21:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Dissecting an Amazon Elastic Beanstalk instance</title>
		<link>http://blog.jetztgrad.net/2011/01/dissecting-an-amazon-elastic-beanstalk-instance/</link>
		<comments>http://blog.jetztgrad.net/2011/01/dissecting-an-amazon-elastic-beanstalk-instance/#comments</comments>
		<pubDate>Sat, 22 Jan 2011 13:15:41 +0000</pubDate>
		<dc:creator>Wolfgang Schell</dc:creator>
				<category><![CDATA[amazon]]></category>
		<category><![CDATA[beanstalk]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[infrastructure]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[s3]]></category>

		<guid isPermaLink="false">http://blog.jetztgrad.net/?p=295</guid>
		<description><![CDATA[Amazon Elastic Beanstalk provides a PaaS similar to Google AppEngine, bundling many of their existing offerings such as Elastic Compute Cloud (EC2), Simple Storage Service (S3), Simple Notification Service (SNS), Elastic Load Balancing, Auto Scaling, and monitoring using Cloud Watch into a simple to use service. Additionally, other Amazon services such as SimpleDB, Relational Database [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://aws.amazon.com/elasticbeanstalk/">Amazon Elastic Beanstalk</a> provides a PaaS similar to <a href="http://code.google.com/appengine/">Google AppEngine</a>, bundling many of their existing offerings such as <a href="http://aws.amazon.com/de/ec2/">Elastic Compute Cloud</a> (EC2), <a href="http://aws.amazon.com/de/s3/">Simple Storage Service</a> (S3), <a href="http://aws.amazon.com/de/sns/">Simple Notification Service</a> (SNS), <a href="http://aws.amazon.com/de/elasticloadbalancing/">Elastic Load Balancing</a>, <a href="http://aws.amazon.com/autoscaling/">Auto Scaling</a>, and monitoring using <a href="http://aws.amazon.com/de/cloudwatch/">Cloud Watch</a> into a simple to use service. Additionally, other <a href="http://aws.amazon.com/">Amazon services</a> such as <a href="http://aws.amazon.com/de/simpledb/">SimpleDB</a>, <a href="http://aws.amazon.com/de/rds/">Relational Database Service</a> (RDS), <a href="http://aws.amazon.com/de/sqs/">Simple Queue Service</a> (SQS) may be used as well.</p>
<p>Currently, Elastic Beanstalk provides a Java-based application container with <a href="http://tomcat.apache.org/">Apache Tomcat</a> as the work horse. All you have to do is to deploy a standard <a href="http://en.wikipedia.org/wiki/WAR_(Sun_file_format)">Java WAR file</a> containing your web application.</p>
<p>Simply create a Java web application with <a href="http://static.springsource.org/spring/docs/3.0.x/reference/mvc.html">Spring MVC</a>, <a href="http://grails.org/">Grails</a>, <a href="http://eclipsesource.com/blogs/2011/01/20/amazon-aws-beanstalk-and-eclipse-equinox/">OSGi</a>, <a href="http://eclipsesource.com/blogs/2011/01/20/amazon-aws-beanstalk-and-eclipse-equinox/">Eclipse RAP</a>, or any other of the numerous Java web frameworks and upload it using the <a href="https://console.aws.amazon.com/elasticbeanstalk/home">AWS web console</a>.</p>
<p>Additional containers for other platforms such as Ruby, Python or PHP may follow later, but as Tomcat hosts standard Java WAR files, anything with a Java implementation may be run. Ruby apps based on <a href="http://rubyonrails.org/">Rails</a> or <a href="http://rack.rubyforge.org/">Rack</a> using <a href="http://caldersphere.rubyforge.org/warbler/">Warbler</a> and <a href="http://jruby.org/">JRuby</a>, Python apps using <a href="http://www.jython.org/">Jython</a>, even PHP apps can be <a href="http://cameronstokes.com/2011/01/20/php-on-aws-elastic-beanstalk/">made to run</a> on Beanstalk.  </p>
<p>In this blog post, I&#8217;ll dive into the inner workings of a Beanstalk server instance and poke around its internals. I invite you to come along for the ride.</p>
<p><strong>Accessing your instance</strong><br />
The first step in dissecting a Beanstalk instance is <a href="http://docs.amazonwebservices.com/elasticbeanstalk/latest/ug/index.html?using-features.ec2connect.html">getting access via SSH</a>.<br />
In order to acces your running instance(s), you first need to configure the SSH key pair to be used:<br />
<div id="attachment_297" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.jetztgrad.net/wp-content/uploads/2011/01/config-server.png"><img src="http://blog.jetztgrad.net/wp-content/uploads/2011/01/config-server-300x204.png" alt="Configuration dialog in Elastic Beanstalk web console" title="config-server" width="300" height="204" class="size-medium wp-image-297" /></a><p class="wp-caption-text">Configuration dialog in Elastic Beanstalk web console</p></div></p>
<p>Enter the name of a key pair as configured in your <a href="https://console.aws.amazon.com/ec2/home#s=KeyPairs">EC2 web console</a>. See the <a href="http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?using-credentials.html">EC2 guide</a> and the description in the <a href="http://docs.amazonwebservices.com/elasticbeanstalk/latest/ug/index.html?using-features.managing.ec2.html">Elastic Beanstalk guide</a> for details on creating and configuring a key pair.</p>
<p>Setting the key pair requires a restart of your Beanstalk environment, which may take a couple of minutes.</p>
<p>Finally <a href="http://docs.amazonwebservices.com/elasticbeanstalk/latest/ug/index.html?using-features.ec2connect.html">look up your instance id</a> and get the instance&#8217;s hostname. Connecting to the server is now as simple as this:</p>
<p><code>ssh -i .ec2/mykeypair.pem ec2-user@ec2-184-72-134-2.compute-1.amazonaws.com</code></p>
<p>Please note, that you need to connect as user <code>ec2-user</code>, <code>root</code> access can be reached using the command</p>
<p><code>sudo su -</code></p>
<p><strong>Getting around your instance</strong><br />
The first steps are to collect some interessting facts. The instance uses a <a href="http://aws.amazon.com/amazon-linux-ami/">Amazon Linux AMI</a> (release 2010.11.1 (beta), <a href="https://gist.github.com/791135">README</a>). The AMI id for the ElasticBeanstalk-Tomcat6-32bit is <code>ami-7609f81f</code>, the kernel id is <code>aki-407d9529</code>. The instance is EBS-based and there is no ephemeral storage. Currently, Beanstalk is only available in the US East zone.</p>
<p><strong>Software</strong><br />
The <a href="https://gist.github.com/791133">process list</a> reveals: along with <a href="http://tomcat.apache.org/">Apache Tomcat</a>, Beanstalk uses the venerable <a href="http://httpd.apache.org/">Apache Web Server</a>. Additional software includes <a href="https://github.com/arya/bluepill">Bluepill</a> for basic process monitoring, and Amazons own HostManager (see below), which is run within a <a href="http://code.macournoyer.com/thin/">Thin</a> web server.</p>
<p><strong>Network setup</strong><br />
Elastic Beanstalk scales EC2 instances as needed. Therefore the first target is a load balancer provided by <a href="http://aws.amazon.com/de/elasticloadbalancing/">Elastic Load Balancing</a>. Each instance runs Apache as the front end on port <code>80</code>, with web request being reverse proxied into Tomcat on port <code>8080</code>. Requests for URI <code>/_hostmanager</code> are forwarded to HostManager on port <code>8999</code>.</p>
<p>CloudWatch performs health checks by periodically requesting the root page (URI <code>/</code>) of your application. Both health check URI and frequency are configurable. If an instance is no longer available or the load changes, CloudWatch starts or stops instances. </p>
<p><img src="http://media.amazonwebservices.com/blog/cb_env_1.png" alt="Application stack" /><br />
[Image from <a href="http://aws.typepad.com/aws/2011/01/aws-beanstalk-concepts.html">AWS Elastic Beanstalk Concepts</a> blog post]</p>
<p><strong>HostManager</strong><br />
Local instance management is performed by Amazons HostManager. HostManager is a Ruby application based on Rack and running in a <a href="http://code.macournoyer.com/thin/">Thin</a> server on port 8999. It receives requests on URI <code>/_hostmanager</code>.</p>
<p>Some examples from the access log:</p>
<p><code>72.21.217.96 (72.21.217.96) - - [21/Jan/2011:22:00:45 +0000] "POST /_hostmanager/tasks HTTP/1.1" 200 368 "-" "AWS ElasticBeanstalk Health Check/1.0"<br />
10.223.61.43 (10.223.61.43) - - [21/Jan/2011:22:01:05 +0000] "GET /_hostmanager/healthcheck HTTP/1.1" 200 90 "-" "ELB-HealthChecker/1.0"<br />
10.122.19.154 (10.122.19.154) - - [21/Jan/2011:22:01:11 +0000] "GET /_hostmanager/healthcheck HTTP/1.1" 200 90 "-" "ELB-HealthChecker/1.0"<br />
10.223.61.43 (10.223.61.43) - - [21/Jan/2011:22:01:36 +0000] "GET /_hostmanager/healthcheck HTTP/1.1" 200 90 "-" "ELB-HealthChecker/1.0"<br />
10.122.19.154 (10.122.19.154) - - [21/Jan/2011:22:01:42 +0000] "GET /_hostmanager/healthcheck HTTP/1.1" 200 90 "-" "ELB-HealthChecker/1.0"<br />
72.21.217.96 (72.21.217.96) - - [21/Jan/2011:22:01:46 +0000] "POST /_hostmanager/tasks HTTP/1.1" 200 368 "-" "AWS ElasticBeanstalk Health Check/1.0"<br />
10.223.61.43 (10.223.61.43) - - [21/Jan/2011:22:02:07 +0000] "GET /_hostmanager/healthcheck HTTP/1.1" 200 90 "-" "ELB-HealthChecker/1.0"<br />
10.122.19.154 (10.122.19.154) - - [21/Jan/2011:22:02:13 +0000] "GET /_hostmanager/healthcheck HTTP/1.1" 200 90 "-" "ELB-HealthChecker/1.0"<br />
10.223.61.43 (10.223.61.43) - - [21/Jan/2011:22:02:38 +0000] "GET /_hostmanager/healthcheck HTTP/1.1" 200 90 "-" "ELB-HealthChecker/1.0"<br />
10.122.19.154 (10.122.19.154) - - [21/Jan/2011:22:02:44 +0000] "GET /_hostmanager/healthcheck HTTP/1.1" 200 90 "-" "ELB-HealthChecker/1.0"<br />
72.21.217.96 (72.21.217.96) - - [21/Jan/2011:22:02:47 +0000] "POST /_hostmanager/tasks HTTP/1.1" 200 368 "-" "AWS ElasticBeanstalk Health Check/1.0"<br />
</code></p>
<p><strong>Files</strong><br />
HostManager is installed in <code>/opt/elasticbeanstalk/srv/hostmanager</code>. A file list can be found <a href="https://gist.github.com/791104">here</a>. <code>/opt/elasticbeanstalk/lib</code> also contains a full Ruby 1.9.1 installation.</p>
<p>Some log files can be found at <code>/opt/elasticbeanstalk/var/</code>:</p>
<p><code>/opt/elasticbeanstalk<br />
/opt/elasticbeanstalk/var<br />
/opt/elasticbeanstalk/var/state<br />
/opt/elasticbeanstalk/var/state/hostmanager.pid<br />
/opt/elasticbeanstalk/var/state/healthcheck<br />
/opt/elasticbeanstalk/var/tmp<br />
/opt/elasticbeanstalk/var/log<br />
/opt/elasticbeanstalk/var/log/LogDirectoryMonitor.log<br />
/opt/elasticbeanstalk/var/log/DaemonManager.log<br />
/opt/elasticbeanstalk/var/log/bluepill.log<br />
/opt/elasticbeanstalk/var/log/hostmanager.log<br />
/opt/elasticbeanstalk/var/log/ApplicationHealthcheck.log<br />
/opt/elasticbeanstalk/var/log/CatalinaLogMonitor.log<br />
</code></p>
<p><strong>Final words</strong><br />
That&#8217;s all for today&#8217;s blog post. Further posts will take a closer look at HostManager and deployment including the application setup sequence.</p>
<p>I&#8217;m looking forward to any feedback and additional information.</p>
<p>Maybe we can even hack HostManager to accept other application containers, e.g. for OSGi applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jetztgrad.net/2011/01/dissecting-an-amazon-elastic-beanstalk-instance/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Introducing groovyx.osgi: OSGi DSL for Groovy</title>
		<link>http://blog.jetztgrad.net/2011/01/groovyx-osgi-osgi-dsl-for-groovy/</link>
		<comments>http://blog.jetztgrad.net/2011/01/groovyx-osgi-osgi-dsl-for-groovy/#comments</comments>
		<pubDate>Tue, 18 Jan 2011 10:40:46 +0000</pubDate>
		<dc:creator>Wolfgang Schell</dc:creator>
				<category><![CDATA[groovy]]></category>
		<category><![CDATA[osgi]]></category>

		<guid isPermaLink="false">http://blog.jetztgrad.net/?p=270</guid>
		<description><![CDATA[Programming for and in an OSGi environment is sometimes hard. Getting started is hard as well. groovyx.osgi helps both setting up an OSGi environment and simplifies programming by providing support for easy access to OSGi services, etc. Setting up an OSGi environment Setting up an OSGi environment is hard work: you have to download an [...]]]></description>
			<content:encoded><![CDATA[<p>Programming for and in an OSGi environment is sometimes hard. Getting started is hard as well. <code>groovyx.osgi</code> helps both setting up an OSGi environment and simplifies programming by providing support for easy access to OSGi services, etc.</p>
<p><strong>Setting up an OSGi environment</strong></p>
<p>Setting up an OSGi environment is hard work: you have to download an OSGi  implementation (usually <a href="http://felix.apache.org/">Apache Felix</a> or <a href="http://eclipse.org/equinox/">Eclipse Equinox</a>, but there are <a href="/osgi-stuff/osgi-runtime-comparison/">others</a> as well). Then there are many dependencies to download. There is an excellent tool, which simplifies the startup part: <a href="http://paxrunner.ops4j.org/">Pax Runner</a>. Pax Runner can resolve dependencies from URLs or Maven repositories and start the OSGi framework.</p>
<p>One problem remains: you need to download Pax Runner and the configuration is a (set of) static text file(s). To simplify things and allow scripting in the &#8220;recipes&#8221;, the module <a href="https://github.com/jetztgradnet/groovyx-osgi/tree/master/groovyx-osgi-runtime">groovyx.osgi.runtime</a> (<a href="https://github.com/jetztgradnet/groovyx-osgi/tree/master/groovyx-osgi-runtime#readme">README</a>) provides a nice Groovy DSL for creating and starting an OSGi framework.</p>
<p>Features:</p>
<ul>
<li>provision bundles from filesystem, web, Maven repositories</li>
<li>run Eclipse Equinox or Apache Felix OSGi runtimes</li>
<li>flexible Groovy DSL, fully programmable</li>
<li>lifecycle callback closures</li>
</ul>
<p>The dependency resolution code is derived from <a href="http://grails.org/">Grails</a> and was written by <a href="http://twitter.com/graemerocher">Graeme Rocher</a>.</p>
<p>Simple example:</p>
<script src="http://gist.github.com/742786.js"></script>
<p>A more complete example including automatic download of dependencies can be found <a href="https://gist.github.com/784209">here</a>. Another <a href="https://gist.github.com/784220">example</a> provisions an entire OSGi environment including Apache Felix WebConsole on port 8081.</p>
<p><strong>Simplified Programming Model</strong></p>
<p>The OSGi programming model is based on services (or micro-services, as Peter Kriens <a href="http://www.osgi.org/blog/2010/03/services.html">likes to call</a> them), which are accessed via the <a href="http://www.osgi.org/javadoc/r4v42/org/osgi/framework/BundleContext.html">BundleContext</a>. Services are dynamic, they can come and go any time during the lifetime of an OSGi application. This is both a strength, as an application can be extended or updated without application shutdown, and a weakness, as it requires careful handling of service dynamics.</p>
<p>Looking up and using a service requires a lot of boiler plate code. A simple example in Java:</p>
<script src="http://gist.github.com/784237.js"></script>
<p>The equivalent Groovy code using module <code>groovyx.osgi</code> looks like this:</p>
<script src="http://gist.github.com/784239.js"></script>
<p>The <code>groovyx.osgi</code> module (<a href="https://github.com/jetztgradnet/groovyx-osgi/tree/master/groovyx-osgi#readme">README</a>) contains helper classes to make OSGi programming easier. This package was inspired by <a href="https://github.com/weiglewilczek/scalamodules/wiki">ScalaModules</a>.</p>
<p>Features:</p>
<ul>
<li>simplifies working with OSGi service registry</li>
<li>safe access to OSGi services, without fear for OSGi dynamics</li>
<li>Service finder DSL</li>
<li>OSGi service filter DSL.</li>
</ul>
<p>The filter support is derived from the <a href="http://code.google.com/p/filter4osgi/">filter4osgi</a> project and was contributed by <a href="http://hamletdarcy.blogspot.com/">Hamlet D’Arcy</a>.</p>
<p>An overview on basic usage of Groovy with OSGi can be found at the <a href="http://groovy.codehaus.org/OSGi+and+Groovy">Groovy Homepage</a>.</p>
<p><strong>Source code and binaries</strong></p>
<p><code>groovyx.osgi</code> and <code>groovyx.osgi.runtime</code> are released under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html">Apache 2.0 license</a>. The code is available at <a href="https://github.com/jetztgradnet/groovyx-osgi/">GitHub</a>.</p>
<p>You can either <a href="https://github.com/jetztgradnet/groovyx-osgi/archives/master">download</a> <code>groovyx.osgi</code> and <code>groovyx.osgi.runtime</code> <code>0.1</code> from GitHub or install it using <a href="http://groovy.codehaus.org/Grape">Grape</a>, <a href="http://ant.apache.org/ivy/">Ivy</a>, or <a href="http://maven.apache.org/">Maven</a> from the Maven repository at <a href="https://github.com/jetztgradnet/repository/raw/master">https://github.com/jetztgradnet/repository/raw/master</a>. </p>
<p>A simple example using <a href="http://groovy.codehaus.org/Grape">Grape</a>:</p>
<script src="http://gist.github.com/784211.js"></script>
<p>This script is executable with nothing but Groovy (>= 1.7.5) installed.</p>
<p><strong>Roadmap</strong></p>
<p>The following items are planned for the next releases:</p>
<p><code>groovyx.osgi</code></p>
<ul>
<li>simplified service registration <code>MyObject.registerService(Map, Closure)</code></li>
<li>simplified use of <a href="http://www.osgi.org/javadoc/r4v42/org/osgi/util/tracker/ServiceTracker.html">ServiceTracker</a>, <a href="http://www.osgi.org/javadoc/r4v42/org/osgi/service/cm/ManagedService.html">ManagedService</a>, and <a href="http://www.osgi.org/javadoc/r4v42/org/osgi/service/cm/ManagedServiceFactory.html">ManagedServiceFactory</a></li>
<li>improve docs</li>
</ul>
<p><code>groovyx.osgi.runtime</code></p>
<ul>
<li>add support for pre-defined provisioning profiles</li>
<li>add support for OSGi <a href="http://www.osgi.org/javadoc/r4v42/org/osgi/service/cm/ConfigurationAdmin.html">ConfigurationAdmin</a></li>
<li>improve handling of external OSGi runtimes</li>
<li>improve docs</li>
</ul>
<p><a href="http://grails.org/plugin/osgi">Grails OSGi plugin</a></p>
<ul>
<li>use <code>groovyx.osgi</code> and <code>groovyx.osgi.runtime</code></li>
<li>migrate usage of <a href="http://www.springsource.org/osgi">Spring DM</a> to its successor Eclipse <a href="http://www.eclipse.org/gemini/blueprint/">Gemini Blueprint</a> and <a href="http://www.eclipse.org/gemini/web/">Gemini Web</a></li>
<li>add support for easy access to OSGi services</li>
</ul>
<p><strong>Final thoughts</strong></p>
<p>OSGi provides no silver bullet for modularization, but it greatly helps, once you wrapped your head around bundles, services and dependencies. It&#8217;s not always an easy road, but there are many helpful tools and <a href="http://www.osgi.org/Planet/Feed">people</a> out there. I hope, <code>groovyx.osgi</code> can help you to create great applications. Have fun playing in your OSGi sandbox and don&#8217;t forget to send me your thoughts. Any feedback is greatly appreciated, either in the comments or <a href="https://github.com/jetztgradnet/groovyx-osgi/issues">open a issue</a> at GitHub.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jetztgrad.net/2011/01/groovyx-osgi-osgi-dsl-for-groovy/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Grails on OSGi (3): Released Grails OSGi plugin 0.1</title>
		<link>http://blog.jetztgrad.net/2010/01/released-grails-osgi-plugin-0-1/</link>
		<comments>http://blog.jetztgrad.net/2010/01/released-grails-osgi-plugin-0-1/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 02:35:54 +0000</pubDate>
		<dc:creator>Wolfgang Schell</dc:creator>
				<category><![CDATA[grails]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://blog.jetztgrad.net/?p=133</guid>
		<description><![CDATA[The Grails OSGi plugin provides scripts to package a Grails application as an OSGi bundle. Additionally the bundle(s) may be run in an OSGi container assembled ad hoc by the excellent Pax Runner or deployed to a SpringSource DM Server. License The OSGi plugin is released under the Apache License 2.0. Installation Simply call grails [...]]]></description>
			<content:encoded><![CDATA[<p>The Grails OSGi plugin provides scripts to package a Grails application as an OSGi bundle. Additionally the bundle(s) may be run in an OSGi container assembled ad hoc by the excellent <a href="http://paxrunner.ops4j.org">Pax Runner</a> or deployed to a <a href="http://www.springsource.org/dmserver">SpringSource DM Server</a>.</p>
<p><b>License</b></p>
<p>The OSGi plugin is released under the <a href="http://apache.org/licenses/LICENSE-2.0.txt">Apache License 2.0</a>.</p>
<p><b>Installation</b></p>
<p>Simply call <code>grails install-plugin osgi</code> to install the OSGi plugin. </p>
<p><b>Usage:</b></p>
<p><b>Creating an OSGi bundle from the Grails application</b></p>
<p><code>grails bundle<br />
grails prod bundle</code></p>
<p><b>Running the bundle</b></p>
<p><code>grails run-bundle<br />
grails prod run-bundle</code></p>
<p>The application can be accessed at <a href="http://localhost:8080/myapp/">http://localhost:8080/myapp/</a>.</p>
<p>Note: at first start the OSGi runtime is assembled, which may take some time, while Maven is downloading the internet&#8230;</p>
<p><b>Creating a zipped OSGi runtime</b></p>
<p><code>grails assemble-osgi-runtime<br />
grails prod assemble-osgi-runtime</code></p>
<p><b>Deploy bundle to DM Server</b></p>
<p><code>grails dmserver deploy</code> (Not yet implemented)</p>
<p><b>Getting around the OSGi runtime</b></p>
<p>The OSGi runtime is based on the <a href="http://www.eclipse.org/equinox">Equinox</a> OSGi framework, <a href="http://paxweb.ops4j.org">Pax Web</a> and some additional bundles.</p>
<p><b>Web Console</b></p>
<p>The <a href="http://felix.apache.org/site/apache-felix-web-console.html">Felix Web Management Console</a> provides excellent insight into the inner workings (see Screenshots). It can be accessed at <a href="http://localhost:8080/system/console/">http://localhost:8080/system/console/</a> with user &#8220;admin&#8221; and password &#8220;admin&#8221;.</p>
<p><a href="http://blog.jetztgrad.net/wp-content/uploads/2010/01/ManagementConsole.png"><img src="http://blog.jetztgrad.net/wp-content/uploads/2010/01/ManagementConsole-197x300.png" alt="" title="Web Management Console" width="197" height="300" class="aligncenter size-medium wp-image-158" /></a></p>
<p><a href="http://blog.jetztgrad.net/wp-content/uploads/2010/01/ManagementConsole-GrailsAppBundle.png"><img src="http://blog.jetztgrad.net/wp-content/uploads/2010/01/ManagementConsole-GrailsAppBundle-77x300.png" alt="" title="Management Console: Details of the Grails application bundle" width="77" height="300" class="aligncenter size-medium wp-image-160" /></a></p>
<p><b>Shell Console</b></p>
<p>The command <code>grails run-bundle</code> drops the user in the Equinox Shell. Typing <code>help</code> shows the available commands.</p>
<p><b>How it works</b></p>
<p>In order to be a valid OSGi bundle, the application is war&#8217;ed and provided with the necessary bundle manifest headers (see <code>scripts/_Event.groovy</code> for details).<br />
The bundle can be created using <code>grails bundle</code>.  </p>
<p>The OSGi runtime is assembled in the <code>target/osgi</code> directory.</p>
<p><b>Source code and Issues</b></p>
<p>The source code is hosted at <a href="http://github.com/jetztgradnet/grails-osgi-plugin">GitHub</a>, issues can be reported <a href="http://github.com/jetztgradnet/grails-osgi-plugin/issues">here</a>.</p>
<p><b>Roadmap</b></p>
<ul>
<li>make bundle generation configurable (e.g. include/exclude dependencies, &#8230;)</li>
<li>make OSGi runtime created by <code>grails run-bundle</code> and <code>grails assemble-osgi-runtime</code> configurable</li>
<li>support auto-reloading of changed artifacts</li>
<li>use Spring DM instead of Pax Web as Web extender</li>
<li>remove dependencies from bundle and package them as their own plugins (re-using existing bundles from the <a href="http://www.springsource.com/repository">SpringSource Enterprise Repository</a></li>
<li>export main Grails beans and application context as OSGi service</li>
<li>export services as OSGi service (via <code>static expose = 'osgi'</code>)</li>
<li>provide access to OSGi <code>BundleContext</code> to artifacts (controllers, services, &#8230;)</li>
<li>implement deployment to DM Server</li>
<li>consider other deployment options: Apache Karaf, &#8230;</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.jetztgrad.net/2010/01/released-grails-osgi-plugin-0-1/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>Grails on OSGi (2): First steps</title>
		<link>http://blog.jetztgrad.net/2009/11/grails-on-osgi-2-first-steps/</link>
		<comments>http://blog.jetztgrad.net/2009/11/grails-on-osgi-2-first-steps/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 11:43:07 +0000</pubDate>
		<dc:creator>Wolfgang Schell</dc:creator>
				<category><![CDATA[grails]]></category>
		<category><![CDATA[osgi]]></category>

		<guid isPermaLink="false">http://blog.jetztgrad.net/?p=77</guid>
		<description><![CDATA[This part of the series shows the necessary step to get a Grails application running in an OSGi environment as a monolithic bundle.]]></description>
			<content:encoded><![CDATA[<p>The first step on the road to running Grails applications in an OSGi environment is to get a simple application to run as a monolithic bundle (almost) without changes.</p>
<p><br/></p>
<p><b>Test application</b></p>
<p>We create a simple Grails application (e.g. the one described in a <a href="https://www.ibm.com/developerworks/java/library/j-grails01158/">article on developer works</a>; the application has a single domain class <code>Trip</code>, the controller and all views are generated). A single domain class and the corresponding controller is all we need for a simple test.</p>
<p><br/></p>
<p><b>Bundle 101</b></p>
<p>For the first attempt, the Grails application will be transformed, into a single, monolithic bundle (see <a href="/2009/11/grails-on-osgi-1-thoughts">part 1</a> for possible modularization levels) containing all dependencies like Grails, Groovy, Hibernate, Spring, &#8230; </p>
<p>A bundle is basically a JAR or WAR with some special headers in its manifest file. Required headers are <code>Bundle-SymbolicName</code>, which uniquely identifies the bundle, <code>Bundle-Version</code>, which specifies the bundle version (multiple versions of the bundle can run concurrently!) and <code>Bundle-ClassPath</code>, which specifies the classpath within the bundle. Other important headers are <code>Import-Package</code> and <code>Export-Package</code>, which are necessary when using code and resources from and providing classes to other bundles.</p>
<p><br/></p>
<p><b>Preparing the bundle</b></p>
<p>In order to create a valid bundle manifest, <code>$GRAILS_HOME/scripts/_GrailsWar.groovy</code> must be patched with <a href="http://github.com/jetztgradnet/grails-osgi-testenv/blob/master/bundle-manifest.patch"> bundle-manifest.patch</a>:</p>
<p><code>cd $GRAILS_HOME<br />
patch -p0 < /pacth/to/bundle-manifest.patch<br />
</code></p>
<p>In the future, the changes could either be integrated into Grails directly  or into a OSGi plugin.</p>
<p>Our Grails application will need to be transformed into a bundle, so we package it using <code>grails war</code>. The application and all dependencies are contained in the resulting WAR file.</p>
<p>The bundle manifest can now be inspected using the following command (on Linux or Mac OSX):</p>
<p><code>unzip -p target/trip-planner-0.1.war META-INF/MANIFEST.MF</code></p>
<p>The manifest now looks like this:</p>
<p><code><br />
Manifest-Version: 1.0<br />
Ant-Version: Apache Ant 1.7.1<br />
Created-By: 14.1-b02-92 (Apple Inc.)<br />
Bundle-ManifestVersion: 2<br />
Bundle-Name: trip-planner<br />
Bundle-SymbolicName: trip-planner<br />
Bundle-Version: 0.1<br />
Bundle-ClassPath: WEB-INF/classes,WEB-INF/lib/antlr-2.7.6.jar,WEB-INF/<br />
 lib/aopalliance-1.0.jar,WEB-INF/lib/aspectjrt-1.6.2.jar,WEB-INF/lib/a<br />
 spectjweaver-1.6.2.jar,WEB-INF/lib/cglib-nodep-2.1_3.jar,WEB-INF/lib/<br />
 commons-beanutils-1.8.0.jar,WEB-INF/lib/commons-codec-1.3.jar,WEB-INF<br />
 /lib/commons-collections-3.2.1.jar,WEB-INF/lib/commons-dbcp-1.2.2.jar<br />
 ,WEB-INF/lib/commons-el-1.0.jar,WEB-INF/lib/commons-fileupload-1.2.1.<br />
 jar,WEB-INF/lib/commons-io-1.4.jar,WEB-INF/lib/commons-lang-2.4.jar,W<br />
 EB-INF/lib/commons-pool-1.5.3.jar,WEB-INF/lib/commons-validator-1.3.1<br />
 .jar,WEB-INF/lib/dom4j-1.6.1.jar,WEB-INF/lib/ehcache-1.6.1.jar,WEB-IN<br />
 F/lib/ejb3-persistence-1.0.2.GA.jar,WEB-INF/lib/grails-bootstrap-1.2-<br />
 M4.jar,WEB-INF/lib/grails-core-1.2-M4.jar,WEB-INF/lib/grails-crud-1.2<br />
 -M4.jar,WEB-INF/lib/grails-docs-1.2-M4.jar,WEB-INF/lib/grails-gorm-1.<br />
 2-M4.jar,WEB-INF/lib/grails-resources-1.2-M4.jar,WEB-INF/lib/grails-s<br />
 pring-1.2-M4.jar,WEB-INF/lib/grails-web-1.2-M4.jar,WEB-INF/lib/groovy<br />
 -all-1.6.5.jar,WEB-INF/lib/hibernate-annotations-3.4.0.GA.jar,WEB-INF<br />
 /lib/hibernate-commons-annotations-3.3.0.ga.jar,WEB-INF/lib/hibernate<br />
 -core-3.3.1.GA.jar,WEB-INF/lib/hibernate-ehcache-3.3.1.GA.jar,WEB-INF<br />
 /lib/hsqldb-1.8.0.10.jar,WEB-INF/lib/javassist-3.4.GA.jar,WEB-INF/lib<br />
 /jcl-over-slf4j-1.5.6.jar,WEB-INF/lib/jta-1.1.jar,WEB-INF/lib/jul-to-<br />
 slf4j-1.5.6.jar,WEB-INF/lib/log4j-1.2.15.jar,WEB-INF/lib/org.springfr<br />
 amework.aop-3.0.0.RC1.jar,WEB-INF/lib/org.springframework.asm-3.0.0.R<br />
 C1.jar,WEB-INF/lib/org.springframework.aspects-3.0.0.RC1.jar,WEB-INF/<br />
 lib/org.springframework.beans-3.0.0.RC1.jar,WEB-INF/lib/org.springfra<br />
 mework.context-3.0.0.RC1.jar,WEB-INF/lib/org.springframework.context.<br />
 support-3.0.0.RC1.jar,WEB-INF/lib/org.springframework.core-3.0.0.RC1.<br />
 jar,WEB-INF/lib/org.springframework.expression-3.0.0.RC1.jar,WEB-INF/<br />
 lib/org.springframework.instrument-3.0.0.RC1.jar,WEB-INF/lib/org.spri<br />
 ngframework.jdbc-3.0.0.RC1.jar,WEB-INF/lib/org.springframework.jms-3.<br />
 0.0.RC1.jar,WEB-INF/lib/org.springframework.orm-3.0.0.RC1.jar,WEB-INF<br />
 /lib/org.springframework.oxm-3.0.0.RC1.jar,WEB-INF/lib/org.springfram<br />
 ework.transaction-3.0.0.RC1.jar,WEB-INF/lib/org.springframework.web-3<br />
 .0.0.RC1.jar,WEB-INF/lib/org.springframework.web.servlet-3.0.0.RC1.ja<br />
 r,WEB-INF/lib/oro-2.0.8.jar,WEB-INF/lib/oscache-2.4.1.jar,WEB-INF/lib<br />
 /sitemesh-2.4.jar,WEB-INF/lib/slf4j-api-1.5.6.jar,WEB-INF/lib/slf4j-l<br />
 og4j12-1.5.6.jar,WEB-INF/lib/standard-1.1.2.jar,WEB-INF/lib/xpp3_min-<br />
 1.1.3.4.O.jar<br />
Import-Package: javax.servlet,javax.servlet.http,javax.servlet.resourc<br />
 es,javax.servlet.jsp.resources;resolution:=optional,javax.xml.parsers<br />
 ,org.w3c.dom,org.xml.sax,org.xml.sax.ext,org.xml.sax.helpers<br />
Webapp-Context: trip-planner</p>
<p>Name: Grails Application<br />
Implementation-Title: trip-planner<br />
Implementation-Version: 0.1<br />
Grails-Version: 1.2-M4<br />
</code></p>
<p>Note that <code>Bundle-ClassPath</code> contains all dependencies required by Grails, JAR files from the <code>lib/</code> directory, and those contributed by installed Grails plugins.</p>
<p>The bundle imports some packages from the <a href="http://java.sun.com/products/servlet/2.5/docs/servlet-2_5-mr2/index.html">Servlet specification</a>. This is to ensure, that the bundle uses the same classes as the web container, otherwise the classes would not be compatible, as they would be loaded by different class loaders.</p>
<p>BTW: if you need to have a look at the generated web.xml, you can achieve it like this:</p>
<p><code>unzip -p target/trip-planner-0.1.war WEB-INF/web.xml | xmllint --format -</code></p>
<p><br/></p>
<p><b>Running the bundle</b></p>
<p>In order to run the bundle, it must be installed into an OSGi container like <a href="http://eclipse.org/equinox">Equinox</a> (the base for the Eclipse IDE), <a href="http://felix.apache.org">Apache Felix</a>, or <a href="http://www.knopflerfish.org/">Knopflerfish</a>. The test environment described below uses Equinox. Other frameworks could be used as well, but I haven't tested them yet.</p>
<p>Additionally we need a web container like <a href="http://tomcat.apache.org/">Tomcat</a> or <a href="http://www.mortbay.org/jetty/">Jetty</a>. The web container needs also to be installed within the OSGi container, so we skip the download on the main site(s), but go looking for OSGI-fied versions. Jetty is OSGi-capable out of the box, an adapted Tomcat also used in <a href="http://www.springsource.com/products/dmserver">Spring dm server</a> can be found at the SpringSource <a href="http://www.springsource.com/repository/app/">Enterprise Bundle Repository</a>. (Note: Tomcat does not yet work, so we currently use Jetty. I get no errors, but all requests seem to get silently ignored.)</p>
<p>The remaining part is a module usually called Web Extender, which bridges the gap between web applications and the web container. The web extender looks for bundles matching a certain criteria (e.g. existance of <code>WEB-INF/web.xml</code> or some bundle headers) and configures these as a web application. Candidates are <a href="http://wiki.ops4j.org/display/paxweb/Pax+Web">Pax Web</a> and <a href="http://www.springsource.org/osgi">Spring-DM</a>.</p>
<p>As Pax Web is currently not able to configure a Grails applications because of <a href="http://issues.ops4j.org/browse/PAXWEB-148">PAXWEB-148</a>, and Spring-DM will probably be required for other OSGi and Spring related stuff anyway, we use the latter as Web Extender.</p>
<p><br/></p>
<p><b>Test environment</b></p>
<p>The test environment is made up of the excellent <a href="http://paxrunner.ops4j.org/">Pax Runner</a> with a <a href="http://github.com/jetztgradnet/grails-osgi-testenv">set of configuration files</a>. Pax Runner is basically a starter for OSGi applications. It supports different OSGi frameworks and provisions both framework and bundles from sources like Maven repos, web servers, or directories.</p>
<p>The test environment loads the Equinox OSGi Framework (version 3.5.1), Spring-DM 2.0M1, Spring 3.0RC1, and Jetty (Tomcat doesn’t work right know). All configuration files be found on <a href="http://github.com/jetztgradnet/grails-osgi-testenv">GitHub</a>.</p>
<p>The test environment can be installed using the following commands:</p>
<p>Create a directory and change into it:</p>
<p><code>mkdir testenv; cd testenv</code></p>
<p>Download Pax Runner, extract it and create a version agnostic link:</p>
<p><code>curl -o pax-runner-assembly-1.3.0-jdk15.tar.gz http://repo1.maven.org/maven2/org/ops4j/pax/runner/pax-runner-assembly/1.3.0/pax-runner-assembly-1.3.0-jdk15.tar.gz</code></p>
<p><code>tar xzf pax-runner-assembly-1.3.0-jdk15.tar.gz</code></p>
<p><code>ln -s pax-runner-1.3.0 pax-runner</code></p>
<p>Get the example configuration:</p>
<p><code>git clone git://github.com/jetztgradnet/grails-osgi-testenv.git</code></p>
<p>The framework can be started with the following command:</p>
<p><code>cd grails-osgi-testenv<br />
./pax-osgitest</code></p>
<p>After lots of log messages, we arrive at a prompt of the command shell. Help is available using <code>help</code>.</p>
<p>We now type <code>ss</code> to get an overview over all running bundles:</p>
<p><code><br />
osgi> ss</p>
<p>Framework is launched.</p>
<p>id	State       Bundle<br />
0	ACTIVE      org.eclipse.osgi_3.5.1.R35x_v20090827<br />
1	ACTIVE      org.eclipse.osgi.util_3.2.0.v20090520-1800<br />
2	ACTIVE      org.eclipse.osgi.services_3.2.0.v20090520-1800<br />
3	ACTIVE      org.springframework.aop_3.0.0.RC1<br />
4	ACTIVE      org.springframework.asm_3.0.0.RC1<br />
5	ACTIVE      org.springframework.aspects_3.0.0.RC1<br />
6	ACTIVE      org.springframework.beans_3.0.0.RC1<br />
7	ACTIVE      org.springframework.context_3.0.0.RC1<br />
8	ACTIVE      org.springframework.context.support_3.0.0.RC1<br />
9	ACTIVE      org.springframework.core_3.0.0.RC1<br />
10	ACTIVE      org.springframework.expression_3.0.0.RC1<br />
11	ACTIVE      org.springframework.jdbc_3.0.0.RC1<br />
12	INSTALLED   org.springframework.jms_3.0.0.RC1<br />
13	ACTIVE      org.springframework.orm_3.0.0.RC1<br />
14	ACTIVE      org.springframework.transaction_3.0.0.RC1<br />
15	ACTIVE      org.springframework.web_3.0.0.RC1<br />
16	ACTIVE      org.springframework.web.servlet_3.0.0.RC1<br />
17	ACTIVE      com.springsource.org.aopalliance_1.0.0<br />
18	ACTIVE      com.springsource.org.objectweb.asm_2.2.3<br />
19	ACTIVE      com.springsource.net.sf.cglib_2.1.3<br />
20	ACTIVE      org.springframework.osgi.core_2.0.0.M1<br />
21	ACTIVE      org.springframework.osgi.extender_2.0.0.M1<br />
22	ACTIVE      org.springframework.osgi.io_2.0.0.M1<br />
23	ACTIVE      org.springframework.osgi.web_2.0.0.M1<br />
24	ACTIVE      org.springframework.osgi.web.extender_2.0.0.M1<br />
	            Fragments=28<br />
25	ACTIVE      com.springsource.org.mortbay.jetty.server_6.1.9<br />
26	ACTIVE      com.springsource.org.mortbay.util_6.1.9<br />
27	ACTIVE      org.springframework.osgi.jetty.start.osgi_1.0.0<br />
28	RESOLVED    org.springframework.osgi.jetty.web.extender.fragment.osgi_1.0.1<br />
	            Master=24<br />
29	ACTIVE      com.springsource.javax.activation_1.1.1<br />
30	ACTIVE      com.springsource.javax.annotation_1.0.0<br />
31	ACTIVE      com.springsource.javax.el_1.0.0<br />
32	ACTIVE      com.springsource.javax.ejb_3.0.0<br />
33	ACTIVE      com.springsource.javax.mail_1.4.1<br />
34	ACTIVE      com.springsource.javax.persistence_1.99.0<br />
35	ACTIVE      com.springsource.javax.transaction_1.1.0<br />
36	ACTIVE      com.springsource.javax.servlet_2.5.0<br />
37	ACTIVE      com.springsource.javax.servlet.jsp_2.1.0<br />
38	ACTIVE      com.springsource.javax.xml.bind_2.1.7<br />
39	ACTIVE      com.springsource.javax.xml.rpc_1.1.0<br />
40	ACTIVE      com.springsource.javax.xml.soap_1.3.0<br />
41	ACTIVE      com.springsource.javax.xml.stream_1.0.1<br />
42	ACTIVE      com.springsource.javax.xml.ws_2.1.1<br />
43	ACTIVE      org.apache.felix.webconsole_2.0.2<br />
45	ACTIVE      org.ops4j.pax.logging.pax-logging-api_1.4.0<br />
46	ACTIVE      org.ops4j.pax.logging.pax-logging-service_1.4.0<br />
47	ACTIVE      org.eclipse.equinox.util_1.0.100.v20090520-1800<br />
48	ACTIVE      org.eclipse.equinox.ds_1.1.1.R35x_v20090806<br />
49	ACTIVE      org.eclipse.equinox.cm_1.0.100.v20090520-1800<br />
50	ACTIVE      org.eclipse.equinox.supplement_1.1.0.v20080421-2006<br />
51	ACTIVE      org.eclipse.equinox.common_3.4.0.v20080421-2006<br />
52	ACTIVE      org.eclipse.equinox.preferences_3.2.201.R34x_v20080709<br />
53	ACTIVE      org.ops4j.pax.url.assembly_1.1.1<br />
54	ACTIVE      org.ops4j.pax.url.classpath_1.1.1<br />
55	ACTIVE      org.ops4j.pax.url.cache_1.1.1<br />
56	ACTIVE      org.ops4j.pax.url.mvn_1.1.1<br />
57	ACTIVE      org.ops4j.pax.url.link_1.1.1<br />
58	ACTIVE      org.ops4j.pax.url.war_1.1.1<br />
59	ACTIVE      org.ops4j.pax.url.wrap_1.1.1<br />
</code></p>
<p>We can now install our bundle:</p>
<p><code>install file:/path/to/trip-planner-0.1.war<br />
Bundle id is 60<br />
</code></p>
<p>After installing we run <code>ss</code> again. Our bundle is now installed and in the <code>RESOLVED</code> state. With the id of our bundle (the number in the first column), we can now start it:</p>
<p><code>start 60</code></p>
<p>The application should now be reachable at <a href="http://localhost:8080/trip-planner-0.1/">http://localhost:8080/trip-planner-0.1/</a>. If you get a <code>404</code> HTTP error, wait a moment, to give the web extender time to configure the bundle.</p>
<p>The <code>system</code> directory serves as the current directory of the OSGi container. The HSQLdb files from our test application will be created there, log messages of the container are written to the <code>system/logs</code> directory.</p>
<p>If our web bundle has been changed, we can simply update it using <code> update 60</code>. If this does not work, we can un- and reinstall it using <code>uninstall 60</code> and the installation procedure described above.</p>
<p><br/></p>
<p><b>Next steps</b></p>
<p>As outlined in <a href="/2009/11/grails-on-osgi-1-thoughts">part 1</a>, the ultimate goal is to create modular Grails applications. The next step will be to extract the dependencies from the monolithic bundle and put them into their own bundles. Spring and Groovy are already available as bundles, other dependencies may need to be replaced with an OSGi-ready version, e.g. from the SpringSource <a href="http://www.springsource.com/repository/app/">Bundle Repository</a>. </p>
<p>There will be some issues regarding singletons (e.g. <code>ApplicationHolder</code>, <code>ConfigurationHolder</code>) and class loading (Hibernate), but I think, they can be resolved with some work.</p>
<p>The findings may finally find their way into Grails or a Grails OSGi plugin.</p>
<p>Stay tuned...</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jetztgrad.net/2009/11/grails-on-osgi-2-first-steps/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Grails on OSGi (1): Thoughts</title>
		<link>http://blog.jetztgrad.net/2009/11/grails-on-osgi-1-thoughts/</link>
		<comments>http://blog.jetztgrad.net/2009/11/grails-on-osgi-1-thoughts/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 01:41:02 +0000</pubDate>
		<dc:creator>Wolfgang Schell</dc:creator>
				<category><![CDATA[grails]]></category>
		<category><![CDATA[osgi]]></category>

		<guid isPermaLink="false">http://blog.jetztgrad.net/?p=30</guid>
		<description><![CDATA[Running a Grails application in an OSGi environment provides many benefits such as better modularization. There are different levels of OSGi support, each with its own set of advantages and disadvantages.]]></description>
			<content:encoded><![CDATA[<p><b>What is OSGi</b></p>
<p>The <a href="http://www.osgi.org">OSGi</a> Alliance (formerly known as the Open Services Gateway initiative) is a consortium of companies in the Java world, which develop the OSGi Service Platform, a framework for component-oriented software. Originally developed for embeded devices, OSGi frameworks can now also be found in enterprise, mobile, home, telematics and consumer products.</p>
<p>Applications in an OSGi environment are split into individual modules called bundles, which are usually provided as jar files. Each bundle provides a manifest file containing meta data, which describe its name, version, dependencies and offerings, i.e. code and services. An OSGi container can host multiple applications at once, each application can be started or stopped any time.</p>
<p>The OSGi <a href="http://www.osgi.org/Specifications/HomePage">specifications</a> describe both the core framework and a set of standard services for common functionality such as logging, web access, declarative services, etc.  A more detailed description can be found <a href="http://www.osgi.org/About/Technology">here</a>.</p>
<p>There are multiple OSGi implementations available. Well-known open source implementations include <a href="http://eclipse.org/equinox">Equinox</a>, which is the base for the Eclipse IDE and eco system, <a href="http://felix.apache.org">Apache Felix</a> and <a href="http://www.knopflerfish.org/">Knopflerfish</a>.</p>
<p><br/></p>
<p><b>Benefits</b></p>
<p>Running a Grails application in an OSGi environment would bring some benefits:</p>
<ul>
<li>Support for modularization</li>
<li>Handling and versioning of components and dependencies (*)</li>
<li>Separation of applications</li>
<li>Dependencies and used libraries can be transferred independently to the application server, which makes for smaller application bundles and therefore faster transmission</li>
<li>Easy in-place update and reloading of individual components during runtime</li>
<li>Service-oriented architecture</li>
</ul>
<p>(*) Alltough starting with version 1.2 Grails provides good support for <a href="http://grails.org/doc/1.2.x/guide/3.%20Configuration.html#3.7%20Dependency%20Resolution"> versioning and  dependency resolution</a> with the integration of Ivy)</p>
<p><br/></p>
<p><b>Progress so far</b></p>
<p>JIRA issue <a href="http://jira.codehaus.org/browse/GRAILS-2221">GRAILS-2221</a> for OSGi support for Grails exists for quite some time. Originally OSGi support was requested with an eye towards a plugin system. Grails now has its own plugin system, but OSGi support is on the roadmap for Grails 2.0, whenever that will be released <img src='http://blog.jetztgrad.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><em>Update:</em> Grails 1.2 will contain a valid OSGi <a href="http://github.com/grails/grails/blob/master/grails/maven/grails-core.mf">bundle manifest</a>, so the Grails jars may already be pulled out of a Grails application bundle and installed sepearately.</p>
<p><br/></p>
<p><b>Possible implementation levels</b></p>
<p>There are several possibilities running a Grails application in an OSGi environment:</p>
<ul>
<li>Monolithic application (Compatibility mode)</li>
<li>Modularized application</li>
<li>Fully componentized application</li>
</ul>
<p><br/></p>
<p><b> Monolithic application (Compatibility mode)</b></p>
<p>This can be seen as a first step of an OSGi-fied Grails application and should be already possible today with some manual steps. </p>
<p>The Grails application is packaged as a WAR file with the manifest file containing necessary OSGi headers, like <code>Bundle-SymbolicName</code>, <code>Bundle-Version</code>, <code>Bundle-ClassPath</code>, and <code>Import-Package</code>. </p>
<p>An OSGi framework providing a web service and corresponding web extender like <a href="http://www.springsource.org/osgi">Spring-DM</a> or <a href="http://wiki.ops4j.org/display/paxweb/Pax+Web">Pax Web</a> can now run this application. </p>
<p>Advantages:</p>
<ul>
<li>Already possible today</li>
<li>No classloading issues</li>
</ul>
<p>Disadvantages:</p>
<ul>
<li>No modularization</li>
<li>Big, monolithic bundle, slow upload to an application server</li>
</ul>
<p><br/></p>
<p><b>Modularized application</b></p>
<p>The next step will be splitting a Grails application into individual bundles. Ideally each of Grails&#8217; and the application&#8217;s dependencies like Hibernate, Sitemesh, etc. would come as its own (set of) bundle(s). </p>
<p>Spring and Groovy already contain OSGi meta data and can be run unmodified in an OSGi environment, OSGi-fied bundles of some other dependencies can be found in the bundle repositories provided by <a href="http://www.springsource.com/repository/app/">SpringSource</a>, <a href="http://felix.apache.org/obr/">Apache Felix</a>, or <a href="http://www.knopflerfish.org/repo/repository.xml">Knopflerfish</a>. Eclipse also hosts some third-party libraries, e.g. many commonly-used Apache jars, which were converted to OSGi bundles, in the <a href="http://eclipse.org/orbit/">Orbit</a> project.</p>
<p>The Grails application itself would be another bundle. As it contains no dependencies, it would be quite small and can therefore easily be transferred to an application server.</p>
<p>Advantages:</p>
<ul>
<li>Shared dependencies for all Grails applications</li>
<li>Small bundle for faster upload to an application server</li>
</ul>
<p>Disadvantages:</p>
<ul>
<li>Issues with Grails&#8217; singletons, when running more than one Grails application in a single VM (*)</li>
<li>Classloading issues</li>
</ul>
<p>(*) This is also the case when running more than one Grails application in a servlet container with shared jars, e.g. using <code>grails war --nojars</code>.</p>
<p><br/></p>
<p><b>Fully componentized application</b></p>
<p>Many posts on the Grails <a href="http://grails.org/Mailing+lists">mailing list</a> ask for ways to modularize big web applications. The most common answer and approach is to split the application into multiple Grails plugins. </p>
<p>In an OSGi environment, the Grails application could be split into multiple bundles, each of which can be individually updated or reloaded. Each Grails plugin would compose a bundle of its own, which could be used and shared by multiple Grails applications.</p>
<p>A starting point for implementing this approach could be the newly created <a href="http://blog.springsource.com/2009/06/22/modular-web-applications-with-springsource-slices/">Spring Slices</a> project.</p>
<p>Advantages:</p>
<ul>
<li>Full modularization</li>
<li>Small bundles for fast uploads to an application server</li>
</ul>
<p>Disadvantages:</p>
<ul>
<li>Issues with Grails&#8217; singletons, when running more than one Grails application in a single VM</li>
<li>Classloading issues</li>
</ul>
<p><br/></p>
<p><b>OSGi-fied Development mode</b></p>
<p>The Grails development mode (aka <code>grails run-app</code>) could also profit from OSGi support. With the OSGi framework constantly running, changes could be integrated by simply updating or reloading individual bundles. Even major changes would only mean reloading some bundles. This would reduce startup times, as the VM is always running and does not need to be stopped and restarted.</p>
<p>For extreme cases, each controller/domain class/Grails artefact could even be temporarily packaged in its own bundle. </p>
<p><br/></p>
<p><b>Conclusion</b></p>
<p>Real OSGi support for Grails is still some time in the future. There is a lot to do and some issues regarding classloading and singletons to resolve. This series of blog posts will look at OSGi support from different angles and try to find solutions to emerging problems. Stay tuned&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jetztgrad.net/2009/11/grails-on-osgi-1-thoughts/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

