Skip to main content

OSGi: Starters Guide for Install, Update and Refresh Bundles

In OSGi, with a Bundle you could Install, Update or Refresh. There is a subtle difference in all these three. Just enough for a beginner to entangle the mind. To help, This post gives an a practical insight. I recorded the commands and thier out puts.

To Begin with, Install puts a bundle in the framework runtime. It also records the file location (on FileSystem or URL). It doesnot start or resolve dependents on it.

sarath@sar-akshaya:~/zbin/equinox$ ls
bundles  equinox.jar  org.eclipse.osgi_3.4.0.v20080605-1900.jar
sarath@sar-akshaya:~/zbin/equinox$ ls bundles/
FirstBundle-1.0.0.jar   SecondBundle-1.0.0.jar  
sarath@sar-akshaya:~/zbin/equinox$ java -jar equinox.jar -console

osgi> ss

Framework is launched.

id State       Bundle
0 ACTIVE      org.eclipse.osgi_3.4.0.v20080605-1900

osgi>  install file:bundles/FirstBundle-1.0.0.jar
Bundle id is 1

//Try starting 
osgi> start 1
org.osgi.framework.BundleException: The bundle could not be resolved. Reason: Missing Constraint: Import-Package: com.so.samples.osgi.second; version="0.0.0"
 at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:305)
 at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:265)
 at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:257)
 at org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._start(FrameworkCommandProvider.java:257)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.execute(FrameworkCommandInterpreter.java:150)
 at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(FrameworkConsole.java:302)
 at org.eclipse.osgi.framework.internal.core.FrameworkConsole.console(FrameworkConsole.java:287)
 at org.eclipse.osgi.framework.internal.core.FrameworkConsole.run(FrameworkConsole.java:223)
 at java.lang.Thread.run(Thread.java:619)

osgi> diag 1
file:bundles/FirstBundle-1.0.0.jar [1]
  Direct constraints which are unresolved:
    Missing imported package com.so.samples.osgi.second_0.0.0.

osgi> install file:bundles/SecondBundle-1.0.0.jar
Bundle id is 2

osgi> ss

Framework is launched.

id State       Bundle
0 ACTIVE      org.eclipse.osgi_3.4.0.v20080605-1900
1 INSTALLED   com.so.samples.osgi.FirstBundle_1.0.0
2 INSTALLED   com.so.samples.osgi.SecondBundle_1.0.0

//Try starting Again
osgi> start 1
org.osgi.framework.BundleException: The bundle could not be resolved. Reason: Missing Constraint: Import-Package: com.so.samples.osgi.second; version="0.0.0"
 at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:305)
 at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:265)
 at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:257)
 at org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._start(FrameworkCommandProvider.java:257)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.execute(FrameworkCommandInterpreter.java:150)
 at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(FrameworkConsole.java:302)
 at org.eclipse.osgi.framework.internal.core.FrameworkConsole.console(FrameworkConsole.java:287)
 at org.eclipse.osgi.framework.internal.core.FrameworkConsole.run(FrameworkConsole.java:223)
 at java.lang.Thread.run(Thread.java:619)

osgi> diag 1
file:bundles/FirstBundle-1.0.0.jar [1]
  Direct constraints which are unresolved:
    Missing imported package com.so.samples.osgi.second_0.0.0.

Refresh resolves dependencies. If run on a bundle with an active dependent, it refreshes the dependents too. If a bundle has an activator, It stops and restarts.

osgi> refresh 1

osgi> ss   

Framework is launched.

id State       Bundle
0 ACTIVE      org.eclipse.osgi_3.4.0.v20080605-1900
1 RESOLVED    com.so.samples.osgi.FirstBundle_1.0.0
2 RESOLVED    com.so.samples.osgi.SecondBundle_1.0.0

osgi> start 1
Started Bundle:From Second 1.0.0

osgi> shutdown
Stopped Bundle:From Second 1.0.0

