Defining Factory of OSGI schedulers(Dynamic Schedulers) in Adobe Experience Manager(AEM)
This post explains the approach to define factory of OSGI schedulers(Dynamic Schedulers) in Adobe Experience Manager(AEM)
Define a factory class to capture the configurations:
Define a component and enable as configuration factory(configurationFactory=true)
Configure all the required properties run the scheduler job.
Retrieve the properties through activate method and assign the values to class variable, define the getters to retrieve the property values in Job Class.
Specify the label to identify the configuration in OSGI console.
@Component(
configurationFactory = true, policy = ConfigurationPolicy.OPTIONAL, metatype = true, immediate = true, label = "
Scheduled Package Generator")
@Service(value = GeneratePackageSchedulerRequest.class)
public class GeneratePackageSchedulerRequest {
final Logger logger = LoggerFactory.getLogger(this.getClass());
@Property(unbounded=PropertyUnbounded.DEFAULT, label="Scheduler Expression", description="Scheduler Expression", value="")
private static final String SCHEDULER_EXPRESSION = "sheduleExpression";
private String sheduleExpression;
@Property(unbounded = PropertyUnbounded.ARRAY, label = "Packages Filter String", cardinality = 50, description = "Packages Filter String")
public static final String PACKAGE_FILTERS = "packageFilters";
private String[] packageFilters;
@Property(unbounded=PropertyUnbounded.DEFAULT, label="Package Name", description="Package Name")
private static final String PACKAGE_NAME = "packgeName";
private String packageName;
@Property(unbounded=PropertyUnbounded.DEFAULT, label="Root Path to store the package", description="Root Path")
private static final String ROOT_PATH = "rootpath";
private String rootPath;
@Activate
protected void activate(final ComponentContext ctx) {
Dictionary<?, ?> props = ctx.getProperties();
sheduleExpression = PropertiesUtil.toString(props.get(SCHEDULER_EXPRESSION), "");
packageFilters = PropertiesUtil.toStringArray(props.get(PACKAGE_FILTERS), null);
packageName = PropertiesUtil.toString(props.get(PACKAGE_NAME), null);
rootPath=PropertiesUtil.toString(props.get(ROOT_PATH), null);
}
public String[] getPackageFilters() {
return packageFilters;
}
public String getJobname() {
return packageName;
}
public String getSheduleExpression() {
return sheduleExpression;
}
public String getRootPath() {
return rootPath;
}
}