Featured post

Docker setup for Liferay 7 with MySQL

Tuesday, 10 April 2018

Osgi Target, Property attributes and Multiple Implementations

Osgi Target and Property attributes

In Spring you can use @Qualifier to get the correct class for respective instances.
How can we achieve this in OSGI framework is the question?

With help of Osgi and it's SCR(Service Component Runtime) you can use dynamic instantiation of Declarative Services.
Correct implementation should be selected for each instance to develop and use IS-A relationships.

Developers can instantiate a interface with different implementations by utlizing "target" attribute inside @Reference annotation. All you need is to enable the classes to get it from SCR with "property" attribute inside @Component annotation.

Below is the sample code to achieve the described matter

Problem Statement : We need to convert Numbers from string in different formats like Integer, Double, Float etc. and use them in different osgi components.


We will create interface and two classes which will implement this interface and consume them in another component for demonstration purpose.



public interface OsgiTarget {

 public Number convert(String str);
}

As you can see we defined multiple properties inside @Component annotation.

@Component(property = {
        "osgi.target.example.integer=true",
        "osgi.target.example.integer.again=true" // Dummy entry for multiple target example, you can get this instance with this property as well
})
public class OsgiTargetIntegerImpl implements OsgiTarget {
 @Override
 public Integer convert(String str) {
  return Integer.valueOf(str);
 }
}

Here we have single property for the same.

@Component(property = "osgi.target.example.double=true")
public class OsgiTargetDoubleImpl implements OsgiTarget{

 @Override
 public Double convert(String str) {
  return Double.valueOf(str);
 }
}


Now we have basic converters with different implementations.
We will use them in our component to show how it's going to work.


@Component(immediate = true)
public class OsgiTargetExampleConsumer {
 
 // Osgi target property for OsgiTargetIntegerImpl
 @Reference(target = "(osgi.target.example.integer=true)")
 OsgiTarget osgiTargetInteger;
 
 // Osgi target property for OsgiTargetIntegerImpl with another property but same instance 
 @Reference(target = "(osgi.target.example.integer.again=true)")
 OsgiTarget osgiTargetIntegerAgain;
 
 // Osgi target property for OsgiTargetDoubleImpl
 @Reference(target = "(osgi.target.example.double=true)")
 OsgiTarget osgiTargetDouble;

 
 @Activate
 public void run() {
  System.out.println("__________________" + osgiTargetInteger.convert("21"));
  System.out.println("__________________");
  System.out.println("__________________" + osgiTargetInteger.convert("12"));
  System.out.println("__________________");
  System.out.println("__________________" + osgiTargetDouble.convert("1987"));
 }
}


In the above class we are using the interface with @Reference annotation to get the object from SCR with respective classes just by adding target . If you look closely, you can see one class can be invoked by multiple properties as well.

Output will be similar like this :



You are just done, Try & Enjoy the function.............:)

