Hello,
I have some special needs for accessing OSGi services and would be
happy, if someone could give me a hint how I can archive this in a safe way.
Some common facts:
- a generic "Function" interface defines a method "work"
- all functions have to implement this interface
- all functions should be threadsafe
- all functions have some identifiers (name, version)
- different implementations of a named function should be available at
runtime in multiple instances with different versions
By registering different function-instances with specific filter
attributes as OSGi services, I can make the functions available.
But how do I solve this?
- functionA should be able to use functionB#work() only by name
- the used instance of functionB has to by dynamic changable per call,
depending on some "context"-parameters without making a decision in
functionA itself. For example: 2 calls of the same functionA instance
result in calls to 2 different versions of functionB.
Variant 1 is to use a "Retriever"-Service. It should create a filter
with the context-parameters and return the matching service from the
local stored BundleContext.
The retriever itself would be a registered service too and would be
referenced by every function instance.
FunctionA would use something like this in its work-method:
Function functionB = retriever.getByName("B");
functionB.work();
In variant 2 all functions extend an abstractFunction with a method
"getByName". So every function instance itself holds the BundleContext
or uses it from the bundleactivator to retrieve other functions dynamically.
Can I use services in that way?
Which variant is better? Or are there other solutions for retrieving
services dynamically?
Do I have to release the recieved functionB after leaving the work-scope
of functionA?
Thank you in advance!
Regards,
Lars
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]