Hi Christian,

What is it that you’re trying to achieve?

> is it possible to have multiple equal instances of a service or is this 
> breaking the principle rules of OSGI?


Yes, you can have multiple service registrations for the same object instance, 
but this doesn’t make a whole lot of sense. You still only have the one object, 
so the multiple registrations just make the service registry look more 
confusing.

If what you want is to have the ability to create multiple independent 
instances (i.e. ones that can have local state) then you can achieve this using 
a prototype scoped service and the ServiceObjects type from OSGi R6. You will 
be responsible for garbage collecting this type, although it should be pretty 
easy to create a Scoped Resource for managing the Scoped Object.

> I also see the need of parallel processing of messages. How do you do this 
> with a single service instance without starting multiple threads?

I’m a little confused by this question. There isn’t a way to do parallel 
processing without multiple threads involved. You may have request-level 
parallelism (e.g. the threads are at the level of the Servlet Container) or 
task level parallelism (you break the task into small parallel pieces that run 
on different threads) but there are always multiple threads involved. The OSGi 
Async Service may be able to help you with the latter model, but this still 
involves having multiple threads.

Regards,

Tim

> On 20 Oct 2016, at 07:06, cniehues <christian.nieh...@its-telco.de> wrote:
> 
> I am still asking me the question: is it possible to have multiple equal
> instances of a service or is this breaking the principle rules of OSGI?
> Because beside my wish of context specific instances I also see the need of
> parallel processing of messages. How do you do this with a single service
> instance without starting multiple threads?
> 
> 
> 
> --
> View this message in context: 
> http://karaf.922171.n3.nabble.com/Best-practice-for-context-specific-service-instances-tp4048410p4048455.html
> Sent from the Karaf - User mailing list archive at Nabble.com.

Reply via email to