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

Add jquery in Chrome console

Many a time, a page you are debugging doesnot have jquery. This simple js will add(or prompt you to overwrite) jquery to any page from chrome console.

javascript:if(!window.jQuery||confirm('Overwrite\x20current\x20version?\x20v'+jQuery.fn.jquery))(function(d,s){s=d.createElement('script');s.src='https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.js';(d.head||d.documentElement).appendChild(s)})(document);

Javascript: Convert Strings to Binary (and representing in a nerdy way!)

I follow those GoogleDevelopers Videos. Sometime back, in one of the presentations on GoogleIO, there was this interesting string of dots at the bottom of each page of the presentation. They looked like random big and small dots. A similar bunch of dots were also on the T-shirt of a presenter was wearing in another presentation. While it seemed something in the pattern, I could not find what it was. Finally, another presenter cleared the matter that those dots are just binary representation of "GOOGLEIO" (So much for advertizing Google IO, Impressive!).

So I wanna do it. Takes me back to days of those DSP classes at school. Nerdy me had to churn some old brain cells. I remember those first programming language classes in Pascal and C when you were asked to do fibonacci series and converting a binary string to ascii codes. That *experience* came handy here: Check it out!

Text to Binarize:
For those who came to copy the javascript code to convert string to binary, Here it is…

The easiest way to install docker on Ubuntu

Docker releases come out faster than ubuntu updating thier repositories. Docker mainitains a ppa. One can add the ppa key, and then add to sources.list.d and then update sources and then install lxc-docker. OR..
curl -sSL https://get.docker.com/ubuntu/ | sudo sh