Skip to content
This repository

AS7-5265 EJB timer - @Schedule and @Timer #317

Closed
wants to merge 1 commit into from

4 participants

Ondrej Zizka sgilda Pete Muir Vineet Reynolds
Ondrej Zizka

No description provided.

ejb-timer/README.md
... ...
@@ -0,0 +1,95 @@
  1
+wicket-war: Wicket Framework used in a WAR.
  2
+===========================================
  3
+Author: Ondrej Zizka <ozizka@redhat.com>
  4
+Level: Basic
3
Pete Muir Owner
pmuir added a note July 30, 2012

Should be "Beginner" :-)

Ondrej Zizka
OndraZizka added a note July 31, 2012

I will change this, as well as remove notions of Wicket (result of copy-paste)

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ejb-timer/README.md
((39 lines not shown))
  39
+        For Linux:   JBOSS_HOME/bin/standalone.sh
  40
+        For Windows: JBOSS_HOME\bin\standalone.bat
  41
+
  42
+
  43
+Build and Deploy the Quickstart
  44
+-------------------------
  45
+
  46
+_NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See [Build and Deploy the Quickstarts](../README.md#buildanddeploy) for complete instructions and additional options._
  47
+
  48
+1. Make sure you have started the JBoss Server as described above.
  49
+2. Open a command line and navigate to the root directory of this quickstart.
  50
+3. Type this command to build and deploy the archive:
  51
+
  52
+        mvn clean package jboss-as:deploy
  53
+
  54
+4. This will deploy `target/jboss-as-wicket-war.war` to the running instance of the server.
2
Pete Muir Owner
pmuir added a note July 30, 2012

Needs an update :-)

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ejb-timer/src/main/java/org/jboss/as/quickstarts/ejbTimer/TimeoutExample.java
((10 lines not shown))
  10
+
  11
+/**
  12
+ * Demonstrates how to use the EJB's @Timeout.
  13
+ * 
  14
+ * @author <a href="mailto:ozizka@redhat.com">Ondrej Zizka</a>
  15
+ */
  16
+@Singleton
  17
+@Startup
  18
