The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

schildmeijer (15) [Avatar] Offline
#1
The third import in Circle.java is "import org.foo.shape.SimpleShape;"

That is only possible (as far as i know) if the .jar file containing the interface SimpleShape is in the classpath/buildpath during the build step(?)

So my question is then: is it necessary that SimpleShapes bundle is installed in the osgi framework, in order to get Circle to run?
stuart.mcculloch (29) [Avatar] Offline
#2
Re: Chapter 4. paint example
In the provided example you will need to install the bundle providing the SimpleShape interface before the Circle bundle will resolve properly.

In practice this interface could be provided from any bundle - you could even have more than one bundle providing it and the OSGi framework will pick one to be the exporter. See section 4.5.5 for a short discussion about this.

So you could re-work the example to add the SimpleShape interface to the main paint bundle, or even add it to every shape bundle. Then you wouldn't need the separate API bundle anymore.
schildmeijer (15) [Avatar] Offline
#3
Re: Chapter 4. paint example
Thanks for this information.

(I still have one unsolved issues regarding this left)
What I cant seem to understand is this:
When you compile Circle.java the SimpleShape interface must be accesible. (eg. the jarfile containing the interface is addded to the classpath).
So my questions is: Isnt this the only thing necessary for the class file (Circle.class) to have runtime access to the SimpleShape interface?
stuart.mcculloch (29) [Avatar] Offline
#4
Re: Chapter 4. paint example
> What I cant seem to understand is this:
> When you compile Circle.java the SimpleShape
> interface must be accesible. (eg. the jarfile
> containing the interface is addded to the
> classpath).
> So my questions is: Isnt this the only thing
> necessary for the class file (Circle.class) to have
> runtime access to the SimpleShape interface?

remember that compilation is separate from deployment, and that you still need access to the interface classes at runtime (Java does not statically embed interfaces inside the binary bytecode)

another way to look at it is:

compile configuration = javac -cp shape.jar <circle-sources> => circle.jar

deploy configuration = OSGi framework + install shape.jar + install circle.jar

in the provided example we actually start a new process to deploy the OSGi bundles, so while it looks like it's all part of the same build it is actually running the framework outside of Maven and does not inherit its classpath

btw, you might want to look at the new (simpler) Ant-based build over at:

http://osgi-in-action.googlecode.com/files/osgi-in-action-20090225.zip

which now has the deploy as a separate step - first you build the example using "ant" then you deploy it using "java -jar launcher.jar bundles", where "bundles" is the folder containing the compiled example bundles.
schildmeijer (15) [Avatar] Offline
#5
Re: Chapter 4. paint example
aha, thanks alot.

"Java does not statically embed interfaces inside the binary bytecode"

Thats the sentence that solved it all smilie
schildmeijer (15) [Avatar] Offline
#6
Re: Chapter 4. paint example
Hope its ok if ask another question about pseudo registration and ServiceTrackers in this thread. I just asked a question at stackoverflow:

http://stackoverflow.com/questions/654400/servicetracker-in-osgi-r4-1

Im doing a simple experiment and my servicetracker finds all the predefined services. So i cant see the purpose of pseudo registration (thought I understand the concept)
richard.hall (87) [Avatar] Offline
#7
Re: Chapter 4. paint example
If you are using the ServiceTracker, then it is not necessary to do pseudo-registration since it correctly will locate existing matching services. Perhaps it is not clear in the chapter, but we illustrate how to do it manually to give you some idea of all of the issues you need to be concerned about and in the end we show you ServiceTracker, which does all of this for you.
schildmeijer (15) [Avatar] Offline
#8
Re: Chapter 4. paint example
thanks again smilie