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:
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!"); // ... } // ... }
Solved! Go to Solution.
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."
Views
Replies
Total Likes
Are you using Maven to setup your project?
Views
Replies
Total Likes
I do
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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).
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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 ).
See sections 112.2.2 and 112.2.3 of the Declarative Services specification for more information.
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."
Views
Replies
Total Likes