+public class TimeoutExample {
  19
+
  20
+    @Resource
  21
+    private TimerService timerService;
  22
+    
  23
+    @Timeout
  24
+    public void scheduler(Timer timer) {
  25
+        System.out.println("SingletonTimer: Info="+timer.getInfo());
2
Pete Muir Owner
pmuir added a note July 30, 2012

Some more spaces might be nice here.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ejb-timer/src/main/webapp/WEB-INF/web.xml
((10 lines not shown))
  10
+    OF ANY KIND, either express or implied. See the License for the specific 
  11
+    language governing permissions and limitations under the License. -->
  12
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  13
+    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  14
+    version="2.5">
  15
+
  16
+    <display-name>JBoss AS Quickstart: Wicket WAR</display-name>
  17
+
  18
+    <!-- A message displayed on the page, externalized into web.xml -->
  19
+    <env-entry>
  20
+        <env-entry-name>welcomeMessage</env-entry-name>
  21
+        <env-entry-type>java.lang.String</env-entry-type>
  22
+        <env-entry-value>Welcome to the JBoss AS Quickstart showing the use of Wicket, packaged in an EAR</env-entry-value>
  23
+    </env-entry>
  24
+
  25
+</web-app>
3
Pete Muir Owner
pmuir added a note July 30, 2012

Do we need this file at all?

Ondrej Zizka
OndraZizka added a note July 31, 2012

Nope :) I originally intended to make it a web app, but keeping web out keeps it much clearer.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ejb-timer/src/main/webapp/WEB-INF/ejb-timer-quickstart-ds.xml
((17 lines not shown))
  17
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  18
+    xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_1.xsd">
  19
+    <!-- The datasource is bound into JNDI at this location. We reference 
  20
+        this in META-INF/persistence.xml -->
  21
+    <datasource jndi-name="java:jboss/datasources/EjbTimerQuickstartDS"
  22
+        pool-name="ejb-timer-quickstart" enabled="true"
  23
+        use-java-context="true">
  24
+        <connection-url>jdbc:h2:mem:ejb-timer-quickstart;DB_CLOSE_ON_EXIT=FALSE</connection-url>
  25
+        <driver>h2</driver>
  26
+        <security>
  27
+            <user-name>sa</user-name>
  28
+            <password>sa</password>
  29
+        </security>
  30
+    </datasource>
  31
+</datasources>
  32
+ 
4
Pete Muir Owner
pmuir added a note July 30, 2012

Probable we don't need a DS at all?

Ondrej Zizka
OndraZizka added a note July 31, 2012

Regarding DS - I thought it might be necessary for persistent timeouts. But that's probably only true for AS 5 and 6, right? AS 7 puts this to files?

Pete Muir Owner
pmuir added a note August 03, 2012

I think the app server will just use it's own persistent store for that, not one you define.

Removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ejb-timer/src/main/webapp/WEB-INF/beans.xml
((4 lines not shown))
  4
+    the copyright.txt in the distribution for a full listing of individual contributors. 
  5
+    Licensed under the Apache License, Version 2.0 (the "License"); you may not 
  6
+    use this file except in compliance with the License. You may obtain a copy 
  7
+    of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required 
  8
+    by applicable law or agreed to in writing, software distributed under the 
  9
+    License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 
  10
+    OF ANY KIND, either express or implied. See the License for the specific 
  11
+    language governing permissions and limitations under the License. -->
  12
+<!-- This file can be an empty text file (0 bytes) -->
  13
+<!-- We're declaring the schema to save you time if you do have to configure 
  14
+   this in the future -->
  15
+<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16
+   xsi:schemaLocation="
  17
+        http://java.sun.com/xml/ns/javaee 
  18
+        http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
  19
+</beans>
3
Pete Muir Owner
pmuir added a note July 30, 2012

Does this use CDI?

Ondrej Zizka
OndraZizka added a note July 31, 2012

I am so messy. Will fix.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sgilda
Collaborator
sgilda commented July 31, 2012

Following the instructions in the README, I get a deployment errror. This is in the server log:

14:25:11,069 INFO org.jboss.weld.deployer JBAS016005: Starting Services for CDI deployment: jboss-as-ejb-timer.war
14:25:11,093 INFO org.jboss.as.connector.subsystems.datasources JBAS010400: Bound data source [jboss/datasources/EjbTimerQuickstartDS]
14:25:11,228 INFO org.jboss.as.server JBAS015870: Deploy of deployment "jboss-as-ejb-timer.war" was rolled back with failure message {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"jboss-as-ejb-timer.war#primary\"jboss.naming.context.java.jboss.datasources.WicketQuickstartDSMissing[jboss.persistenceunit.\"jboss-as-ejb-timer.war#primary\"jboss.naming.context.java.jboss.datasources.WicketQuickstartDS]"]}
14:25:11,237 INFO org.jboss.as.connector.subsystems.datasources JBAS010409: Unbound data source [jboss/datasources/EjbTimerQuickstartDS]
14:25:11,251 INFO org.jboss.as.server.deployment JBAS015877: Stopped deployment jboss-as-ejb-timer.war in 24ms
14:25:11,253 INFO org.jboss.as.controller JBAS014774: Service status report
JBAS014775: New missing/unsatisfied dependencies:
service jboss.naming.context.java.jboss.datasources.WicketQuickstartDS (missing) dependents: [service jboss.persistenceunit."jboss-as-ejb-timer.war#primary

As Pete suggested, maybe the datasource isn't needed?

sgilda
Collaborator
sgilda commented July 31, 2012

I got it to work by doing the following:

  • I removed the resources/ directory and its contents as you don't need the persistence.xml file.
  • I removed the webapp/WEB-INF/ejb-timer-quickstart-ds.xml file.

Removing the web.xml file resulted in the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project jboss-as-ejb-timer: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]

I got around that by adding this plugin to the pom.xml build section:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<!-- Java EE 6 doesn't require web.xml, Maven needs to catch
up! -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>

Ondrej Zizka

I've reflected all comments and pushed the result.

sgilda
Collaborator

When I build and deploy this, I get BUILD FAILURE and this error in the server log:

10:33:47,348 INFO org.jboss.as.server JBAS015870: Deploy of deployment "jboss-as-ejb-timer.war" was rolled back with failure message {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"jboss-as-ejb-timer.war#primary\"jboss.naming.context.java.jboss.datasources.WicketQuickstartDSMissing[jboss.persistenceunit.\"jboss-as-ejb-timer.war#primary\"jboss.naming.context.java.jboss.datasources.WicketQuickstartDS]"]}
10:33:47,357 INFO org.jboss.as.server.deployment JBAS015877: Stopped deployment jboss-as-ejb-timer.war in 8ms
10:33:47,358 INFO org.jboss.as.controller JBAS014774: Service status report
JBAS014776: Newly corrected services:
service jboss.naming.context.java.jboss.datasources.WicketQuickstartDS (new available)

