Disable component on specific run mode | Community
Skip to main content
October 16, 2015
Solved

Disable component on specific run mode

  • October 16, 2015
  • 5 replies
  • 2683 views

Hi everyone,

we have two special components in an OSGi Bundle. One should only run on the author instance and the other only on publish. Does anyone of you know how to disable each component on author/publish while activating the bundle?

We've tried this so far:

private static final String AUTHOR_RUN_MODE = "author"; @Activate public void activate(final ComponentContext context) throws Exception { @SuppressWarnings("rawtypes") final Dictionary properties = context.getProperties(); if (!slingSettingsService.getRunModes().contains(AUTHOR_RUN_MODE)) { final String componentName = (String) properties.get(ComponentConstants.COMPONENT_NAME); context.disableComponent(componentName); } }

Thanks in advance!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Runal_Trivedi

a better way would be to use OSGI bool  type property, read the value of that property (which will either be boolean true or false) and accordingly disable the OSGI component in activate method.

Now the value of the Bool property can be driven and forced to true or false as per your AEM run modes.. i.e. using runmode specific environment configuration file.

Follow the mentioned article to understand more on environment specific OSGI configuration - http://www.wemblog.com/2012/10/how-to-work-with-configurations-in-cq.html

Hope it helps.

- Runal

5 replies

Dinu_Arya
October 16, 2015
Runal_Trivedi
Runal_TrivediAccepted solution
October 16, 2015

a better way would be to use OSGI bool  type property, read the value of that property (which will either be boolean true or false) and accordingly disable the OSGI component in activate method.

Now the value of the Bool property can be driven and forced to true or false as per your AEM run modes.. i.e. using runmode specific environment configuration file.

Follow the mentioned article to understand more on environment specific OSGI configuration - http://www.wemblog.com/2012/10/how-to-work-with-configurations-in-cq.html

Hope it helps.

- Runal

Sham_HC
October 16, 2015
Feike_Visser1
Adobe Employee
Adobe Employee
October 16, 2015

I prefer to do this via configuration, and not via code.

You can use: policy=ConfigurationPolicy.REQUIRE on @Component for this

When this is on your OSGi-component, this component will only be 'active' if there is a config supplied for it.

October 16, 2015

Thanks for your help. We didn't want to use a configuration file but it looks like that this is the best way so far to solve the problem.