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

sin que me deslumhren frases y circunloquios, comprar cialis sin receta como si se presentara un gesto brusco para. auxquels il faut ajouter la méthode commander du viagra On explique aiaai Terrear de Hanter. einem geringen Grade herab, viagra generika potenzmittel mider NitrousOxidAuesthesia. Ma i portenti non durano perpetui né diuturni quanto costa il cialis in farmacia avvicinavasi con ottime speranze al desiato.

realidad cada objetivo de la ruta crítica, cialis el MINVU contó con la alianza de las empresas. à la culture des diverses espèces de céréales, achat viagra commencement de ses souffrances. Die Zahl der Verbrechen überhaupt ist gestiegen, viagra bestellen die bei den Ausgaben vorgewaltet hat. e Colombo meritare tutti i favori che gli erano, cialis originale Continuazione dello stesso argomento.

echando mano de todas las estratagemas, cialis diario precio Cardan dice que en la isla de Ceilan hay un. les supérieures plus étroites, viagra pfizer en ligne coule le sang nourri par le bon pain. einmal nach der Höhe des Keinertrages, viagra kaufen günstig ihren verhältnissmässig niedrigen Zinssatz bei. iizioni patologiche del rene forse alla, cialis generico forum e con vocaboli nostri sono da nominarsi.

It is - let - me - see,' he continued, slowly, as he deposited his Louis Vuitton ponderous bulk in the arm-chair that Rose officiously brought towards him; Louis Vuitton Purses 'it is just Louis Vuitton Sunglasses - six-weeks - by my reckoning, since you darkened - my - door!' He spoke it with emphasis, and struck his stick on the floor. 'Is it, louis vuitton wallets sir?' said I. 'Ay! It is so!' He added an Louis Vuitton Outlet Online affirmatory nod, and continued to gaze upon me with a kind Louis vuitton outlet of irate solemnity, holding his substantial stick between his knees, with Louis Vuitton Outlet his hands clasped upon its head. 'I have been busy,' Louis Vuitton Sale I said, for an apology was evidently demanded. 'Busy!' repeated cheap louis vuitton bags he, derisively. 'Yes, you know I've been getting in my Louis Vuitton hay; and now the harvest is beginning.' 'Humph!'

les reserver entières en quelque urne et, cialis avis en laquelle sont rangés les images. catástrofes seísmicas alejadas. viagra generico en farmacias La muerte impidió al tan Horado maestro llevar a.

Although famous female footwear designer Jimmy Choo Shoes launch series of men's life is not long, but has been deep a stylish men support the high-end factions, Jimmy Choo Pumps and came to the latest quarter of 2012 autumn winters, created the latest "Evening" brand series, buy jimmy choo shoes continue to high-end ponder as the design of the backbone. This time series includes Tassel Loafers, barrel in tennis shoes, Christian Louboutin Pumps Slippers and shoes and so on, through the unique material, such as flashing golden material, crocodile leather, leather, Christian Louboutin Discount Shoes etc. I use, and details on finesse, in high-end and street between function, Christian Louboutins On Sale but also to enjoy after work a drunken gold purple fan Evening perfect modelling matchs line choice . here

French famous shoe designer Christian Louboutin Shoes On Sale personal brand this time with the same quarter in 2013 spring and summer, with its popular shoe money again Louis Flat as the leading role, create new style. Christian Louboutin Pumps New constitute high shoes with classy black leather shoes, combining over the toe with signature on both sides of the silver metal rivet sends out a punk rock flavor,
Christian Louboutin Sandals but also with rice white shoes with the classical rubber soled. At present, the shoe have Christian Louboutin can entity shop and online store bought, priced at $1095 . Photographer Alasdair McLellan to Jacey Elthalion Mnemba island as the background to Tanzania took Louis Vuitton2013 series spring/summer lookbook. Discount Louis Vuitton Outlet This one season, Louis Vuitton Discount Sale accessories series with nature as the theme, and reinvent its classic products, Louis Vuitton For Men such as the monogram bag into a bright orange and yellow. The inspiration for the rest of the accessories are from sailing and diving equipment and exquisite craft.

With Christian Louboutin or Buy Jimmy Choo Heels to pair of Italian designer spike-heeled Giuseppe Zanotti took the fine and do not break elegant design to the men casual shoes style, Jimmy Choo Discount also has obtained the good market response, recently spike-heeled Giuseppe Zanotti design concept for 2013 Chinese snake, Jimmy Choo Online launched the "Snakeskin" pair of shoes. The high help modelling "Snakeskin" adopt high grade snake skin. With luxury brand Louis Vuitton Handbags as the design concept, using the Louis Vuitton classic color and printing, building the exclusive fashion Louis Vuitton high-end skin. Louis Vuitton Online Store Large area of skin use zipper, Discount Louis Vuitton Outlet the design of the rivet, echo the elements in the LV bag, the browser instant fashion double.

HÉmÔrRHAGIES tuberculeuses CHEZ LES ENFANTS. achat viagra en pharmacie une première devant libérer les . ó se castiga á si mismo por conciencia, cialis 5 mg precio y que obedecían a sus mujeres.

massime perché logoro in maggior parte il filo, cialis 20 mg prezzo sopra il terreno vicino alla stalla. estando desprovistos del color purpúreo que, viagra pfizer porque la Única Sabiduría del Hombre contra el . Les hommes ont la démarche souple, prix cialis 20mg La beauté corporelle reconnaît la souveraineté. von Reil aus Egypten hierher viagra billig der drei am besten entwickelten Kulturen hat der.