You removed the datasource, but I believe you also need to remove the persistence.xml file as well since it is not needed. It deploys fine when I remove it.

Also, would you mind squashing all the commits into one so it's easier to review? :-)

Pete Muir
Owner

@OndraZizka just a quick status check

Ondrej Zizka

Ah, right... I will fix this during this week, hopefully.

sgilda
Collaborator

20121217: Sent email reminder.

sgilda
Collaborator

2013-04-09: At the time we last talked, this only had a minor issue to remove the persistence.xml file and squash the commits.

I ran the QS Tools report and believe the only other changes required are the following:

  • Add the following metadata to the README.md file:

    Target Product: EAP
    Source: <https://github.com/jboss-jdf/jboss-as-quickstart/>
    
  • Make sure the licenses match the license template in the root of the quickstart directory.

sgilda
Collaborator

@OndraZizka : Just checking in to see how things are going with your quickstart. Please let me know when it's ready for review again.

sgilda
Collaborator
sgilda commented May 08, 2013

@OndraZizka : Just checking on the status of this quickstart. :-)

sgilda
Collaborator

@OndraZizka thinks this will be a quick fix and hopes to finish it up in the next week.

sgilda
Collaborator

Sent email to @OndraZizka to let him know we will be closing pull requests in a few days to reorganize the quickstarts, so this needs to be finished ASAP.

sgilda
Collaborator

Since I haven't had a response from Ondra, I will close this one for now. He can repen it at a later date.

sgilda sgilda closed this August 21, 2013
sgilda sgilda reopened this August 21, 2013
Ondrej Zizka

Now it should be okay to merge.

sgilda
Collaborator

Thanks Ondra. I'll check it out next!

sgilda
Collaborator

@OndraZizka : There 41 files changed in your 6 commits. The first commit even says
Java source 1.6 for some quickstarts, mostly DeltaSpike

I believe you should only have 4 files committed for this quickstart. Can you clean up the commits so that only the ejb-timer source is included?

Also, can you run the QS tools utility on your quickstart? It's reporting some violations. Some are due to changes since you started this quickstart. See step 8 here: https://github.com/jboss-jdf/jboss-as-quickstart/blob/master/CONTRIBUTING.md

I did test the quickstart and it compiles, deploys, and works fine.

ejb-timer/README.md
... ...
@@ -0,0 +1,98 @@
  1
+ejb-timer: EJB Timers example - @Schedule and @Timeout
  2
+===========================================
  3
+Author: Ondrej Zizka <ozizka@redhat.com>
  4
+Level: Beginner
  5
+Technologies: EJB 3.1 Timer
  6
+Summary: Demonstrates how to use EJB 3.1 Timer (@Schedule and @Timeout) with the JBoss AS server.
  7
+
2
sgilda Collaborator
sgilda added a note August 23, 2013

Please add the following:

Target Product: EAP
Source: https://github.com/jboss-jdf/jboss-as-quickstart/

Can't get rid of Content for metadata [Source: = https://github.com/jboss-jdf/jboss-as-quickstart/] should follow the [<(http|https)://\w.*>] pattern

The other warnings are gone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ejb-timer/pom.xml
((28 lines not shown))
  28
+    </licenses>
  29
+
  30
+    <description>
  31
+        A sample JAVA EE 6 project demonstrating how to use EJB 3.1 timer (@Schedule and @Timeout).
  32
+    </description>
  33
+
  34
+
  35
+    <properties>
  36
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  37
+        <!-- Define the version of JBoss' Java EE 6 APIs we want to import. -->
  38
+        <jboss.spec.version>3.0.0.Final</jboss.spec.version>
  39
+        <!-- Alternatively, comment out the above line, and un-comment the 
  40
+            line below to use version 3.0.0.Final-redhat-1 which is a release certified 
  41
+            to work with JBoss EAP 6. It requires you have access to the JBoss EAP 6 
  42
+            maven repository. -->
  43
+        <!-- <jboss.spec.version>3.0.0.Final-redhat-1</jboss.spec.version> -->
2
sgilda Collaborator
sgilda added a note August 23, 2013

These property names were changed and the versions have been updated. This section should now be:

    <version.jboss.spec.javaee.6.0>3.0.2.Final</version.jboss.spec.javaee.6.0>
    <!-- Alternatively, comment out the above line, and un-comment the 
        line below to use version 3.0.2.Final-redhat-3 which is a release certified 
        to work with JBoss EAP 6. It requires you have access to the JBoss EAP 6 
        maven repository. -->
    <!-- <version.jboss.spec.javaee.6.0>3.0.2.Final-redhat-3</version.jboss.spec.javaee.6.0> -->

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ejb-timer/pom.xml
((44 lines not shown))
  44
