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...

How to Make a Local (Offline) Repository in Ubuntu / Debian

If you are in a place where you dont have internet (or have a bad one) You want to download .deb packages and install them offline. Each deb file is packaged as a seperate unit but may contain dependencies (recursively). apt-get automagically solves all the dependencies and installs all that are necessary. Manually install deb files one by one resolving each dependency would be tedious. A better approach is to make your own local repository. Before you actually make a repo, You need *all* deb files. You dont practically have to mirror all of the packages from the internet, but enough to resolve all dependencies. Also, You have to make sure, you are getting debs of the correct architecture of your system (i386 etc) # 1. make a dir accessible (atleast by root) sudo mkdir /var/my-local-repo # 2. copy all the deb files to this directory. # 3. make the directory as a sudo dpkg-scanpackages /var/my-local-repo /dev/null > \ /var/my-local-repo/Packages # 4. add the local repo to sour...