Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

AEM 5.6: bundle activate callback not called!

Avatar

Level 4

Hi,

I have this problem where a bunch of my OSGi bundles (not all of them), upon installation, doesn't call my services activate methods.  I read this post:

http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...

But that seem to be targeted at 5.6.1/JDK1.7.  I am running AEM 5.6.0.20130125 + JDK 1.6.0_65-b14-462-11M4609.

OTOH, the services in my bundles are accessible, and activation occur when some other components needs it.  But I would like activation to happen at bundle installation time as I am registering listeners.

If you have ideas on why this is happening, I would be grateful.

Thanks.

P.S.  I'm using the felix annotations for activation/service references etc.

ex.

@Component @Service(value = ProjectFactory.class) public class ProjectFactoryImpl extends BaseServiceImpl implements ProjectFactory, EventListener { private final Logger logger = LoggerFactory.getLogger(ProjectFactoryImpl.class); @Reference private LanguageManager languageManager; @Reference private SlingRepository repository; @Reference private ResourceResolverFactory resolverFactory; private Session session = null; @Activate public void activate() { logger.info("Please activate!"); // ... } // ... }
1 Accepted Solution

Avatar

Correct answer by
Employee

OSGi Event Listeners are actually a great example for why immediate=true is *not* the default. If you read the sections of the specification I mentioned, you'll see that event listeners are mentioned explicilty.

"The component configuration will only be activated once the Event Admin
service requires the service because it has an event to deliver on the topic to
which the component subscribed."

View solution in original post

7 Replies

Avatar

Level 10

Are you using Maven to setup your project? 

Avatar

Level 10

I am going to create a test project using AEM 5.6 and and OSGi and write out log message in the activate method. I am want to see if i can duplicate your results. 

Avatar

Level 4

Like I said, it's weird, because some of them are working (I can see traces of their activation in the log file), but some of them seem to be lazy (waiting for first use).

Avatar

Level 4

I see.  But then, what would be recommended for, say, registering listeners which need to be initialized at bundle install time?

P.S. why the immediate==true isn't recommended anyway? looks convenient to me.

Avatar

Employee

All DS components which are services are lazily activated by default. You can force them to be immediately activated by adding immediate=true to the @Component annotation. But this is generally not a good idea (thus, why it isn't the default smiley).

See sections 112.2.2 and 112.2.3 of the Declarative Services specification for more information.

Avatar

Correct answer by
Employee

OSGi Event Listeners are actually a great example for why immediate=true is *not* the default. If you read the sections of the specification I mentioned, you'll see that event listeners are mentioned explicilty.

"The component configuration will only be activated once the Event Admin
service requires the service because it has an event to deliver on the topic to
which the component subscribed."