+    </properties>
  45
+
  46
+    <dependencyManagement>
  47
+        <dependencies>
  48
+            <!-- JBoss distributes a complete set of Java EE 6 APIs including 
  49
+                a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or 
  50
+                a collection) of artifacts. We use this here so that we always get the correct 
  51
+                versions of artifacts. Here we use the jboss-javaee-6.0-with-tools stack 
  52
+                (you can read this as the JBoss stack of the Java EE 6 APIs, with some extras 
  53
+                tools for your project, such as Arquillian for testing) and the jboss-javaee-6.0-with-hibernate 
  54
+                stack you can read this as the JBoss stack of the Java EE 6 APIs, with extras 
  55
+                from the Hibernate family of projects) -->
  56
+            <dependency>
  57
+                <groupId>org.jboss.spec</groupId>
  58
+                <artifactId>jboss-javaee-6.0</artifactId>
  59
+                <version>${jboss.spec.version}</version>
2
sgilda Collaborator
sgilda added a note August 23, 2013
    <version>${version.jboss.spec.javaee.6.0}</version>

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ejb-timer/pom.xml
... ...
@@ -0,0 +1,135 @@
  1
+<?xml version="1.0"?>
  2
+<!-- JBoss, Home of Professional Open Source Copyright 2012, Red Hat, Inc. 
  3
+    and/or its affiliates, and individual contributors by the @authors tag. See 
  4
+    the copyright.txt in the distribution for a full listing of individual contributors. 
  5
+    Licensed under the Apache License, Version 2.0 (the "License"); you may not 
  6
+    use this file except in compliance with the License. You may obtain a copy 
  7
+    of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required 
  8
+    by applicable law or agreed to in writing, software distributed under the 
  9
+    License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 
  10
+    OF ANY KIND, either express or implied. See the License for the specific 
  11
+    language governing permissions and limitations under the License. -->
2
sgilda Collaborator
sgilda added a note August 23, 2013

This license text is out of date. You can copy it from one of he other quickstart POM files. It should be:

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ejb-timer/pom.xml
((23 lines not shown))
  23
+        <license>
  24
+            <name>Apache License, Version 2.0</name>
  25
+            <distribution>repo</distribution>
  26
+            <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
  27
+        </license>
  28
+    </licenses>
  29
+
  30
+    <description>
  31
+        A sample JAVA EE 6 project demonstrating how to use EJB 3.1 timer (@Schedule and @Timeout).
  32
+    </description>
  33
+
  34
+
  35
+    <properties>
  36
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  37
+        <!-- Define the version of JBoss' Java EE 6 APIs we want to import. -->
  38
+        <jboss.spec.version>3.0.0.Final</jboss.spec.version>
2
sgilda Collaborator
sgilda added a note August 23, 2013

Before this line, define the maven plugin property here:

    <version.jboss.maven.plugin>7.3.Final</version.jboss.maven.plugin>

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ejb-timer/pom.xml
((90 lines not shown))
  90
+        </dependency>
  91
+
  92
+    </dependencies>
  93
+
  94
+
  95
+    <build>
  96
+        <!-- Set the name of the war, used as the context root when the app 
  97
+            is deployed. -->
  98
+        <finalName>${project.artifactId}</finalName>
  99
+
  100
+        <plugins>
  101
+            <!-- JBoss AS plugin to deploy the war. -->
  102
+            <plugin>
  103
+                <groupId>org.jboss.as.plugins</groupId>
  104
+                <artifactId>jboss-as-maven-plugin</artifactId>
  105
+                <version>7.4.Final</version>
2
sgilda Collaborator
sgilda added a note August 23, 2013

We don't use hard-coded versions. Use the property:

    <version>${version.jboss.maven.plugin}</version>

Just for this one or any plugin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sgilda sgilda commented on the diff August 23, 2013
ejb-timer/src/main/java/org/jboss/as/quickstarts/ejbTimer/ScheduleExample.java
... ...
@@ -0,0 +1,21 @@
  1
+
2
sgilda Collaborator
sgilda added a note August 23, 2013

This file is missing the license header.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sgilda sgilda commented on the diff August 23, 2013
ejb-timer/src/main/java/org/jboss/as/quickstarts/ejbTimer/TimeoutExample.java
... ...
@@ -0,0 +1,44 @@
  1
+
2
sgilda Collaborator
sgilda added a note August 23, 2013

