deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject [2/2] git commit: DELTASPIKE-657 scheduler playground example
Date Fri, 04 Jul 2014 10:15:25 GMT
DELTASPIKE-657 scheduler playground example


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/5aaff2bf
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/5aaff2bf
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/5aaff2bf

Branch: refs/heads/master
Commit: 5aaff2bfd7f435cf93c4119dd1aad463db9c22ed
Parents: 31d0266
Author: gpetracek <gpetracek@apache.org>
Authored: Fri Jul 4 11:51:35 2014 +0200
Committer: gpetracek <gpetracek@apache.org>
Committed: Fri Jul 4 12:09:42 2014 +0200

----------------------------------------------------------------------
 deltaspike/examples/pom.xml                     |   7 +-
 .../examples/scheduler-playground/pom.xml       | 131 +++++++++++++++++++
 .../example/scheduler/GlobalResultHolder.java   |  50 +++++++
 .../scheduler/RequestScopedNumberProvider.java  |  32 +++++
 .../scheduler/SimpleSchedulerExample.java       |  58 ++++++++
 .../example/scheduler/SimpleSchedulerJob1.java  |  43 ++++++
 .../example/scheduler/SimpleSchedulerJob2.java  |  43 ++++++
 .../src/main/resources/META-INF/beans.xml       |  23 ++++
 8 files changed, 384 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5aaff2bf/deltaspike/examples/pom.xml
----------------------------------------------------------------------
diff --git a/deltaspike/examples/pom.xml b/deltaspike/examples/pom.xml
index dc3ca9f..cf5ebfe 100644
--- a/deltaspike/examples/pom.xml
+++ b/deltaspike/examples/pom.xml
@@ -35,9 +35,10 @@
 
     <modules>
         <module>jse-examples</module>
