BUG Community

Welcome! Log In

kgilmer's Blog

R-OSGi, or how to call OSGi services remotely: Part I

When learning OSGi and discovering the power and simplicity of the service registry, a common thought is "Oh, I want to use this service remotely...how can I do that?"  And, well, currently the answer is you can't!   While there is active work going into remote services in R4.2, the existing OSGi specification only defines what happens inside of a single JVM instance.  But what if you really want to remote your OSGi? One sweet solution is R-OSGi

The BUG runs the Concierge OSGi framework, and happily it was written to support R-OSGi, but other frameworks should work as well.  The HOWTO will cover installing R-OSGi on the BUG and Virtual BUG, creating a service server and client.  A forthcoming post will detail service discovery and "seemless" distributed apps.  If you don't have or care about BUG, this HOWTO works great on regular Java on regular machines.  So, continue on to learn about R-OSGi!

1. SDK Setup

Make sure you have the latest version of the SDK.  Now download the "Remote OSGi" application from BUGnet into the SDK.  Your SDK should look something like this:

created on: 01/06/09

Now you'll notice that there are some compiler errors.  This is because R-OSGi requires the Event Admin, an OSGi service designed for pub/sub messaging.  Let's install the event admin application from BUGnet.  Search for and download Event Admin.  Your workspace should now look like this:

created on: 01/06/09

 

 

Now let's start the Virtual BUG and use the console to see if our new bundles are running.  Type 'bundles' at the Concierge prompt.  Here is what I got:

created on: 01/06/09

Great!  Now our Virtual BUG has R-OSGi!  Let's now install Remote and EventAdmin on the BUG.  Simply connect the BUG and download the apps.  Notice how the R-OSGi bundle does not show up in the applications folder on your BUG.  This is because it's not designated as a "BUG Application".  You can add the header "Bug-Bundle-Type: Application" to the manifest to make it show up.

2. A Remotable Service

Now R-OSGi is running both on the real BUG and the Virtual BUG.  Let's create a service, a bundle that exports the service, and a bundle that consumes the service.  We'll deploy the server to the BUG and consume it on the Virtual BUG.  To keep things simple, we'll create a service that has one method that returns a string.  Notice that we add one property to the service to let R-OSGi know that we want to make it accessible by remote clients.

Activator.java: package serviceproducer; import java.util.Dictionary; import java.util.Hashtable; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; import serviceproducer.pub.RemoteServiceDefinition; public class Activator implements BundleActivator { private ServiceRegistration sr; public void start(BundleContext context) throws Exception { Dictionary d = new Hashtable(); d.put("service.remote.registration", Boolean.TRUE); sr = context.registerService(RemoteServiceDefinition.class.getName(), new RemoteService(), d); } public void stop(BundleContext context) throws Exception { sr.unregister(); } }

RemoteService.java: package serviceproducer; import serviceproducer.pub.RemoteServiceDefinition; public class RemoteService implements RemoteServiceDefinition { public String getMessage() { return System.getProperty("os.arch"); } }

RemoteServiceDefinition.java: package serviceproducer.pub; public interface RemoteServiceDefinition { String getMessage(); }

The app is here on BUGnet: http://buglabs.net/applications/ServiceProducer  Now let's install the app on the BUG via the SDK.  After installing, type "services" at the OSGi console on the BUG.  You should see your new service registered:

