/* * Copyright 2014 Adobe Systems Incorporated * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.ninedemons.aemtesting.core.impl.schedulers; import java.util.Map; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Properties; import org.apache.felix.scr.annotations.Property; import org.apache.felix.scr.annotations.Service; import org.apache.sling.commons.osgi.PropertiesUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * A simple demo for cron-job like tasks that get executed regularly. * It also demonstrates how property values can be set. Users can * set the property values in /system/console/configMgr */ @Component(metatype = true, label = "A scheduled task", description = "Simple demo for cron-job like task with properties") @Service(value = Runnable.class) @Properties({ @Property(name = "scheduler.expression", value = "*/30 * * * * ?", description = "Cron-job expression"), @Property(name = "scheduler.concurrent", boolValue=false, description = "Whether or not to schedule this task concurrently") }) public class SimpleScheduledTask implements Runnable { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Override public void run() { logger.debug("SimpleScheduledTask is now running, myParameter='{}'", this.myParameter); } @Property(label = "A parameter", description = "Can be configured in /system/console/configMgr") public static final String MY_PARAMETER = "myParameter"; private String myParameter; @Activate protected void activate(final Map<String, Object> config) { configure(config); } private void configure(final Map<String, Object> config) { this.myParameter = PropertiesUtil.toString(config.get(MY_PARAMETER), null); logger.debug("configure: myParameter='{}''", this.myParameter); } }