osgi> close

sarath@sar-akshaya:~/zbin/equinox$ java -jar equinox.jar -console

osgi> Started Bundle:From Second 1.0.0

osgi> ss

Framework is launched.

id State       Bundle
0 ACTIVE      org.eclipse.osgi_3.4.0.v20080605-1900
1 ACTIVE      com.so.samples.osgi.FirstBundle_1.0.0
2 RESOLVED    com.so.samples.osgi.SecondBundle_1.0.0

osgi> packages 1
No exported packages

osgi> packages 2
com.so.samples.osgi.second; version="0.0.0"
  file:bundles/FirstBundle-1.0.0.jar [1] imports

//make change 1.0.1
osgi> install file:bundles/SecondBundle-1.0.0.jar        
Bundle id is 2

osgi> stop 1
Stopped Bundle:From Second 1.0

osgi> start 1
Started Bundle:From Second 1.0

osgi> refresh 2
Stopped Bundle:From Second 1.0
Started Bundle:From Second 1.0

osgi> stop 1
Stopped Bundle:From Second 1.0

Update just RE-puts the bundle into framework. This is slightly different from install, that you can ONLY update a bundle with same [Bundle-SymbolicName:Bundle-Version] combination. Meaning-- You cannot Install a same jar (same uri or different) or an updated jar(new code) with the same combination. You only have to UPDATE it in the framework. Update can be done by the BundleId in the runtime. To update with a Different jar (uri is different)

osgi> update 2 

osgi> refresh 2

osgi> Stopped Bundle:From Second 1.0
Started Bundle:From Second - 1.0.0 update

osgi> update 1
Stopped Bundle:From Second - 1.0.0 update
Started Bundle:From Second - 1.0.0 update

osgi>update 1 file:bundles/newfirst.jar //with same symname:version combo
Stopped Bundle:From Second - 1.0.0 update 
Started Bundle:From Second - 1.0.0 update 
Hope this helps.. Read more on Osgi

Popular posts from this blog

Powered By

As it goes, We ought to give thanks to people who power us. This page will be updated, like the version page , to show all the tools, and people this site is Powered By! Ubuntu GIMP Firebug Blogger Google [AppEngine, Ajax and other Apis] AddtoAny Project Fondue jQuery

Decorator for Memcache Get/Set in python

I have suggested some time back that you could modularize and stitch together fragments of js and css to spit out in one HTTP connection. That makes the page load faster. I also indicated that there ways to tune them by adding cache-control headers. On the server-side however, you could have a memcache layer on the stitching operation. This saves a lot of Resources (CPU) on your server. I will demonstrate this using a python script I use currently on my site to generate the combined js and css fragments. So My stitching method is like this @memize(region="jscss") def joinAndPut(files, ext): res = files.split("/") o = StringIO.StringIO() for f in res: writeFileTo(o, ext + "/" + f + "." + ext) #writes file out ret = o.getvalue() o.close() return ret; The method joinAndPut is * decorated * by memize. What this means is, all calls to joinAndPut are now wrapped (at runtime) with the logic in memize. All you wa...

Faster webpages with fewer CSS and JS

Its easy, have lesser images, css and js files. I will cover reducing number of images in another post. But If you are like me, You always write js and css in a modular fashion. Grouping functions and classes into smaller files (and Following the DRY rule, Strictly!). But what happens is, when you start writing a page to have these css and js files, you are putting them in muliple link rel=style-sheet or script tags. Your server is being hit by (same) number of HTTP Requests for each page call. At this point, its not the size of files but the number server roundtrips on a page that slows your page down. Yslow shows how many server roundtrips happen for css and js. If you have more than one css call and one js call, You are not using your server well. How do you achieve this? By concatinating them and spitting out the content as one stream. So Lets say I have util.js, blog.js and so.js. If I have a blog template that depends on these three, I would call them in three script tags. Wh...