Skip to content

Commit

Permalink
Add QueuJ as a scheduling and asynchronous provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
daveoxley committed Jun 27, 2011
1 parent 330781b commit f1c06b4
Show file tree
Hide file tree
Showing 17 changed files with 839 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pom.xml
Expand Up @@ -27,8 +27,10 @@
<module>spi</module>
<module>tck</module>
<module>providers/scheduling/quartz</module>
<module>providers/scheduling/queuj</module>
<module>providers/asynchronous/threads</module>
<module>providers/asynchronous/quartz</module>
<module>providers/asynchronous/queuj</module>
</modules>

<properties>
Expand Down Expand Up @@ -176,6 +178,11 @@
<artifactId>seam-cron-asynchronous-quartz</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.seam.cron</groupId>
<artifactId>seam-cron-asynchronous-queuj</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.seam.cron</groupId>
<artifactId>seam-cron-asynchronous-threads</artifactId>
Expand All @@ -186,6 +193,11 @@
<artifactId>seam-cron-scheduling-quartz</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.seam.cron</groupId>
<artifactId>seam-cron-scheduling-queuj</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.seam.cron</groupId>
<artifactId>seam-cron-reference-guide</artifactId>
Expand Down Expand Up @@ -246,6 +258,26 @@
<scope>runtime</scope>
</dependency>

<!-- Dependencies for providers/queuj sub-project -->
<!-- Runtime Dependencies -->
<dependency>
<groupId>com.workplacesystems.queuj</groupId>
<artifactId>queuj</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5.4</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<scope>runtime</scope>
</dependency>

<!-- Dependencies for examples -->
<dependency>
<groupId>jfree</groupId>
Expand Down
76 changes: 76 additions & 0 deletions providers/asynchronous/queuj/pom.xml
@@ -0,0 +1,76 @@

<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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.seam.cron</groupId>
<artifactId>seam-cron-asynchronous-queuj</artifactId>
<packaging>jar</packaging>
<version>3.0.0-SNAPSHOT</version>
<name>Seam Cron Asynchronous Provider: QueuJ</name>
<description>The Queuj provider of asynchronous method invocation for Seam Cron.
"Schedules" an @Asynchronous method to be executed a very short time into the future,
and returns immediately.
</description>
<url>http://seamframework.org/Seam3/CronModule</url>

<parent>
<artifactId>seam-cron-parent</artifactId>
<groupId>org.jboss.seam.cron</groupId>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../../../</relativePath>
</parent>

<dependencies>
<!-- Provided dependencies -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Compile-time dependencies -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>seam-cron-spi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.workplacesystems.queuj</groupId>
<artifactId>queuj</artifactId>
<scope>compile</scope>
</dependency>

