Skip to content

Commit

Permalink
Initial Cron support.
Browse files Browse the repository at this point in the history
  • Loading branch information
alesj committed Mar 31, 2014
1 parent a2f7c07 commit 3ee53a7
Show file tree
Hide file tree
Showing 17 changed files with 644 additions and 42 deletions.
11 changes: 8 additions & 3 deletions appidentity/pom.xml
Expand Up @@ -26,24 +26,29 @@
<artifactId>capedwarf-aspects</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.capedwarf.blue</groupId>
<artifactId>capedwarf-blobstore</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.capedwarf.blue</groupId>
<artifactId>capedwarf-common</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.capedwarf.blue</groupId>
<artifactId>capedwarf-environment</artifactId>
<artifactId>capedwarf-cron</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.capedwarf.blue</groupId>
<artifactId>capedwarf-log</artifactId>
<artifactId>capedwarf-environment</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.capedwarf.blue</groupId>
<artifactId>capedwarf-blobstore</artifactId>
<artifactId>capedwarf-log</artifactId>
</dependency>

<dependency>
Expand Down
Expand Up @@ -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 <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
*/
public class CDIListener implements ServletContextListener {

private static Logger log = Logger.getLogger(CDIListener.class.getName());

/**
* The impl detail
*/
Expand All @@ -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) {
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Expand Up @@ -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.
Expand All @@ -39,33 +35,11 @@
* @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
* @author <a href="mailto:mluksa@redhat.com">Marko Luksa</a>
*/
class DistributableWrapper<V> implements DistributedCallable<Object, Object, V>, Serializable {
class DistributableWrapper<V> extends WireWrapper<V> implements DistributedCallable<Object, Object, V> {
private static final long serialVersionUID = 1L;

private final String appId;
private final String module;
private final CapedwarfEnvironment env;
private final Callable<V> callable;

DistributableWrapper(Callable<V> 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")
Expand Down
@@ -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 <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
* @author <a href="mailto:mluksa@redhat.com">Marko Luksa</a>
*/
public class WireWrapper<V> implements Callable<V>, Serializable {
private static final long serialVersionUID = 1L;

private final String appId;
private final String module;
private final CapedwarfEnvironment env;
protected final Callable<V> callable;

public WireWrapper(Callable<V> 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();
}
}
}
103 changes: 103 additions & 0 deletions cron/pom.xml
@@ -0,0 +1,103 @@
<!--
~ 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<!-- Parent -->
<parent>
<groupId>org.jboss.capedwarf.blue</groupId>
<artifactId>capedwarf-build</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>capedwarf-cron</artifactId>
<packaging>jar</packaging>
<name>CapeDwarf Cron</name>
<url>http://www.jboss.org/capedwarf</url>
<description>CapeDwarf Cron</description>

<dependencies>

<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.capedwarf.shared</groupId>
<artifactId>capedwarf-shared</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.capedwarf.blue</groupId>
<artifactId>capedwarf-aspects</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.capedwarf.blue</groupId>
<artifactId>capedwarf-common</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.capedwarf.blue</groupId>
<artifactId>capedwarf-environment</artifactId>
</dependency>

<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
</dependency>

<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-tools-sdk</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.capedwarf.blue</groupId>
<artifactId>capedwarf-common</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>

</dependencies>

</project>

0 comments on commit 3ee53a7

Please sign in to comment.