This file is missing the license header.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Ondrej Zizka

Regarding "Java source 1.6 for some quickstarts, mostly DeltaSpike", that's because those were unbuildable. They need the changes, otherwise fail to compile as Java 1.3 source format. But I'll remove these changes and offer as separate PR.

Ondrej Zizka

Squashed to one commit. Removed DeltaSpike stuff.

sgilda
Collaborator

@OndraZizka : This looks much better. I'll review it tomorrow.

sgilda
Collaborator

@OndraZizka - This looks good. One minor issue is still reported by the QS tools utility. The URL for the 'Source:' metadata tag should be linkable: Source: <https://github.com/jboss-jdf/jboss-as-quickstart/>. I can fix what when I merge it.

@VineetReynolds will do a code review on this tomorrow and if he gives the word, I will merge.

ejb-timer/src/main/java/org/jboss/as/quickstarts/ejbTimer/TimeoutExample.java
((31 lines not shown))
  31
+@Singleton
  32
+@Startup
  33
+public class TimeoutExample {
  34
+
  35
+    @Resource
  36
+    private TimerService timerService;
  37
+    
  38
+    @Timeout
  39
+    public void scheduler(Timer timer) {
  40
+        System.out.println("EJB Timer: Info=" + timer.getInfo());
  41
+    }
  42
+    
  43
+    @PostConstruct
  44
+    public void initialize( InvocationContext ctx ) {
  45
+        ScheduleExpression se = new ScheduleExpression();
  46
+        // Set schedule to every 10 seconds.
3

The 'second' expression for the ScheduleExpressions is '0/3' which implies 'every 3 seconds starting at second 0' i.e. 0,3,6,9,...57,60 seconds. So this comment should not read 'every 10 seconds'. Maybe you could incorporate what I wrote in the previous sentence.

Otherwise this looks good.

Right. I changed to more frequent and forgot to change the comment. Changing.

// Set schedule to every 3 seconds (starting at second 0 of every minute).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sgilda
Collaborator

Made minor adjustments to fix new qstools issues and merged.

sgilda sgilda closed this August 28, 2013
Ondrej Zizka

I see, so the <...> brackets are meant literally... I thought it's JUnit's style string comparison. Get it.

sgilda
Collaborator

@OndraZizka : Are you referring to the change I made to the Source metadata URL?

Ondrej Zizka

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 2 authors.

Aug 28, 2013
@Schedule example, @Timeout example. 779d091
This page is out of date. Refresh to see the latest.
100  ejb-timer/README.md
Source Rendered
... ...
@@ -0,0 +1,100 @@
  1
+ejb-timer: EJB Timers example - @Schedule and @Timeout
  2
+===========================================
  3
+Author: Ondrej Zizka <ozizka@redhat.com>
  4
+Level: Beginner
  5
+Technologies: EJB 3.1 Timer
  6
+Summary: Demonstrates how to use EJB 3.1 Timer (@Schedule and @Timeout) with the JBoss AS server.
  7
+Target Product: EAP
  8
+Source: https://github.com/jboss-jdf/jboss-as-quickstart/
  9
+
  10
+What is it?
  11
+-----------
  12
+
  13
+Demonstrates how to use EJB 3.1 Timer (@Schedule and @Timeout) with the JBoss AS server.
  14
+
  15
+
  16
+Features used:
  17
+
  18
+ * Usage of `@Schedule`
  19
+ * Usage of `@Timeout`
  20
+ 
  21
+
  22
+System requirements
  23
+-------------------
  24
+
  25
+All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven 3.0 or better.
  26
+
  27
+The application this project produces is designed to be run on JBoss Enterprise Application Platform 6 or JBoss AS 7. 
  28
+
  29
+ 
  30
+Configure Maven
  31
+---------------
  32
+
  33
+If you have not yet done so, you must [Configure Maven](../README.md#mavenconfiguration) before testing the quickstarts.
  34
+
  35
+
  36
+Start JBoss Enterprise Application Platform 6 or JBoss AS 7 with the Web Profile
  37
+-------------------------
  38
+
  39
+1. Open a command line and navigate to the root of the JBoss server directory.
  40
+2. The following shows the command line to start the server with the web profile:
  41
+
  42
+        For Linux:   JBOSS_HOME/bin/standalone.sh
  43
+        For Windows: JBOSS_HOME\bin\standalone.bat
  44
+
  45
+
  46
+Build and Deploy the Quickstart
  47
+-------------------------
  48
+
  49
+_NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See [Build and Deploy the Quickstarts](../README.md#buildanddeploy) for complete instructions and additional options._
  50
+
  51
+1. Make sure you have started the JBoss Application Server as described above.
  52
+2. Open a command line and navigate to the root directory of this quickstart.
  53
+3. Type this command to build and deploy the archive:
  54
+
  55
+        mvn clean package jboss-as:deploy
  56
+
  57
+This will deploy `target/jboss-as-ejb-timer.war` to the running instance of the server.  
  58
+To undeploy, use
  59
+
  60
+        mvn jboss-as:undeploy
  61
+
  62
+
  63
+Access the application
  64
+----------------------
  65
+
  66
+This application only prints messages to stdout.
  67
+To see it working, check the server log. You should see similar output:
  68
+
  69
+    ...
  70
+    18:33:36,004 INFO  [stdout] (EJB default - 7) Hi from the EJB timer example!
  71
+    18:33:38,003 INFO  [stdout] (EJB default - 8) Hi from the EJB timer example!
  72
+    18:33:40,002 INFO  [stdout] (EJB default - 9) Hi from the EJB timer example!
  73
+    18:33:42,002 INFO  [stdout] (EJB default - 10) Hi from the EJB timer example!
  74
+    18:33:44,003 INFO  [stdout] (EJB default - 1) Hi from the EJB timer example!
  75
+    18:33:46,004 INFO  [stdout] (EJB default - 2) Hi from the EJB timer example!
  76
+    18:33:48,003 INFO  [stdout] (EJB default - 3) Hi from the EJB timer example!
  77
+    ...
  78
+
  79
+The parentheses contain name of thread executing the particular invocation.
  80
+There are pre-created threads in thread pool, and they are rotated. Hence the changing number.
  81
+
  82
+
  83
+Undeploy the Archive
  84
+--------------------
  85
+
  86
+1. Make sure you have started the JBoss Server as described above.
  87
+2. Open a command line and navigate to the root directory of this quickstart.
  88
+3. When you are finished testing, type this command to undeploy the archive:
  89
+
  90
+        mvn jboss-as:undeploy
  91
+
  92
+
  93
+Debug the Application
  94
+------------------------------------
  95
+
  96
+If you want to debug the source code or look at the Javadocs of any library in the project, 
  97
+run either of the following commands to pull them into your local repository. The IDE should then detect them.
  98
+
  99
+        mvn dependency:sources
  100
+        mvn dependency:resolve -Dclassifier=javadoc
141  ejb-timer/pom.xml
... ...
@@ -0,0 +1,141 @@
  1
+<?xml version="1.0"?>
  2
+<!--
  3
+    JBoss, Home of Professional Open Source
  4
+    Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
  5
+    contributors by the @authors tag. See the copyright.txt in the
  6
+    distribution for a full listing of individual contributors.
  7
+
  8
+    Licensed under the Apache License, Version 2.0 (the "License");
  9
+    you may not use this file except in compliance with the License.
  10
+    You may obtain a copy of the License at
  11
+    http://www.apache.org/licenses/LICENSE-2.0
  12
+    Unless required by applicable law or agreed to in writing, software
  13
+    distributed under the License is distributed on an "AS IS" BASIS,
  14
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15
+    See the License for the specific language governing permissions and
  16
+    limitations under the License.
  17
+-->
  18
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  19
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  20
+    <modelVersion>4.0.0</modelVersion>
  21
+
  22
+    <groupId>org.jboss.as.quickstarts</groupId>
  23
+    <artifactId>jboss-as-ejb-timer</artifactId>
  24
+    <version>7.1.2-SNAPSHOT</version>
  25
+    <packaging>war</packaging>
  26
+
  27
+    <name>JBoss AS Quickstarts: EJB Timer</name>
  28
+    <licenses>
  29
+        <license>
  30
+            <name>Apache License, Version 2.0</name>
  31
+            <distribution>repo</distribution>
  32
+            <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
  33
+        </license>
  34
+    </licenses>
  35
+
  36
+    <description>
  37
+        A sample JAVA EE 6 project demonstrating how to use EJB 3.1 timer (@Schedule and @Timeout).
  38
+    </description>
  39
+
  40
+
  41
+    <properties>
  42
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  43
+        <version.jboss.maven.plugin>7.4.Final</version.jboss.maven.plugin>
  44
+        <!-- Define the version of JBoss' Java EE 6 APIs we want to import. -->
  45
+        <version.jboss.spec.javaee.6.0>3.0.2.Final</version.jboss.spec.javaee.6.0>
  46
+        <!-- Alternatively, comment out the above line, and un-comment the line below
  47
+            to use version 3.0.2.Final-redhat-3 which is a release certified to work 
  48
+            with JBoss EAP 6. It requires you have access to the JBoss EAP 6 maven repository. -->
  49
+        <!-- <version.jboss.spec.javaee.6.0>3.0.2.Final-redhat-3</version.jboss.spec.javaee.6.0> -->
  50
+    </properties>
  51
+
  52
+    <dependencyManagement>
  53
+        <dependencies>
  54
+            <!-- JBoss distributes a complete set of Java EE 6 APIs including 
  55
+                a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or 
  56
+                a collection) of artifacts. We use this here so that we always get the correct 
  57
+                versions of artifacts. Here we use the jboss-javaee-6.0-with-tools stack 
  58
+                (you can read this as the JBoss stack of the Java EE 6 APIs, with some extras 
  59
+                tools for your project, such as Arquillian for testing) and the jboss-javaee-6.0-with-hibernate 
  60
+                stack you can read this as the JBoss stack of the Java EE 6 APIs, with extras 
  61
+                from the Hibernate family of projects) -->
  62
+            <dependency>
  63
+                <groupId>org.jboss.spec</groupId>
  64
+                <artifactId>jboss-javaee-6.0</artifactId>
  65
+                <version>${version.jboss.spec.javaee.6.0}</version>
  66
+                <type>pom</type>
  67
+                <scope>import</scope>
  68
+            </dependency>
  69
+        </dependencies>
  70
+    </dependencyManagement>
  71
+
  72
+    <!-- Dependencies. -->
  73
+
  74
+    <dependencies>
  75
+        <!-- "provided" scope used for API's included in JBoss AS 7. -->
  76
+
  77
+        <!-- Import the CDI API. -->
  78
+        <dependency>
  79
+            <groupId>javax.enterprise</groupId>
  80
+            <artifactId>cdi-api</artifactId>
  81
+            <scope>provided</scope>
  82
+        </dependency>
  83
+
  84
+        <!-- Import the Common Annotations API (JSR-250). -->
  85
+        <dependency>
  86
+            <groupId>org.jboss.spec.javax.annotation</groupId>
  87
+            <artifactId>jboss-annotations-api_1.1_spec</artifactId>
  88
+            <scope>provided</scope>
  89
+        </dependency>
  90
+
  91
+        <!-- Import the EJB API. -->
  92
+        <dependency>
  93
+            <groupId>org.jboss.spec.javax.ejb</groupId>
  94
+            <artifactId>jboss-ejb-api_3.1_spec</artifactId>
  95
+            <scope>provided</scope>
  96
+        </dependency>
  97
+
  98
+    </dependencies>
  99
+
  100
+
  101
+    <build>
  102
+        <!-- Set the name of the war, used as the context root when the app 
  103
+            is deployed. -->
  104
+        <finalName>${project.artifactId}</finalName>
  105
+
  106
+        <plugins>
  107
+            <!-- JBoss AS plugin to deploy the war. -->
  108
+            <plugin>
  109
+                <groupId>org.jboss.as.plugins</groupId>
  110
+                <artifactId>jboss-as-maven-plugin</artifactId>
  111
+                <version>${version.jboss.maven.plugin}</version>
  112
+                <configuration>
  113
+                    <fileNames>
  114
+                        <fileName>target/${build.finalName}.war</fileName>
  115
+                    </fileNames>
  116
+                </configuration>
  117
+            </plugin>
  118
+            
  119
+            <plugin>
  120
+                <artifactId>maven-war-plugin</artifactId>
  121
+                <version>2.4</version>
  122
+                <configuration>
  123
+                    <!-- Prevent Maven complaining about missing web.xml - not needed in Java EE 6. -->
  124
+                    <failOnMissingWebXml>false</failOnMissingWebXml>
  125
+                </configuration>
  126
+            </plugin>
  127
+
  128
+            <!-- Enforce Java 1.6 compatibility and activate annotation processors. -->
  129
+            <plugin>
  130
+                <artifactId>maven-compiler-plugin</artifactId>
  131
+                <version>3.1</version>
  132
+                <configuration>
  133
+                    <source>1.6</source>
  134
+                    <target>1.6</target>
  135
+                </configuration>
  136
+            </plugin>
  137
+        </plugins>
  138
+    </build>
  139
+
  140
+</project>
  141
+
36  ejb-timer/src/main/java/org/jboss/as/quickstarts/ejbTimer/ScheduleExample.java
... ...
@@ -0,0 +1,36 @@
  1
+/*
  2
+ * JBoss, Home of Professional Open Source
  3
+ * Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
  4
+ * contributors by the @authors tag. See the copyright.txt in the
  5
+ * distribution for a full listing of individual contributors.
  6
+ *
  7
+ * Licensed under the Apache License, Version 2.0 (the "License");
  8
+ * you may not use this file except in compliance with the License.
  9
+ * You may obtain a copy of the License at
  10
+ * http://www.apache.org/licenses/LICENSE-2.0
  11
+ * Unless required by applicable law or agreed to in writing, software
  12
+ * distributed under the License is distributed on an "AS IS" BASIS,
  13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14
+ * See the License for the specific language governing permissions and
  15
+ * limitations under the License.
  16
+ */
  17
+package org.jboss.as.quickstarts.ejbTimer;
  18
+
  19
+import javax.ejb.Schedule;
  20
+import javax.ejb.Singleton;
  21
+
  22
+
  23
+/**
  24
+ * Demonstrates how to use the EJB's @Schedule.
  25
+ * 
  26
+ * @author <a href="mailto:ozizka@redhat.com">Ondrej Zizka</a>
  27
+ */
  28
+@Singleton
  29
+public class ScheduleExample {
  30
+  
  31
+    @Schedule(second="*/2", minute="*",hour="*", persistent=false)
  32
+    public void doWork(){
  33
+        System.out.println( "Hi from the EJB timer example!" );
  34
+    }
  35
+    
  36
+}
59  ejb-timer/src/main/java/org/jboss/as/quickstarts/ejbTimer/TimeoutExample.java
... ...
@@ -0,0 +1,59 @@
  1
+/*
  2
+ * JBoss, Home of Professional Open Source
  3
+ * Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
  4
+ * contributors by the @authors tag. See the copyright.txt in the
  5
+ * distribution for a full listing of individual contributors.
  6
+ *
  7
+ * Licensed under the Apache License, Version 2.0 (the "License");
  8
+ * you may not use this file except in compliance with the License.
  9
+ * You may obtain a copy of the License at
  10
+ * http://www.apache.org/licenses/LICENSE-2.0
  11
+ * Unless required by applicable law or agreed to in writing, software
  12
+ * distributed under the License is distributed on an "AS IS" BASIS,
  13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14
+ * See the License for the specific language governing permissions and
  15
+ * limitations under the License.
  16
+ */
  17
+package org.jboss.as.quickstarts.ejbTimer;
  18
+
  19
+import javax.annotation.PostConstruct;
  20
+import javax.annotation.PreDestroy;
  21
+import javax.annotation.Resource;
  22
+import javax.ejb.*;
  23
+import javax.interceptor.InvocationContext;
  24
+
  25
+
  26
+/**
  27
+ * Demonstrates how to use the EJB's @Timeout.
  28
+ * 
  29
+ * @author <a href="mailto:ozizka@redhat.com">Ondrej Zizka</a>
  30
+ */
  31
+@Singleton
  32
+@Startup
  33
+public class TimeoutExample {
  34
+
  35
+    @Resource
  36
+    private TimerService timerService;
  37
+    
  38
+    @Timeout
  39
+    public void scheduler(Timer timer) {
  40
+        System.out.println("EJB Timer: Info=" + timer.getInfo());
  41
+    }
  42
+    
  43
+    @PostConstruct
  44
+    public void initialize( InvocationContext ctx ) {
  45
+        ScheduleExpression se = new ScheduleExpression();
  46
+        // Set schedule to every 3 seconds (starting at second 0 of every minute).
  47
+        se.hour("*").minute("*").second("0/3");
  48
+        timerService.createCalendarTimer( se, new TimerConfig("Hi from TimeoutExample!", false) );
  49
+    }
  50
+    
  51
+    @PreDestroy
  52
+    public void stop() {    
  53
+        System.out.println("Stop all existing timers");
  54
+        for (Timer timer : timerService.getTimers()) {
  55
+            System.out.println("Stopping timer: " + timer.getInfo());
  56
+            timer.cancel();
  57
+        }
  58
+    }
  59
+}
1  pom.xml
@@ -203,6 +203,7 @@
203 203
                 <module>ejb-security-plus</module>
204 204
                 <module>ejb-security-interceptors</module>
205 205
                 <module>ejb-throws-exception</module>
  206
+                <module>ejb-timer</module>
206 207
                 <module>ejb-multi-server</module>
207 208
                 <module>greeter</module>
208 209
                 <module>greeter-spring</module>
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.