You are on page 1of 1

package com.job.my.scheduler; import import import import import org.apache.felix.scr.annotations.*; org.apache.sling.commons.osgi.PropertiesUtil; org.osgi.service.component.ComponentContext; org.slf4j.Logger; org.slf4j.

LoggerFactory;

@Service @Component(name="My JOB Name", label="MY Job Label", description="My Job Description", metatype=true) @Properties({ @Property(label="Quartz Cron Expression", description="Quartz Scheduler specific cron expression. Do not put unix cron expression " + "Example usage: Seconds Minutes Hours Days Months Years", name="scheduler.expression", value="0 0 7 * * ?"), @Property( label="Job Enabled?", description="Turn on or off the Job", name="myjob.enabled", boolValue=false ), @Property( label="Email Recipient", description="Email Address, where the report should be sent (default:user@host.com)", name="emailRecipient", value="user@host.com" )} ) public class MyJobService implements Runnable { private static Logger log = LoggerFactory.getLogger(MyJobService.class); private String emailRecipient; private boolean run; @Activate protected void activate(ComponentContext ctx) { emailRecipient = PropertiesUtil.toString(ctx.getProperties().get("emailRecipient"),""); run = PropertiesUtil.toBoolean(ctx.getProperties().get("myjob.enabled"),false); } public void run() { if (run) { log.debug("Running Job"); // TODO: Do your Stuff // TODO: Send Email } } else { log.debug("Skipping Job"); }