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

One page Stock

Alright.. That was a long absence. The whole last week I dint blog. I dint go away. I was "occupied". I was learning stock trading. Its very fascinating. I have a good weeeked blog for you all. Here is my experience. I can literally hyper-link every word from the following paragraphs, but I am writing it as simple as I can so you can look up the italicised words in wikipedia . I got a paper trading account from a brokerage firm . You need one brokerage account first. Then it can be an Equity account where all your money is yours or a Margin account , where some of the money is lent by the brokerage firm. Then I get Buying power , which is the dollor value of how much stocks you can buy. I can make profit by simple rules. Buy when Price is low. Sell when price is high. There is another more intersting way of earning money. Selling short . Thats when price is not high, per say, but when are confident that the price WILL go down. then buy back when its lowest. This is what