-	<module>jsf-examples</module>
-    <module>jsf-playground</module>
-  </modules>
+        <module>jsf-examples</module>
+        <module>jsf-playground</module>
+        <module>scheduler-playground</module>
+    </modules>
 
     <properties>
         <deploy.skip>false</deploy.skip>

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5aaff2bf/deltaspike/examples/scheduler-playground/pom.xml
----------------------------------------------------------------------
diff --git a/deltaspike/examples/scheduler-playground/pom.xml b/deltaspike/examples/scheduler-playground/pom.xml
new file mode 100644
index 0000000..0df902a
--- /dev/null
+++ b/deltaspike/examples/scheduler-playground/pom.xml
@@ -0,0 +1,131 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you 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.
+-->
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.deltaspike.examples</groupId>
+        <artifactId>examples-project</artifactId>
+        <version>1.0.1-SNAPSHOT</version>
+    </parent>
+
+    <groupId>org.apache.deltaspike.examples</groupId>
+    <artifactId>deltaspike-scheduler-example</artifactId>
+
+    <name>Apache DeltaSpike Java-SE Scheduler Examples</name>
+
+    <packaging>jar</packaging>
+
+    <properties>
+        <deploy.skip>true</deploy.skip>
+    </properties>
+
+    <profiles>
+        <profile>
+            <id>OWB</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+            <dependencies>
+                <dependency>
+                    <groupId>org.apache.openwebbeans</groupId>
+                    <artifactId>openwebbeans-impl</artifactId>
+                    <scope>runtime</scope>
+                </dependency>
+
+                <dependency>
+                    <groupId>org.apache.openwebbeans</groupId>
+                    <artifactId>openwebbeans-spi</artifactId>
+                    <scope>compile</scope>
+                </dependency>
+
+                <dependency>
+                    <groupId>org.javassist</groupId>
+                    <artifactId>javassist</artifactId>
+                    <version>3.17.1-GA</version>
+                </dependency>
+
+                <dependency>
+                    <groupId>org.apache.deltaspike.cdictrl</groupId>
+                    <artifactId>deltaspike-cdictrl-owb</artifactId>
+                    <scope>runtime</scope>
+                </dependency>
+            </dependencies>
+        </profile>
+        <profile>
+            <id>Weld</id>
+            <dependencies>
+                <dependency>
+                    <groupId>org.apache.deltaspike.cdictrl</groupId>
+                    <artifactId>deltaspike-cdictrl-weld</artifactId>
+                    <scope>runtime</scope>
+                </dependency>
+
+                <dependency>
+                    <groupId>org.jboss.weld.se</groupId>
+                    <artifactId>weld-se</artifactId>
+                    <version>${weld.version}</version>
+                    <scope>runtime</scope>
+                </dependency>
+            </dependencies>
+        </profile>
+    </profiles>
+
+    <dependencies>
+
+        <!-- DeltaSpike modules -->
+        <dependency>
+            <groupId>org.apache.deltaspike.core</groupId>
+            <artifactId>deltaspike-core-api</artifactId>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.deltaspike.core</groupId>
+            <artifactId>deltaspike-core-impl</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.deltaspike.modules</groupId>
+            <artifactId>deltaspike-scheduler-module-api</artifactId>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.deltaspike.modules</groupId>
+            <artifactId>deltaspike-scheduler-module-impl</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.deltaspike.cdictrl</groupId>
+            <artifactId>deltaspike-cdictrl-api</artifactId>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.quartz-scheduler</groupId>
+            <artifactId>quartz</artifactId>
+            <version>2.2.1</version>
+        </dependency>
+    </dependencies>
+</project>
+

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5aaff2bf/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/GlobalResultHolder.java
----------------------------------------------------------------------
diff --git a/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/GlobalResultHolder.java
b/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/GlobalResultHolder.java
new file mode 100644
index 0000000..56fa83a
--- /dev/null
+++ b/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/GlobalResultHolder.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.example.scheduler;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import java.util.concurrent.atomic.AtomicInteger;
+
+@ApplicationScoped
+public class GlobalResultHolder
+{
+    private AtomicInteger count = new AtomicInteger();
+
+    @Inject
+    private RequestScopedNumberProvider numberProvider;
+
+
+    @PostConstruct
+    protected void init()
+    {
+        count.set(0);
+    }
+
+    public void increase()
+    {
+        count.addAndGet(numberProvider.getNumber());
+    }
+
+    public int getCount()
+    {
+        return count.get();
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5aaff2bf/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/RequestScopedNumberProvider.java
----------------------------------------------------------------------
diff --git a/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/RequestScopedNumberProvider.java
b/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/RequestScopedNumberProvider.java
new file mode 100644
index 0000000..f09cb20
--- /dev/null
+++ b/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/RequestScopedNumberProvider.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.example.scheduler;
+
+import javax.enterprise.context.RequestScoped;
+import java.math.BigDecimal;
+
+@RequestScoped
+public class RequestScopedNumberProvider
+{
+    public int getNumber()
+    {
+        int result = new BigDecimal(Math.random() % 10).intValue();
+        return result != 0 ? result : 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5aaff2bf/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/SimpleSchedulerExample.java
----------------------------------------------------------------------
diff --git a/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/SimpleSchedulerExample.java
b/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/SimpleSchedulerExample.java
new file mode 100644
index 0000000..94c68ad
--- /dev/null
+++ b/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/SimpleSchedulerExample.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.example.scheduler;
+
+import org.apache.deltaspike.cdise.api.CdiContainer;
+import org.apache.deltaspike.cdise.api.CdiContainerLoader;
+import org.apache.deltaspike.cdise.api.ContextControl;
+import org.apache.deltaspike.core.api.provider.BeanProvider;
+
+import javax.enterprise.context.ApplicationScoped;
+import java.util.logging.Logger;
+
+public class SimpleSchedulerExample
+{
+    private static final Logger LOG = Logger.getLogger(SimpleSchedulerExample.class.getName());
+
+    private SimpleSchedulerExample()
+    {
+    }
+
+    public static void main(String[] args) throws InterruptedException
+    {
+        CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
+        cdiContainer.boot();
+
+        ContextControl contextControl = cdiContainer.getContextControl();
+        contextControl.startContext(ApplicationScoped.class);
+
+        GlobalResultHolder globalResultHolder =
+            BeanProvider.getContextualReference(GlobalResultHolder.class);
+
+        while (globalResultHolder.getCount() < 100)
+        {
+            Thread.sleep(500);
+            LOG.info("current count: " + globalResultHolder.getCount());
+        }
+        LOG.info("completed!");
+
+        contextControl.stopContext(ApplicationScoped.class);
+        cdiContainer.shutdown();
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5aaff2bf/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/SimpleSchedulerJob1.java
----------------------------------------------------------------------
diff --git a/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/SimpleSchedulerJob1.java
b/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/SimpleSchedulerJob1.java
new file mode 100644
index 0000000..734591b
--- /dev/null
+++ b/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/SimpleSchedulerJob1.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.example.scheduler;
+
+import org.apache.deltaspike.scheduler.api.Scheduled;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
+import javax.inject.Inject;
+import java.util.logging.Logger;
+
+@Scheduled(cronExpression = "0/2 * * * * ?")
+public class SimpleSchedulerJob1 implements Job
+{
+    private static final Logger LOG = Logger.getLogger(SimpleSchedulerJob1.class.getName());
+
+    @Inject
+    private GlobalResultHolder globalResultHolder;
+
+    @Override
+    public void execute(JobExecutionContext context) throws JobExecutionException
+    {
+        LOG.info("#increase called by " + getClass().getName());
+        globalResultHolder.increase();
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5aaff2bf/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/SimpleSchedulerJob2.java
----------------------------------------------------------------------
diff --git a/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/SimpleSchedulerJob2.java
b/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/SimpleSchedulerJob2.java
new file mode 100644
index 0000000..fc011c5
--- /dev/null
+++ b/deltaspike/examples/scheduler-playground/src/main/java/org/apache/deltaspike/example/scheduler/SimpleSchedulerJob2.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.example.scheduler;
+
+import org.apache.deltaspike.scheduler.api.Scheduled;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
+import javax.inject.Inject;
+import java.util.logging.Logger;
+
+@Scheduled(cronExpression = "0/1 * * * * ?")
+public class SimpleSchedulerJob2 implements Job
+{
+    private static final Logger LOG = Logger.getLogger(SimpleSchedulerJob2.class.getName());
+
+    @Inject
+    private GlobalResultHolder globalResultHolder;
+
+    @Override
+    public void execute(JobExecutionContext context) throws JobExecutionException
+    {
+        LOG.info("#increase called by " + getClass().getName());
+        globalResultHolder.increase();
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5aaff2bf/deltaspike/examples/scheduler-playground/src/main/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/deltaspike/examples/scheduler-playground/src/main/resources/META-INF/beans.xml
b/deltaspike/examples/scheduler-playground/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..4070730
--- /dev/null
+++ b/deltaspike/examples/scheduler-playground/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you 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">
+</beans>


Mime
View raw message