79 comments:

  1. Awesome and interesting article. Great things you've always shared with us. Thanks. Just continue composing this kind of post. Sloane Residences City Condo

    ReplyDelete
  2. Useful post.All the details are explained in clear manner.Thanks for sharing this good information. Stock Audit | Customer Reconciliation | Inventory Audit

    ReplyDelete
  3. I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. https://www.valsqld.com.au/

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Very helpful post. Very clear commentary and suggested phrasing are most impressive, and your generosity in sharing this explanation and example. Keep it up. Duplicate Payment Review
    Duplicate Payment Recovery
    Continuous Transaction Monitoring

    ReplyDelete
  6. Always so interesting to visit your site.What a great info, thank you for sharing. this will help me so much in my learning Real Estate Developments Mount Sophia

    ReplyDelete
  7. Great Post,really it was very helpful for us.
    Thanks a lot for sharing!
    I found this blog to be very useful!!
    JAVA training in Bangalore

    ReplyDelete
  8. Pretty good post. 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. Choose the right Handyman

    ReplyDelete
  9. I wish more authors of this type of content would take the time you did to research and write so well. I am very impressed with your vision and insight. gutter repair raleigh

    ReplyDelete
  10. I am doing a report on this subject. Your article is full of really useful information. I will make sure to come back to check out your posts for my next report. Residential Gutter systems

    ReplyDelete
  11. Thanks for the valuable information and insights you have so provided here... Affinity at serangoon price

    ReplyDelete
  12. Thank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our. 99 Years Leasehold Development

    ReplyDelete
  13. This means that net and gross leases can be evident in the same property and have different impact on the outgoings position for the landlord.stop my foreclosure

    ReplyDelete
  14. This is certainly additionally an exceedingly wonderful offer everyone truly qualified on the lookout with. It’s always not likely everyday there is chances read a little something. extremely well written article as . I will be sure to bookmark and return to read more of your useful information. Thanks for the post. I’ll certainly comeback.Phoenix AZ Real Estate

    ReplyDelete
  15. I think I didn't write clearly. Where supply is inelastic, rents and supply are relatively unaffected by raising property taxes. Where supply is elastic, rents reflect marginal costs, so the tax falls on the consumer as it would in other markets.hiring a ghostwriter cos

    ReplyDelete

  16. These real estate agents want to play with people till they are satisfied with it. I do not know why they do that. If they really want something from their consumer, they should have just let them know about the fact rather than doing such thing.Apartamentos en Venta

    ReplyDelete
  17. Excelr is providing emerging & trending technology training, such as for data science, Machine learning, Artificial Intelligence, AWS, Tableau, Digital Marketing. Excelr is standing as a leader in providing quality training on top demanding technologies in 2019. Excelr`s versatile training is making a huge difference all across the globe. Enable ?business analytics? skills in you, and the trainers who were delivering training on these are industry stalwarts. Get certification on "data science training institutes in hyderabad"and get trained with Excelr. Chip Eng Seng Real Estate Developer

    ReplyDelete
  18. We actually just updated our trust this year–we had created it years ago, but since then a lot has changed, including having another child, selling our house and buying another one, and the couple that we had designated as guardians getting a divorce–so it was definitely time. The relief of having it all up-to-date now is huge.apartments for rent in dubai

    ReplyDelete
  19. Very interesting. Property taxes are probably the way to go. I do not see much traction on this score.jacksonville locksmith

    ReplyDelete
  20. Great post on REITS! I have invested in a retirement home REIT, and it’s the only one of my investments that has not gone down since the market started doing badly. Sooo, best decision i think i could have made! Definitely interested in looking into another one though, since buying a house is not really an option for me right now. Thanks for sharing this!!raleigh roofing

    ReplyDelete
  21. I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. Real estate

    ReplyDelete
  22. Your commercial tenant failed to pay rent. You have heard that things are not going very well for them, but now it is apparent. As a property manager your duty and obligation is to resolve the issue as quickly as possible. When the tenant failed to pay by the due date they have effectively breached the lease and you are entitled to evict the tenant from the property. property management

    ReplyDelete
  23. You should mainly superior together with well-performing material, which means that see it: Car Removals

    ReplyDelete
  24. Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!Raingo Raleigh

    ReplyDelete
  25. I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post. Hats off to you! The information that you have provided is very helpful. Confidence Training Adelaide

    ReplyDelete
  26. You might comment on the order system of the blog. You should chat it's splendid. Your blog audit would swell up your visitors. I was very pleased to find this site.I wanted to thank you for this great read.Real Estate Malta

    ReplyDelete
  27. I really like this friend's website I have read a lot of useful information that you have written and shared I find you have thought a lot for the sharing articles that are very helpful for me and everyone personally. think sorichmond hill homes for sale

    ReplyDelete
  28. Many properties at that time that were costing less than this within inner London were returning over £1200.00 per month in rent.Forestry Mulching

    ReplyDelete
  29. A wide-area network, or WAN, connects and communicates with multiple local-area networks, or LANs. These LANs provide service to separate locations within a business’s overall communications structure, and the WAN is the system that oversees the entire structure at once.Home for sale in Bucks County

    ReplyDelete
  30. This comment has been removed by the author.

    ReplyDelete
  31. This comment has been removed by the author.

    ReplyDelete
  32. Can I simply say what a aid to search out somebody who actually is aware of what theyre talking about on the internet. You positively know tips on how to carry an issue to light and make it important. Extra individuals need to read this and perceive this aspect of the story. I cant consider youre no more popular since you undoubtedly have the giftproperty in bangalore

    ReplyDelete
  33. I really loved reading your blog. It was very well authored and easy to undertand. Unlike additional blogs I have read which are really not tht good. I also found your posts very interesting.Forett Bukit Timah

    ReplyDelete
  34. Content quality is your first concern however there are numerous different issues that you need to stress over.blog comment service

    ReplyDelete
  35. Most real estate investors fail within the first few months of trying to make a business enterprise out of real estate investing.  Real Estate

    ReplyDelete
  36. Thank you for the good writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! By the way, how could we communicate? property management in chennai

    ReplyDelete
  37. for example, paper publicizing, master advanced advertising offices will focus on web based promoting instead of "promoting organizations" who normally focus on TV, radio and print showcasing. Logo Design

    ReplyDelete
  38. Wonderful article, thanks for putting this together! This is obviously one great post. Thanks for the valuable information and insights you have so provided herechattanooga homes for sale

    ReplyDelete
  39. Your information is so useful, the tax issue has always bothered me, now I know what I need to do dowel jig reviews, thank you for sharing.Minivan & VAN Rental Nelspruit

    ReplyDelete
  40. The purchase price will be the price we expect to pay for a particular property. The initial monthly rent will be the price for which we expect to rent out the property. Dacor, Viking, Wolf, KitchenAid, Ovens Repair Near Me

    ReplyDelete
  41. I am impressed by the information that you have on this blog. It shows how well you understand this subject. Costa Del Sol Property For Sale

    ReplyDelete
  42. Your information is so useful, the tax issue has always bothered me, now I know what I need to do dowel jig reviews, thank you for sharing.Penrose showflat

    ReplyDelete
  43. I like your post. It is good to see you verbalize from the heart and clarity on this important subject can be easily observed... Mallorca concierge service mallorca

    ReplyDelete
  44. Really I enjoy your site with effective and useful information. It is included very nice post with a lot of our resources.thanks for share. i enjoy this post. contest property taxes

    ReplyDelete
  45. Accounting is the tracking of expenses minus revenue as products are being purchased, used or sold. Profit in business comes from repeat paid customers, customers that boast about your project or service, and that bring friends with them. Sonia Randhawa

    ReplyDelete
  46. If you are buying or selling a property, you should be known of its legal procedures,otherwise you may have problems regarding that property in further future. You can be cheated too. You can contact to the link below to avoid such kind of problem and proceed legally. They will help you to legally buy and sell property.Sonia Randhawa

    ReplyDelete
  47. This is thus a very interesting approach for obtaining chemical accuracy using methods that are sufficiently fast to study thousands of molecules. The caveat is that about 1000 high level calculations appears to be needed to train the method but perhaps more generally applicable parameter sets can be found using, for example, functional group identification.sonirw

    ReplyDelete
  48. I found it quiet interesting ,Thank you for posting the great content…I was looking for something like this…, hopefully you will keep posting such blogs.bat dong san ping land

    ReplyDelete
  49. With thanks with regard to the particular article i have been on the lookout with regard to this kind of advice on the net for sum time these days and so with thanks.bat dong san ping land

    ReplyDelete
  50. They're produced by the very best degree developers who will be distinguished for your polo dress creating. You'll find polo Ron Lauren inside exclusive array which include particular classes for men, women.Sonia Randhawa

    ReplyDelete
  51. I think I didn't write clearly. Where supply is inelastic, rents and supply are relatively unaffected by raising property taxes. Where supply is elastic, rents reflect marginal costs, so the tax falls on the consumer as it would in other markets.Dubai Hills Estate Golf Club

    ReplyDelete
  52. Can I simply say what a aid to search out somebody who actually is aware of what theyre talking about on the internet. You positively know tips on how to carry an issue to light and make it important. Extra individuals need to read this and perceive this aspect of the story. I cant consider youre no more popular since you undoubtedly have the gift.Dubai Hills Estate Golf Club

    ReplyDelete
  53. I liked that you mentioned removing all the items in your living room that may break during a professional carpet cleaning. My sister is thinking about hiring a carpet cleaning company, and we are looking for advice. I will let her know to remove all items from her living room before the process to make sure nothing breaks.Sonia Randhawa

    ReplyDelete
  54. Costa Blanca Property For Sale Very efficiently written information. It will be beneficial to anybody who utilizes it, including me. Keep up the good work. For sure i will check out more posts. This site seems to get a good amount of visitors.

    ReplyDelete
  55. I have bookmarked your website because this site contains valuable information in it. I am really happy with articles quality and presentation. Thanks a lot for keeping great stuff. I am very much thankful for this site.college essay brainstorming

    ReplyDelete
  56. Costa Del Sol Property For Sale This is my first visit to your web journal! We are a group of volunteers and new activities in the same specialty. Website gave us helpful data to work.

    ReplyDelete
  57. There are incredibly lots of details like that take into consideration. This is a excellent point to raise up. I provide you with the thoughts above as general inspiration but clearly you will discover questions like the one you mention in which the most critical factor will probably be doing work in honest great faith. I don?t determine if recommendations have emerged about such things as that, but Almost certainly your job is clearly identified as a fair game. Both boys and girls have the impact of merely a moment’s pleasure, for the rest of their lives. house for sale makati

    ReplyDelete


  58. Wow! This blog looks just like my old one! It as on a completely different topic but it has pretty much the same layout and design. Outstanding choice of colors!Sonia Randhawa

    ReplyDelete
  59. This is my first time i visit here and I found so many interesting stuff in your blog especially it's discussion, thank you. Learn more

    ReplyDelete
  60. I have bookmarked your website because this site contains valuable information in it. I am really happy with articles quality and presentation. Thanks a lot for keeping great stuff. I am very much thankful for this site.we buy houses florida

    ReplyDelete

  61. I definitely agree with the first tip because you have to make sure your home is ready before you list it in the market. Improvements are really important and staging as well will help in getting the best possible price when selling your home. After the improvements, it is also good to get a professional photographer to take photos of your home that will highlight the areas of your home and help to attract potential buyers. Awesome blog by the way and thanks for sharing.best florida online real estate school

    ReplyDelete
  62. You might comment on the order system of the blog. You should chat it's splendid. Your blog audit would swell up your visitors. I was very pleased to find this site.I wanted to thank you for this great read.best florida online real estate school

    ReplyDelete
  63. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. TwentyMilliseconds Loans

    ReplyDelete
  64. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. TwentyMilliseconds Loans

    ReplyDelete
  65. I like your post. It is good to see you verbalize from the heart and clarity on this important subject can be easily observed... North Pacific Property Management

    ReplyDelete
  66. Nice costumes for the fashion show I hope you'll win this challenge but if anytime you face animal costumes fashion challenge then I'll suggest you select realistic dinosaur costume for a fashion show. And thank you, author, for sharing this amazing content."
    sleep dentistry"

    ReplyDelete
  67. Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!Thanks.pokies online new zealand

    ReplyDelete
  68. Holders of student cards get discounted entry to both of these fantastic buildings. Rent in Budapest

    ReplyDelete
  69. Excellent effort to make this blog more wonderful and attractive. rates

    ReplyDelete
  70. I admire this article for the well-researched content & excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill.paint by number kits

    ReplyDelete
  71. Can I simply say what a aid to search out somebody who actually is aware of what theyre talking about on the internet. You positively know tips on how to carry an issue to light and make it important. Extra individuals need to read this and perceive this aspect of the story. I cant consider youre no more popular since.Sonia Randhawa

    ReplyDelete
  72. This is thus a very interesting approach for obtaining chemical accuracy using methods that are sufficiently fast to study thousands of molecules. The caveat is that about 1000 high level calculations appears to be needed to train the method but perhaps more generally applicable parameter sets can be found using, for example, functional group identification.Sonia Randhawa

    ReplyDelete
  73. Definitely agree with the first tip because you have to make sure your home is ready before you list it in the market. Improvements are really important and staging as well will help in getting the best possible price when selling your home. After the improvements, it is also good to get a professional photographer to take photos of your home that will highlight the areas of your home and help to attract potential buyers. Awesome blog by the way and thanks for sharing.Sonia Randhawa

    ReplyDelete
  74. Continue to maintain up the superb operate. I simply extra up your RSS feed to my MSN News Reader. In search of forward to reading more from you later on.Sonia Randhawa

    ReplyDelete
  75. whoah this blog is great i love reading your articles. Keep up the great work! You know, a lot of people are hunting around for this info, you could aid them greatly.Sonia Randhawa

    ReplyDelete


  76. I wish more authors of this type of content would take the time you did to research and write so well. I am very impressed with your vision and insight.Manchester Market

    ReplyDelete
  77. Concrete paving maintenance cost over time, is far less expensive than asphalt paving. Commercial Paving Colorado Springs CO

    ReplyDelete
  78. It's superior, however , check out material at the street address. repossessed property auctions

    ReplyDelete