1
votes

I have an Apache Felix component who's definition looks like this:

...
@Component(immediate=true)

@Service
public class myClass implements myClassInterface {
    ...
    @Activate
    public void activate(final Map<String, Object> properties) {
        //Do activation stuff
    }
    ...
}

From reading the Apache Felix documentation on the @Component and @Activate annotations (http://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin/scr-annotations.html#component) I understand that the immediate=true attribute for the @Component is "activated immediately". My problem is that my activate method never seems to be invoked. I have my debugger on from the moment I build my project until the moment I request the service myClass using OSGi, but the activate method never seems to be invoked.

So, my question has a few layers: 1. Telling me that immediate=true attribute causes the component to be "activated immediately" doesn't give me enough information. Does this mean that the component is activated immediately after the project is built, immediately after an instance of myClass is created, or immediately after the service myClass is requested by the OSGi bundle? 2. Is there anything that might cause my activate method to not be invoked in spite of my usage of immediate=true? If so, what can I do to correct the issue?

Thanks in advance for your help. Please let me know if I need to provide additional information.

1

1 Answers

4
votes

Immediate=false means the component is only activated once it is requested by another component. Immediate=true means it is activated once all its mandatory references are present.

So if your component is not activated then maybe a service it needs is not present. You can look into the status of the components by using the scr commands in the gogo shell.

Another thing is to define what interface to publish the service with. I am not sure about the felix SCR annotations but with DS annotations you need to set @Component(service=myClass.class) if the class does not implement any interface.

Btw. You should switch to the standard DS annotations. See http://enroute.osgi.org/doc/217-ds.html. The felix ones are deprecated now.