On Sun, May 31, 2009 at 8:09 PM, Stuart McCulloch <[email protected]> wrote:
> 2009/6/1 Aaron Zeckoski <[email protected]>
>>
>> I am having trouble utilizing the service tracker events. There are 3
>> of them (add, modify, remove) and I am calling my own methods which
>> try to start my service if the services I require are available (or
>> shut it down when they are no longer available).
>>
>> The issue is that the adding event happens before the service is added
>> into the tracker so when I call my start method it cannot find the
>> service yet.
>
> that's part of the design - the instance returned by the "addingService"
> method is the object you want tracked, so it won't be available from the
> trackers "getService" method until "addingService" returns.
>
> however, you could pass the service object (which is available inside
> the "addingService" method) to some sort of "combiner" that collects
> together all the various service dependencies and only activates your
> component (or in this case registers the servlet) when it has them all

I was trying not to hold onto instances of the services in my own
structure since that seems to be what the servicetracker is doing. I
just wanted to make sure I was not missing something. I think that
using the ST + SL is probably the way to go then.

> you might also want to consider using a ServiceTrackerCustomizer
> to extend the behaviour rather than sub-classing the service tracker

I tried that at first but since I needed access to the context it
ended up being less code to extend the ST and just use the one it has
already.

>> Here is the code if anyone is insterested:
>>
>> http://code.google.com/p/azsandbox/source/browse/trunk/osgi-sample/sample-servlet/src/main/java/org/azeckoski/sample/internal/SampleServletActivator.java
>>
>> I ended up creating something a lot more complicated which uses both
>> the servicetracker and also the servicelistener and only uses the
>> listener events but it seems like maybe I am doing something wrong
>> here. Is it possible to utilize the servicetracker events and also use
>> it to get the service out while the event method is triggering or is
>> that not really what the events are for?
>>
>> I would prefer to not to have to use DS or big libraries for such a
>> simple bundle in this case but maybe that is just not practical.
>
> FWIW the Apache Felix DS implementation (called SCR) is only ~100k

The issue is less that the library is large and more that there are
OSGi instances without a DS bundle installed. For simple libraries it
seems like a framework should not be required anyway (this is probably
an old fashioned way of thinking...).
In this case, I want to walk before I run and make sure I have a good
feel of what it is like to do this stuff manually before relying on
the frameworks.

-AZ


>> --
>> Aaron Zeckoski ([email protected])
>> Senior Research Engineer - CARET - Cambridge University
>> https://twitter.com/azeckoski - http://www.linkedin.com/in/azeckoski
>> http://aaronz-sakai.blogspot.com/ -
>> http://confluence.sakaiproject.org/confluence/display/~aaronz/
>> _______________________________________________
>> OSGi Developer Mail List
>> [email protected]
>> https://mail.osgi.org/mailman/listinfo/osgi-dev
>
> --
> Cheers, Stuart
>
> _______________________________________________
> OSGi Developer Mail List
> [email protected]
> https://mail.osgi.org/mailman/listinfo/osgi-dev
>



-- 
Aaron Zeckoski ([email protected])
Senior Research Engineer - CARET - Cambridge University
https://twitter.com/azeckoski - http://www.linkedin.com/in/azeckoski
http://aaronz-sakai.blogspot.com/ -
http://confluence.sakaiproject.org/confluence/display/~aaronz/
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to