1

Uses Apache Felix 4.2.1 iPOJO 1.11.0.

Requires programmatically create component instances when the user request. But i can not use none-static field in static factory method.

@Component
@Provides(specifications = {IProcessSearch.class})
public class ProcessSearch implements IProcessSearch {
    ...
    @Requires(filter = "(factory.name=ProcessSearch)")
    private Factory mProcessSearchFactory;
    ...
    /**
     * Factory methods for receive new component instance:
     */
    public static ProcessSearch createInstance() {
        return createInstance(null);
    }
    public static ProcessSearch createInstance(Properties pProperties) {
        InstanceManager lInstanceManager = (InstanceManager) mProcessSearchFactory.createComponentInstance(pProperties);
        return (ProcessSearch) lInstanceManager.getPojoObject();
    }

1) If I understand correctly, then field with @Requires annotation can not be static. How to create factory method which take properties and receive new component instance?

2) Is it normal practice to do so?

Aleksandr
  • 1,303
  • 2
  • 11
  • 19

1 Answers1

1

Do do that, you need to provide your own creation strategy. This strategy is applied on the provided service (@Provides) and not on the consumer side (@Requires).

More info on: http://felix.apache.org/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/providing-osgi-services.html#service-serving-object-creation

Clement
  • 2,817
  • 1
  • 12
  • 11
  • Strategy - defines service provided strategy (one service for all bundles or new service for each bundle or custom...)(Or am I mistaken?). But i need to create instances. Could you give an example code (or give a link with example) how to use custom CreationStrategy on the consumer side? For example - i need to create n (user enter n) instances of MyService component. Need create all instances programmatically after user enter n. Thanks. – Aleksandr Nov 28 '13 at 17:12