BUG Community

Welcome! Log In

kgilmer's Blog

Using ServiceTrackerHelper rather than the AST

 

While working on some tutorial material I pulled up the old SimpleGUI application.  It's pretty basic, but I've always been mildly troubled by the verbosity of the boiler plate code in the AbstractServiceTracker.  A while back I wrote some helper code that hides as much of that code as possible (for simple service tracking cases only) called ServiceTrackerHelper.  Here's the result:

Using AbstractServiceTracker (Activator.java):

public class Activator implements BundleActivator { private OneButtonAWTServiceTracker stc; private ServiceTracker st; /* * (non-Javadoc) * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) */ public void start(BundleContext context) throws Exception { //Create the service tracker and run it. stc = new OneButtonAWTServiceTracker(context); Filter f = context.createFilter(ServiceFilterGenerator.generateServiceFilter(stc.getServices())); st = new ServiceTracker(context, f, stc); st.open(); } /* * (non-Javadoc) * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext context) throws Exception { stc.stop(); } }

Using ServiceTrackerHelper (Activator.java):

public class Activator implements BundleActivator { private ServiceTracker st; public void start(BundleContext context) throws Exception { st = ServiceTrackerHelper.createAndOpen(context, "com.buglabs.bug.module.lcd.pub.IModuleDisplay", new GUIApp()); } public void stop(BundleContext context) throws Exception { st.close(); } }

And, there is no need to subclass AbstractServiceTracker!  I simply have my application class implement RunnableWithServices:

public class GUIApp implements RunnableWithServices, ActionListener { //... public void allServicesAvailable(IServiceProvider serviceProvider) { this.display = (IModuleDisplay) serviceProvider.getService(IModuleDisplay.class); createUI(); } public void serviceUnavailable(IServiceProvider serviceProvider, ServiceReference sr, Object service) { frame.dispose(); } }

That's it!  The current limitiation with this is that there is no support in the SDK to automatically generate code this way.

Post Comments

Add Your Comment!

Log in to leave a comment or Create an account

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. cơ bụng đẹp

Summer has arrived, and the scorching sun, your eyes can stand the test, in order to this window, you should choose a suitable for yourself cheap oakleys sunglasses. oakley new launch 2013 new fashion sunglasses, with the latest trends and meet the trend of fashion sports summer demand. discount oakley sunglasses fashion sunglasses this season introduced a variety of series, the atmosphere of the frame and lenses, color stable yet stylish, but also bring a sense of cool temperament, not only blocking the sun baked, but also perfect modification of the face, oakley sunglasses cheap is a perfect interpretation of current fashion trends.

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.

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

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.

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.

In our forum has many hot Topics like: don xin ly hon, meo vat hang ngay, blog hay, and luat doanh nghiep, So huu tri tue, Dien dan tam su gia dinh. More over, we have main service at topiclaw.com such as: cong bo thuc pham, cong bo my pham, dich vu cong bo thuc pham, thanh lap cong ty, giai the cong ty and Tu van dau tu nuoc ngoai. If anyone love to contact us please follow us Topiclaw on maxitalk, Media and Topiclaw HCM

For casual holiday vacation style, take a cue from Coach outlet store online and kick back in a cozy coach outlet shirt, black coach purses and shearling boots. Or a woman who knows how to carry herself and her style, not to mention a great bag. Pick up these http://www.ftccoachoutletonline.org/ coach outlet store online pieces for yourself, and take pleasure in it.Life According to coach factory outlet: If Coach outlet didn't talk about coach crossbody bags, it's almost like it didn't even happen. Now, we're partnering with http://www.usa-coachoutletonline.com/ coach outlet online http://www.cocoachfactoryoutlet.com/ coach factory Weeknd's hold. coach swingpack coach factory outlet coach wristletscoach factory online

Him tightly to coach factory outlet her coach outlet online locking, with an intense coach bags outlet strong, gentle and coach outlet overbearing stroked her the 丨 tongue, as if with the slightest punishment taste, coach factory online take away all of her breathing, waiting for her cheap coach bags fainting before the second, little by little, gave her the air.

Elevator kind of coach factory child enough, at the moment, in the helicopter, the real continuation of the down, lingering hot, seems insufficient to describe at the coach outlet online moment, that coach outlet online seven years beyond coach factory outlet the reach of the rain, miss.

What.Taileisha staring eyes, said sternly: coach outlet store online "you say who is tiger?P small children, less smoke!What do you see!"

A general turmoil.In the Alice sort, Taileisha hands pulled worry-free coach factory online brother face, worry-free brother a hand in Taileisha metal coach outlet online hollow breastplate, another hand is more directly into the following short metal helm.

After registration, there coach outlet canada are exactly a month before the school.During this period, worry-free brother with Azhisha advance coach purses outlet up coach handbags outlet to grudge practicing methods.

Carefree brother in Alice's belly, through coach factory outlet Alice know about the basic knowledge of war.Now tell Azhisha learn, is how coach outlet store online to exercise the body, developed chest you coach outlet sea.

Mump is coach factory outlet everyone can practice, but to cultivate the vindictive person, but only a small louis vuitton handbags part of.Just before the age of fifteen, relying on the tenacious will break through the limits of the human body, in the chest developed bucket Qihai, truly entered the ranks of vindictive cultivators.

» All comments
» Comments RSS

Powered by Community Engine