Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Service Provider Extension in jar - URGENT  RSS feed

 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did a little test and created a quick service (MessageService with one non-abstract method "getMessage()") and then a provider, created the correct META-INF file and then went about starting on the client. That's where I got stuck. The only example I can find for LOCATING a provider of a service is "Service.providers(...)" and there is NO class "Service" in the entire 1.4 API. Looking in the community source, and runtime, the only such class is: "sun.misc.Service". And looking in the JavaDoc for that class, the text they use seems to imply that this IS the only way for ALL implementations of Java to get a service (even though it appears to be undocumented):

(Source="sun.misc.Service:JavaDoc")
A simple service-provider lookup mechanism...Service providers may be installed in an implementation of the Java platform in the form of extensions, that is, jar files placed into any of the usual extension directories.

Wow. That's pretty stupid. I mean, all this class appears to be doing (I'm pretty sure I am not allowed to post the actual code for this, but not sure) is asking the ClassLoader static method getSystemResources for any files of the name "<package>.<service_class_name>", and then it reads out from this all the non-commented lines and returns the loaded class from that. So technically it's easy to implement, but if we did that, what'd be the purpose of Services? Because then no one would know what to call in any given Java implementation to find services!!
Does anyone have the IBM Java VM? Can you check to see how it implements (if it does) the Service finding mechanism?
Am I completely wrong on this? For the spec I'm talking about (it's NOT JNDI service provider) check out:
http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider
(If it doesn't go to the Service Provider section, just scrol down on the table of contents and choose the section "Service Provider", and make sure you read ALL the sub-sections of that too)
Anxiously awaiting someone to tell me Sun did NOT do what it appears they did,
Robert
 
Ulf Jaehrig
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is (unfortunately) as you are saying. The Service class is sun.misc.Service. There is an RFE (Bug-ID 4640520), that the class should be promoted to java.util.
But to give you a little bit confidence, the IBM JDK 1.3 contains the sun.misc.Service class in its runtime too. It don't know what's with other JREs...
Ulf
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Ulf! Please, everyone! Vote for this, it's very useful:
http://developer.java.sun.com/developer/bugParade/bugs/4640520.html
(The vote is on the lower left, just click a radio button that says "Empty
Vote" and vote, it will change with the bug name instead of "empty vote" -
not intuitive)
Robert
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!