Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Providing interface as bundle with implementations as bundle
Providing interface as bundle with implementations as bundle [message #480998] Wed, 19 August 2009 10:03 Go to next message
Oliver Pfau is currently offline Oliver PfauFriend
Messages: 28
Registered: July 2009
Junior Member
Hi,

I try to do the following:

- define bundle "ServiceInterface" which defines an interface
- define bundle "ServiceImpl1" with Version 1.0.0 which implements the
interface from "ServiceInterface"
- deiine bundle "ServiceImpl2" with Version 1.0.1 which implements the
interface from "ServiceInterface"

"ServiceImpl1" and "ServiceImpl2" depending from "ServiceInterface"

I started equinox with the 3 bundles by EclipseStarter.startup(). The
starting class has the version information to find the implementation that
fits. The Problem is now, the starter class has another class loader than
the bundles and the cast from the object delivered as service by
"ServiceImpl1" or "ServiceImpl2" (depending on desired version) fails.

Has anyone an idea how to "get" a implementation for an interface by
version from "outside" where the interface and all implementations are in
separate bundles ?

Thanks,
Oliver
Re: Providing interface as bundle with implementations as bundle [message #481003 is a reply to message #480998] Wed, 19 August 2009 10:34 Go to previous messageGo to next message
Gunnar Wagenknecht is currently offline Gunnar WagenknechtFriend
Messages: 486
Registered: July 2009
Location: San Francisco ✈ Germany
Senior Member

Oliver Pfau schrieb:
> Hi,
>
> I try to do the following:
>
> - define bundle "ServiceInterface" which defines an interface
> - define bundle "ServiceImpl1" with Version 1.0.0 which implements the
> interface from "ServiceInterface"
> - deiine bundle "ServiceImpl2" with Version 1.0.1 which implements the
> interface from "ServiceInterface"
>
> "ServiceImpl1" and "ServiceImpl2" depending from "ServiceInterface"

I assume that the BSN of "ServiceImpl1" and "ServiceImpl2" are the same
and the one from "ServiceInterface" is totally different?

> I started equinox with the 3 bundles by EclipseStarter.startup(). The
> starting class has the version information to find the implementation that
> fits. The Problem is now, the starter class has another class loader than
> the bundles and the cast from the object delivered as service by
> "ServiceImpl1" or "ServiceImpl2" (depending on desired version) fails.

It looks like that you start Equinox from an outer application and you
want to access the OSGi service from this outer application. Is this
correct? If yes, then you need to ensure that the bundles within the
Equinox framework instance use the same interface class as the outer
application, i.e. you need to instruct Equinox to *not* load
"ServiceInterface" from the "ServiceInterface" bundle but from the outer
application's classpath.

ServiceInterface needs to be in its own package. This package needs to
be added to the 'org.osgi.framework.system.packages' property.

-Gunnar

--
Gunnar Wagenknecht
gunnar@wagenknecht.org
http://wagenknecht.org/
Re: Providing interface as bundle with implementations as bundle [message #481015 is a reply to message #481003] Wed, 19 August 2009 11:09 Go to previous messageGo to next message
Oliver Pfau is currently offline Oliver PfauFriend
Messages: 28
Registered: July 2009
Junior Member
What do you mean with BSN ?

Thanks for the information with the system interface. I will try this.
Re: Providing interface as bundle with implementations as bundle [message #481061 is a reply to message #481003] Wed, 19 August 2009 13:16 Go to previous messageGo to next message
Oliver Pfau is currently offline Oliver PfauFriend
Messages: 28
Registered: July 2009
Junior Member
I added the interface in the config.ini to the property
org.osgi.framework.system.packages and checked on osgi console with
getprops. Now the 2 service implemenations will first be found in equinox
and then set to null. Framework.class line 1238
(org.eclipse.osgi_3.4.0.v20080605-1900.jar). There is a statement
context.isAssignableTo((ServiceReferenceImpl) services[i]) which is false
and then the service is set to null. Any idea ?
Re: Providing interface as bundle with implementations as bundle [message #482307 is a reply to message #481015] Wed, 26 August 2009 07:44 Go to previous messageGo to next message
Gunnar Wagenknecht is currently offline Gunnar WagenknechtFriend
Messages: 486
Registered: July 2009
Location: San Francisco ✈ Germany
Senior Member

Oliver Pfau schrieb:
> What do you mean with BSN ?

bundle symbolic name

-Gunnar


--
Gunnar Wagenknecht
gunnar@wagenknecht.org
http://wagenknecht.org/
Re: Providing interface as bundle with implementations as bundle [message #482308 is a reply to message #481061] Wed, 26 August 2009 07:47 Go to previous messageGo to next message
Gunnar Wagenknecht is currently offline Gunnar WagenknechtFriend
Messages: 486
Registered: July 2009
Location: San Francisco ✈ Germany
Senior Member

Oliver Pfau schrieb:
> context.isAssignableTo((ServiceReferenceImpl) services[i]) which is false

I think there is still something wrong with your setup. Please verify
that there should be *no* bundle deployed exporting the service
interface, i.e. the only point where the service interface is on your
classpath is in the outer application. You also need to verify that you
use Import-Package not Require-Bundle.

-Gunnar

--
Gunnar Wagenknecht
gunnar@wagenknecht.org
http://wagenknecht.org/
Re: Providing interface as bundle with implementations as bundle [message #482833 is a reply to message #482308] Fri, 28 August 2009 09:34 Go to previous message
Oliver Pfau is currently offline Oliver PfauFriend
Messages: 28
Registered: July 2009
Junior Member
It was a class loader problem I think. The problem was solved by import
the packages of the service finding bundle in the service finding bundle
itself. I read this was a change from osgi rev 3 to rev 4. In 3 the import
was implicit done, but no more in rev 4.
Previous Topic:installing from feature based repository failed
Next Topic:Automatic restart a service
Goto Forum:
  


Current Time: Fri Apr 26 23:37:20 GMT 2024

Powered by FUDForum. Page generated in 0.03480 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top