diff --git a/appidentity/pom.xml b/appidentity/pom.xml index e8bd91b6..37b2e55c 100644 --- a/appidentity/pom.xml +++ b/appidentity/pom.xml @@ -26,6 +26,11 @@ capedwarf-aspects + + org.jboss.capedwarf.blue + capedwarf-blobstore + + org.jboss.capedwarf.blue capedwarf-common @@ -33,17 +38,17 @@ org.jboss.capedwarf.blue - capedwarf-environment + capedwarf-cron org.jboss.capedwarf.blue - capedwarf-log + capedwarf-environment org.jboss.capedwarf.blue - capedwarf-blobstore + capedwarf-log diff --git a/appidentity/src/main/java/org/jboss/capedwarf/appidentity/CDIListener.java b/appidentity/src/main/java/org/jboss/capedwarf/appidentity/CDIListener.java index addcc6cc..f9e37431 100644 --- a/appidentity/src/main/java/org/jboss/capedwarf/appidentity/CDIListener.java +++ b/appidentity/src/main/java/org/jboss/capedwarf/appidentity/CDIListener.java @@ -22,20 +22,21 @@ package org.jboss.capedwarf.appidentity; +import java.util.logging.Logger; + import javax.enterprise.inject.spi.BeanManager; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; -import java.util.logging.Logger; /** * @author Ales Justin */ public class CDIListener implements ServletContextListener { - private static Logger log = Logger.getLogger(CDIListener.class.getName()); + /** * The impl detail */ @@ -62,8 +63,9 @@ protected BeanManager getBeanManager() { public void contextInitialized(ServletContextEvent sce) { final BeanManager manager = getBeanManager(); - if (manager != null) + if (manager != null) { sce.getServletContext().setAttribute(BM_KEY, manager); + } } public void contextDestroyed(ServletContextEvent sce) { diff --git a/appidentity/src/main/java/org/jboss/capedwarf/appidentity/GAEListener.java b/appidentity/src/main/java/org/jboss/capedwarf/appidentity/GAEListener.java index 362eabaa..98b74630 100644 --- a/appidentity/src/main/java/org/jboss/capedwarf/appidentity/GAEListener.java +++ b/appidentity/src/main/java/org/jboss/capedwarf/appidentity/GAEListener.java @@ -37,6 +37,7 @@ import org.jboss.capedwarf.common.apiproxy.CapedwarfDelegate; import org.jboss.capedwarf.common.config.CapedwarfEnvironment; import org.jboss.capedwarf.common.security.PrincipalInfo; +import org.jboss.capedwarf.cron.CapewarfCron; import org.jboss.capedwarf.log.ExposedLogService; import org.jboss.capedwarf.shared.components.AppIdFactory; import org.jboss.capedwarf.shared.components.SimpleAppIdFactory; @@ -98,9 +99,13 @@ public void contextInitialized(ServletContextEvent sce) { servletContext.setAttribute("org.jboss.capedwarf.module", module); appIdFactory = new SimpleAppIdFactory(appId, module); + + CapewarfCron.getInstance().start(applicationConfiguration.getCronXml()); } public void contextDestroyed(ServletContextEvent sce) { + CapewarfCron.getInstance().stop(); + ServletContext servletContext = sce.getServletContext(); String deadlineParameter = servletContext.getInitParameter("lifecycle-manager-deadline"); long deadline = Long.parseLong((deadlineParameter != null) ? deadlineParameter : "0"); diff --git a/bytecode/src/main/java/org/jboss/capedwarf/bytecode/CapedwarfTransformerMojo.java b/bytecode/src/main/java/org/jboss/capedwarf/bytecode/CapedwarfTransformerMojo.java index 09282aaf..5803926e 100644 --- a/bytecode/src/main/java/org/jboss/capedwarf/bytecode/CapedwarfTransformerMojo.java +++ b/bytecode/src/main/java/org/jboss/capedwarf/bytecode/CapedwarfTransformerMojo.java @@ -28,6 +28,7 @@ import java.io.IOException; import java.nio.file.Files; import java.util.Arrays; +import java.util.TimeZone; import java.util.logging.Logger; import org.jboss.maven.plugins.transformer.TransformerUtils; @@ -39,6 +40,11 @@ public class CapedwarfTransformerMojo { public static void main(String[] args) { + TimeZone tz = TimeZone.getTimeZone("GMTq"); + System.out.println("tz = " + tz); + } + + public static void mainx(String[] args) { Logger.getLogger(CapedwarfTransformerMojo.class.getName()).info("Args: " + Arrays.asList(args)); for (String pathToJar : args) { diff --git a/common/src/main/java/org/jboss/capedwarf/common/async/DistributableWrapper.java b/common/src/main/java/org/jboss/capedwarf/common/async/DistributableWrapper.java index 93fb81f7..8e7c31e4 100644 --- a/common/src/main/java/org/jboss/capedwarf/common/async/DistributableWrapper.java +++ b/common/src/main/java/org/jboss/capedwarf/common/async/DistributableWrapper.java @@ -22,15 +22,11 @@ package org.jboss.capedwarf.common.async; -import java.io.Serializable; import java.util.Set; import java.util.concurrent.Callable; import org.infinispan.Cache; import org.infinispan.distexec.DistributedCallable; -import org.jboss.capedwarf.common.config.CapedwarfEnvironment; -import org.jboss.capedwarf.shared.components.AppIdFactory; -import org.jboss.capedwarf.shared.components.SimpleAppIdFactory; /** * Distributable callable. @@ -39,33 +35,11 @@ * @author Ales Justin * @author Marko Luksa */ -class DistributableWrapper implements DistributedCallable, Serializable { +class DistributableWrapper extends WireWrapper implements DistributedCallable { private static final long serialVersionUID = 1L; - private final String appId; - private final String module; - private final CapedwarfEnvironment env; - private final Callable callable; - DistributableWrapper(Callable callable) { - this.appId = AppIdFactory.getAppId(); - this.module = AppIdFactory.getModule(); - this.env = CapedwarfEnvironment.cloneThreadLocalInstance(); - this.callable = callable; - } - - public V call() throws Exception { - AppIdFactory.setCurrentFactory(new SimpleAppIdFactory(appId, module)); - try { - final CapedwarfEnvironment previous = CapedwarfEnvironment.setThreadLocalInstance(env); - try { - return callable.call(); - } finally { - CapedwarfEnvironment.setThreadLocalInstance(previous); - } - } finally { - AppIdFactory.resetCurrentFactory(); - } + super(callable); } @SuppressWarnings("unchecked") diff --git a/common/src/main/java/org/jboss/capedwarf/common/async/WireWrapper.java b/common/src/main/java/org/jboss/capedwarf/common/async/WireWrapper.java new file mode 100644 index 00000000..d7aa548a --- /dev/null +++ b/common/src/main/java/org/jboss/capedwarf/common/async/WireWrapper.java @@ -0,0 +1,70 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2014, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.capedwarf.common.async; + +import java.io.Serializable; +import java.util.Set; +import java.util.concurrent.Callable; + +import org.infinispan.Cache; +import org.infinispan.distexec.DistributedCallable; +import org.jboss.capedwarf.common.config.CapedwarfEnvironment; +import org.jboss.capedwarf.shared.components.AppIdFactory; +import org.jboss.capedwarf.shared.components.SimpleAppIdFactory; + +/** + * Distributable callable. + * Can be shared accross the wire. + * + * @author Ales Justin + * @author Marko Luksa + */ +public class WireWrapper implements Callable, Serializable { + private static final long serialVersionUID = 1L; + + private final String appId; + private final String module; + private final CapedwarfEnvironment env; + protected final Callable callable; + + public WireWrapper(Callable callable) { + this.appId = AppIdFactory.getAppId(); + this.module = AppIdFactory.getModule(); + this.env = CapedwarfEnvironment.cloneThreadLocalInstance(); + this.callable = callable; + } + + public V call() throws Exception { + AppIdFactory.setCurrentFactory(new SimpleAppIdFactory(appId, module)); + try { + final CapedwarfEnvironment previous = CapedwarfEnvironment.setThreadLocalInstance(env); + try { + return callable.call(); + } finally { + CapedwarfEnvironment.setThreadLocalInstance(previous); + } + } finally { + AppIdFactory.resetCurrentFactory(); + } + } +} diff --git a/cron/pom.xml b/cron/pom.xml new file mode 100644 index 00000000..88ab05f8 --- /dev/null +++ b/cron/pom.xml @@ -0,0 +1,103 @@ + + + + + + org.jboss.capedwarf.blue + capedwarf-build + 1.0.0-SNAPSHOT + + + 4.0.0 + capedwarf-cron + jar + CapeDwarf Cron + http://www.jboss.org/capedwarf + CapeDwarf Cron + + + + + org.quartz-scheduler + quartz + + + + org.jboss.capedwarf.shared + capedwarf-shared + + + + org.jboss.capedwarf.blue + capedwarf-aspects + + + + org.jboss.capedwarf.blue + capedwarf-common + + + + org.jboss.capedwarf.blue + capedwarf-environment + + + + com.google.appengine + appengine-api-1.0-sdk + + + + com.google.appengine + appengine-tools-sdk + + + + org.jboss.spec.javax.servlet + jboss-servlet-api_3.1_spec + provided + + + + org.jboss.arquillian.junit + arquillian-junit-container + test + + + + junit + junit + test + + + + org.jboss.capedwarf.blue + capedwarf-common + test-jar + test + + + + + diff --git a/cron/src/main/java/org/jboss/capedwarf/cron/CapewarfCron.java b/cron/src/main/java/org/jboss/capedwarf/cron/CapewarfCron.java new file mode 100644 index 00000000..746aad2f --- /dev/null +++ b/cron/src/main/java/org/jboss/capedwarf/cron/CapewarfCron.java @@ -0,0 +1,101 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2014, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.capedwarf.cron; + +import java.util.TimeZone; +import java.util.concurrent.Callable; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.jboss.capedwarf.common.async.WireWrapper; +import org.jboss.capedwarf.shared.config.CronEntry; +import org.jboss.capedwarf.shared.config.CronXml; +import org.jboss.capedwarf.shared.util.Utils; +import org.quartz.JobBuilder; +import org.quartz.JobDataMap; +import org.quartz.JobDetail; +import org.quartz.ScheduleBuilder; +import org.quartz.Scheduler; +import org.quartz.SchedulerException; +import org.quartz.SchedulerFactory; +import org.quartz.Trigger; +import org.quartz.TriggerBuilder; +import org.quartz.impl.StdSchedulerFactory; + +/** + * @author Ales Justin + */ +public class CapewarfCron { + private static final Logger log = Logger.getLogger(CapewarfCron.class.getName()); + private static final CapewarfCron INSTANCE = new CapewarfCron(); + + private Scheduler scheduler; + + private CapewarfCron() { + } + + public static CapewarfCron getInstance() { + return INSTANCE; + } + + public void start(CronXml cronXml) { + try { + SchedulerFactory factory = new StdSchedulerFactory(); + scheduler = factory.getScheduler(); + scheduler.start(); + + applyCrons(cronXml); + } catch (SchedulerException e) { + throw Utils.toRuntimeException(e); + } + } + + private void applyCrons(CronXml cronXml) throws SchedulerException { + for (CronEntry entry : cronXml.getEntries()) { + final String timezone = entry.getTimezone() != null ? entry.getTimezone() : "GMT"; + final String name = String.format("%s@%s#%s", entry.getUrl(), entry.getSchedule(), timezone); + + Callable callable = new WireWrapper<>(new CronCallable(entry.getUrl())); + JobDataMap map = new JobDataMap(); + map.put("callable", callable); + JobDetail jobDetail = JobBuilder.newJob(CronJob.class).withIdentity(name).usingJobData(map).build(); + + ScheduleBuilder scheduleBuilder = new GrocScheduleBuilder(new GoogleGrocAdapter(entry.getSchedule(), TimeZone.getTimeZone(timezone))); + Trigger trigger = TriggerBuilder.newTrigger().withIdentity(name).withSchedule(scheduleBuilder).build(); + + scheduler.scheduleJob(jobDetail, trigger); + } + } + + public void stop() { + try { + try { + scheduler.clear(); + } finally { + scheduler.shutdown(); + } + } catch (SchedulerException e) { + log.log(Level.WARNING, String.format("Error during cron stop."), e); + } + } +} diff --git a/cron/src/main/java/org/jboss/capedwarf/cron/CronCallable.java b/cron/src/main/java/org/jboss/capedwarf/cron/CronCallable.java new file mode 100644 index 00000000..392628de --- /dev/null +++ b/cron/src/main/java/org/jboss/capedwarf/cron/CronCallable.java @@ -0,0 +1,48 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2014, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.capedwarf.cron; + +import java.io.Serializable; +import java.util.concurrent.Callable; + +import com.google.appengine.api.taskqueue.Queue; +import com.google.appengine.api.taskqueue.QueueFactory; +import com.google.appengine.api.taskqueue.TaskOptions; +import org.jboss.capedwarf.shared.config.QueueXml; + +/** + * @author Ales Justin + */ +public class CronCallable implements Callable, Serializable { + private final String url; + + public CronCallable(String url) { + this.url = url; + } + + public Void call() throws Exception { + Queue queue = QueueFactory.getQueue(QueueXml.INTERNAL); + queue.add(TaskOptions.Builder.withUrl(url)); + return null; + } +} diff --git a/cron/src/main/java/org/jboss/capedwarf/cron/CronJob.java b/cron/src/main/java/org/jboss/capedwarf/cron/CronJob.java new file mode 100644 index 00000000..d6f01c4e --- /dev/null +++ b/cron/src/main/java/org/jboss/capedwarf/cron/CronJob.java @@ -0,0 +1,45 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2014, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.capedwarf.cron; + +import java.io.Serializable; +import java.util.concurrent.Callable; + +import org.quartz.Job; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; + +/** + * @author Ales Justin + */ +public class CronJob implements Job, Serializable { + @SuppressWarnings("unchecked") + public void execute(JobExecutionContext context) throws JobExecutionException { + try { + Callable callable = (Callable) context.getMergedJobDataMap().get("callable"); + callable.call(); + } catch (Exception e) { + throw new JobExecutionException(e); + } + } +} diff --git a/cron/src/main/java/org/jboss/capedwarf/cron/GoogleGrocAdapter.java b/cron/src/main/java/org/jboss/capedwarf/cron/GoogleGrocAdapter.java new file mode 100644 index 00000000..6c854fef --- /dev/null +++ b/cron/src/main/java/org/jboss/capedwarf/cron/GoogleGrocAdapter.java @@ -0,0 +1,66 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2014, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.capedwarf.cron; + +import java.util.Date; +import java.util.TimeZone; + +import com.google.appengine.repackaged.com.google.cron.GrocTimeSpecification; + +/** + * @author Ales Justin + */ +public class GoogleGrocAdapter extends GrocAdapter { + public GoogleGrocAdapter(String schedule, TimeZone timeZone) { + super(schedule, timeZone); + } + + private GrocTimeSpecification create() { + return GrocTimeSpecification.create(getSchedule(), getTimeZone()); + } + + protected Date getStartDate() { + GrocTimeSpecification grocTimeSpecification = create(); + return grocTimeSpecification.getMatch(new Date()); + } + + Date getFireTimeAfter(Date afterTime) { + GrocTimeSpecification grocTimeSpecification = create(); + return grocTimeSpecification.getMatch(afterTime); + } + + int computeNumTimesFiredBetween(Date start, Date end) { + GrocTimeSpecification grocTimeSpecification = create(); + Date next = grocTimeSpecification.getMatch(start); + int count = 0; + while (next != null && next.before(end)) { + count++; + next = grocTimeSpecification.getMatch(next); + } + return count; + } + + Date getFinalFireTime() { + return null; + } +} diff --git a/cron/src/main/java/org/jboss/capedwarf/cron/GrocAdapter.java b/cron/src/main/java/org/jboss/capedwarf/cron/GrocAdapter.java new file mode 100644 index 00000000..32c5a3c9 --- /dev/null +++ b/cron/src/main/java/org/jboss/capedwarf/cron/GrocAdapter.java @@ -0,0 +1,53 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2014, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.capedwarf.cron; + +import java.io.Serializable; +import java.util.Date; +import java.util.TimeZone; + +/** + * @author Ales Justin + */ +public abstract class GrocAdapter implements Serializable { + private String schedule; + private TimeZone timeZone; + + protected GrocAdapter(String schedule, TimeZone timeZone) { + this.schedule = schedule; + this.timeZone = timeZone; + } + + public String getSchedule() { + return schedule; + } + + public TimeZone getTimeZone() { + return timeZone; + } + + abstract Date getStartDate(); + abstract Date getFireTimeAfter(Date afterTime); + abstract int computeNumTimesFiredBetween(Date start, Date end); + abstract Date getFinalFireTime(); +} diff --git a/cron/src/main/java/org/jboss/capedwarf/cron/GrocScheduleBuilder.java b/cron/src/main/java/org/jboss/capedwarf/cron/GrocScheduleBuilder.java new file mode 100644 index 00000000..5dd8ee8a --- /dev/null +++ b/cron/src/main/java/org/jboss/capedwarf/cron/GrocScheduleBuilder.java @@ -0,0 +1,41 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2014, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.capedwarf.cron; + +import org.quartz.ScheduleBuilder; +import org.quartz.spi.MutableTrigger; + +/** + * @author Ales Justin + */ +public class GrocScheduleBuilder extends ScheduleBuilder { + private GrocAdapter grocAdapter; + + public GrocScheduleBuilder(GrocAdapter grocAdapter) { + this.grocAdapter = grocAdapter; + } + + protected MutableTrigger build() { + return new GrocTrigger(grocAdapter); + } +} diff --git a/cron/src/main/java/org/jboss/capedwarf/cron/GrocTrigger.java b/cron/src/main/java/org/jboss/capedwarf/cron/GrocTrigger.java new file mode 100644 index 00000000..c2ff427f --- /dev/null +++ b/cron/src/main/java/org/jboss/capedwarf/cron/GrocTrigger.java @@ -0,0 +1,65 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2014, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.capedwarf.cron; + +import java.util.Date; + +import org.quartz.ScheduleBuilder; +import org.quartz.impl.triggers.SimpleTriggerImpl; + +/** + * @author Ales Justin + */ +public class GrocTrigger extends SimpleTriggerImpl { + private GrocAdapter grocAdapter; + + GrocTrigger(GrocAdapter grocAdapter) { + this.grocAdapter = grocAdapter; + setStartTime(grocAdapter.getStartDate()); + } + + @Override + public Date getFireTimeAfter(Date afterTime) { + if (afterTime == null) { + afterTime = new Date(); + } + return grocAdapter.getFireTimeAfter(afterTime); + } + + @Override + public int computeNumTimesFiredBetween(Date start, Date end) { + return grocAdapter.computeNumTimesFiredBetween(start, end); + } + + @Override + public Date getFinalFireTime() { + return grocAdapter.getFinalFireTime(); + } + + @SuppressWarnings("unchecked") + @Override + public ScheduleBuilder getScheduleBuilder() { + return new GrocScheduleBuilder(grocAdapter); + } +} + diff --git a/mail/src/main/java/org/jboss/capedwarf/mail/CapedwarfInboundMailMDB.java b/mail/src/main/java/org/jboss/capedwarf/mail/CapedwarfInboundMailMDB.java index 3f382c82..d46503b7 100644 --- a/mail/src/main/java/org/jboss/capedwarf/mail/CapedwarfInboundMailMDB.java +++ b/mail/src/main/java/org/jboss/capedwarf/mail/CapedwarfInboundMailMDB.java @@ -124,9 +124,7 @@ private void deliverBounceNotification(final Message message) throws IOException mimeMultipart.updateHeaders(); Queue queue = QueueFactory.getQueue(QueueXml.INTERNAL); - queue.add( - withUrl(BOUNCE_URL) - .payload(toBytes(mimeMultipart), mimeMultipart.getContentType())); + queue.add(withUrl(BOUNCE_URL).payload(toBytes(mimeMultipart), mimeMultipart.getContentType())); } private MimeBodyPart createFormDataPart(String name, String content) throws MessagingException { @@ -142,9 +140,7 @@ private void deliverRegularMessage(Message message) throws MessagingException, I Address[] recipients = message.getRecipients(Message.RecipientType.TO); for (Address recipient : recipients) { if (isLocalRecipient(recipient)) { - queue.add( - withUrl(MAIL_URL_PREFIX + recipient) - .payload(toBytes(message), message.getContentType())); + queue.add(withUrl(MAIL_URL_PREFIX + recipient).payload(toBytes(message), message.getContentType())); } } } diff --git a/pom.xml b/pom.xml index b901b4a8..c07d64e1 100644 --- a/pom.xml +++ b/pom.xml @@ -26,6 +26,7 @@ channel cluster cluster-tests + cron datastore endpoints environment @@ -58,6 +59,7 @@ 1.0-SP4 1.9.1 + 1.9.1 15.0 3.2.1 @@ -91,6 +93,7 @@ 3.7.2 1.9.12 1.0.0.Final + 2.2.1 3.1 3.1.3-1 @@ -101,7 +104,7 @@ 3.0.1 4.11 - 1.1.1.Final + 1.1.4.Final 8.0.0.Final 3.2.0.Final 1.0.0.Beta7 @@ -352,6 +355,12 @@ ${project.version} + + org.jboss.capedwarf.blue + capedwarf-cron + ${project.version} + + org.jboss.capedwarf.blue capedwarf-datastore @@ -558,6 +567,12 @@ ${version.com.google.gae.api} + + com.google.appengine + appengine-tools-sdk + ${version.com.google.gae.tools} + + com.google.appengine appengine-api-labs @@ -836,6 +851,12 @@ ${version.org.apache.httpcomponents} + + org.quartz-scheduler + quartz + ${version.org.quartz} + + diff --git a/testsuite/src/test/java/org/jboss/test/capedwarf/testsuite/config/test/CapedwarfEnvironmentTest.java b/testsuite/src/test/java/org/jboss/test/capedwarf/testsuite/config/test/CapedwarfEnvironmentTest.java index a59b3562..b7cee27f 100644 --- a/testsuite/src/test/java/org/jboss/test/capedwarf/testsuite/config/test/CapedwarfEnvironmentTest.java +++ b/testsuite/src/test/java/org/jboss/test/capedwarf/testsuite/config/test/CapedwarfEnvironmentTest.java @@ -26,6 +26,7 @@ import org.jboss.capedwarf.shared.config.ApplicationConfiguration; import org.jboss.capedwarf.shared.config.BackendsXml; import org.jboss.capedwarf.shared.config.CapedwarfConfiguration; +import org.jboss.capedwarf.shared.config.CronXml; import org.jboss.capedwarf.shared.config.IndexesXml; import org.jboss.capedwarf.shared.config.QueueXml; import org.jboss.test.capedwarf.common.support.JBoss; @@ -54,7 +55,7 @@ public class CapedwarfEnvironmentTest { public void setUp() throws Exception { config = new CapedwarfConfiguration(); env = CapedwarfEnvironment.createThreadLocalInstance(); - env.setApplicationConfiguration(new ApplicationConfiguration(null, config, new QueueXml(), new BackendsXml(), new IndexesXml())); + env.setApplicationConfiguration(new ApplicationConfiguration(null, config, new QueueXml(), new BackendsXml(), new IndexesXml(), new CronXml())); } @After