<!-- Runtime Dependencies -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>seam-cron-tck</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.el</groupId>
<artifactId>jboss-el-api_2.2_spec</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
14 changes: 14 additions & 0 deletions providers/asynchronous/queuj/src/etc/header.txt
@@ -0,0 +1,14 @@
JBoss, Home of Professional Open Source
Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual
contributors by the @authors tag. See the copyright.txt in the
distribution for a full listing of individual contributors.

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.
@@ -0,0 +1,36 @@
/**
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* 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 org.jboss.seam.cron.asynchronous.queuj;

import com.workplacesystems.queuj.process.java.JavaProcessRunner;
import org.jboss.seam.cron.impl.asynchronous.exception.AsynchronousMethodInvocationException;
import org.jboss.seam.cron.spi.asynchronous.support.FutureInvokerSupport;

/**
*
* @author Dave Oxley
*/
public class AsyncMethodInvocationJob extends JavaProcessRunner {

public void execute(final FutureInvokerSupport resultCallable) {
try {
resultCallable.executeInvocationContext();
} catch (Exception ex) {
throw new AsynchronousMethodInvocationException("Error invoking method inside a QueuJ Job", ex);
}
}
}
@@ -0,0 +1,89 @@
/**
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* 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 org.jboss.seam.cron.asynchronous.queuj;

import com.workplacesystems.queuj.QueueFactory;
import com.workplacesystems.queuj.process.QueujFactory;
import com.workplacesystems.queuj.process.java.JavaProcessBuilder;
import java.util.Locale;
import java.util.UUID;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Inject;

import org.jboss.logging.Logger;
import org.jboss.seam.cron.impl.asynchronous.exception.AsynchronousMethodInvocationException;
import org.jboss.seam.cron.impl.scheduling.exception.CronProviderDestructionException;
import org.jboss.seam.cron.impl.scheduling.exception.CronProviderInitialisationException;
import org.jboss.seam.cron.spi.CronProviderLifecycle;
import org.jboss.seam.cron.spi.asynchronous.CronAsynchronousProvider;
import org.jboss.seam.cron.spi.asynchronous.Invoker;
import org.jboss.seam.cron.spi.asynchronous.support.FutureInvokerSupport;

/**
* Simple asynchronous method invocation which schedules @Asynchronous methods
* to be executed at some point in the very near future using the QueuJ scheduler.
*
* @author Dave Oxley
*/
public class QueuJAsynchronousProvider implements CronProviderLifecycle, CronAsynchronousProvider {

private static final Logger log = Logger.getLogger(QueuJAsynchronousProvider.class);
@Inject
BeanManager beanManager;

/**
* Initialises the scheduler.
*
*/
public void initProvider() throws CronProviderInitialisationException {
try {
QueujFactory.getProcessServer((String)null);
} catch (Exception ex) {
throw new CronProviderInitialisationException("Error initializing QueuJ for asynchronous method invocation", ex);
}
}

/**
* Shutdown the scheduler on application close.
*/
public void destroyProvider() throws CronProviderDestructionException {
}

public void executeWithoutReturn(final Invoker inkover) {
executeMethodAsScheduledJob(inkover);
}

public Future executeAndReturnFuture(final Invoker invoker) {
FutureTask asyncResult = new FutureTask(executeMethodAsScheduledJob(invoker));
new Thread(asyncResult).start();
return asyncResult;
}

private FutureInvokerSupport executeMethodAsScheduledJob(final Invoker invoker) throws AsynchronousMethodInvocationException {
JavaProcessBuilder jpb = QueueFactory.DEFAULT_QUEUE.newProcessBuilder(Locale.getDefault());
final String jobName = UUID.randomUUID().toString();
jpb.setProcessName(jobName);
final FutureInvokerSupport drs = new FutureInvokerSupport(invoker);
jpb.setProcessDetails(new AsyncMethodInvocationJob(), "execute", new Class[] { FutureInvokerSupport.class }, new Object[] { drs });
jpb.setProcessPersistence(false);
jpb.newProcess();
return drs;
}
}
24 changes: 24 additions & 0 deletions providers/asynchronous/queuj/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,24 @@
<!--
JBoss, Home of Professional Open Source
Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual
contributors by the @authors tag. See the copyright.txt in the
distribution for a full listing of individual contributors.
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.
-->
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
<interceptors>
<class>org.jboss.seam.cron.spi.asynchronous.AsynchronousInterceptor</class>
</interceptors>
</beans>
@@ -0,0 +1,35 @@
/**
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* 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 org.jboss.seam.cron.asynchronous.test;

import org.jboss.arquillian.api.Deployment;
import org.jboss.seam.cron.asynchronous.queuj.QueuJAsynchronousProvider;
import org.jboss.seam.cron.test.asynchronous.tck.SeamCronAsynchronousTCKTest;
import org.jboss.shrinkwrap.api.spec.JavaArchive;

/**
*
* @author Dave Oxley
*/
public class QueuJAsynchronousTCKTest extends SeamCronAsynchronousTCKTest {

@Deployment
public static JavaArchive deployment() {
return SeamCronAsynchronousTCKTest.createAsynchronousTckTestArchive()
.addPackages(true, QueuJAsynchronousProvider.class.getPackage());
}
}

0 comments on commit f1c06b4

Please sign in to comment.