(: services ... 31 serviceproducer.pub.RemoteServiceDefinition service.ranking = 0, service.remote.registration = true,

 3. A client that consumes a remote service.

Now let's create our client bundle.  Create a new BUG application and call it ServiceConsumer.  Again to keep things simple, we will not get fancy with our consumer. 

Activator.java: package serviceconsumer; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.util.tracker.ServiceTracker; import com.buglabs.application.IServiceProvider; import com.buglabs.application.RunnableWithServices; import com.buglabs.application.ServiceTrackerHelper; import serviceproducer.pub.RemoteServiceDefinition; public class Activator implements BundleActivator, RunnableWithServices { private ServiceTracker st; public void start(BundleContext context) throws Exception { st = ServiceTrackerHelper.createAndOpen(context, RemoteServiceDefinition.class.getName(), this); } public void stop(BundleContext context) throws Exception { st.close(); } public void allServicesAvailable(IServiceProvider serviceProvider) { RemoteServiceDefinition svc = (RemoteServiceDefinition) serviceProvider.getService(RemoteServiceDefinition.class); System.out.println("The Remote Message: " + svc.getMessage()); } public void serviceUnavailable(IServiceProvider serviceProvider, ServiceReference sr, Object service) { } }

Now you should be able to run a Virtual BUG and see this all working (locally).  In the log output you should see something like: "The Remote Message: i386"   Funny, I'm not using a 386.  Oh well.

This, as it is, will not work as remotable.  There are ways to add other things that will allow this bundle, as is now, to be able to consume a remote service.  This is the very powerful aspect of R-OSGi and will be covered in the next installment. 

For now we'll need to simply tell R-OSGi how to get our remote service.  Here is our new activator.  Notice we are tracking the Remote OSGi Service and a NetworkChannelFactory.

Activator.java: package serviceconsumer; import java.io.IOException; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; import org.osgi.framework.ServiceReference; import org.osgi.util.tracker.ServiceTracker; import com.buglabs.application.IServiceProvider; import com.buglabs.application.RunnableWithServices; import com.buglabs.application.ServiceTrackerHelper; import serviceproducer.pub.RemoteServiceDefinition; import ch.ethz.iks.r_osgi.RemoteOSGiException; import ch.ethz.iks.r_osgi.RemoteOSGiService; import ch.ethz.iks.r_osgi.RemoteServiceReference; import ch.ethz.iks.r_osgi.URI; import ch.ethz.iks.r_osgi.channels.NetworkChannelFactory; public class Activator implements BundleActivator, RunnableWithServices { private RemoteOSGiService remote; private URI connURI; private ServiceTracker st; public void start(BundleContext context) throws Exception { st = ServiceTrackerHelper.createAndOpen(context, new String [] {RemoteOSGiService.class.getName(), NetworkChannelFactory.class.getName()}, this); } public void stop(BundleContext context) throws Exception { st.close(); } public void allServicesAvailable(IServiceProvider serviceProvider) { remote = (RemoteOSGiService) serviceProvider.getService(RemoteOSGiService.class); connURI = new URI("r-osgi://10.10.10.10:9278"); try { RemoteServiceReference[] svcRef = remote.getRemoteServiceReferences(connURI, RemoteServiceDefinition.class.getName(), null); if (svcRef != null && svcRef.length > 0) { RemoteServiceDefinition svc = (RemoteServiceDefinition) remote.getRemoteService(svcRef[0]); System.out.println("Remote Service: " + svc.getMessage()); } else { System.out.println("Service unavailable."); } } catch (RemoteOSGiException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void serviceUnavailable(IServiceProvider serviceProvider, ServiceReference sr, Object service) { remote.disconnect(connURI); } }

Notice I'm connecting to my BUG which is connected via USBNET on a static IP address of 10.10.10.10.   9278 is the standard R-OSGi port.  In my service tracker, I get a reference to the remote service and then get a reference to a RemoteServiceDefinition implementation. 

But wait, there is a problem!  When the Virtual BUG starts you will notice an error message: ch.ethz.iks.r_osgi.RemoteOSGiException: No NetworkChannelFactory for r-osgi found. at ch.ethz.iks.r_osgi.impl.RemoteOSGiServiceImpl.connect(RemoteOSGiServiceImpl.java:564) at ch.ethz.iks.r_osgi.impl.RemoteOSGiServiceImpl.getRemoteServiceReferences(RemoteOSGiServiceImpl.java:620) at serviceconsumer.Activator.allServicesAvailable(Activator.java:41) at com.buglabs.application.ServiceTrackerCustomizerAdapter.doStart(ServiceTrackerCustomizerAdapter.java:69) at com.buglabs.application.ServiceTrackerCustomizerAdapter.addingService(ServiceTrackerCustomizerAdapter.java:94) at org.osgi.util.tracker.ServiceTracker$Tracked.track(ServiceTracker.java:815) at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:747) at ch.ethz.iks.concierge.framework.Framework.notifyServiceListeners(Framework.java:1227) at ch.ethz.iks.concierge.framework.Framework$BundleContextImpl.registerService(Framework.java:1916) at ch.ethz.iks.concierge.framework.Framework$BundleContextImpl.registerService(Framework.java:1937) at ch.ethz.iks.r_osgi.impl.RemoteOSGiActivator.start(RemoteOSGiActivator.java:93) at ch.ethz.iks.concierge.framework.BundleImpl.startBundle(BundleImpl.java:446) at ch.ethz.iks.concierge.framework.Framework$SystemBundle.setLevel(Framework.java:2468) at ch.ethz.iks.concierge.framework.Framework$SystemBundle.access$0(Framework.java:2428) at ch.ethz.iks.concierge.framework.Framework.startup(Framework.java:485) at ch.ethz.iks.concierge.framework.Framework.main(Framework.java:315)

What's happening here is that our ServiceTracker is running before R-OSGi is fully loaded.  Unfortunately in the current SDK (1.2.2) there is no way to fix this, because you can't set bundle start order.  However you can simply restart the bundle after everything has been loaded and it should work, like so:

(: stop 18 ServiceConsumer: active -> resolved (: start 18 Remote Service: armv6l ServiceConsumer: resolved -> active

And viola!  You've called a OSGi service on the BUG from a Virtual BUG.  Notice my machine is now an armv6l. 

In summary we've covered the basics of R-OSGi: calling a service remotely.  This, however, isn't as cool as it could be.  First of there seems to be more code than necessary to do all this, and I have to hardcode the connections from client to server.  Don't fret because R-OSGi has more tricks up it's sleave to relieve these problems!  Stay tuned for the next post in the R-OSGi HOWTO!

 

Post Comments

Add Your Comment!

Log in to leave a comment or Create an account

er ist arm, aber er ist nicht M��ll" wei?. ' , Und ich bin verdammt, wenn ich jeden Mann , darky [linlei0929] orWhite haben , warf auf ihn. Es gibt [linlei0929] nicht einen besseren Mann in dieser Grafschaft, oder Michael Kors outlet online sale warum
Wissen , und war Wie man Michael Kors shoes online gut mit Anderen speak und Stellen Sicher SIE Michael Kors purses , Kompliment switch intelligente und modische Menschen. WENN cheaps michael kors wallets Sie- out h ? Ngen mit Au -Modus Michael Kors outlet purses ? Enseiter , Werden Sie Auch
Machen michael kors sunglasses purse und Haben Eine inspirierende Pers ? Nlichkeit , michael kors watches so dass. sterben Menschen Beginnen m ? Gen 2014 michael kors watches Musikersuche und dr ? Ngen , nachdem your Michael Kors bags wholesale Linien zu Markt folgen . Seien SIE charismatisch Michael Kors outlet stores ,

Technology IST Eine Zwei Semester Nat��rlich , WENN Eine Markt auf Vollzeit -Basis ( ETWA Ein Jahr ) Aufgenommen . Sollten Sie new balance shoes Es vorziehen , k ? Nnen SIE bestimmte Kurse vor-Ort von zu Michael Kors Outlet nehmen ,
Technologie - Standards zu erf��llen und Administratoren helfen eV Christian Louboutin Outlet Store , ?hm positive Ver ? nderungen in ihrer Schulsysteme Machen . Mit ture religion sale H?hle oben genannten Anmeldeinformationen k ? Nnen SIE
Welt ZUSAMMEN mit michael kors beabsichtigte Botschaft . Good Design und Jobs klare Navigation helfen eV , Louis Vuitton mehr Die Bildungs ??-Technologie- Industrie , Druck Objektes besonders mit Dell p Moncler Outlet Online ? Dagogische

new balance outlet online

h¨¹bsch, und ich wei? verdammt gut, sie haben kein Whisky,

Michael Kors Outlet Handbags

Roggen Vaters ber¨¹hren bekam . " " Ashley Wilkes sagte,

michael kors

dass sie eine Menge von Landschaft und Musik. Ashley
Unter

gucci bags

sterben Masse Kosten senken Kann unterlassen . Und VOR Allem

Michael Kors Outlet Store

Nicht KOPIEREN your TV -Star sofort nach der Show, ?h

Michael Kors Outlet

Nicht bezeichnet einen Nachahmer zu unterlassen . Kurz ges?gt, ?hm

kate spade

Eine
theslightest macht flattern und kreischen . "" Nun, man

prada outlet

kann nicht ihre Schuld . Sie haben zu schie?en Cade

Louis Vuitton Store

im Bein . "" Nun , ich wurde lickered oder

chanel outlet online

ich h?tte es nicht getan ", sagte Stuart .
gesch?lt

Louis Vuitton Outlet

, bis wir sie aus. Alles, was sie werden wissen,

 

 

 

y LV handbags cheaper items from youIn your business plan, you should always provide a complete coach factory outlet store breakdown of the funds that you'd need and how it will be used Kate Spade Outlet Online as it relates to your business The first is an open loop method Michael Kors Outlet Store with an independent force control gadget that is positioned between the endofarmtooling and Michael Kors Outlet Online the robot
Whatever you buy, make sure that you do your research first Louis Vuitton USA But then again, having the ability to see virtually everything from the outside kate spade bags can make inspection a lot more handy for traveler as well as security michael kors bags online sale personnel Be particular also using the rates, interest and late charges, which have barbour sale been somewhat "hidden Use this list to determine if the contractor check all coach outlet online that apply The most recent virtual PBX attributes includes the phone services as coach outlet online store e

und sie erz?hlte uns dort w¨¹rde ein engagementannounced morgen Abend an der Wilkes Ball sein. " louis vuitton outlet " Oh, ich wei?, ¨¹ber gucci outlet online das, "sagte Scarlett in Entt?uschung. michael kors handbags "Das dumme Neffe von ihr, louis vuitton outlet
Die Zwillinge sahen einander jubelnd christian louboutin shoes outlet , aber mit einiger ¨¹berraschung michael kors . Obwohl sie consideredthemselves Scarlett louis vuitton purses beg¨¹nstigt Freier, sie nie zuvor louis vuitton outlet online Token dieser Gunst gewonnen michael kors outlet so Authentic Louis Vuitton Bags leicht .
ihr zwei. "" Sie ein Mauerbl¨¹mchen ! " Die Jungen lachten schallend . "Schau, Honig. Sie haben mir den louis vuitton handbags ersten Walzer-und Stu die letzte michael kors purses

I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon. Máy tập cơ bụng ab rocket

This celebration by famous Tusk charity fund Christian Louboutin Wedding Shoes , and designed to recognize and review in recent years, Jimmy Choo Shoes Store the organization to deal with the problem of African regional environment, human rights and other aspects of outstanding achievements. Christian Louboutin Shop And as one of the main sponsors of the foundation, prince William, of course, was invited to attend, Christian Louboutin Cheap and will be close to the end of the ceremony on behalf of the British royal family. At the same time, for the 31-year-old Kate princess, she gave birth to Prince George Jimmy Choo Boots after publicly for the first time to attend a similar celebration, and for the graceful princess, Shop Jimmy Choo Heels a celebration of the modelling natural mess. And it has been proved that the princess's unique taste is still worthy of praise.

Red bottom shoe designer Christian Louboutin Sale not only in Paris, France has a luxurious house, in the land of Egypt will have a unique villa. Christian Louboutin Men Not many people would buy villa in Egypt? The villa of Christian louboutin is really unique. Appearance, Red Bottom Shoes is a castle, indoor display is more simple. Mr Christian louboutin will come to the villa at least twice a year. Jimmy Choo Shoes Outlet Here on vacation, come here to have a dream, to count the stars in the night sky here, come here to look for the design inspiration of red bottom shoes. Christian Louboutin Discount Shoes Of course, it contains the first with your eyes closed can carry out the principles of economics. Although a designer product profit bonus is far too high, around sixty percent, Buy Christian Louboutin but also shows that a 30000 - yuan handbag, its cost is accounted for more than ten thousand yuan

Always with unique design and popular fashion shoes brand Christian louboutin Discount 2013 series bring brand-new visual impact feeling, Designer Women Shoes strong colors with all kinds of fashionable elements make every pair of shoes are unique and elegant and attractive. Christian louboutin Shoes Sale When this pair of shoes in front of you, you definitely will stop hurried footsteps watching this pair of shoes is unique. Because of such a pair of unique design and rugged red bottom shoes are you have never seen. Jimmy Choo Online Is still the enchanting myriad red soles, Manolo Blahnik Sale but very different uppers. Elegant fine shoes, shoe surface decorated with a strange decorations look like facebook. Fabulous and with a strong exotic, like from distant indians the mysterious elements, Louboutin Pumps only one eye, is enough to make you surprised.

It specifically designed for women perfume is full of fashion sense and lavish tastes, Jimmy Choo Shoes Online with delicate beautiful amber bottle design is a symbol of luxury brand noble, jimmy choo bridal also received the Tamara interest in antiques and modern high-quality goods. Many facets of the silkworm cocoon shape bottle design combined with the importance of traditional and contemporary design, presents the jiao Manolo Blahnik Shoes Sale drops of sexy female temperament, will embrace in perceptual balsam. The perfume bottle with silver and black cubic bottle cap highlights the fashion sense of design. Manolo Blahnik Store Online In addition to the bottle is full of modern glass art design elegant charm, the brand to use "the world's sexiest, Louboutin UK most luxurious leather" snakeskin pattern match with rose pink outer-package of embossing as a design element, make "jimmy choo uk perfume" has become the most fashionable sweet atmosphere

Italian brand of spike-heeled Giuseppe Zanotti shoes, Giuseppe Zanotti Online magnificent style and bold, not only favor by celebrity socialite for women's shoes, Jimmy Choo Sale brand launch of men's shoes for the first time last year, and soon became a fashionable and stylish men to be bestowed favor on newly, also let Aaron kwok, Jimmy Choo Sale UK show hit shoes, a dancer exquisite both in spike-heeled Giuseppe Zanotti shoes silver rivet, Manolo Blahnik High Heels let steps dance work more shiny. Italian designer spike-heeled Giuseppe Zanotti's fortune in 1985, Jimmy Choo For Sale he itself is stylish men, last year to build up the men's shoes, not only using multivariate rich material to make a change, Jimmy Choo Online Shop grab an eye and fact wear high tasseled loafers more popular.

Oakley sunglasses cheap sports professional Sun glasses with design and most dark-coated lenses, to fully block UV rays and harmful eyes Blu-ray, favored by professional sports players favor, especially in the ski and bike racing, players often wear. Discount oakley sunglasses can create an invisible layer of waterproof technology, owns the three excellent features. Easily prevent sweat, rain, Sun cream, skin oils, dirt and dust has a negative impact. These easy to clean cheap oakley sunglasses lenses, and compared with the normal lens, you can maintain the cleanliness of the longer and more clear water resistance show lens cheap oakley sunglasses for sale -coated permanent waterproof coating the whole process of how to waterproof.

Summer to should be particularly pay attention to the choice of shoes, Women Handbags Online but the stars have a favorite. Called star never far, LV bags Sale summer is a variety of banquet, cocktail party and parties "season", persisting some cool decorous grade follow sandal high, of course, is the top priority. LV Bags Online It today for you recommend a few pairs of women's favorite star Jimmy Choo sandals. When the metro-goldwyn-mayer (MGM) Jimmy Choo Heel company agreed to take comedy "Legally Blonde 2" (Legally Blonde 2), when people are in doubt, Robert this Sue mulberry Jimmy Choo Wedges Online is the target audience. But the 40 s company acquisitions and restructuring expert Jimmy Choo Pumps For Cheap who has attended with aflame mood in the UK premiere of the film

French brand Christian Louboutin Store New York will be located in the Meatpacking OuDeNan shoe store, covers an area of 1035 square feet, Discount Christian Louboutin Heels for the store design still has not yet been determined, but at least there is one thing certain, that the store will be laid on the designer's most iconic red carpet. Christian Louboutin Shoes Outlet In addition to men's shoes, also plans to introduce more men's products, such as men's bag. French brand Christian Louboutin, Louis Vuitton Bags Sale Christian Louboutin brand Alexis Mourot chief operating officer said, "although the men's shoes is only a small part in the fashion industry, Louis Vuitton Online Sale but we believe that the future it will be potential" .
here

We d like to have a lot of people have such problems: poor, Jimmy Choo Sale out of a short trip, at the feast the way back home, Jimmy Choo Shoes have to take a few clothes, but form a complete set of shoes is very bad. Buy Jimmy Choo How is bad to put inside the box, fear of extrusion deformation better shoes, larger and very take a place, can only every time out to find a contradiction by wearing shoes. So first saw this shoe bag Jimmy Choo shoe case, Christian Louboutin Heels I think it must be. The shoes package shoe case is slightly a little expensive, because just a bag of shoes also with the crocodile skin material. Priced at $2295, Buy Christian Louboutin Shoes said despondently did back to look for alternatives. Or a shoe bag price is more expensive than a pile of shoes also, it is not too can accept, away from home when I don't know what is the love of shoes or love this bag .
louboutin uk

» All comments
» Comments RSS

Powered by Community Engine

Top
Login
Close