felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clement Escoffier <clement.escoff...@gmail.com>
Subject Re: ipojo late injection
Date Thu, 27 Mar 2014 06:26:45 GMT
Hi,

There are a couple of ways to do what you want to do:

1) using a contextual filter and a context source

You can write a filter using a variable such as (version=${user.version}). Then you implement
a context-source service (http://felix.apache.org/ipojo/api/1.11.0/src-html/org/apache/felix/ipojo/ContextSource.html#line.29)
that provides the required variable and notifies listeners when this one changes. I would
recommend to use a default value such as in (|(version=${user.version})(version=generic)).

2) Using the iPOJO reconfiguration mechanism

You can change the filter of an instance using it’s ‘Architecture’ service:
    // Retrieve the architecture of your instance
    @Requires(filter="(instance.name=my-instance)")
    Architecture architecture;
    
    public void reconfigure() {
        // Gets the dependency handler
        DependencyHandlerDescription description = (DependencyHandlerDescription) 
                architecture.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:dependency");
        // Select your dependency
        DependencyDescription dependency = description.getDependencies()[0];
        // Set the filter
        dependency.getDependency().setFilter(filter);
    }

3) Using tracking or ranking interceptors

In iPOJO1.11.x, we have introduced service binding interceptors that can refine the service
selection and ranking without changing the component code.
http://felix.apache.org/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/service-binding-interceptors.html

In you case, I would recommend a ranking interceptor which move the service matching the user
requirement first:

So, now you just have to pick a solution !

Clement

PS: Richard’s suggestion also works. It is very close to the solution #2, but requires the
deployment of another bundle.

On 26 mars 2014, at 21:37, Alejandro.Endo@miranda.com wrote:

> Hello everyone,
> 
> I am just starting with iPOJO and I was wondering what is the 
> right/recommended way in iPOJO to select a service late at runtime. 
> Imagine a textbox in a GUI that asks for a version and only after the user 
> entered version=1.3.5 I can know that the service I want injected is 
> v1.3.5. In this case annotations or xml don't work since they are static
> 
> What I am currently doing is using an aggregate dependency and then I loop 
> myself over all the services (the version is a property of the service 
> BTW) and return the one that matches the request
> 
> I though of multiple ways of doing this but I don't know if they are 
> possible or make sense
> 
> 1) doing some kind of service registry query where I can explicitly ask 
> for the service with the given properties and I will have it returned 
> right away
> 2) modifying the injection filter at runtime; however with this technique 
> I would have to wait for the framework to do the injection whenever it 
> wants instead of when I need it. i.e. it is asynchronous
> 3) using the iPOJO API to modify the dependency. Again this solution would 
> be async
> 4) The one I mentioned first. Keep a list of all the services via an 
> aggregate dependency and loop through them to find the one that matches
> 5) other?
> 
> Thank you in advance,
> 
> Alejandro Endo | Software Designer/Concepteur de logiciels
> 
> DISCLAIMER:
> Privileged and/or Confidential information may be contained in this
> message. If you are not the addressee of this message, you may not
> copy, use or deliver this message to anyone. In such event, you
> should destroy the message and kindly notify the sender by reply
> e-mail. It is understood that opinions or conclusions that do not
> relate to the official business of the company are neither given
> nor endorsed by the company.
> Thank You.


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message