Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [equinox-dev] is this a service tracker bug?

Mark,

Since your service interface (IA.java) is contained within bundleA,
bundleB requires a package import from bundleA.  The effect that
you're seeing is that the old version of bundleA remains in the system
and is still used by bundleB after you call "update".  Therefore you
now have two instances of bundleA in the system: the old one, still
used by bundleB, and the new refreshed one.

Since you called 'refresh', the old bundleA was stopped, and so were
any registered services (which is why you see 'removedService').  The
new bundleA was also started, and a new IA service was registered.
However, since bundleB is still using the package import from the old
bundleA, it does not get notified of the new bundleA's service (refer
to ServiceListener vs. AllServiceListener).

Calling 'refresh' instructs the framework to perform the steps
outlined at http://www2.osgi.org/javadoc/r4/org/osgi/service/packageadmin/PackageAdmin.html#refreshPackages(org.osgi.framework.Bundle[]).
 This in turn stops bundleB, gets rid of the old bundleA and links
bundleB to the new bundleA's package source.  When bundleB is
restarted and linked to the new bundleA, it can once again see the IA
service.

Sorry if that was a bit confusing.. maybe someone else can clarify a bit more.

-Jeremy

On Jan 25, 2008 11:33 AM, Mark <javamark@xxxxxxxxx> wrote:
>
> This is driving me mad. I have two bundles A and B. B track the service
> offered by A.
>
> However if I call update on A then I get a remove Service notification but
> no add Service notification - that is until I issue a refresh command ? is
> this a bug?
>
> I have written the same simple code 10 time .. see the results.
>
> I have attached the two bundles and the two eclipse plugin projects (as one
> zip) - just in case a Eclipse/OSGi guru like yourself can figure it out?
>
> ========================================
>
>  C:\eg>java -jar equinox.osgi.jar -console
>
> osgi> ss
>
> Framework is launched.
>
> id      State       Bundle
> 0       ACTIVE      org.eclipse.osgi_3.4.0.v20071207
>
> osgi> install file:bundleA_1.0.0.jar
> Bundle id is 1
>
> osgi> install file:bundleB_1.0.0.jar
> Bundle id is 2
>
> osgi> ss
>
> Framework is launched.
>
> id      State       Bundle
> 0       ACTIVE      org.eclipse.osgi_3.4.0.v20071207
> 1       INSTALLED   bundleA_1.0.0
> 2       INSTALLED   bundleB_1.0.0
>
> osgi> start 1
>
> osgi> start 2
> addingService
>
> osgi> stop 1
> removedService
>
> osgi> start 1
> addingService
>
> osgi> update 1
> removedService <----- no add !
>
> osgi> stop 2
>
> osgi> start 2
>
> osgi> refresh <- Only get add after refresh
>
> osgi> addingService
>
>
> osgi>
>
>
>
> On 25/01/2008, Neil Bartlett <njbartlett@xxxxxxxxx > wrote:
> >
> >
> > Hi Mark,
> >
> >
> > Many thanks for your kind words!
> >
> >
> > Regarding the service tracker problem... that's not the behaviour I would
> expect to see, and I've just put together a small test case which prints a
> message in the addingService, removedService and modifiedService methods of
> the ServiceTracker. When I update the bundle that registered the service, I
> see the following:
> >
> >
> > osgi> update 5
> > Removed service
> > Added service
> >
> > osgi>
> >
> >
> >
> > Which seems to be the way it should work. I suggest posting a message to
> the equinox-dev mailing list (
> https://dev.eclipse.org/mailman/listinfo/equinox-dev) explaining the problem
> in detail and including a minimal code sample that reproduces the problem.
> >
> >
> > Regards,
> > Neil
> >
> >
> >
> >
> >
> >
> >
> > On 25 Jan 2008, at 13:42, Mark wrote:
> >
> > Neil,
> >
> > First off I have to thank you in a big way, because it was you articles
> that got me up and running on OSGI.
> >
> > I am also glad that you are putting together a book... because I was
> thinking about it myself...in practice or in action!, would you like some
> help?
> >
> > ..Anyway the reason for this mail...
> >
> > I was looking at the Listeners Considered Harmful: The "Whiteboard"
> Pattern white paper, and I put together a very simple two bundle example (on
> Equinox),
> >
> > Bundle A (offers a service)
> > Bundle B (consumes service A, using a Service Tracker)
> >
> > So far so good, and not exactly rocket science.
> >
> > However this morning I discovered that if you update A - then you must
> refresh A in order for B to receive the added service event.
> >
> > This came as a surprise, go I Googled a while, and came up short. So I was
> wondering if you had some words of widom for me on this ?
> >
> > Kind Regards
> >
> > Mark
> >
> >
>
>
>
> _______________________________________________
> equinox-dev mailing list
> equinox-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/equinox-dev
>
>


Back to the top