<?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>The moons of Verthandi - Blog by Dani Giribet</title>
	<atom:link href="http://dani.calidos.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://dani.calidos.com</link>
	<description></description>
	<lastBuildDate>Mon, 01 Feb 2010 23:44:39 +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>Firefox for N900 with Flash disabled. Ah, the irony&#8230;</title>
		<link>http://dani.calidos.com/2010/02/02/firefox-for-n900-with-flash-disabled-ah-the-irony/</link>
		<comments>http://dani.calidos.com/2010/02/02/firefox-for-n900-with-flash-disabled-ah-the-irony/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 23:44:39 +0000</pubDate>
		<dc:creator>dani</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Digital Video]]></category>
		<category><![CDATA[Media]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flash is dead]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[ipad]]></category>

		<guid isPermaLink="false">http://dani.calidos.com/?p=232</guid>
		<description><![CDATA[From the Firefox for Nokia N900 1.0 release notes themselves, stumbled upon this little gem:

Initially, Firefox for N900 does not support browser plug-ins. Due to performance problems using Adobe Flash within Firefox on many websites, especially those with multiple plug-ins on them, we have disabled plugins for Firefox for Maemo 1.0. We plan to provide [...]]]></description>
			<content:encoded><![CDATA[<p>From the Firefox for Nokia N900 1.0 <a href="http://www.mozilla.com/en-US/mobile/1.0/releasenotes/">release notes</a> themselves, stumbled upon this little gem:</p>
<blockquote><p>
Initially, Firefox for N900 does not support browser plug-ins. Due to performance problems using Adobe Flash within Firefox on many websites, especially those with multiple plug-ins on them, we have disabled plugins for Firefox for Maemo 1.0. We plan to provide a browser add-on that will enable you to selectively enable plugins on certain sites, because some sites, like YouTube, work well.
</p></blockquote>
<p>So the good folks of the Mozilla Foundation have gone and released the thing. Given the recent turn of events, it&#8217;s interesting to see <a href="http://blogs.adobe.com/flashplatform/2010/01/apples_ipad_--_a_broken_link.html">the reality brick hitting the Adobe head</a>, so to speak. Couldn&#8217;t think of a more appropriate support for the <a href="http://www.apple.com/ipad/">Apple iPad</a>, really.</p>
<p>Even if the eventually release it with plug-in support enabled, they will probably stick with letting users enable Flash selectively&#8230; This is <a href="http://dani.calidos.com/2009/09/22/flash-the-wider-picture-of-an-identy-crisis/">yet another nail in the Flash coffin</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://dani.calidos.com/2010/02/02/firefox-for-n900-with-flash-disabled-ah-the-irony/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>El disseny d&#8217;interfícies no és cosa de molts</title>
		<link>http://dani.calidos.com/2010/01/17/el-disseny-dinterficies-no-es-cosa-de-molts/</link>
		<comments>http://dani.calidos.com/2010/01/17/el-disseny-dinterficies-no-es-cosa-de-molts/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 21:24:39 +0000</pubDate>
		<dc:creator>dani</dc:creator>
				<category><![CDATA[Catalan]]></category>
		<category><![CDATA[Management]]></category>
		<category><![CDATA[UXD]]></category>
		<category><![CDATA[disseny]]></category>
		<category><![CDATA[informatica]]></category>
		<category><![CDATA[usabilitat]]></category>

		<guid isPermaLink="false">http://dani.calidos.com/?p=229</guid>
		<description><![CDATA[Article boníssim sobre el disseny d&#8217;interfícies i l&#8217;impacte de qualsevol decisió de disseny sobre l&#8217;usabilitat.
Ens parla dels compromisos inherents en qualsevol decisió de disseny. També del mal que pot fer el disseny d&#8217;aplicacions en un comité on tothom hi diu la seva. També planteja la idea d&#8217;objectivar les decisions que es prenguin i construïr si [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.digital-web.com/articles/user_interface_design_taking_the_good_with_the_bad/">Article</a> boníssim sobre el disseny d&#8217;interfícies i l&#8217;impacte de qualsevol decisió de disseny sobre l&#8217;usabilitat.</p>
<p>Ens parla dels compromisos inherents en qualsevol decisió de disseny. També del mal que pot fer el disseny d&#8217;aplicacions en un comité on tothom hi diu la seva. També planteja la idea d&#8217;objectivar les decisions que es prenguin i construïr si cal una taula amb les avantatges i les consequències de cadascuna de les decisions.</p>
<p>Lectura obligada si ens dediquem al disseny i conceptualització de productes. Bookmark afegit.</p>
]]></content:encoded>
			<wfw:commentRss>http://dani.calidos.com/2010/01/17/el-disseny-dinterficies-no-es-cosa-de-molts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Components on the server (5): better Unit Testing</title>
		<link>http://dani.calidos.com/2010/01/04/components-on-the-server-5-better-unit-testing/</link>
		<comments>http://dani.calidos.com/2010/01/04/components-on-the-server-5-better-unit-testing/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 23:20:15 +0000</pubDate>
		<dc:creator>dani</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Equinox]]></category>
		<category><![CDATA[java servlets]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[tomcat]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://dani.calidos.com/?p=217</guid>
		<description><![CDATA[In this installment of the OSGi series, we add more complete Unit Testing support in the project. We also establish that some behaviour of the Servlet Bridge may not be what we want  and then provide a way to customize it.

Please make sure you read the previous installments before you continue with this article…
To [...]]]></description>
			<content:encoded><![CDATA[<p>In this installment of the OSGi series, we add more complete Unit Testing support in the project. We also establish that some behaviour of the Servlet Bridge may not be what we want  and then provide a way to customize it.</p>
<p><span id="more-217"></span></p>
<p>Please make sure you read the<a href="http://dani.calidos.com/category/computing/java/"> previous installments </a>before you continue with this article…</p>
<p>To ensure greater flexibility, performance and encapsulation, we will be using OSGi fragments.</p>
<p>http://static.springsource.org/osgi/docs/1.1.3/reference/html/appendix-tips.html</p>
<p>OSGi fragments attach to &#8220;host&#8221; bundles and can be used to extend functionality, provide configuration and even extra manifest entries.</p>
<p>On the first part, we move our unit tests to fragments. This has the benefit of being able to separate tests from actual code as well as allowing us to deploy using a smaller footprint in situations where we don&#8217;t want test code such as production deployments.</p>
<p>If we start with the cache code we&#8217;ve got so far we need to separate the test code from two bundles: &#8216;com.calidos.dani.osgi.cache.provider.memory&#8217; and &#8216;com.calidos.dani.osgi.cache.provider.memcached&#8217;. That is easy enough.</p>
<p>We create a new OSGi bundle fragment project like this:</p>
<p><img alt="New fragment" src="http://dani.calidos.com/img/2010/osgi-05/new-fragment.png" title="New fragment" width="472" height="566" /></p>
<p>We specify the bundle the new fragment is attaching to:</p>
<p><img alt="Specify host bundle" src="http://dani.calidos.com/img/2010/osgi-05/specify-bundle.png" title="Specify host bundle" width="455" height="107" /></p>
<p>The next step is to move the JUnit code from the main bundle onto the fragment. If we run the test independently we see that it passes as the classpath of the host and fragment bundles is merged into one.</p>
<p>We then add the fragment to our existing run configuration and it will be loaded onto our environment. So far so good, but there is no way to run the tests outside our controlled Eclipse.</p>
<p>Slim Ouertani at Javalobby shows us how to <a href="http://java.dzone.com/articles/osgi-junit-test-extender-using">run fragment tests from within the OSGi environment</a> in a great article. His code uses the new bundle tracker feature to discover any test fragments and exposing functionality to be able to run the tests.</p>
<p>You can get the source at kenai: <a href="http://kenai.com/projects/testosgifragment">http://kenai.com/projects/testosgifragment</a></p>
<p>We read the article thoroughly, fetch the source and build test.extender using maven:</p>
<p><code><br />
mvn install<br />
</code></p>
<p>The code works great but has a bug which is triggered when the code looks for the host of the fragment by reading the &#8216;Fragment-Host:&#8217; header. If the value specifies any kind of version qualifier it fails. It also crashes when trying to test a bundle or a fragment that doesn&#8217;t have the &#8216;Unit-Test&#8217; custom header.</p>
<p>The &#8216;Unit-Test&#8217; custom header lives on the fragment manifest and is used by test.extender to control who is able to be tested and if tests are done manually or automatically.</p>
<p>If no &#8216;Unit-Test&#8217; header is present or if its value is empty, test.extender will refuse to run any tests present on the bundle. If the value is &#8216;true&#8217; then test.extender will run the tests automatically whenever the test fragment bundle is loaded. If the value is anything else the tests won&#8217;t run automatically but you can still run them using the &#8216;test&#8217; and &#8216;testall&#8217; commands.</p>
<p>I have patched the code to accept a version qualifier for the fragment host as well as giving out an informative error message when attempting to test the wrong bundle.</p>
<p>Once this is done, we play with the test.extender by obtaining the fragment bundle id and issuing &#8216;test &lt;id&gt;&#8217; on the console:</p>
<p><code><br />
osgi&gt; test 80<br />
Bundle : [80] : com.calidos.dani.osgi.cache.provider.memory.test<br />
_<br />
CLASS : [com.calidos.dani.osgi.cache.provider.memory.test.MemoryCacheTest]<br />
___________________________________________________________________________<br />
Method : [ testClear ] PASS<br />
Method : [ testInit ] PASS<br />
Method : [ testInitInt ] PASS<br />
Method : [ testSize ] PASS<br />
Method : [ testSet ] PASS<br />
Method : [ testGet ] PASS<br />
Method : [ testGetStatus ] PASS<br />
___________________________________________________________________________<br />
_<br />
</code></p>
<p>We can also use the &#8216;testall&#8217; command which will look for all the testable fragment bundles and run the test there.</p>
<p>Having tested that functionality, we separate the tests from the memcached bundle and move them onto their own bundle.</p>
<p><a href="http://dani.calidos.com/img/2010/osgi-05/test-fragments.tar.gz">Here</a> you can download the two test fragments and the <a href="http://dani.calidos.com/img/2010/osgi-05/test-extender-patch">patch</a> to modify test.extender, neat.</p>
<p>Ok then, we move onto the next thing that is looking closely at the Servlet Bridge and its behaviour. What we are interested in is what happens when the container deploys and inits the Web app itself, starting up the servlet bridge. The bridge uses the container temporary folder to deploy the OSGi environment in a subfolder, copying any bundles into that subfolder. If the subfolder exists and there are bundles that have the same names, they won&#8217;t be copied. I have found this behaviour to be very confusing for newbies to the platform and very annoying for veterans. I&#8217;m not entirely sure if this is deliberate and has performance reasons or what. Calling the framework controls to prevent that is not optimal and manually removing the temporary folder isn&#8217;t, either. One possible solution would be to use a building system that increments the micro number every time there is a build and remember to clear up the container temporary folder from time to time. That is not always desirable or possible but fortunately, the servlet bridge implementation provides a way to customize it to our heart&#8217;s content.</p>
<p>Basically we have the following code in the bridge init() method:</p>
<pre class="java:nocontrols:nogutter">
	framework.init(getServletConfig());
	framework.deploy();
	framework.start();
	frameworkStarted = true;
</pre>
<p>In this case, &#8216;framework&#8217; is a instance of the FrameworkLauncher class which is created just before this code snippet. The FrameworkLauncher is the class responsible for deploying and launching OSGi. We note that the object is created by default as a plain FrameworkLauncher instance. However, the class to be used can be customized by specifying it in the web.xml file using the  &#8216;frameworkLauncherClass&#8217; servlet initialization parameter. As long as that class is a subclass of FrameworkLauncher the appropriate contract is fulfilled.</p>
<p>This means we can override some behaviour and delete the framework deployment folders upon startup:</p>
<pre class="java:nocontrols:nogutter">
@Override
public void init() {

super.init();

File servletTemp = (File) context.getAttribute("javax.servlet.context.tempdir");
File platformDirectory = new File(servletTemp, "eclipse");

if (platformDirectory.exists()) {
	deleteDirectory(platformDirectory);
}

}
</pre>
<p>Cool, so we need to export this as a jar file named dani-frameworklauncher.jar into the package project lib folder:</p>
<p><img alt="Export framework launcher" src="http://dani.calidos.com/img/2010/osgi-05/export-launcher.png" title="Export framework launcher" width="485" height="589" /></p>
<p>Next we change the servletbridge web.xml configuration parameter to load the new framework launcher:</p>
<p><code><br />
&lt;init-param&gt;<br />
&lt;param-name&gt;frameworkLauncherClass&lt;/param-name&gt;<br />
&lt;param-value&gt;com.calidos.dani.osgi.servletbridge.FrameworkLauncher2&lt;/param-value&gt;<br />
&lt;/init-param&gt;<br />
</code></p>
<p>To test, we can add a file onto the $APACHE_TOMCAT/work/Catalina/localhost/<webappname>/eclipse folder and restart Tomcat. Before this new launcher was in place, the file would be kept but now it is deleted alongside the rest. Any other methods can also be extended to customize the bridge behaviour without having to modify the launcher class.</p>
<p><a href="http://dani.calidos.com/img/2010/osgi-05/dani-framework-launcher.tar.gz">Here</a> you can download the framework launcher project, put it on the WEB-INF/lib folder alongside the servlet bridge and enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://dani.calidos.com/2010/01/04/components-on-the-server-5-better-unit-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automàticament Monster Lego</title>
		<link>http://dani.calidos.com/2009/12/27/automaticament-monster-lego/</link>
		<comments>http://dani.calidos.com/2009/12/27/automaticament-monster-lego/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 21:07:28 +0000</pubDate>
		<dc:creator>dani</dc:creator>
				<category><![CDATA[Catalan]]></category>
		<category><![CDATA[Entertainment]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[lego]]></category>
		<category><![CDATA[música]]></category>
		<category><![CDATA[the automatic]]></category>

		<guid isPermaLink="false">http://dani.calidos.com/?p=213</guid>
		<description><![CDATA[Fent unes reescoltes he trobat aquest genial remake del clàssic &#8216;Monster&#8217; dels galesos The Automatic. Genial!

]]></description>
			<content:encoded><![CDATA[<p>Fent unes reescoltes he trobat aquest genial remake del clàssic &#8216;Monster&#8217; dels galesos <a href="http://theautomatic.co.uk/">The Automatic</a>. Genial!</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/yrLumdqIrDM&#038;hl=es_ES&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/yrLumdqIrDM&#038;hl=es_ES&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://dani.calidos.com/2009/12/27/automaticament-monster-lego/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Components on the server (4): adding Tomcat support</title>
		<link>http://dani.calidos.com/2009/12/01/components-on-the-server-4-adding-tomcat-support/</link>
		<comments>http://dani.calidos.com/2009/12/01/components-on-the-server-4-adding-tomcat-support/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 08:42:31 +0000</pubDate>
		<dc:creator>dani</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Equinox]]></category>
		<category><![CDATA[java servlets]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://dani.calidos.com/?p=196</guid>
		<description><![CDATA[In this post, we examine what is needed to deploy OSGi in a regular Servlet Container using the Equinox Servlet Bridge. We also use the Servlet Bridge to deploy our OSGi cache using Tomcat and wrap it up all together in a standalone WAR archive.
Please read the previous installments to get up to speed and [...]]]></description>
			<content:encoded><![CDATA[<p>In this post, we examine what is needed to deploy OSGi in a regular Servlet Container using the Equinox Servlet Bridge. We also use the Servlet Bridge to deploy our OSGi cache using Tomcat and wrap it up all together in a standalone WAR archive.</p>
<p>Please read the <a href="http://dani.calidos.com/tag/osgi/">previous installments</a> to get up to speed and see the source used in this post.</p>
<p>Firstly, we need to setup some kind of project to hold all that is going in the WAR archive. This can be done using the WTP (Web Tools Project) or just as a regular project.</p>
<p>In this case we do it using a plain-vanilla resource project but feel free to use WTP as the basics are the same.</p>
<p>So firstly we create a resources project to hold the stuff, named &#8216;com.calidos.dani.osgi.cache.package&#8217; for instance.<br />
Secondly, we create the folder structure we need to hold all the files that need to reside in the final WAR webapp, so we create a WEB-INF folder to hold all the classes, libraries metadata and configuration.</p>
<p>We also know we need a web.xml file to define all the servlets this webapp declares. This is where the Equinox Servlet Bridge kicks in. It provides a Servlet that loads up the environment as well as forwards any HTTP requests onto our OSGi-managed Servlet instances.</p>
<p>We check the Equinox in a servlet container <a href="http://www.eclipse.org/equinox/server/http_in_container.php">article</a> and learn what the bridge Servlet is called, what parameters it can take and any other web.xml details we need.</p>
<p>For instance, we declare that the webapp service class is our BridgeServlet class:<br />
<code><br />
&lt;servlet-class&gt;org.eclipse.equinox.servletbridge.BridgeServlet&lt;/servlet-class&gt;<br />
&lt;init-param&gt;<br />
	&lt;param-name&gt;commandline&lt;/param-name&gt;<br />
	&lt;param-value&gt;-console&lt;/param-value&gt;<br />
&lt;/init-param&gt;<br />
&lt;init-param&gt;<br />
	&lt;param-name&gt;enableFrameworkControls&lt;/param-name&gt;<br />
	&lt;param-value&gt;true&lt;/param-value&gt;<br />
&lt;/init-param&gt;<br />
</code></p>
<p>We also add two parameters (more information and additional options can be found on the FrameworkLauncher servlet bridge class and the Equinox documentation).</p>
<p>Next, we need this special servlet itself. I prefer to check out the servlet from CVS and compile it myself but you can also find it <a href="http://download.eclipse.org/equinox/">here</a> (from the the Latest Release pick up the org.eclipse.equinox.servletbridge jar). In the case of using the source, the CVS connection data is the following:</p>
<p><code><br />
Method: pserver<br />
User: anonymous<br />
Host: dev.eclipse.org<br />
Repository path: /cvsroot/rt<br />
CVS Module: org.eclipse.equinox/server-side/bundles/org.eclipse.equinox.servletbridge<br />
</code></p>
<p>Once we import the project into Eclipse it looks like this:</p>
<p><img alt="Servlet bridge project" src="http://dani.calidos.com/img/2009/osgi-04/01-servlet-bridge.png" title="Servlet bridge project" width="300" height="181" /></p>
<p>As we can see, there are just three classes which compose the servlet, a special classloader and finally a class that launches OSGi.</p>
<p>If we import the project into our workspace, we have compiled classes in the bin/ folder of the project but we really want them neatly packaged as a jar file. Therefore, we right-click on the project to export as a JAR java package:</p>
<p><img alt="Servlet bridge JAR export" src="http://dani.calidos.com/img/2009/osgi-04/02-servlet-bridge-export.png" title="Servlet bridge JAR export" width="483" height="568" /></p>
<p>We take this JAR archive and save it in our package project WEB-INF/lib folder. We also check the composition of the file to make sure it includes all the classes we need.</p>
<p>This takes care of the plain webapp side of things so we move onto actually loading OSGi and what configuration it needs.</p>
<p>As mandated by Equinox we add a launch.ini file to clear and possibly override System properties (please see the source for details on that).</p>
<p>We then create an eclipse folder, which the servlet bridge expects to find the OSGi platform jar and any bundles (including ours).</p>
<p>We select all our project bundles, right-click and select the &#8216;Export&#8230;:Deployable plug-ins and fragments&#8217; option.</p>
<p>This leaves us with a list of bundles that compose our custom code:<br />
<code><br />
com.calidos.dani.osgi.cache.controller_1.0.0.beta.jar<br />
com.calidos.dani.osgi.cache.frontend.http_1.0.0.beta.jar<br />
com.calidos.dani.osgi.cache.log4jconfig_1.0.0.beta.jar<br />
com.calidos.dani.osgi.cache.provider.memcached_1.0.0.beta.jar<br />
com.calidos.dani.osgi.cache.provider.memory_0.0.1.dev.jar<br />
</code></p>
<p>Good, as we know, there are some standard and some special bundle dependencies we need as well. Let&#8217;s go through them by groups. We get a bunch of basic OSGi bundles we should include in most projects:<br />
<code><br />
org.eclipse.equinox.registry_3.4.100.v20090520-1800.jar<br />
org.eclipse.osgi.services_3.2.0.v20090520-1800.jar<br />
org.eclipse.osgi.util_3.2.0.v20090520-1800.jar<br />
org.eclipse.osgi_3.5.1.R35x_v20090827.jar<br />
</code></p>
<p>There are several options to obtain these bundles:</p>
<p>For expediency, we can go to our Eclipse installation folder and look for them in the &#8216;plugins&#8217; subfolder. We then copy them into our package &#8216;plugins&#8217; folder and there you go.</p>
<p>The second option is to get them from the <a href="http://download.eclipse.org/equinox/">Equinox distribution</a>.</p>
<p>Another option is to the prepackaged servlet bridge feature which can be picked from CVS as well:</p>
<p>Method: pserver<br />
User: anonymous<br />
Host: dev.eclipse.org<br />
Repository path: /cvsroot/rt<br />
CVS Module: org.eclipse.equinox/server-side/features/org.eclipse.equinox.servletbridge.feature</p>
<p>Once that is loaded onto our workspace, we open the feature.xml and select the &#8216;Export Wizard&#8217;  form the &#8216;Exporting&#8217; section. This lets us export these minimum bundles and generate both the deployment &#8216;feature.xml&#8217; file as well as the bundle listing (even though the wizard actually takes them from our Eclipse platform).</p>
<p>We also have some more dependencies related to doing HTTP and the logging platform:<br />
<code><br />
org.apache.log4j_1.2.13.v200903072027.jar<br />
org.eclipse.equinox.common_3.5.1.R35x_v20090807-1100.jar<br />
org.eclipse.equinox.http.registry_1.0.200.v20090520-1800.jar<br />
org.eclipse.equinox.http.servlet_1.0.200.v20090520-1800.jar<br />
org.eclipse.equinox.registry_3.4.100.v20090520-1800.jar<br />
</code></p>
<p>These can also be obtained from the Eclipse plugins folder or Equinox distribution folder. One should note that modifying the feature.xml taken from the Eclipse CVS repository, adding any  required plugins there and then running the Export Wizard. </p>
<p>Finally, we have two dependencies we need to pay special attention to:<br />
<code><br />
org.eclipse.equinox.http.servletbridge_1.0.200.200911180023.jar<br />
javax.servlet_2.4.0.200911240836.jar<br />
</code></p>
<p>In the first case, it&#8217;s a special minimal bundle that hooks the plain webapp servlet bridge with the OSGi &#8216;org.eclipse.equinox.http.servlet&#8217; standard component which publishes a servlet service onto the OSGi platform.</p>
<p>This are the details to get it from CVS:</p>
<p>Method: pserver<br />
User: anonymous<br />
Host: dev.eclipse.org<br />
Repository path: /cvsroot/rt<br />
CVS Module: org.eclipse.equinox/server-side/bundles/org.eclipse.equinox.http.servletbridge</p>
<p>We export it as a deployable plug-in and add it to the mix. We can also download it from the Equinox distribution site as well.</p>
<p>In the second case, this bundle contains the basic servlet classes and interfaces and I have found problems of class signatures when using 2.5 along with the servlet bridge so unless all is compiled against 2.5 the safest bet is to go with 2.4.</p>
<p>(Check <a href="http://www.eclipse.org/equinox/documents/quickstart.php">http://www.eclipse.org/equinox/documents/quickstart.php</a> for more info).</p>
<p>Next, Equinox requires an XML file to define some metadata about the loaded bundles and make our configuration easier. The file sits in a folder called &#8216;features&#8217; plus a subfolder with a reverse DNS name and is called feature.xml.</p>
<p>The structure is quite simple (though it can be created using the Eclipse Feature Export Wizard) and mainly holds a list of plugins, their version data and some more fields:<br />
<code></p>
<plugin<br />
         id="org.eclipse.osgi"<br />
         download-size="0"<br />
         install-size="0"<br />
         version="3.5.1.R35x_v20090827"<br />
         unpack="false"/>
<plugin<br />
         id="org.eclipse.osgi.services"<br />
         download-size="0"<br />
         install-size="0"<br />
         version="3.2.0.v20090520"<br />
         unpack="false"/><br />
</code></p>
<p>We complete the list with all our bundles, fully knowing that we can extend our environment on the fly once it&#8217;s loaded if we need it.</p>
<p>Next, we create the config.ini file which really tells equinox which of the bundles stated in the feature file to start, at which start level and lets us add even more bundles (though we need to specify where the actual file is located and the full filename in that case). It also lets us configure the environment pretty thoroughly.</p>
<p>The resulting config.ini file looks like this:</p>
<p><code><br />
#Eclipse Runtime Configuration File<br />
osgi.bundles=org.eclipse.equinox.common@1:start, org.apache.log4j@start, org.eclipse.osgi.util@start, org.eclipse.osgi.services@start, org.eclipse.equinox.http.servlet@start, \<br />
 org.eclipse.equinox.servletbridge.extensionbundle, \<br />
 org.eclipse.equinox.http.servletbridge@start, \<br />
 javax.servlet@start, org.eclipse.equinox.registry@start, org.eclipse.equinox.http.registry@start, org.eclipse.equinox.servletbridge.extensionbundle \<br />
 org.eclipse.equinox.http.servlet@start, org.eclipse.equinox.common@start, com.calidos.dani.osgi.cache.log4jconfig, \<br />
 com.calidos.dani.osgi.cache.provider.memcached@3:start, com.calidos.dani.osgi.cache.provider.memory, com.calidos.dani.osgi.cache.controller@4:start, \<br />
 com.calidos.dani.osgi.cache.frontend.http@5:start</p>
<p>osgi.bundles.defaultStartLevel=4<br />
</code></p>
<p>We decide not to start the in memory bundle as it only works reliably in a single instance deployment scenario. Otherwise, in a multiple server setup the in-memory cache data would become inconsistent.</p>
<p>Also, be sure to check the <a href="http://www.eclipse.org/equinox/documents/quickstart.php">Equinox quickstart guide</a> and documentation for more information.</p>
<p>Once all is is done, the project looks like this:</p>
<p><img alt="Finished package project" src="http://dani.calidos.com/img/2009/osgi-04/03-danicache-package.png" title="Finished package project" width="423" height="414" /></p>
<p>Time to right-click on the project and select &#8216;Export:Archive file&#8217; to save it in zip format and rename it to .war. Ready to deploy! Remember to access it using the URL /<WAR-name>/cache/<cache-key>. In web.xml the &#8216;-console 6666&#8242; parameter means that doing a telnet on port 6666 of the machine initiates a session within the OSGi console. <strong>WARNING: there is absolutely NO SECURITY so disable, firewall or ACL that port NOW.</strong></p>
<p>As usual, here you can find the <a href="http://dani.calidos.com/img/2009/osgi-04/danicache.tar.gz">source</a> and the<a href="http://dani.calidos.com/img/2009/osgi-04/danicache.war"> completed WAR</a> though they are one and the same.</p>
]]></content:encoded>
			<wfw:commentRss>http://dani.calidos.com/2009/12/01/components-on-the-server-4-adding-tomcat-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Idea: ens treiem de Google a veure que passa</title>
		<link>http://dani.calidos.com/2009/11/25/idea-ens-treiem-de-google-a-veure-que-passa/</link>
		<comments>http://dani.calidos.com/2009/11/25/idea-ens-treiem-de-google-a-veure-que-passa/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 19:58:41 +0000</pubDate>
		<dc:creator>dani</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Catalan]]></category>
		<category><![CDATA[Management]]></category>
		<category><![CDATA[Media]]></category>
		<category><![CDATA[bing]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[newscorp]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://dani.calidos.com/?p=194</guid>
		<description><![CDATA[La idea més absurda que he sentit últimament, de mans de News Corp i Microsoft. Arribar a un acord d&#8217;exclusivitat perque el cercador de MS Bing sigui l&#8217;únic que indexa les seves notícies.
Sense comentaris.
]]></description>
			<content:encoded><![CDATA[<p>La idea més absurda que he sentit últimament, de mans de News Corp i Microsoft. Arribar a un acord d&#8217;exclusivitat perque el cercador de MS Bing sigui <a href="http://www.pcworld.com/article/182849/News_Corp_and_Microsoft_Plot_Anti_Google_Pact_Says_Report.html">l&#8217;únic que indexa les seves notícies</a>.</p>
<p>Sense comentaris.</p>
]]></content:encoded>
			<wfw:commentRss>http://dani.calidos.com/2009/11/25/idea-ens-treiem-de-google-a-veure-que-passa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Components on the server (3): adding a HTTP frontend</title>
		<link>http://dani.calidos.com/2009/11/08/components-on-the-server-3-adding-a-http-frontend/</link>
		<comments>http://dani.calidos.com/2009/11/08/components-on-the-server-3-adding-a-http-frontend/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 15:06:40 +0000</pubDate>
		<dc:creator>dani</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Equinox]]></category>
		<category><![CDATA[java servlets]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[osgi]]></category>

		<guid isPermaLink="false">http://dani.calidos.com/?p=182</guid>
		<description><![CDATA[Welcome to the third instalment of our OSGi ABC tutorial. Please make sure you check both the 1st installment and the 2nd.
In this post, we will add another cache provider implementation to the mix as well as provide an HTTP front-end so the whole application can be tested.
First of all, let&#8217;s present a conceptual diagram [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the third instalment of our OSGi ABC tutorial. Please make sure you check both the <a href="http://dani.calidos.com/2009/08/24/components-on-the-server-an-osgi-mini-project/">1st</a> installment and the <a href="http://dani.calidos.com/2009/10/24/components-on-the-server-2-creating-the-first-bundles/">2nd</a>.</p>
<p>In this post, we will add another cache provider implementation to the mix as well as provide an HTTP front-end so the whole application can be tested.</p>
<p>First of all, let&#8217;s present a conceptual diagram of all the bundles and fragments involved so far.</p>
<p><img src="http://dani.calidos.com/img/2009/osgi-03/Pasted-Graphic-4.png" alt="Components diagram" /></p>
<p>Read on for more&#8230;</p>
<p><span id="more-182"></span></p>
<p>We start with providing the extra implementation. We will be making a memcached cache provider using the excellent memcached-spy java library (MIT licensed).</p>
<p>As usual, we create a new plug-in project and name it accordingly (com.calidos.dani.osgi.cache.provider.memcached). We firstly create source folders named &#8217;src&#8217; and &#8216;test&#8217; to hold any unit tests. Secondly, we download the spy memcached library from <a href="http://code.google.com/p/spymemcached/">here</a>.</p>
<p>We create a &#8216;lib&#8217; folder on the project to hold the library and modify the classpath of the plug-in so its code is able to see the memcached client classes (but not the bundle clients!). In the runtime section of the MANIFEST.MF editor we select the library like this:</p>
<img alt="Classpath for memcached bundle" src="http://dani.calidos.com/img/2009/osgi-03/Pasted-Graphic-1.png" title="Classpath for memcached bundle" width="269" height="234" />
<p>We also add the controller as a dependency so we can properly implement the CacheProvider service interface.</p>
<p>Secondly, we &#8220;copy&#8221; the unit testing code from the Memory cache bundle as all tests will be quite similar (as both bundles basically fulfil the same contract).</p>
<p>When doing all this work, we discover that the memcached system doesn&#8217;t have some functionality other cache systems might have. For instance, the number of elements in the cache can&#8217;t be counted (not easily and cheaply). Additionally, the cache can&#8217;t really be cleared without restarting all memcached instances.</p>
<p>So it makes sense to add the UnsupportedOperationException exception to the interface, acknowledging the fact that some cache implementations might not provide all the facilities of the service. Other strategies would be to use subclassing, specialise the providers, etc In this case, we opt for adding the exceptions where it makes sense. That is, in the case of the get and set operations we can&#8217;t allow a service that doesn&#8217;t let you manage its elements. That&#8217;s not our definition of &#8220;cache&#8221;.</p>
<p>We adjust the code and tests in the Memory cache if necessary to adapt to the new interface and implement the mecached client (the unit tests will need some modification).</p>
<p>The memcached bundle in the project view ends looking like this:</p>
<img alt="Memcached bundle project view" src="http://dani.calidos.com/img/2009/osgi-03/Pasted-Graphic.png" title="Memcached bundle project view" width="271" height="277" />
<p>We make sure tests pass on this new bundle, to do that we need to tweak the test code a little bit (to capture new exceptions being thrown).</p>
<p>Next, we register the Cache service proper from the core controller tracker like this:</p>
<pre class="java:nocontrols:nogutter">
controller = new CacheControllerCore();
controller.addCacheProvider(cacheProvider);

//we have a provider, we can start publishing our service
registration = context.registerService(Cache.class.getName(),controller,null);
</pre>
<p>Note that we register the Cache service once we have added the first provider backend. This ensures that at least a backend is available as soon as the main service is registered.</p>
<p>At this point, things are looking good on backend implementation bits so we can move to providing a nice HTTP front-end for the cache so it can be used.</p>
<p>Therefore, we create a new bundle and call it something appropriate, such as &#8216;com.calidos.dani.osgi.cache.frontend.http&#8217;. The main function of this bundle is to glue together a HTTP Service being made available in the context to the business logic Cache service (provided by the core controller bundle). In this manner, the controller bundle does not need to know anything about HTTP or Servlet implementation. Moreover, this bundle only uses the Cache and doesn&#8217;t know about providers or implementation details.</p>
<p>We need to import a few packages and require the equinox http bundle to be present:</p>
<img alt="Required plugins for http frontend bundle" src="http://dani.calidos.com/img/2009/osgi-03/Pasted-Graphic-3.png" title="Required plugins for http frontend bundle" width="359" height="174" />
<img alt="Required packages for http frontend bundle" src="http://dani.calidos.com/img/2009/osgi-03/Pasted-Graphic-2.png" title="Required packages for http frontend bundle" width="348" height="196" />
<p>As an HTTP provider we can use the one provided by Jetty (that is bundled with Equinox).</p>
<p>Following the same model that on the controller bundle, we register two trackers one for the http service and another for the Cache service. Once both are made available we can create the servlet and glue them together.</p>
<p>There is a method to register the servlet on a particular URL:</p>
<pre class="java:nocontrols:nogutter">
cacheHttpFrontend.setCacheService(cacheService);
httpService.registerServlet("/cache", cacheHttpFrontend, null, null);
</pre>
<p>From that moment onwards we are sending any &#8216;/cache&#8217; URLs onto the servlet instance, which will use &#8216;/cache&#8217;<rest-of-the-URL> as the key.</p>
<p>The servlet can implement the usual methods &#8216;doPost&#8217; and &#8216;doPut&#8217; to add data onto the cache and doGet to retrieve it. These method calls translate into the appropriate Cache calls. Any exceptions or null values can be translated into equivalent HTTP errors or responses. For example, we can return a 500 if an unrecoverable exception is thrown from the cache or a 400 if the path is simply &#8216;/cache&#8217; (which means no key is provided).</p>
<p>As a result of thinking in HTTP terms, we come to realise we need some metadata about the contents of the cache. At least, we need to store the mime type of the data so we can properly serve multimedia and any content other than text. Moreover, we could store some more metadata to tune up the cache, do automatic refreshing of the content, etc.</p>
<p>One possible strategy is to ask the Cache to store a POJO instance that holds the metadata as well as the cached content itself. This seems the simplest approach at the moment so this is what we do. The Cache is still a generic service and as long as we prefix the HTTP caches accordingly at the app level we will be fine with using it in other clients (and these might revert to MIME as their way to tag content types as well).</p>
<p>We can create a custom class POJO but that means that any backend that does POJO serialisation needs access to this class so it can create one. To avoid that class and encapsulation break we just use a plain vanilla serialisable class (Map). In any case, we need to make a not of this problem of the design so it is addressed in the future.</p>
<p>NOTE: it could be addressed in a simple enough manner. The cache entry object interface could be formalised and exported by the controller. In this manner, the front-end and the providers could make use of it and serialise it properly.</p>
<p>We create the cache entry Map instance in a simple enough manner:</p>
<pre class="java:nocontrols:nogutter">
HashMap<String, CharSequence> httpCacheEntry = new HashMap<String, CharSequence>(2);
httpCacheEntry.put(ENTRY_BODY_KEY, body);
httpCacheEntry.put(ENTRY_MIME_KEY, contentType);
cache.set(key,httpCacheEntry);
</pre>
<p>In this manner, we can recover the appropriate metadata (in this case MIME type) from the entry cache whenever we do a get() operation. This doesn&#8217;t mean we expect all requested entries to have that structure (principle of robustness), it just means we will use it if it&#8217;s there, setting the HTTP response MIME type accordingly.</p>
<p>With these enhancements and a few more small code refactors we can stabilise our code and call it a day. To summarise what we have done in this post:</p>
<ul>
<li>Created a new CacheProvider implementation using memcached</li>
<li>Added a bundle that provides a frontend of the system using HTTP and a Servlet</li>
<li>Devised a way to store some metadata on the cache</li>
<li>Done some code cleanup and refactoring.</li>
</ul>
<p>As usual, you can download the code <a href="http://dani.calidos.com/img/2009/osgi-03/OSGI-abc-3rd-installment.tar.gz">here</a>. Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://dani.calidos.com/2009/11/08/components-on-the-server-3-adding-a-http-frontend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Una mica de remember, no?</title>
		<link>http://dani.calidos.com/2009/11/01/una-mica-de-remember-no/</link>
		<comments>http://dani.calidos.com/2009/11/01/una-mica-de-remember-no/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 18:23:50 +0000</pubDate>
		<dc:creator>dani</dc:creator>
				<category><![CDATA[Catalan]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[duncan dhu]]></category>
		<category><![CDATA[pop]]></category>

		<guid isPermaLink="false">http://dani.calidos.com/?p=178</guid>
		<description><![CDATA[Simplement genial&#8230; 

Aquesta cançó sí que és un bon punt i final a la dècada dels 80 (l&#8217;album &#8220;Autobiografía&#8221; va sortir el 89)
]]></description>
			<content:encoded><![CDATA[<p>Simplement genial&#8230; </p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/c0B4PktEj3E&#038;hl=en&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/c0B4PktEj3E&#038;hl=en&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>Aquesta cançó sí que és un bon punt i final a la dècada dels 80 (l&#8217;album &#8220;Autobiografía&#8221; va sortir el 89)</p>
]]></content:encoded>
			<wfw:commentRss>http://dani.calidos.com/2009/11/01/una-mica-de-remember-no/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Components on the server (2): creating the first bundles</title>
		<link>http://dani.calidos.com/2009/10/24/components-on-the-server-2-creating-the-first-bundles/</link>
		<comments>http://dani.calidos.com/2009/10/24/components-on-the-server-2-creating-the-first-bundles/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 18:37:11 +0000</pubDate>
		<dc:creator>dani</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Equinox]]></category>
		<category><![CDATA[osgi]]></category>

		<guid isPermaLink="false">http://dani.calidos.com/?p=158</guid>
		<description><![CDATA[Hopefully you enjoyed the OSGi journey in its first installment.
Though simple and easy to understand, the first example does nothing out of the ordinary. It is far more interesting to start exploiting some of the basic features OSGi gets us &#8220;for free&#8221;.
For instance, we could begin by moving our first basic implementation into a separate [...]]]></description>
			<content:encoded><![CDATA[<p>Hopefully you enjoyed the OSGi journey in its <a href="http://dani.calidos.com/2009/08/24/components-on-the-server-an-osgi-mini-project/">first installment</a>.</p>
<p>Though simple and easy to understand, the first example does nothing out of the ordinary. It is far more interesting to start exploiting some of the basic features OSGi gets us &#8220;for free&#8221;.</p>
<p>For instance, we could begin by moving our first basic implementation into a separate &#8220;model&#8221; bundle and enhancing the interface so it can throw exceptions. For instance, an exception can be thrown when no implementations are available or cannot be contacted/operated.</p>
<p>Read the rest of the post for the implementation details&#8230;</p>
<p><span id="more-158"></span></p>
<p>We start by picking up the project as we left it and firstly export the controller service. Open the MANIFEST.MF and on the &#8216;Runtime&#8217; section we add the &#8216;com.calidos.dani.osgi.cache.controller&#8217; package. This will enable any bundle clients to use the cache.</p>
<p>Secondly we create and expose the backend interface we want the model bundles to implement. This is the &#8217;service&#8217; the bundles can offer that our controller is interested in and is able to use as engines to store the cache data. The interface obviously needs to mimic most if not all of the cache&#8217;s public service but we also add lower level functionality, etc. A trivial way to do that is to have the declared backend interface inherit from the public service one.</p>
<pre class="java:nocontrols:nogutter">
public interface CacheProvider extends Cache {

CacheProviderStatus getStatus();	

}
</pre>
<p>At the moment we define a method to get the status of the backend implementation, we return an object as opposed to a simple type to be able to enrich it in the future. If we place this interface in its own package we need to export it on the plug-in manifest as well.</p>
<p>We then the enhance  the original interface with exceptions, which give information about the cause of the problem yet they shouldn&#8217;t  break up too much encapsulation.</p>
<pre class="java:nocontrols:nogutter">
public interface Cache {
[...]
void init() throws CacheProviderException;
[…]
</pre>
<p>It is interesting to note that depending on how we leverage the component nature of OSGi some of these errors can actually be recoverable which is what makes exceptions shine in java.</p>
<p>When adding the exceptions all our tests don&#8217;t compile anymore so it&#8217;s time to fix them by for example adding the throws declaration into the test signature as at the moment there is squat we can do about exceptions being thrown and these should be test failures anyway.</p>
<p>Cool, so next we create a new project to hold the in-memory implementation of the cache on its own. So we create a new plug-in project and name it accordingly:</p>
<p><img src="http://dani.calidos.com/img/2009/osgi-02/osgi-2nd-new.png" alt="Imported packages" /></p>
<p>Good, next we move our code from the controller bundle onto the new one. First of all we need to modify the new plug-in MANIFEST.MF to reflect we depend on the CacheProvider and Cache interfaces:</p>
<p><img src="http://dani.calidos.com/img/2009/osgi-02/osgi-2nd-imported.png" alt="Imported packages" /></p>
<p>This means we can move the code from the controller onto this new provider bundle. Code compiles but our original tests don&#8217;t as the actual code has moved.<br />
We first need to change the BasicCacheController class so it implements the more low-level provider interface, time for some refactoring (we also rename the implementation class to something more indicative of its function). </p>
<p>The tests need passing and actually we can move the old test code onto the new component as it effectively tests the in-memory implementation perfectly well. The controller component will need more sophisticated code which we will do after we finish the cleanup. Once the test is moved and the refactoring is complete tests on the new plug-in pass.</p>
<p>Summarizing:</p>
<ul>
<li>Move BasicCache class to com.calidos.dani.osgi.cache.provider.memory bundle</li>
<li>Rename BasicCache to MemoryCache</li>
<li>Move test from old bundle onto com.calidos.dani.osgi.cache.provider.memory</li>
<li>Fix compiling errors on the test and rename it to MemoryCacheTest</li>
<li>Make MemoryCache implement the CacheProvider interface</li>
<li>Modify the MemoryCacheTest class to test the extended CacheProvider functionality</li>
</ul>
<p>hat&#8217;s cool so now it is time to work in the OSGi world to wire the components together. To do that we edit the memory cache provider Activator class to register the service once it is activated like this:</p>
<pre class="java:nocontrols:nogutter">
public class Activator implements BundleActivator {

private MemoryCache cacheService;
private ServiceRegistration registration;

<em>/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/</em>
public void start(BundleContext context) throws Exception {

cacheService = new MemoryCache();
cacheService.init();
registration = context.registerService(CacheProvider.class.getName(), cacheService, null);

}

<em>/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/</em>
public void stop (BundleContext context) throws Exception {

registration.unregister();
cacheService.clear();

}

}
</pre>
<p>On the start() method we are creating a memory cache object and then registering it under the CacheProvider interface class name. This means that any other bundle in the OSGi environment that is interested in cache services can use the service provided by this bundle.</p>
<p>This highlights an interesting problem. Is it better to be active like this code and init the service before registering it? Or should we wait for the consumer to do it and follow a more lazy-loading design? That is actually a good question and I have just decided to create self-contained services that are fully operative once published as I think that leverages OSGi better but YMMV.</p>
<p>Next, we need the main controller to wait for cache provider services. To do that we can create a ServiceTracker subclass on the controller component. On that subclass we implement two methods that are called whenever a cache provider is registered into the context and when it is unregistered. We also supply a constructor that stores the controller Activator so we can pass the services back.</p>
<pre class="java:nocontrols:nogutter">
public class CacheProviderTracker extends ServiceTracker {

protected Activator activator;
protected static Logger log = Logger.getLogger(CacheProviderTracker.class);

public CacheProviderTracker (BundleContext context, String clazz,
		ServiceTrackerCustomizer customizer, Activator activator) {

super(context, clazz, customizer);
log.debug("CacheProviderTracker built");
this.activator = activator;

}

@Override
public Object addingService (ServiceReference reference) {		

	CacheProvider cacheProvider = (CacheProvider) context.getService(reference);
	log.debug("Obtained a new CacheProvider service");
	return cacheProvider;

}

@Override
public void removedService(ServiceReference reference, Object service) {

	log.debug("A CacheProvider service has been removed from the context");
	context.ungetService(reference);		

}

}
</pre>
<p>We then modify the callbacks so the services are actually passed onto the Activator for their use. We need to create the appropriate methods in the Activator and we will fill them up next.</p>
<pre class="java:nocontrols:nogutter">
public void addCacheProvider(CacheProvider cacheProvider) {
}

public void removeService(CacheProvider service) {
}
</pre>
<p>Now we need to glue the backend provider with the controller so any Cache interface requests are passed onto CacheProvider services. To do that we create a new Cache interface implementation class in the controller bundle (appropriately named CacheControllerCore). The signature is something like:</p>
<pre class="java:nocontrols:nogutter">
public class CacheController implements Cache {
</pre>
<p>Which means we can offer this class as a Cache service once it&#8217;s ready. So when should we create a CacheControllerCore instance and offer it as a service? Well, whenever we have backend providers ready, not before. Therefore we now complete the addCacheProvider in the Activator method to do so:</p>
<pre class="java:nocontrols:nogutter">
if (controller==null) {
	controller = new CacheControllerCore();
	controller.addCacheProvider(cacheProvider);
} else {
	controller.addCacheProvider(cacheProvider);
}
</pre>
<p>This creates the instance only the fist time a provider is registered and after that just simply tells the controller class that an extra one is available. An added bonus of doing on a controller class instead of directly in the Activator is that we don&#8217;t want to overload the Activator with lots of logic. We also complete the removeService method. If in the future we deal with more services we will need a refactor as we would be dealing with a lot of handover methods from the activator class onto the core controller.</p>
<p>Okay, so what is the main goal of the CacheControllerCore then? To maintain a list of providers and hand over requests to them. As a convention and for greater flexiblity, it will send all messages to all services except for get, which will basically hand over the first object it finds.</p>
<p><strong>DESIGN WARNING</strong>: <em>in doing the implementation of the core controller we realise there are potential thread-safe potential problems in accessing the provider list. This is a cache and not an ACID system and we are looking for speed + 99.99% efficacy when changing providers and 100% efficacy when providers are stable. One should consider that in 99.9999999% of the time we are not changing providers mid-flight we wouldn&#8217;t want to compromise the overall efficiency of the architecture by the odd chance that two or three requests out of a million might actually get a miss from the cache where they should have had a hit or a cache set operation needs to be retried. Therefore, we implement a few basic checks on the core to minimize problems and provide graceful degradation of service in edge cases as opposed to meaningless null pointer exceptions.</em></p>
<p>Once this cautious but hopefully practical implementation is complete we can take a step back and review what we have done so far.</p>
<ul>
<li>We have defined a cache backend provider interface</li>
<li>Also created a simple provider implementation that stores data in memory</li>
<li>We have also glued the backend example to the core and refactored things a bit</li>
<li>The core now loops through available backends and is reasonably resilient</li>
</ul>
<p>Click <a href="http://dani.calidos.com/img/2009/osgi-02/OSGI-abc-second-installment.tar.gz">here</a> to download the code as it stands. More to come!</p>
]]></content:encoded>
			<wfw:commentRss>http://dani.calidos.com/2009/10/24/components-on-the-server-2-creating-the-first-bundles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Com passa el temps en el món de la indústria informàtica</title>
		<link>http://dani.calidos.com/2009/10/21/com-passa-el-temps-en-el-mon-de-la-industria-informatica/</link>
		<comments>http://dani.calidos.com/2009/10/21/com-passa-el-temps-en-el-mon-de-la-industria-informatica/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 18:24:26 +0000</pubDate>
		<dc:creator>dani</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Catalan]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Media]]></category>
		<category><![CDATA[accions]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[borsa]]></category>
		<category><![CDATA[market cap]]></category>

		<guid isPermaLink="false">http://dani.calidos.com/?p=153</guid>
		<description><![CDATA[Estava llegint l&#8217;article curtet de la BusinessWeek que comenta breument l&#8217;evolució de la situació d&#8217;Apple a nivell de borsa.
M&#8217;ha cridat l&#8217;atenció la següent llista del valor total de l&#8217;empresa (market cap):

Microsoft — $236 billion
Apple — $183 billion
Google — $176 billion
IBM — $162 billion
Cisco — $140 billion
HP — $115 billion
Oracle — $111 billion
Dell — $30 billion

Les [...]]]></description>
			<content:encoded><![CDATA[<p>Estava llegint l&#8217;<a href="http://www.businessweek.com/technology/ByteOfTheApple/blog/archives/2009/10/apple_stock_hit.html">article</a> curtet de la BusinessWeek que comenta breument l&#8217;evolució de la situació d&#8217;Apple a nivell de borsa.</p>
<p>M&#8217;ha cridat l&#8217;atenció la següent llista del valor total de l&#8217;empresa (<em>market cap</em>):<br />
<code><br />
Microsoft — $236 billion<br />
Apple — $183 billion<br />
Google — $176 billion<br />
IBM — $162 billion<br />
Cisco — $140 billion<br />
HP — $115 billion<br />
Oracle — $111 billion<br />
Dell — $30 billion<br />
</code></p>
<p>Les accions pujen i baixen, però a hores d&#8217;ara aquesta és la situació. Com passa el temps i com canvien les <a href="http://news.cnet.com/Beleaguered-Apple/2010-1071_3-281110.html">coses</a>, no? </p>
]]></content:encoded>
			<wfw:commentRss>http://dani.calidos.com/2009/10/21/com-passa-el-temps-en-el-mon-de-la-industria-informatica/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
