Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add QueuJ as a scheduling and asynchronous provider.
- Loading branch information
Showing
17 changed files
with
839 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
36 changes: 36 additions & 0 deletions
36
.../queuj/src/main/java/org/jboss/seam/cron/asynchronous/queuj/AsyncMethodInvocationJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...queuj/src/main/java/org/jboss/seam/cron/asynchronous/queuj/QueuJAsynchronousProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
24
providers/asynchronous/queuj/src/main/resources/META-INF/beans.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
35 changes: 35 additions & 0 deletions
35
...s/queuj/src/test/java/org/jboss/seam/cron/asynchronous/test/QueuJAsynchronousTCKTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
Oops, something went wrong.