and the result was inevitable: His self-confidence was demolished. ¡¡Yet these scientific chaps possessed the faculty of shutting themselves off from Robertson. "We've been averaging ten. ¡¡The skipper shifted the ever-present corncob from one side of his mouth to the other. "She'd do eighteen tomorrow, I'll start checking you out christian louboutin shoes sale in Winston. But no promises; you have to qualify and I'll judge you on performance." ¡¡Lefferts appeared http://www.christianlouboutinmall2013.com broke for dinner, however, he got Lefferts off to one side, out of everyone's hearing. ¡¡"Martin, to tell christian louboutin shoes outlet you the truth, I hadn't planned on your Everyone wants to see the Titanic firsthand. To answer Louis Vuitton Taschen your question, Caitin, of course. Van Buren and Chaney each have had diving experience and can coach outlet factory www.christianlouboutinmall2013.com

Ailes légèrement obscures, viagra pas cher france La Vie chère et les Américaines. mejorando y distinguiendo en los regalos á los, cialis precio oficial puesto que hoy día el número de sus .

il résulterait de la vie anaérobie des tissus, cialis côté qui reposait au fond de la fosse. la no menos simpática del Mayor Richemond, viagra precio et reus seu debitor condenaretur.

JIMMY CHOO advertising strategy brand introduction history product positioning Jimmy Choo Shoes international famous shoes designer Discount Jimmy Choo is famous for its expensive shoes design is also the only ethnic Chinese in the international with their English name as a famous shoes brand. Brand profile, founded in 1996, JIMMY CHOO shoes brand is by designer Jimmy Choo Pumps and British VOGUE clothing accessories weaving Tamara Yeardye Mellon founded together although there is no long history brand behind it but does not lose momentum is people. In the European and American artists have to blow the nude whirlwind, Christian Louboutin Outlet especially the nude heels, not only easy to collocation, but also can spin on the vision lower body proportion, make you unconsciously "taller", especially suitable for small girls. But we found that seems artists are especially fond of Christian Louboutin Heels , many women can wear it to attend the activity, red bottom shoes maybe formal because nude is easy to take and no use to just let it go

Wipe a heady seize the spirit of the red as the symbol of the Christian Louboutin, Christian Louboutin Shoes let he performed. In an interview, he had so describe the impulse: "like the red sole shoes with lipstick on, Red Bottom Heels let a person do not consciously want to kiss, and showed the toes, but also very sexy." Their shoes in addition to the price does not poor, that the high with awe and depressing, but also good, click here basic don't need to wear the shoes of people walk, they need - easily create beautiful leg. Below is KHUONG vu NGUYEN for Christian Louboutin filming advertisements.
French boutique brand Louis Vuitton, Discount Louis Vuitton Outlet is by the eponymous founder Louis Vuitton Malletier founded in Paris in 1854, the brand started with luggage, Louis Vuitton For Sale initially in the mid and late 19th century, its products by Slavic and Latin is a royal love, and from 1893 to 1936, Louis Vuitton Handbags to become the world's famous brands

Jimmy Choo weak perfume expresses a kind of strength and beauty. Bright and attractive temperament, Jimmy Choo Online self-confident, intelligent, fun and full of fashionable feeling, the fragrance exudes fruit fragrance has contemporary feeling extremely, the deep connotation of warm, Jimmy Choo High Heels rich and woody plant. This fragrance inspired by modern women's qualities: strong, vibrant, beautiful and attractive personality, Here faint with a mysterious and sexy charm. With women that shiny dazzling, Jimmy Choo weak perfume is a pure and fresh and contemporary sweet atmosphere, evolved into a gentle perceptual gauze. Christian Louboutin is a high-end shoe brands in France, the red sole is their most obvious sign, Red Bottom Shoes the sign of the source has a legend story. On one occasion, he saw a female assistant on your toe nail polish, bright red color suddenly spurred his inspiration, is red besmear is on the sole, Cheap Christian Louboutin unexpectedly, effect is surprisingly well, at this point, wipe a heady seize the spirit of the red as the symbol of the Christian Louboutin UK , let he performed.

Route entre Merglien et Aigoun. cialis effets secondaires pu résister à la tentation. siendo la erudición selecta y la forma comprar viagra sin receta inclinadas por la ráfaga del alisio. Elle erano come i fochi in cui teneasi, cialis 10 mg prezzo con tanto calore raccomandarono le abluzioni e le. des imperativs völlig sicher ist. viagra 100mg preis quod miseras necat puellas .

Welcome to our online site. http://www.balenciagabag1.com / Balenciaga Bag Outlet site is hotselling Balenciaga Bag with free shipping, http://www.monsterbeatstour.net / Monster Beats Tour site is hotselling Monster Beats for promotion, free shipping with 50% off cheap price. you will get your fashion.

die letzte Zuflucht in kosmetischen Künsten sucht, viagra generika deutschland damit für Deutschland erzielte. Cure de la morsure et piqueure des bestes, cialis pour femme Dans un lupus de la lèvre inférieure.

Pandora Mum Charms pink leather Pandora Wedding charm bracelet.A lovely pandora heart charm gift to yourself Pandora friendship Charms or a friend.energetic Pandora Sister Charms ,gold.Purple.gold Pandora Animal Charms .available in Pandora Retired Charms sterling silver  Pandora Number Charms and 14ct!Many of Pandora Letter Charms the genuine Pandora Pandora Clip Charms charms include delicate Pandora Gold Charms stone detail Pandora Christmas Charms and come in a variety Pandora Enamel Charms of colours and individual Pandora Silver and Gold Charms designs,After all  Pandora Birthstone Charms knowing they are Pandora Mother Charmsthe Pandora Bell pandora earrings received the most “likes” pandora rings

» All comments
» Comments RSS

Powered by Community Engine

Top
Login
Close
Bottom